@graphql-codegen/cli 2.6.0-alpha-679ebe9ab.0 → 2.6.0-alpha-aa96076e9.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 +10 -39
- package/index.js +10 -39
- package/index.mjs +10 -39
- package/package.json +2 -2
- package/utils/file-system.d.ts +2 -2
package/bin.js
CHANGED
|
@@ -57,7 +57,7 @@ const os = require('os');
|
|
|
57
57
|
const Listr = _interopDefault(require('listr'));
|
|
58
58
|
const isGlob = _interopDefault(require('is-glob'));
|
|
59
59
|
const debounce = _interopDefault(require('debounce'));
|
|
60
|
-
const
|
|
60
|
+
const mkdirp = _interopDefault(require('mkdirp'));
|
|
61
61
|
const crypto = require('crypto');
|
|
62
62
|
const inquirer = _interopDefault(require('inquirer'));
|
|
63
63
|
const detectIndent = _interopDefault(require('detect-indent'));
|
|
@@ -1256,22 +1256,23 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1256
1256
|
});
|
|
1257
1257
|
};
|
|
1258
1258
|
|
|
1259
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
|
|
1259
1260
|
function writeFile(filepath, content) {
|
|
1260
|
-
return
|
|
1261
|
+
return fsWriteFile(filepath, content);
|
|
1261
1262
|
}
|
|
1262
1263
|
function readFile(filepath) {
|
|
1263
|
-
return
|
|
1264
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1264
1265
|
}
|
|
1265
1266
|
async function fileExists(filePath) {
|
|
1266
1267
|
try {
|
|
1267
|
-
return (await
|
|
1268
|
+
return (await fsStat(filePath)).isFile();
|
|
1268
1269
|
}
|
|
1269
1270
|
catch (err) {
|
|
1270
1271
|
return false;
|
|
1271
1272
|
}
|
|
1272
1273
|
}
|
|
1273
1274
|
function unlinkFile(filePath, cb) {
|
|
1274
|
-
|
|
1275
|
+
fs.unlink(filePath, cb);
|
|
1275
1276
|
}
|
|
1276
1277
|
|
|
1277
1278
|
const hash = (content) => crypto.createHash('sha1').update(content).digest('base64');
|
|
@@ -1309,39 +1310,9 @@ async function generate(input, saveToFile = true) {
|
|
|
1309
1310
|
}
|
|
1310
1311
|
await context.profiler.run(async () => {
|
|
1311
1312
|
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1312
|
-
await Promise.all(generationResult.map(async (result) => {
|
|
1313
|
-
const exists = await fileExists(result.filename);
|
|
1314
|
-
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1315
|
-
return;
|
|
1316
|
-
}
|
|
1317
|
-
const content = result.content || '';
|
|
1318
|
-
const currentHash = hash(content);
|
|
1319
|
-
let previousHash = recentOutputHash.get(result.filename);
|
|
1320
|
-
if (!previousHash && exists) {
|
|
1321
|
-
previousHash = hash(await readFile(result.filename));
|
|
1322
|
-
}
|
|
1323
|
-
if (previousHash && currentHash === previousHash) {
|
|
1324
|
-
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1325
|
-
return;
|
|
1326
|
-
}
|
|
1327
|
-
if (content.length === 0) {
|
|
1328
|
-
return;
|
|
1329
|
-
}
|
|
1330
|
-
recentOutputHash.set(result.filename, currentHash);
|
|
1331
|
-
const basedir = path.dirname(result.filename);
|
|
1332
|
-
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1333
|
-
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1334
|
-
await fsExtra.mkdirp(basedir);
|
|
1335
|
-
const absolutePath = path.isAbsolute(result.filename)
|
|
1336
|
-
? result.filename
|
|
1337
|
-
: path.join(input.cwd || process.cwd(), result.filename);
|
|
1338
|
-
await writeFile(absolutePath, result.content);
|
|
1339
|
-
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1340
|
-
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1341
|
-
}));
|
|
1342
1313
|
}, 'Lifecycle: beforeAllFileWrite');
|
|
1343
|
-
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1344
|
-
const exists = fileExists(result.filename);
|
|
1314
|
+
await context.profiler.run(async () => await Promise.all(generationResult.map(async (result) => {
|
|
1315
|
+
const exists = await fileExists(result.filename);
|
|
1345
1316
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1346
1317
|
return;
|
|
1347
1318
|
}
|
|
@@ -1352,7 +1323,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1352
1323
|
previousHash = hash(await readFile(result.filename));
|
|
1353
1324
|
}
|
|
1354
1325
|
if (previousHash && currentHash === previousHash) {
|
|
1355
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1326
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1356
1327
|
return;
|
|
1357
1328
|
}
|
|
1358
1329
|
if (content.length === 0) {
|
|
@@ -1362,7 +1333,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1362
1333
|
const basedir = path.dirname(result.filename);
|
|
1363
1334
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1364
1335
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1365
|
-
|
|
1336
|
+
await mkdirp(basedir);
|
|
1366
1337
|
const absolutePath = path.isAbsolute(result.filename)
|
|
1367
1338
|
? result.filename
|
|
1368
1339
|
: path.join(input.cwd || process.cwd(), result.filename);
|
package/index.js
CHANGED
|
@@ -58,7 +58,7 @@ const Listr = _interopDefault(require('listr'));
|
|
|
58
58
|
const child_process = require('child_process');
|
|
59
59
|
const isGlob = _interopDefault(require('is-glob'));
|
|
60
60
|
const debounce = _interopDefault(require('debounce'));
|
|
61
|
-
const
|
|
61
|
+
const mkdirp = _interopDefault(require('mkdirp'));
|
|
62
62
|
const crypto = require('crypto');
|
|
63
63
|
const inquirer = _interopDefault(require('inquirer'));
|
|
64
64
|
const detectIndent = _interopDefault(require('detect-indent'));
|
|
@@ -1257,22 +1257,23 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1257
1257
|
});
|
|
1258
1258
|
};
|
|
1259
1259
|
|
|
1260
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = fs.promises;
|
|
1260
1261
|
function writeFile(filepath, content) {
|
|
1261
|
-
return
|
|
1262
|
+
return fsWriteFile(filepath, content);
|
|
1262
1263
|
}
|
|
1263
1264
|
function readFile(filepath) {
|
|
1264
|
-
return
|
|
1265
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1265
1266
|
}
|
|
1266
1267
|
async function fileExists(filePath) {
|
|
1267
1268
|
try {
|
|
1268
|
-
return (await
|
|
1269
|
+
return (await fsStat(filePath)).isFile();
|
|
1269
1270
|
}
|
|
1270
1271
|
catch (err) {
|
|
1271
1272
|
return false;
|
|
1272
1273
|
}
|
|
1273
1274
|
}
|
|
1274
1275
|
function unlinkFile(filePath, cb) {
|
|
1275
|
-
|
|
1276
|
+
fs.unlink(filePath, cb);
|
|
1276
1277
|
}
|
|
1277
1278
|
|
|
1278
1279
|
const hash = (content) => crypto.createHash('sha1').update(content).digest('base64');
|
|
@@ -1310,39 +1311,9 @@ async function generate(input, saveToFile = true) {
|
|
|
1310
1311
|
}
|
|
1311
1312
|
await context.profiler.run(async () => {
|
|
1312
1313
|
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1313
|
-
await Promise.all(generationResult.map(async (result) => {
|
|
1314
|
-
const exists = await fileExists(result.filename);
|
|
1315
|
-
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1316
|
-
return;
|
|
1317
|
-
}
|
|
1318
|
-
const content = result.content || '';
|
|
1319
|
-
const currentHash = hash(content);
|
|
1320
|
-
let previousHash = recentOutputHash.get(result.filename);
|
|
1321
|
-
if (!previousHash && exists) {
|
|
1322
|
-
previousHash = hash(await readFile(result.filename));
|
|
1323
|
-
}
|
|
1324
|
-
if (previousHash && currentHash === previousHash) {
|
|
1325
|
-
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
if (content.length === 0) {
|
|
1329
|
-
return;
|
|
1330
|
-
}
|
|
1331
|
-
recentOutputHash.set(result.filename, currentHash);
|
|
1332
|
-
const basedir = path.dirname(result.filename);
|
|
1333
|
-
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1334
|
-
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1335
|
-
await fsExtra.mkdirp(basedir);
|
|
1336
|
-
const absolutePath = path.isAbsolute(result.filename)
|
|
1337
|
-
? result.filename
|
|
1338
|
-
: path.join(input.cwd || process.cwd(), result.filename);
|
|
1339
|
-
await writeFile(absolutePath, result.content);
|
|
1340
|
-
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1341
|
-
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1342
|
-
}));
|
|
1343
1314
|
}, 'Lifecycle: beforeAllFileWrite');
|
|
1344
|
-
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1345
|
-
const exists = fileExists(result.filename);
|
|
1315
|
+
await context.profiler.run(async () => await Promise.all(generationResult.map(async (result) => {
|
|
1316
|
+
const exists = await fileExists(result.filename);
|
|
1346
1317
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1347
1318
|
return;
|
|
1348
1319
|
}
|
|
@@ -1353,7 +1324,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1353
1324
|
previousHash = hash(await readFile(result.filename));
|
|
1354
1325
|
}
|
|
1355
1326
|
if (previousHash && currentHash === previousHash) {
|
|
1356
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1327
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1357
1328
|
return;
|
|
1358
1329
|
}
|
|
1359
1330
|
if (content.length === 0) {
|
|
@@ -1363,7 +1334,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1363
1334
|
const basedir = path.dirname(result.filename);
|
|
1364
1335
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1365
1336
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1366
|
-
|
|
1337
|
+
await mkdirp(basedir);
|
|
1367
1338
|
const absolutePath = path.isAbsolute(result.filename)
|
|
1368
1339
|
? result.filename
|
|
1369
1340
|
: path.join(input.cwd || process.cwd(), result.filename);
|
package/index.mjs
CHANGED
|
@@ -25,13 +25,13 @@ 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 } from 'fs';
|
|
28
|
+
import fs, { promises, unlink, writeFileSync, readFileSync } from 'fs';
|
|
29
29
|
import { cpus } from 'os';
|
|
30
30
|
import Listr from 'listr';
|
|
31
31
|
import { exec } from 'child_process';
|
|
32
32
|
import isGlob from 'is-glob';
|
|
33
33
|
import debounce from 'debounce';
|
|
34
|
-
import
|
|
34
|
+
import mkdirp from 'mkdirp';
|
|
35
35
|
import { createHash } from 'crypto';
|
|
36
36
|
import inquirer from 'inquirer';
|
|
37
37
|
import detectIndent from 'detect-indent';
|
|
@@ -1230,15 +1230,16 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1230
1230
|
});
|
|
1231
1231
|
};
|
|
1232
1232
|
|
|
1233
|
+
const { writeFile: fsWriteFile, readFile: fsReadFile, stat: fsStat } = promises;
|
|
1233
1234
|
function writeFile(filepath, content) {
|
|
1234
|
-
return
|
|
1235
|
+
return fsWriteFile(filepath, content);
|
|
1235
1236
|
}
|
|
1236
1237
|
function readFile(filepath) {
|
|
1237
|
-
return
|
|
1238
|
+
return fsReadFile(filepath, 'utf-8');
|
|
1238
1239
|
}
|
|
1239
1240
|
async function fileExists(filePath) {
|
|
1240
1241
|
try {
|
|
1241
|
-
return (await
|
|
1242
|
+
return (await fsStat(filePath)).isFile();
|
|
1242
1243
|
}
|
|
1243
1244
|
catch (err) {
|
|
1244
1245
|
return false;
|
|
@@ -1283,39 +1284,9 @@ async function generate(input, saveToFile = true) {
|
|
|
1283
1284
|
}
|
|
1284
1285
|
await context.profiler.run(async () => {
|
|
1285
1286
|
await lifecycleHooks(config.hooks).beforeAllFileWrite(generationResult.map(r => r.filename));
|
|
1286
|
-
await Promise.all(generationResult.map(async (result) => {
|
|
1287
|
-
const exists = await fileExists(result.filename);
|
|
1288
|
-
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1289
|
-
return;
|
|
1290
|
-
}
|
|
1291
|
-
const content = result.content || '';
|
|
1292
|
-
const currentHash = hash(content);
|
|
1293
|
-
let previousHash = recentOutputHash.get(result.filename);
|
|
1294
|
-
if (!previousHash && exists) {
|
|
1295
|
-
previousHash = hash(await readFile(result.filename));
|
|
1296
|
-
}
|
|
1297
|
-
if (previousHash && currentHash === previousHash) {
|
|
1298
|
-
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1299
|
-
return;
|
|
1300
|
-
}
|
|
1301
|
-
if (content.length === 0) {
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
recentOutputHash.set(result.filename, currentHash);
|
|
1305
|
-
const basedir = dirname(result.filename);
|
|
1306
|
-
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1307
|
-
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1308
|
-
await mkdirp(basedir);
|
|
1309
|
-
const absolutePath = isAbsolute(result.filename)
|
|
1310
|
-
? result.filename
|
|
1311
|
-
: join(input.cwd || process.cwd(), result.filename);
|
|
1312
|
-
await writeFile(absolutePath, result.content);
|
|
1313
|
-
await lifecycleHooks(result.hooks).afterOneFileWrite(result.filename);
|
|
1314
|
-
await lifecycleHooks(config.hooks).afterOneFileWrite(result.filename);
|
|
1315
|
-
}));
|
|
1316
1287
|
}, 'Lifecycle: beforeAllFileWrite');
|
|
1317
|
-
await context.profiler.run(() => Promise.all(generationResult.map(async (result) => {
|
|
1318
|
-
const exists = fileExists(result.filename);
|
|
1288
|
+
await context.profiler.run(async () => await Promise.all(generationResult.map(async (result) => {
|
|
1289
|
+
const exists = await fileExists(result.filename);
|
|
1319
1290
|
if (!shouldOverwrite(config, result.filename) && exists) {
|
|
1320
1291
|
return;
|
|
1321
1292
|
}
|
|
@@ -1326,7 +1297,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1326
1297
|
previousHash = hash(await readFile(result.filename));
|
|
1327
1298
|
}
|
|
1328
1299
|
if (previousHash && currentHash === previousHash) {
|
|
1329
|
-
debugLog(`Skipping file (${result.filename}) writing due to
|
|
1300
|
+
debugLog(`Skipping file (${result.filename}) writing due to indentical hash...`);
|
|
1330
1301
|
return;
|
|
1331
1302
|
}
|
|
1332
1303
|
if (content.length === 0) {
|
|
@@ -1336,7 +1307,7 @@ async function generate(input, saveToFile = true) {
|
|
|
1336
1307
|
const basedir = dirname(result.filename);
|
|
1337
1308
|
await lifecycleHooks(result.hooks).beforeOneFileWrite(result.filename);
|
|
1338
1309
|
await lifecycleHooks(config.hooks).beforeOneFileWrite(result.filename);
|
|
1339
|
-
mkdirp
|
|
1310
|
+
await mkdirp(basedir);
|
|
1340
1311
|
const absolutePath = isAbsolute(result.filename)
|
|
1341
1312
|
? result.filename
|
|
1342
1313
|
: join(input.cwd || process.cwd(), result.filename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.6.0-alpha-
|
|
3
|
+
"version": "2.6.0-alpha-aa96076e9.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
|
},
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"debounce": "^1.2.0",
|
|
27
27
|
"dependency-graph": "^0.11.0",
|
|
28
28
|
"detect-indent": "^6.0.0",
|
|
29
|
-
"fs-extra": "^9.1.0",
|
|
30
29
|
"glob": "^7.1.6",
|
|
31
30
|
"globby": "^11.0.4",
|
|
32
31
|
"graphql-config": "^4.1.0",
|
|
@@ -38,6 +37,7 @@
|
|
|
38
37
|
"listr-update-renderer": "^0.5.0",
|
|
39
38
|
"log-symbols": "^4.0.0",
|
|
40
39
|
"minimatch": "^3.0.4",
|
|
40
|
+
"mkdirp": "^1.0.4",
|
|
41
41
|
"string-env-interpolation": "^1.0.1",
|
|
42
42
|
"ts-log": "^2.2.3",
|
|
43
43
|
"tslib": "~2.3.0",
|
package/utils/file-system.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function writeFile(filepath: string, content: string):
|
|
2
|
-
export declare function readFile(filepath: string):
|
|
1
|
+
export declare function writeFile(filepath: string, content: string): Promise<void>;
|
|
2
|
+
export declare function readFile(filepath: string): Promise<string>;
|
|
3
3
|
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
4
4
|
export declare function unlinkFile(filePath: string, cb?: (err?: Error) => any): void;
|