File tree Expand file tree Collapse file tree
packages/graphql-codegen-cli/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7979 run : |
8080 pnpm run dev-test:generate:${{matrix.method}}
8181 git diff --exit-code -- dev-test/
82- - name : Test CLI version ${{matrix.method}}
83- run : pnpm run dev-test:test-cli-version:${{matrix.method}}
8482
8583 examples-tests :
8684 name : Examples - Normal
Original file line number Diff line number Diff line change @@ -21,6 +21,3 @@ website/public/_redirects
2121
2222** /cypress /screenshots
2323** /cypress /videos
24-
25- # Generated file for `graphql-codegen --version` to work. See `pnpm prepare-cli-version`.
26- packages /graphql-codegen-cli /src /_version.ts
Original file line number Diff line number Diff line change 77 "generate" : " pnpm generate:esm" ,
88 "generate:cjs" : " node ../../packages/graphql-codegen-cli/dist/cjs/bin.js --require dotenv/config --config codegen.ts dotenv_config_path=.env" ,
99 "generate:esm" : " node ../../packages/graphql-codegen-cli/dist/esm/bin.js --require dotenv/config --config codegen.ts dotenv_config_path=.env" ,
10- "test-cli-version:cjs" : " node ../../packages/graphql-codegen-cli/dist/cjs/bin.js --version" ,
11- "test-cli-version:esm" : " node ../../packages/graphql-codegen-cli/dist/esm/bin.js --version" ,
1210 "watch" : " pnpm watch:esm" ,
1311 "watch:cjs" : " pnpm generate:cjs --watch" ,
1412 "watch:esm" : " pnpm generate:esm --watch"
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ export default [
8383 'dev-test/**' ,
8484 'website/**' ,
8585 'examples/**' ,
86+ 'scripts/**' ,
8687 '**/tests/test-files/**' ,
8788 '**/tests/test-documents/**' ,
8889 '**/react-app-env.d.ts' ,
Original file line number Diff line number Diff line change 77 "node" : " >= 16.0.0"
88 },
99 "scripts" : {
10- "prebuild" : " rimraf dist/ .bob/ tsconfig.tsbuildinfo && pnpm prepare-cli-version " ,
10+ "prebuild" : " rimraf dist/ .bob/ tsconfig.tsbuildinfo" ,
1111 "build" : " bob build" ,
1212 "postbuild" : " pnpm fix-bins" ,
1313 "clean" : " rimraf node_modules/" ,
3030 "prettier" : " prettier --cache --write --list-different ." ,
3131 "prettier:check" : " prettier --cache --check ." ,
3232 "rebuild" : " bob build --incremental" ,
33- "prerelease" : " pnpm build" ,
33+ "prerelease" : " pnpm prepare-cli-version && pnpm build" ,
3434 "release" : " changeset publish" ,
3535 "test" : " vitest" ,
3636 "types:check" : " tsc --noEmit"
Original file line number Diff line number Diff line change @@ -17,14 +17,14 @@ import {
1717 Types ,
1818} from '@graphql-codegen/plugin-helpers' ;
1919import type { UnnormalizedTypeDefPointer } from '@graphql-tools/load' ;
20- import { version } from './_version.js' ; // Run `pnpm prepare-cli-version` to initialize this value
2120import { findAndLoadGraphQLConfig } from './graphql-config.js' ;
2221import {
2322 defaultDocumentsLoadOptions ,
2423 defaultSchemaLoadOptions ,
2524 loadDocuments ,
2625 loadSchema ,
2726} from './load.js' ;
27+ import { version } from './version.js' ;
2828
2929const { lstat } = promises ;
3030
Original file line number Diff line number Diff line change 1+ export const version = '__VERSION__' ;
Original file line number Diff line number Diff line change 11import * as fs from 'fs' ;
2- import packageJson from '../packages/graphql-codegen-cli/package.json' with { type : 'json' } ;
32
43/**
54 * This script extracts the `@graphql-codegen/cli` version ahead of build and publish time,
@@ -16,8 +15,21 @@ import packageJson from '../packages/graphql-codegen-cli/package.json' with { ty
1615 * 5. Use `nodenext` instead of `esnext` for `module` and `moduleResolution`. Maybe a big change?
1716 * 6. Ship ESM-only. This is a big change.
1817 */
18+
19+ const packageJsonFile = '../packages/graphql-codegen-cli/package.json' ;
20+ const versionFile = '../packages/graphql-codegen-cli/src/version.ts' ;
21+
22+ const packageJson = JSON . parse ( fs . readFileSync ( new URL ( packageJsonFile , import . meta. url ) , 'utf8' ) ) ;
23+ const versionFileContent = fs . readFileSync ( new URL ( versionFile , import . meta. url ) , 'utf8' ) ;
24+
1925fs . writeFileSync (
20- './packages/graphql-codegen-cli/src/_version .ts' ,
21- `export const version = ' ${ packageJson . version } ';` ,
26+ './packages/graphql-codegen-cli/src/version .ts' ,
27+ versionFileContent . replace ( '__VERSION__' , packageJson . version || 'unknown' ) ,
2228 'utf8' ,
2329) ;
30+
31+ const updatedVersionContent = fs . readFileSync ( new URL ( versionFile , import . meta. url ) , 'utf8' ) ;
32+
33+ console . log ( '***' ) ;
34+ console . log ( `Updated version.ts content:\n"${ updatedVersionContent } "` ) ;
35+ console . log ( '***' ) ;
You can’t perform that action at this time.
0 commit comments