@stepzen/transpiler 0.0.36 → 0.0.39
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.js +19 -6
- 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 +26 -5
- package/src/utils/copy-workspace-content.ts +41 -0
package/lib/actions/merge.js
CHANGED
|
@@ -10,11 +10,13 @@ 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
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
`.trim();
|
|
19
|
+
const BLANK_QUERY_TYPE = `
|
|
18
20
|
type Query {
|
|
19
21
|
__query: String
|
|
20
22
|
}
|
|
@@ -44,11 +46,19 @@ exports.default = async (original, imported, options = {
|
|
|
44
46
|
throw new Error(`Cannot find imported source directory ${imported.source}`);
|
|
45
47
|
fs.ensureDirSync(options.output);
|
|
46
48
|
// Copy the original into the output.
|
|
47
|
-
|
|
49
|
+
copy_workspace_content_1.default(original, options.output);
|
|
48
50
|
// Ensure an index.graphql exists
|
|
49
51
|
const outputIndex = path.join(options.output, 'index.graphql');
|
|
50
52
|
if (!fs.existsSync(outputIndex)) {
|
|
51
|
-
fs.writeFileSync(outputIndex,
|
|
53
|
+
fs.writeFileSync(outputIndex, options.mergeTypes
|
|
54
|
+
? // (2022-03-09, vluakshov) Not sure what'd break without the
|
|
55
|
+
// blank Query type, but that's why I do not want to remove it
|
|
56
|
+
// from the default code path.
|
|
57
|
+
BLANK_INDEX_TEMPLATE + BLANK_QUERY_TYPE
|
|
58
|
+
: // In the non-default code path that does NOT merge types
|
|
59
|
+
// the blank Query type causes explicit problems
|
|
60
|
+
// (https://github.com/steprz/stepzen-cli/issues/482).
|
|
61
|
+
BLANK_INDEX_TEMPLATE);
|
|
52
62
|
}
|
|
53
63
|
const targetSubfolder = merge_helpers_1.findNextAvailableSubfolder(original, imported.name);
|
|
54
64
|
if (options.mergeTypes) {
|
|
@@ -123,9 +133,12 @@ exports.default = async (original, imported, options = {
|
|
|
123
133
|
});
|
|
124
134
|
}
|
|
125
135
|
else {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
glob.sync('**/*.graphql', { cwd: imported.source }).forEach(relativePath => {
|
|
137
|
+
const importedFullPath = path.join(imported.source, relativePath);
|
|
138
|
+
const targetFullPath = path.join(options.output, targetSubfolder, relativePath);
|
|
139
|
+
fs.ensureDirSync(path.dirname(targetFullPath));
|
|
140
|
+
fs.copyFileSync(importedFullPath, targetFullPath);
|
|
141
|
+
});
|
|
129
142
|
}
|
|
130
143
|
// Make sure all files are referenced in @sdl
|
|
131
144
|
set_files_in_sdl_1.default(options.output);
|
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;A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Y,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;KACH;IAED,6CAA6C;IAC7C,0BAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAE7B,yBAAyB;IACzB,MAAM,MAAM,GAAG,MAAM,gCAAgB,CACnC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACjC,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,OAAO,CAChB,CAAA;IACD,IAAI,MAAM,EAAE;QACV,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QAC3D,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,MAAgB,CAAC,CAAA;KAC/C;IAED,0BAA0B;IAC1B,OAAO,OAAO,CAAC,MAAM,CAAA;AACvB,CAAC,CAAA"}
|
|
@@ -0,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.0.39",
|
|
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,12 +20,15 @@ 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: []) {
|
|
26
27
|
query: Query
|
|
27
28
|
}
|
|
29
|
+
`.trim()
|
|
28
30
|
|
|
31
|
+
const BLANK_QUERY_TYPE = `
|
|
29
32
|
type Query {
|
|
30
33
|
__query: String
|
|
31
34
|
}
|
|
@@ -69,12 +72,23 @@ export default async (
|
|
|
69
72
|
fs.ensureDirSync(options.output)
|
|
70
73
|
|
|
71
74
|
// Copy the original into the output.
|
|
72
|
-
|
|
75
|
+
copyWorkspaceContent(original, options.output)
|
|
73
76
|
|
|
74
77
|
// Ensure an index.graphql exists
|
|
75
78
|
const outputIndex = path.join(options.output, 'index.graphql')
|
|
76
79
|
if (!fs.existsSync(outputIndex)) {
|
|
77
|
-
fs.writeFileSync(
|
|
80
|
+
fs.writeFileSync(
|
|
81
|
+
outputIndex,
|
|
82
|
+
options.mergeTypes
|
|
83
|
+
? // (2022-03-09, vluakshov) Not sure what'd break without the
|
|
84
|
+
// blank Query type, but that's why I do not want to remove it
|
|
85
|
+
// from the default code path.
|
|
86
|
+
BLANK_INDEX_TEMPLATE + BLANK_QUERY_TYPE
|
|
87
|
+
: // In the non-default code path that does NOT merge types
|
|
88
|
+
// the blank Query type causes explicit problems
|
|
89
|
+
// (https://github.com/steprz/stepzen-cli/issues/482).
|
|
90
|
+
BLANK_INDEX_TEMPLATE,
|
|
91
|
+
)
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
const targetSubfolder = findNextAvailableSubfolder(original, imported.name)
|
|
@@ -178,9 +192,16 @@ export default async (
|
|
|
178
192
|
fs.writeFileSync(deduped, print(a.ast))
|
|
179
193
|
})
|
|
180
194
|
} else {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
glob.sync('**/*.graphql', {cwd: imported.source}).forEach(relativePath => {
|
|
196
|
+
const importedFullPath = path.join(imported.source, relativePath)
|
|
197
|
+
const targetFullPath = path.join(
|
|
198
|
+
options.output!,
|
|
199
|
+
targetSubfolder,
|
|
200
|
+
relativePath,
|
|
201
|
+
)
|
|
202
|
+
fs.ensureDirSync(path.dirname(targetFullPath))
|
|
203
|
+
fs.copyFileSync(importedFullPath, targetFullPath)
|
|
204
|
+
})
|
|
184
205
|
}
|
|
185
206
|
|
|
186
207
|
// Make sure all files are referenced in @sdl
|
|
@@ -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
|
+
}
|