@stepzen/transpiler 0.0.38 → 0.2.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/lib/actions/merge.d.ts +2 -0
- package/lib/actions/merge.js +8 -4
- package/lib/actions/merge.js.map +1 -1
- package/lib/utils/copy-workspace-content.d.ts +13 -0
- package/lib/utils/copy-workspace-content.js +38 -0
- package/lib/utils/copy-workspace-content.js.map +1 -0
- package/package.json +4 -4
- package/src/actions/merge.ts +10 -4
- package/src/utils/copy-workspace-content.ts +41 -0
package/lib/actions/merge.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ declare const _default: (original: string, imported: {
|
|
|
7
7
|
silent: boolean;
|
|
8
8
|
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
9
9
|
mergeTypes?: boolean;
|
|
10
|
+
/** merge behaviour when a schema with the given name exists in the source */
|
|
11
|
+
onConflict?: 'overwrite' | 'append';
|
|
10
12
|
}) => Promise<string>;
|
|
11
13
|
export default _default;
|
package/lib/actions/merge.js
CHANGED
|
@@ -10,6 +10,7 @@ const merge_helpers_1 = require("../utils/merge-helpers");
|
|
|
10
10
|
const print_1 = require("./print");
|
|
11
11
|
const set_files_in_sdl_1 = require("../utils/set-files-in-sdl");
|
|
12
12
|
const strip_empty_queries_and_mutations_1 = require("../utils/strip-empty-queries-and-mutations");
|
|
13
|
+
const copy_workspace_content_1 = require("../utils/copy-workspace-content");
|
|
13
14
|
const BLANK_INDEX_TEMPLATE = `
|
|
14
15
|
schema @sdl(files: []) {
|
|
15
16
|
query: Query
|
|
@@ -25,6 +26,7 @@ exports.default = async (original, imported, options = {
|
|
|
25
26
|
output: null,
|
|
26
27
|
silent: false,
|
|
27
28
|
mergeTypes: true,
|
|
29
|
+
onConflict: 'append',
|
|
28
30
|
}) => {
|
|
29
31
|
// Make sure there is an output directory
|
|
30
32
|
if (!options.answers)
|
|
@@ -35,6 +37,8 @@ exports.default = async (original, imported, options = {
|
|
|
35
37
|
options.silent = false;
|
|
36
38
|
if (options.mergeTypes === undefined)
|
|
37
39
|
options.mergeTypes = true;
|
|
40
|
+
if (options.onConflict === undefined)
|
|
41
|
+
options.onConflict = 'append';
|
|
38
42
|
// To stop things like
|
|
39
43
|
// C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
|
|
40
44
|
options.output = merge_helpers_1.dedupeTempFolder(options.output);
|
|
@@ -45,7 +49,7 @@ exports.default = async (original, imported, options = {
|
|
|
45
49
|
throw new Error(`Cannot find imported source directory ${imported.source}`);
|
|
46
50
|
fs.ensureDirSync(options.output);
|
|
47
51
|
// Copy the original into the output.
|
|
48
|
-
|
|
52
|
+
copy_workspace_content_1.default(original, options.output);
|
|
49
53
|
// Ensure an index.graphql exists
|
|
50
54
|
const outputIndex = path.join(options.output, 'index.graphql');
|
|
51
55
|
if (!fs.existsSync(outputIndex)) {
|
|
@@ -59,7 +63,9 @@ exports.default = async (original, imported, options = {
|
|
|
59
63
|
// (https://github.com/steprz/stepzen-cli/issues/482).
|
|
60
64
|
BLANK_INDEX_TEMPLATE);
|
|
61
65
|
}
|
|
62
|
-
const targetSubfolder =
|
|
66
|
+
const targetSubfolder = options.onConflict === 'overwrite'
|
|
67
|
+
? imported.name
|
|
68
|
+
: merge_helpers_1.findNextAvailableSubfolder(original, imported.name);
|
|
63
69
|
if (options.mergeTypes) {
|
|
64
70
|
const merged = merge_1.mergeTypeDefs([
|
|
65
71
|
await merge_helpers_1.getSchema(options.output),
|
|
@@ -132,8 +138,6 @@ exports.default = async (original, imported, options = {
|
|
|
132
138
|
});
|
|
133
139
|
}
|
|
134
140
|
else {
|
|
135
|
-
// Write the files to the output directory
|
|
136
|
-
fs.copySync(original, options.output);
|
|
137
141
|
glob.sync('**/*.graphql', { cwd: imported.source }).forEach(relativePath => {
|
|
138
142
|
const importedFullPath = path.join(imported.source, relativePath);
|
|
139
143
|
const targetFullPath = path.join(options.output, targetSubfolder, relativePath);
|
package/lib/actions/merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,gDAAkD;AAClD,qCAAoC;AACpC,yBAAwB;AACxB,6BAA4B;AAE5B,0DAW+B;AAC/B,mCAA2B;AAC3B,gEAAqD;AACrD,kGAAsF;
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,gDAAkD;AAClD,qCAAoC;AACpC,yBAAwB;AACxB,6BAA4B;AAE5B,0DAW+B;AAC/B,mCAA2B;AAC3B,gEAAqD;AACrD,kGAAsF;AACtF,4EAAkE;AAElE,MAAM,oBAAoB,GAAG;;;;CAI5B,CAAC,IAAI,EAAE,CAAA;AAER,MAAM,gBAAgB,GAAG;;;;CAIxB,CAAC,IAAI,EAAE,CAAA;AAER,kBAAe,KAAK,EAClB,QAAgB,EAChB,QAGC,EACD,UAQI;IACF,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,QAAQ;CACrB,EACD,EAAE;IACF,yCAAyC;IACzC,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,CAAC,OAAO,GAAG,EAAE,CAAA;IAC1C,IAAI,CAAC,OAAO,CAAC,MAAM;QACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,CAAC,MAAM,GAAG,KAAK,CAAA;IAC3C,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;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,0 +1,13 @@
|
|
|
1
|
+
declare const _default: (srcPath: string, dstPath: string) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Copy StepZen workspace content from one directory to another.
|
|
4
|
+
*
|
|
5
|
+
* Include only the files relevant to StepZen:
|
|
6
|
+
* - **/*.graphql
|
|
7
|
+
* - config.yaml
|
|
8
|
+
* - stepzen.config.json
|
|
9
|
+
*
|
|
10
|
+
* Exclude all other files.
|
|
11
|
+
* Exclude special folders, e.g. node_modules
|
|
12
|
+
*/
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const glob = require("glob");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const WORKSPACE_FILE_PATTERNS = [
|
|
8
|
+
'**/*.graphql',
|
|
9
|
+
'stepzen.config.json',
|
|
10
|
+
'config.yaml',
|
|
11
|
+
];
|
|
12
|
+
const IGNORED_PATTERNS = ['node_modules/**'];
|
|
13
|
+
/**
|
|
14
|
+
* Copy StepZen workspace content from one directory to another.
|
|
15
|
+
*
|
|
16
|
+
* Include only the files relevant to StepZen:
|
|
17
|
+
* - **/*.graphql
|
|
18
|
+
* - config.yaml
|
|
19
|
+
* - stepzen.config.json
|
|
20
|
+
*
|
|
21
|
+
* Exclude all other files.
|
|
22
|
+
* Exclude special folders, e.g. node_modules
|
|
23
|
+
*/
|
|
24
|
+
exports.default = (srcPath, dstPath) => {
|
|
25
|
+
if (!fs.existsSync(srcPath)) {
|
|
26
|
+
throw new Error(`Cannot find source directory ${srcPath}`);
|
|
27
|
+
}
|
|
28
|
+
lodash_1.flatMap(WORKSPACE_FILE_PATTERNS, pattern => glob.sync(pattern, {
|
|
29
|
+
cwd: srcPath,
|
|
30
|
+
ignore: IGNORED_PATTERNS,
|
|
31
|
+
})).forEach(relativePath => {
|
|
32
|
+
const srcFileFullPath = path.join(srcPath, relativePath);
|
|
33
|
+
const dstFileFullPath = path.join(dstPath, relativePath);
|
|
34
|
+
fs.ensureDirSync(path.dirname(dstFileFullPath));
|
|
35
|
+
fs.copyFileSync(srcFileFullPath, dstFileFullPath);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=copy-workspace-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-workspace-content.js","sourceRoot":"","sources":["../../src/utils/copy-workspace-content.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,6BAA4B;AAC5B,mCAA8B;AAE9B,MAAM,uBAAuB,GAAG;IAC9B,cAAc;IACd,qBAAqB;IACrB,aAAa;CACd,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAE5C;;;;;;;;;;GAUG;AACH,kBAAe,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE;IAClD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAA;KAC3D;IAED,gBAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC,EAAE,CACzC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACjB,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,gBAAgB;KACzB,CAAC,CACH,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACvB,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QACxD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QACxD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAA;QAC/C,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,eAAe,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stepzen/transpiler",
|
|
3
3
|
"description": "The StepZen transpiler",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@graphql-tools/merge": "^6.2.17",
|
|
24
|
-
"debug": "^4.3.
|
|
24
|
+
"debug": "^4.3.4",
|
|
25
25
|
"dotenv": "^10.0.0",
|
|
26
26
|
"fs-extra": "^9.1.0",
|
|
27
27
|
"glob": "^7.2.0",
|
|
28
28
|
"graphql": "^15.8.0",
|
|
29
|
-
"inquirer": "^8.2.
|
|
29
|
+
"inquirer": "^8.2.2",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"node-fetch": "^2.6.7",
|
|
32
|
-
"prettier": "^2.
|
|
32
|
+
"prettier": "^2.6.2",
|
|
33
33
|
"shelljs": "^0.8.5",
|
|
34
34
|
"yaml": "^1.10.2"
|
|
35
35
|
},
|
package/src/actions/merge.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import print from './print'
|
|
21
21
|
import setFilesInSDL from '../utils/set-files-in-sdl'
|
|
22
22
|
import stripEmptyQueriesAndMutations from '../utils/strip-empty-queries-and-mutations'
|
|
23
|
+
import copyWorkspaceContent from '../utils/copy-workspace-content'
|
|
23
24
|
|
|
24
25
|
const BLANK_INDEX_TEMPLATE = `
|
|
25
26
|
schema @sdl(files: []) {
|
|
@@ -45,11 +46,14 @@ export default async (
|
|
|
45
46
|
silent: boolean
|
|
46
47
|
/** when `false` merge only covers config files and updates @sdl directrive */
|
|
47
48
|
mergeTypes?: boolean
|
|
49
|
+
/** merge behaviour when a schema with the given name exists in the source */
|
|
50
|
+
onConflict?: 'overwrite' | 'append'
|
|
48
51
|
} = {
|
|
49
52
|
answers: {},
|
|
50
53
|
output: null,
|
|
51
54
|
silent: false,
|
|
52
55
|
mergeTypes: true,
|
|
56
|
+
onConflict: 'append',
|
|
53
57
|
},
|
|
54
58
|
) => {
|
|
55
59
|
// Make sure there is an output directory
|
|
@@ -58,6 +62,7 @@ export default async (
|
|
|
58
62
|
options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)
|
|
59
63
|
if (!options.silent) options.silent = false
|
|
60
64
|
if (options.mergeTypes === undefined) options.mergeTypes = true
|
|
65
|
+
if (options.onConflict === undefined) options.onConflict = 'append'
|
|
61
66
|
|
|
62
67
|
// To stop things like
|
|
63
68
|
// C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
|
|
@@ -71,7 +76,7 @@ export default async (
|
|
|
71
76
|
fs.ensureDirSync(options.output)
|
|
72
77
|
|
|
73
78
|
// Copy the original into the output.
|
|
74
|
-
|
|
79
|
+
copyWorkspaceContent(original, options.output)
|
|
75
80
|
|
|
76
81
|
// Ensure an index.graphql exists
|
|
77
82
|
const outputIndex = path.join(options.output, 'index.graphql')
|
|
@@ -90,7 +95,10 @@ export default async (
|
|
|
90
95
|
)
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
const targetSubfolder =
|
|
98
|
+
const targetSubfolder =
|
|
99
|
+
options.onConflict === 'overwrite'
|
|
100
|
+
? imported.name
|
|
101
|
+
: findNextAvailableSubfolder(original, imported.name)
|
|
94
102
|
|
|
95
103
|
if (options.mergeTypes) {
|
|
96
104
|
const merged = mergeTypeDefs([
|
|
@@ -191,8 +199,6 @@ export default async (
|
|
|
191
199
|
fs.writeFileSync(deduped, print(a.ast))
|
|
192
200
|
})
|
|
193
201
|
} else {
|
|
194
|
-
// Write the files to the output directory
|
|
195
|
-
fs.copySync(original, options.output)
|
|
196
202
|
glob.sync('**/*.graphql', {cwd: imported.source}).forEach(relativePath => {
|
|
197
203
|
const importedFullPath = path.join(imported.source, relativePath)
|
|
198
204
|
const targetFullPath = path.join(
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as fs from 'fs-extra'
|
|
2
|
+
import * as glob from 'glob'
|
|
3
|
+
import * as path from 'path'
|
|
4
|
+
import {flatMap} from 'lodash'
|
|
5
|
+
|
|
6
|
+
const WORKSPACE_FILE_PATTERNS = [
|
|
7
|
+
'**/*.graphql',
|
|
8
|
+
'stepzen.config.json',
|
|
9
|
+
'config.yaml',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
const IGNORED_PATTERNS = ['node_modules/**']
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copy StepZen workspace content from one directory to another.
|
|
16
|
+
*
|
|
17
|
+
* Include only the files relevant to StepZen:
|
|
18
|
+
* - **/*.graphql
|
|
19
|
+
* - config.yaml
|
|
20
|
+
* - stepzen.config.json
|
|
21
|
+
*
|
|
22
|
+
* Exclude all other files.
|
|
23
|
+
* Exclude special folders, e.g. node_modules
|
|
24
|
+
*/
|
|
25
|
+
export default (srcPath: string, dstPath: string) => {
|
|
26
|
+
if (!fs.existsSync(srcPath)) {
|
|
27
|
+
throw new Error(`Cannot find source directory ${srcPath}`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
flatMap(WORKSPACE_FILE_PATTERNS, pattern =>
|
|
31
|
+
glob.sync(pattern, {
|
|
32
|
+
cwd: srcPath,
|
|
33
|
+
ignore: IGNORED_PATTERNS,
|
|
34
|
+
}),
|
|
35
|
+
).forEach(relativePath => {
|
|
36
|
+
const srcFileFullPath = path.join(srcPath, relativePath)
|
|
37
|
+
const dstFileFullPath = path.join(dstPath, relativePath)
|
|
38
|
+
fs.ensureDirSync(path.dirname(dstFileFullPath))
|
|
39
|
+
fs.copyFileSync(srcFileFullPath, dstFileFullPath)
|
|
40
|
+
})
|
|
41
|
+
}
|