@graphql-codegen/cli 2.10.1-alpha-7e47fba48.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/bin.js CHANGED
@@ -5,8 +5,8 @@ const cli_js_1 = require("./cli.js");
5
5
  const cli_error_js_1 = require("./utils/cli-error.js");
6
6
  const [, , cmd] = process.argv;
7
7
  (0, cli_js_1.runCli)(cmd)
8
- .then(() => {
9
- process.exit(0);
8
+ .then(returnCode => {
9
+ process.exit(returnCode);
10
10
  })
11
11
  .catch(error => {
12
12
  (0, cli_error_js_1.cliError)(error);
package/cjs/cli.js CHANGED
@@ -32,14 +32,22 @@ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
32
32
  async function runCli(cmd) {
33
33
  await ensureGraphQlPackage();
34
34
  if (cmd === 'init') {
35
- return (0, index_js_1.init)();
35
+ (0, index_js_1.init)();
36
+ return 0;
36
37
  }
37
38
  const context = await (0, config_js_1.createContext)();
38
39
  try {
39
- return await (0, generate_and_save_js_1.generate)(context);
40
+ await (0, generate_and_save_js_1.generate)(context);
41
+ if (context.checkMode && context.checkModeStaleFiles.length > 0) {
42
+ // eslint-disable-next-line no-console
43
+ console.log(`The following stale files were detected:\n${context.checkModeStaleFiles.map(file => ` - ${file}\n`)}`);
44
+ return 1;
45
+ }
46
+ return 0;
40
47
  }
41
48
  catch (error) {
42
49
  await (0, hooks_js_1.lifecycleHooks)(context.getConfig().hooks).onError(error.toString());
50
+ return 1;
43
51
  }
44
52
  }
45
53
  exports.runCli = runCli;
package/cjs/config.js CHANGED
@@ -223,12 +223,17 @@ function updateContextWithCliFlags(context, cliFlags) {
223
223
  if (cliFlags.profile === true) {
224
224
  context.useProfiler();
225
225
  }
226
+ if (cliFlags.check === true) {
227
+ context.enableCheckMode();
228
+ }
226
229
  context.updateConfig(config);
227
230
  }
228
231
  exports.updateContextWithCliFlags = updateContextWithCliFlags;
229
232
  class CodegenContext {
230
233
  constructor({ config, graphqlConfig, filepath, }) {
234
+ this._checkMode = false;
231
235
  this._pluginContext = {};
236
+ this.checkModeStaleFiles = [];
232
237
  this._config = config;
233
238
  this._graphqlConfig = graphqlConfig;
234
239
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -264,6 +269,12 @@ class CodegenContext {
264
269
  ...config,
265
270
  };
266
271
  }
272
+ enableCheckMode() {
273
+ this._checkMode = true;
274
+ }
275
+ get checkMode() {
276
+ return this._checkMode;
277
+ }
267
278
  useProfiler() {
268
279
  this.profiler = (0, plugin_helpers_1.createProfiler)();
269
280
  const now = new Date(); // 2011-10-05T14:48:00.000Z
@@ -62,6 +62,10 @@ async function generate(input, saveToFile = true) {
62
62
  (0, debugging_js_1.debugLog)(`Skipping file (${result.filename}) writing due to indentical hash...`);
63
63
  return;
64
64
  }
65
+ else if (context.checkMode) {
66
+ context.checkModeStaleFiles.push(result.filename);
67
+ return; // skip updating file in dry mode
68
+ }
65
69
  if (content.length === 0) {
66
70
  return;
67
71
  }
package/esm/bin.js CHANGED
@@ -3,8 +3,8 @@ import { runCli } from './cli.js';
3
3
  import { cliError } from './utils/cli-error.js';
4
4
  const [, , cmd] = process.argv;
5
5
  runCli(cmd)
6
- .then(() => {
7
- process.exit(0);
6
+ .then(returnCode => {
7
+ process.exit(returnCode);
8
8
  })
9
9
  .catch(error => {
10
10
  cliError(error);
package/esm/cli.js CHANGED
@@ -6,14 +6,22 @@ import { DetailedError } from '@graphql-codegen/plugin-helpers';
6
6
  export async function runCli(cmd) {
7
7
  await ensureGraphQlPackage();
8
8
  if (cmd === 'init') {
9
- return init();
9
+ init();
10
+ return 0;
10
11
  }
11
12
  const context = await createContext();
12
13
  try {
13
- return await generate(context);
14
+ await generate(context);
15
+ if (context.checkMode && context.checkModeStaleFiles.length > 0) {
16
+ // eslint-disable-next-line no-console
17
+ console.log(`The following stale files were detected:\n${context.checkModeStaleFiles.map(file => ` - ${file}\n`)}`);
18
+ return 1;
19
+ }
20
+ return 0;
14
21
  }
15
22
  catch (error) {
16
23
  await lifecycleHooks(context.getConfig().hooks).onError(error.toString());
24
+ return 1;
17
25
  }
18
26
  }
19
27
  export async function ensureGraphQlPackage() {
package/esm/config.js CHANGED
@@ -213,11 +213,16 @@ export function updateContextWithCliFlags(context, cliFlags) {
213
213
  if (cliFlags.profile === true) {
214
214
  context.useProfiler();
215
215
  }
216
+ if (cliFlags.check === true) {
217
+ context.enableCheckMode();
218
+ }
216
219
  context.updateConfig(config);
217
220
  }
218
221
  export class CodegenContext {
219
222
  constructor({ config, graphqlConfig, filepath, }) {
223
+ this._checkMode = false;
220
224
  this._pluginContext = {};
225
+ this.checkModeStaleFiles = [];
221
226
  this._config = config;
222
227
  this._graphqlConfig = graphqlConfig;
223
228
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -253,6 +258,12 @@ export class CodegenContext {
253
258
  ...config,
254
259
  };
255
260
  }
261
+ enableCheckMode() {
262
+ this._checkMode = true;
263
+ }
264
+ get checkMode() {
265
+ return this._checkMode;
266
+ }
256
267
  useProfiler() {
257
268
  this.profiler = createProfiler();
258
269
  const now = new Date(); // 2011-10-05T14:48:00.000Z
@@ -58,6 +58,10 @@ export async function generate(input, saveToFile = true) {
58
58
  debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
59
59
  return;
60
60
  }
61
+ else if (context.checkMode) {
62
+ context.checkModeStaleFiles.push(result.filename);
63
+ return; // skip updating file in dry mode
64
+ }
61
65
  if (content.length === 0) {
62
66
  return;
63
67
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.10.1-alpha-7e47fba48.0",
3
+ "version": "2.11.0",
4
4
  "peerDependencies": {
5
5
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@graphql-codegen/core": "2.6.1-alpha-7e47fba48.0",
9
- "@graphql-codegen/plugin-helpers": "^2.6.1-alpha-7e47fba48.0",
8
+ "@graphql-codegen/core": "2.6.0",
9
+ "@graphql-codegen/plugin-helpers": "^2.6.1",
10
10
  "@graphql-tools/apollo-engine-loader": "^7.3.1",
11
11
  "@graphql-tools/code-file-loader": "^7.3.0",
12
12
  "@graphql-tools/git-loader": "^7.2.0",
package/typings/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare function runCli(cmd: string): Promise<any>;
1
+ export declare function runCli(cmd: string): Promise<number>;
2
2
  export declare function ensureGraphQlPackage(): Promise<void>;
@@ -10,6 +10,7 @@ export declare type YamlCliFlags = {
10
10
  silent: boolean;
11
11
  errorsOnly: boolean;
12
12
  profile: boolean;
13
+ check?: boolean;
13
14
  verbose?: boolean;
14
15
  debug?: boolean;
15
16
  ignoreNoDocuments?: boolean;
@@ -109,11 +110,13 @@ export declare class CodegenContext {
109
110
  private _graphqlConfig?;
110
111
  private config;
111
112
  private _project?;
113
+ private _checkMode;
112
114
  private _pluginContext;
113
115
  cwd: string;
114
116
  filepath: string;
115
117
  profiler: Profiler;
116
118
  profilerOutput?: string;
119
+ checkModeStaleFiles: any[];
117
120
  constructor({ config, graphqlConfig, filepath, }: {
118
121
  config?: Types.Config;
119
122
  graphqlConfig?: GraphQLConfig;
@@ -122,6 +125,8 @@ export declare class CodegenContext {
122
125
  useProject(name?: string): void;
123
126
  getConfig<T>(extraConfig?: T): T & Types.Config;
124
127
  updateConfig(config: Partial<Types.Config>): void;
128
+ enableCheckMode(): void;
129
+ get checkMode(): boolean;
125
130
  useProfiler(): void;
126
131
  getPluginContext(): {
127
132
  [key: string]: any;