@graphql-codegen/cli 2.6.0-alpha-a52c122aa.0 → 2.6.1-alpha-74513a63e.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/bin.js +27 -22
- package/index.js +27 -22
- package/index.mjs +30 -25
- package/package.json +3 -3
- package/utils/file-system.d.ts +3 -3
package/bin.js
CHANGED
|
@@ -54,6 +54,7 @@ const module$1 = require('module');
|
|
|
54
54
|
const fs = require('fs');
|
|
55
55
|
const fs__default = _interopDefault(fs);
|
|
56
56
|
const crypto = require('crypto');
|
|
57
|
+
const os = require('os');
|
|
57
58
|
const Listr = _interopDefault(require('listr'));
|
|
58
59
|
const isGlob = _interopDefault(require('is-glob'));
|
|
59
60
|
const debounce = _interopDefault(require('debounce'));
|
|
@@ -798,13 +799,14 @@ function hashContent(content) {
|
|
|
798
799
|
return crypto.createHash('sha256').update(content).digest('hex');
|
|
799
800
|
}
|
|
800
801
|
function hashSchema(schema) {
|
|
801
|
-
return hashContent(
|
|
802
|
-
assumeValid: true,
|
|
803
|
-
}));
|
|
802
|
+
return hashContent(graphql.print(pluginHelpers.getCachedDocumentNodeFromSchema(schema)));
|
|
804
803
|
}
|
|
805
804
|
function addHashToSchema(schemaPromise) {
|
|
806
805
|
return schemaPromise.then(schema => {
|
|
807
806
|
// It's consumed later on. The general purpose is to use it for caching.
|
|
807
|
+
if (!schema.extensions) {
|
|
808
|
+
schema.extensions = {};
|
|
809
|
+
}
|
|
808
810
|
schema.extensions['hash'] = hashSchema(schema);
|
|
809
811
|
return schema;
|
|
810
812
|
});
|
|
@@ -1098,7 +1100,6 @@ async function executeCodegen(input) {
|
|
|
1098
1100
|
pluginMap,
|
|
1099
1101
|
pluginContext,
|
|
1100
1102
|
profiler: context.profiler,
|
|
1101
|
-
cache,
|
|
1102
1103
|
}), `Build Generates Section: ${filename}`);
|
|
1103
1104
|
}
|
|
1104
1105
|
else {
|
|
@@ -1113,12 +1114,14 @@ async function executeCodegen(input) {
|
|
|
1113
1114
|
pluginMap,
|
|
1114
1115
|
pluginContext,
|
|
1115
1116
|
profiler: context.profiler,
|
|
1116
|
-
cache,
|
|
1117
1117
|
},
|
|
1118
1118
|
];
|
|
1119
1119
|
}
|
|
1120
1120
|
const process = async (outputArgs) => {
|
|
1121
|
-
const output = await core.codegen(
|
|
1121
|
+
const output = await core.codegen({
|
|
1122
|
+
...outputArgs,
|
|
1123
|
+
cache,
|
|
1124
|
+
});
|
|
1122
1125
|
result.push({
|
|
1123
1126
|
filename: outputArgs.filename,
|
|
1124
1127
|
content: output,
|
|
@@ -1137,8 +1140,7 @@ async function executeCodegen(input) {
|
|
|
1137
1140
|
}), {
|
|
1138
1141
|
// it doesn't stop when one of tasks failed, to finish at least some of outputs
|
|
1139
1142
|
exitOnError: false,
|
|
1140
|
-
|
|
1141
|
-
concurrent: 4,
|
|
1143
|
+
concurrent: os.cpus().length,
|
|
1142
1144
|
});
|
|
1143
1145
|
},
|
|
1144
1146
|
});
|
|
@@ -1285,15 +1287,16 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1285
1287
|
});
|
|
1286
1288
|
};
|
|
1287
1289
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
|
|
1291
|
+
function writeFile(filepath, content) {
|
|
1292
|
+
return fsWriteFile(filepath, content);
|
|
1290
1293
|
}
|
|
1291
|
-
function
|
|
1292
|
-
return
|
|
1294
|
+
function readFile(filepath) {
|
|
1295
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1293
1296
|
}
|
|
1294
|
-
function fileExists(filePath) {
|
|
1297
|
+
async function fileExists(filePath) {
|
|
1295
1298
|
try {
|
|
1296
|
-
return
|
|
1299
|
+
return (await fsStat(filePath)).isFile();
|
|
1297
1300
|
}
|
|
1298
1301
|
catch (err) {
|
|
1299
1302
|
return false;
|
|
@@ -1315,7 +1318,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1315
1318
|
const staleFilenames = previouslyGeneratedFilenames.filter(f => !filenames.includes(f));
|
|
1316
1319
|
staleFilenames.forEach(filename => {
|
|
1317
1320
|
if (shouldOverwrite(config, filename)) {
|
|
1318
|
-
unlinkFile(filename, err => {
|
|
1321
|
+
return unlinkFile(filename, err => {
|
|
1319
1322
|
const prettyFilename = filename.replace(`${input.cwd || process.cwd()}/`, '');
|
|
1320
1323
|
if (err) {
|
|
1321
1324
|
debugLog(`Cannot remove stale file: ${prettyFilename}\n${err}`);
|
|
@@ -1336,9 +1339,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1336
1339
|
if (config.watch) {
|
|
1337
1340
|
removeStaleFiles(config, generationResult);
|
|
1338
1341
|
}
|
|
1339
|
-
await context.profiler.run(
|
|
1342
|
+
await context.profiler.run(async () => {
|
|
1343
|
+
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1344
|
+
}, 'Lifecycle: beforeAllFileWrite');
|
|
1340
1345
|
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1341
|
-
const exists = fileExists(result.filename);
|
|
1346
|
+
const exists = await fileExists(result.filename);
|
|
1342
1347
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1343
1348
|
return;
|
|
1344
1349
|
}
|
|
@@ -1346,10 +1351,10 @@ async function generate(input, saveToFile = true) {
|
|
|
1346
1351
|
const currentHash = hash(content);
|
|
1347
1352
|
let previousHash = recentOutputHash.get(result.filename);
|
|
1348
1353
|
if (!previousHash && exists) {
|
|
1349
|
-
previousHash = hash(
|
|
1354
|
+
previousHash = hash(await readFile(result.filename));
|
|
1350
1355
|
}
|
|
1351
1356
|
if (previousHash && currentHash === previousHash) {
|
|
1352
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1357
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1353
1358
|
return;
|
|
1354
1359
|
}
|
|
1355
1360
|
if (content.length === 0) {
|
|
@@ -1359,11 +1364,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1359
1364
|
const basedir = path.dirname(result.filename);
|
|
1360
1365
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1361
1366
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1362
|
-
mkdirp
|
|
1367
|
+
await mkdirp(basedir);
|
|
1363
1368
|
const absolutePath = path.isAbsolute(result.filename)
|
|
1364
1369
|
? result.filename
|
|
1365
1370
|
: path.join(input.cwd || process.cwd(), result.filename);
|
|
1366
|
-
|
|
1371
|
+
await writeFile(absolutePath, result.content);
|
|
1367
1372
|
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1368
1373
|
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1369
1374
|
})), 'Write files');
|
|
@@ -1378,7 +1383,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1378
1383
|
await context.profiler.run(() => writeOutput(outputFiles), 'writeOutput');
|
|
1379
1384
|
await context.profiler.run(() => lifecycleHooks(config.hooks).beforeDone(), 'Lifecycle: beforeDone');
|
|
1380
1385
|
if (context.profilerOutput) {
|
|
1381
|
-
|
|
1386
|
+
await writeFile(path.join(context.cwd, context.profilerOutput), JSON.stringify(context.profiler.collect()));
|
|
1382
1387
|
}
|
|
1383
1388
|
return outputFiles;
|
|
1384
1389
|
}
|
package/index.js
CHANGED
|
@@ -54,6 +54,7 @@ const module$1 = require('module');
|
|
|
54
54
|
const fs = require('fs');
|
|
55
55
|
const fs__default = _interopDefault(fs);
|
|
56
56
|
const crypto = require('crypto');
|
|
57
|
+
const os = require('os');
|
|
57
58
|
const Listr = _interopDefault(require('listr'));
|
|
58
59
|
const child_process = require('child_process');
|
|
59
60
|
const isGlob = _interopDefault(require('is-glob'));
|
|
@@ -716,13 +717,14 @@ function hashContent(content) {
|
|
|
716
717
|
return crypto.createHash('sha256').update(content).digest('hex');
|
|
717
718
|
}
|
|
718
719
|
function hashSchema(schema) {
|
|
719
|
-
return hashContent(
|
|
720
|
-
assumeValid: true,
|
|
721
|
-
}));
|
|
720
|
+
return hashContent(graphql.print(pluginHelpers.getCachedDocumentNodeFromSchema(schema)));
|
|
722
721
|
}
|
|
723
722
|
function addHashToSchema(schemaPromise) {
|
|
724
723
|
return schemaPromise.then(schema => {
|
|
725
724
|
// It's consumed later on. The general purpose is to use it for caching.
|
|
725
|
+
if (!schema.extensions) {
|
|
726
|
+
schema.extensions = {};
|
|
727
|
+
}
|
|
726
728
|
schema.extensions['hash'] = hashSchema(schema);
|
|
727
729
|
return schema;
|
|
728
730
|
});
|
|
@@ -1016,7 +1018,6 @@ async function executeCodegen(input) {
|
|
|
1016
1018
|
pluginMap,
|
|
1017
1019
|
pluginContext,
|
|
1018
1020
|
profiler: context.profiler,
|
|
1019
|
-
cache,
|
|
1020
1021
|
}), `Build Generates Section: ${filename}`);
|
|
1021
1022
|
}
|
|
1022
1023
|
else {
|
|
@@ -1031,12 +1032,14 @@ async function executeCodegen(input) {
|
|
|
1031
1032
|
pluginMap,
|
|
1032
1033
|
pluginContext,
|
|
1033
1034
|
profiler: context.profiler,
|
|
1034
|
-
cache,
|
|
1035
1035
|
},
|
|
1036
1036
|
];
|
|
1037
1037
|
}
|
|
1038
1038
|
const process = async (outputArgs) => {
|
|
1039
|
-
const output = await core.codegen(
|
|
1039
|
+
const output = await core.codegen({
|
|
1040
|
+
...outputArgs,
|
|
1041
|
+
cache,
|
|
1042
|
+
});
|
|
1040
1043
|
result.push({
|
|
1041
1044
|
filename: outputArgs.filename,
|
|
1042
1045
|
content: output,
|
|
@@ -1055,8 +1058,7 @@ async function executeCodegen(input) {
|
|
|
1055
1058
|
}), {
|
|
1056
1059
|
// it doesn't stop when one of tasks failed, to finish at least some of outputs
|
|
1057
1060
|
exitOnError: false,
|
|
1058
|
-
|
|
1059
|
-
concurrent: 4,
|
|
1061
|
+
concurrent: os.cpus().length,
|
|
1060
1062
|
});
|
|
1061
1063
|
},
|
|
1062
1064
|
});
|
|
@@ -1286,15 +1288,16 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1286
1288
|
});
|
|
1287
1289
|
};
|
|
1288
1290
|
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
|
|
1292
|
+
function writeFile(filepath, content) {
|
|
1293
|
+
return fsWriteFile(filepath, content);
|
|
1291
1294
|
}
|
|
1292
|
-
function
|
|
1293
|
-
return
|
|
1295
|
+
function readFile(filepath) {
|
|
1296
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1294
1297
|
}
|
|
1295
|
-
function fileExists(filePath) {
|
|
1298
|
+
async function fileExists(filePath) {
|
|
1296
1299
|
try {
|
|
1297
|
-
return
|
|
1300
|
+
return (await fsStat(filePath)).isFile();
|
|
1298
1301
|
}
|
|
1299
1302
|
catch (err) {
|
|
1300
1303
|
return false;
|
|
@@ -1316,7 +1319,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1316
1319
|
const staleFilenames = previouslyGeneratedFilenames.filter(f => !filenames.includes(f));
|
|
1317
1320
|
staleFilenames.forEach(filename => {
|
|
1318
1321
|
if (shouldOverwrite(config, filename)) {
|
|
1319
|
-
unlinkFile(filename, err => {
|
|
1322
|
+
return unlinkFile(filename, err => {
|
|
1320
1323
|
const prettyFilename = filename.replace(`${input.cwd || process.cwd()}/`, '');
|
|
1321
1324
|
if (err) {
|
|
1322
1325
|
debugLog(`Cannot remove stale file: ${prettyFilename}\n${err}`);
|
|
@@ -1337,9 +1340,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1337
1340
|
if (config.watch) {
|
|
1338
1341
|
removeStaleFiles(config, generationResult);
|
|
1339
1342
|
}
|
|
1340
|
-
await context.profiler.run(
|
|
1343
|
+
await context.profiler.run(async () => {
|
|
1344
|
+
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1345
|
+
}, 'Lifecycle: beforeAllFileWrite');
|
|
1341
1346
|
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1342
|
-
const exists = fileExists(result.filename);
|
|
1347
|
+
const exists = await fileExists(result.filename);
|
|
1343
1348
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1344
1349
|
return;
|
|
1345
1350
|
}
|
|
@@ -1347,10 +1352,10 @@ async function generate(input, saveToFile = true) {
|
|
|
1347
1352
|
const currentHash = hash(content);
|
|
1348
1353
|
let previousHash = recentOutputHash.get(result.filename);
|
|
1349
1354
|
if (!previousHash && exists) {
|
|
1350
|
-
previousHash = hash(
|
|
1355
|
+
previousHash = hash(await readFile(result.filename));
|
|
1351
1356
|
}
|
|
1352
1357
|
if (previousHash && currentHash === previousHash) {
|
|
1353
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1358
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1354
1359
|
return;
|
|
1355
1360
|
}
|
|
1356
1361
|
if (content.length === 0) {
|
|
@@ -1360,11 +1365,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1360
1365
|
const basedir = path.dirname(result.filename);
|
|
1361
1366
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1362
1367
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1363
|
-
mkdirp
|
|
1368
|
+
await mkdirp(basedir);
|
|
1364
1369
|
const absolutePath = path.isAbsolute(result.filename)
|
|
1365
1370
|
? result.filename
|
|
1366
1371
|
: path.join(input.cwd || process.cwd(), result.filename);
|
|
1367
|
-
|
|
1372
|
+
await writeFile(absolutePath, result.content);
|
|
1368
1373
|
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1369
1374
|
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1370
1375
|
})), 'Write files');
|
|
@@ -1379,7 +1384,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1379
1384
|
await context.profiler.run(() => writeOutput(outputFiles), 'writeOutput');
|
|
1380
1385
|
await context.profiler.run(() => lifecycleHooks(config.hooks).beforeDone(), 'Lifecycle: beforeDone');
|
|
1381
1386
|
if (context.profilerOutput) {
|
|
1382
|
-
|
|
1387
|
+
await writeFile(path.join(context.cwd, context.profilerOutput), JSON.stringify(context.profiler.collect()));
|
|
1383
1388
|
}
|
|
1384
1389
|
return outputFiles;
|
|
1385
1390
|
}
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isDetailedError, DetailedError, createNoopProfiler, createProfiler, normalizeInstanceOrArray, normalizeConfig, normalizeOutputParam
|
|
1
|
+
import { isDetailedError, DetailedError, createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, normalizeInstanceOrArray, normalizeConfig, normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { codegen } from '@graphql-codegen/core';
|
|
3
|
-
import {
|
|
3
|
+
import { AggregateError, isValidPath } from '@graphql-tools/utils';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import logSymbols from 'log-symbols';
|
|
6
6
|
import ansiEscapes from 'ansi-escapes';
|
|
@@ -25,8 +25,9 @@ import { JsonFileLoader } from '@graphql-tools/json-file-loader';
|
|
|
25
25
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
26
26
|
import yaml from 'yaml';
|
|
27
27
|
import { createRequire } from 'module';
|
|
28
|
-
import fs, { promises, writeFileSync, readFileSync
|
|
28
|
+
import fs, { promises, unlink, writeFileSync, readFileSync } from 'fs';
|
|
29
29
|
import { createHash } from 'crypto';
|
|
30
|
+
import { cpus } from 'os';
|
|
30
31
|
import Listr from 'listr';
|
|
31
32
|
import { exec } from 'child_process';
|
|
32
33
|
import isGlob from 'is-glob';
|
|
@@ -689,13 +690,14 @@ function hashContent(content) {
|
|
|
689
690
|
return createHash('sha256').update(content).digest('hex');
|
|
690
691
|
}
|
|
691
692
|
function hashSchema(schema) {
|
|
692
|
-
return hashContent(
|
|
693
|
-
assumeValid: true,
|
|
694
|
-
}));
|
|
693
|
+
return hashContent(print(getCachedDocumentNodeFromSchema(schema)));
|
|
695
694
|
}
|
|
696
695
|
function addHashToSchema(schemaPromise) {
|
|
697
696
|
return schemaPromise.then(schema => {
|
|
698
697
|
// It's consumed later on. The general purpose is to use it for caching.
|
|
698
|
+
if (!schema.extensions) {
|
|
699
|
+
schema.extensions = {};
|
|
700
|
+
}
|
|
699
701
|
schema.extensions['hash'] = hashSchema(schema);
|
|
700
702
|
return schema;
|
|
701
703
|
});
|
|
@@ -989,7 +991,6 @@ async function executeCodegen(input) {
|
|
|
989
991
|
pluginMap,
|
|
990
992
|
pluginContext,
|
|
991
993
|
profiler: context.profiler,
|
|
992
|
-
cache,
|
|
993
994
|
}), `Build Generates Section: ${filename}`);
|
|
994
995
|
}
|
|
995
996
|
else {
|
|
@@ -1004,12 +1005,14 @@ async function executeCodegen(input) {
|
|
|
1004
1005
|
pluginMap,
|
|
1005
1006
|
pluginContext,
|
|
1006
1007
|
profiler: context.profiler,
|
|
1007
|
-
cache,
|
|
1008
1008
|
},
|
|
1009
1009
|
];
|
|
1010
1010
|
}
|
|
1011
1011
|
const process = async (outputArgs) => {
|
|
1012
|
-
const output = await codegen(
|
|
1012
|
+
const output = await codegen({
|
|
1013
|
+
...outputArgs,
|
|
1014
|
+
cache,
|
|
1015
|
+
});
|
|
1013
1016
|
result.push({
|
|
1014
1017
|
filename: outputArgs.filename,
|
|
1015
1018
|
content: output,
|
|
@@ -1028,8 +1031,7 @@ async function executeCodegen(input) {
|
|
|
1028
1031
|
}), {
|
|
1029
1032
|
// it doesn't stop when one of tasks failed, to finish at least some of outputs
|
|
1030
1033
|
exitOnError: false,
|
|
1031
|
-
|
|
1032
|
-
concurrent: 4,
|
|
1034
|
+
concurrent: cpus().length,
|
|
1033
1035
|
});
|
|
1034
1036
|
},
|
|
1035
1037
|
});
|
|
@@ -1259,15 +1261,16 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1259
1261
|
});
|
|
1260
1262
|
};
|
|
1261
1263
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = promises;
|
|
1265
|
+
function writeFile(filepath, content) {
|
|
1266
|
+
return fsWriteFile(filepath, content);
|
|
1264
1267
|
}
|
|
1265
|
-
function
|
|
1266
|
-
return
|
|
1268
|
+
function readFile(filepath) {
|
|
1269
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1267
1270
|
}
|
|
1268
|
-
function fileExists(filePath) {
|
|
1271
|
+
async function fileExists(filePath) {
|
|
1269
1272
|
try {
|
|
1270
|
-
return
|
|
1273
|
+
return (await fsStat(filePath)).isFile();
|
|
1271
1274
|
}
|
|
1272
1275
|
catch (err) {
|
|
1273
1276
|
return false;
|
|
@@ -1289,7 +1292,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1289
1292
|
const staleFilenames = previouslyGeneratedFilenames.filter(f => !filenames.includes(f));
|
|
1290
1293
|
staleFilenames.forEach(filename => {
|
|
1291
1294
|
if (shouldOverwrite(config, filename)) {
|
|
1292
|
-
unlinkFile(filename, err => {
|
|
1295
|
+
return unlinkFile(filename, err => {
|
|
1293
1296
|
const prettyFilename = filename.replace(`${input.cwd || process.cwd()}/`, '');
|
|
1294
1297
|
if (err) {
|
|
1295
1298
|
debugLog(`Cannot remove stale file: ${prettyFilename}\n${err}`);
|
|
@@ -1310,9 +1313,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1310
1313
|
if (config.watch) {
|
|
1311
1314
|
removeStaleFiles(config, generationResult);
|
|
1312
1315
|
}
|
|
1313
|
-
await context.profiler.run(
|
|
1316
|
+
await context.profiler.run(async () => {
|
|
1317
|
+
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1318
|
+
}, 'Lifecycle: beforeAllFileWrite');
|
|
1314
1319
|
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1315
|
-
const exists = fileExists(result.filename);
|
|
1320
|
+
const exists = await fileExists(result.filename);
|
|
1316
1321
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1317
1322
|
return;
|
|
1318
1323
|
}
|
|
@@ -1320,10 +1325,10 @@ async function generate(input, saveToFile = true) {
|
|
|
1320
1325
|
const currentHash = hash(content);
|
|
1321
1326
|
let previousHash = recentOutputHash.get(result.filename);
|
|
1322
1327
|
if (!previousHash && exists) {
|
|
1323
|
-
previousHash = hash(
|
|
1328
|
+
previousHash = hash(await readFile(result.filename));
|
|
1324
1329
|
}
|
|
1325
1330
|
if (previousHash && currentHash === previousHash) {
|
|
1326
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1331
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1327
1332
|
return;
|
|
1328
1333
|
}
|
|
1329
1334
|
if (content.length === 0) {
|
|
@@ -1333,11 +1338,11 @@ async function generate(input, saveToFile = true) {
|
|
|
1333
1338
|
const basedir = dirname(result.filename);
|
|
1334
1339
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1335
1340
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1336
|
-
mkdirp
|
|
1341
|
+
await mkdirp(basedir);
|
|
1337
1342
|
const absolutePath = isAbsolute(result.filename)
|
|
1338
1343
|
? result.filename
|
|
1339
1344
|
: join(input.cwd || process.cwd(), result.filename);
|
|
1340
|
-
|
|
1345
|
+
await writeFile(absolutePath, result.content);
|
|
1341
1346
|
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1342
1347
|
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1343
1348
|
})), 'Write files');
|
|
@@ -1352,7 +1357,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1352
1357
|
await context.profiler.run(() => writeOutput(outputFiles), 'writeOutput');
|
|
1353
1358
|
await context.profiler.run(() => lifecycleHooks(config.hooks).beforeDone(), 'Lifecycle: beforeDone');
|
|
1354
1359
|
if (context.profilerOutput) {
|
|
1355
|
-
|
|
1360
|
+
await writeFile(join(context.cwd, context.profilerOutput), JSON.stringify(context.profiler.collect()));
|
|
1356
1361
|
}
|
|
1357
1362
|
return outputFiles;
|
|
1358
1363
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1-alpha-74513a63e.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.
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
8
|
+
"@graphql-codegen/core": "2.5.1-alpha-74513a63e.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "2.4.1-alpha-74513a63e.0",
|
|
10
10
|
"@graphql-tools/apollo-engine-loader": "^7.0.5",
|
|
11
11
|
"@graphql-tools/code-file-loader": "^7.0.6",
|
|
12
12
|
"@graphql-tools/git-loader": "^7.0.5",
|
package/utils/file-system.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function fileExists(filePath: string): boolean
|
|
1
|
+
export declare function writeFile(filepath: string, content: string): Promise<void>;
|
|
2
|
+
export declare function readFile(filepath: string): Promise<string>;
|
|
3
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
4
4
|
export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
|