Skip to content

Commit

Permalink
Merge pull request #926 from CruGlobal/commit-gql-generated-files
Browse files Browse the repository at this point in the history
[no-Jira] Run `yarn gql:w` alongside the Next.js dev server
  • Loading branch information
canac authored May 2, 2024
2 parents dde4508 + fd3b016 commit e75367d
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ node_modules
.now
public
dist
*.generated.ts

# Storybook cache
/node_modules/.cache
/storybook-static
/storybook-static
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18.13.0
- name: 📦 Install Dependencies
- name: 🔍 Check Yarn Cache
run: yarn install --immutable --immutable-cache --check-cache

onesky-upload:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,3 @@ node_modules

# Storybook
build-storybook.log

# GraphQL
graphql-digest.txt
8 changes: 0 additions & 8 deletions .husky/post-checkout

This file was deleted.

95 changes: 95 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,3 @@ To learn more about Next.js, take a look at the following resources:
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Troubleshooting

If you run into issues with the Typescript linter saying that `types.generated` cannot be found, try running this command to clear out stale generated files:

```bash
find . -type f -name "*.generated.ts" -delete && yarn gql
```
7 changes: 1 addition & 6 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ generates:
- ${API_URL:https://api.stage.mpdx.org/graphql}
- ./pages/api/Schema/**/*.graphql
plugins:
- add:
content: '/* eslint-disable */'
- typescript
config:
scalars:
Expand All @@ -20,8 +18,6 @@ generates:
presetConfig:
baseTypesPath: src/graphql/types.generated.ts
plugins:
- add:
content: '/* eslint-disable */'
- typescript-operations
- typescript-react-apollo
config:
Expand All @@ -43,8 +39,6 @@ generates:
- ${API_URL:https://api.stage.mpdx.org/graphql}
- ./pages/api/Schema/**/*.graphql
plugins:
- add:
content: '/* eslint-disable */'
- typescript
- typescript-resolvers
config:
Expand All @@ -60,3 +54,4 @@ generates:
hooks:
afterAllFileWrite:
- prettier --write
- node deleteStaleFiles.mjs
23 changes: 23 additions & 0 deletions deleteStaleFiles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { execSync } from 'node:child_process';
import { unlinkSync } from 'node:fs';
import { relative } from 'node:path';

const normalize = (filename) => relative(process.cwd(), filename);

// This script receives the list of generated files, each in a separate argument.
// Some of them are relative to the project root, and some of them are absolute.
// Skip the first argument (node) and the second argument (the script filename)
// and convert to a newline-separated list of paths relative to the project root.
const filesToKeep = new Set(process.argv.slice(2).map(normalize));

const allFiles = execSync('find . -type f -name "*.generated.ts"')
.toString()
.trim()
.split('\n')
.map(normalize);

allFiles.forEach((filename) => {
if (!filesToKeep.has(filename)) {
unlinkSync(filename);
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "next dev",
"start": "concurrently 'next dev' 'yarn gql:w' --kill-others",
"build": "next build",
"build:analyze": "ANALYZE=true yarn build",
"build:amplify": "AMPLIFY_NEXTJS_EXPERIMENTAL_TRACE=true next build",
Expand Down Expand Up @@ -129,6 +129,7 @@
"babel-loader": "^8.2.2",
"babel-preset-react-app": "^10.0.0",
"chromatic": "^6.9.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"css-mediaquery": "^0.1.2",
"dnd-core": "^16.0.1",
Expand Down
Loading

0 comments on commit e75367d

Please sign in to comment.