@stepzen/transpiler 0.0.26 → 0.0.30
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/configure.js +7 -4
- package/lib/actions/lint.js +7 -4
- package/lib/actions/merge.js +20 -8
- package/lib/actions/stitch.js +19 -12
- package/lib/actions/transpile.js +2 -1
- package/lib/actions/validate.js +5 -2
- package/lib/utils/merge-helpers.js +8 -5
- package/lib/utils/set-files-in-sdl.js +4 -2
- package/lib/validators/config-exists/index.js +4 -2
- package/package.json +1 -1
package/lib/actions/configure.js
CHANGED
|
@@ -5,6 +5,7 @@ const debug = require("debug");
|
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const glob = require("glob");
|
|
7
7
|
const inquirer = require("inquirer");
|
|
8
|
+
const path = require("path");
|
|
8
9
|
const yaml = require("yaml");
|
|
9
10
|
exports.default = async (source, silent = false, answers = {}) => {
|
|
10
11
|
var e_1, _a, e_2, _b;
|
|
@@ -15,9 +16,10 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
15
16
|
};
|
|
16
17
|
// Now let's parse and add any config.yamls
|
|
17
18
|
for (const y of glob.sync("**/config.yaml", { cwd: source })) {
|
|
18
|
-
const
|
|
19
|
+
const filePath = path.join(source, y);
|
|
20
|
+
const file = fs.readFileSync(filePath, "utf8");
|
|
19
21
|
const asYAML = yaml.parse(file);
|
|
20
|
-
debug('stepzen:transpiler')(`Adding config.yaml ${
|
|
22
|
+
debug('stepzen:transpiler')(`Adding config.yaml ${filePath}`);
|
|
21
23
|
debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asYAML, null, 2)}`);
|
|
22
24
|
if (asYAML.configurationset) {
|
|
23
25
|
config.configurationset = config.configurationset.concat(asYAML.configurationset);
|
|
@@ -32,9 +34,10 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
32
34
|
cwd: source,
|
|
33
35
|
})), _h; _h = await _g.next(), !_h.done;) {
|
|
34
36
|
const j = _h.value;
|
|
35
|
-
const
|
|
37
|
+
const filePath = path.join(source, j);
|
|
38
|
+
const file = fs.readFileSync(filePath, "utf8");
|
|
36
39
|
const asJSON = JSON.parse(file);
|
|
37
|
-
debug('stepzen:transpiler')(`Adding stepzen.config.json ${
|
|
40
|
+
debug('stepzen:transpiler')(`Adding stepzen.config.json ${filePath}`);
|
|
38
41
|
debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asJSON, null, 2)}`);
|
|
39
42
|
if ((_c = asJSON.config) === null || _c === void 0 ? void 0 : _c.questions) {
|
|
40
43
|
try {
|
package/lib/actions/lint.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const node_fetch_1 = require("node-fetch");
|
|
4
4
|
const fs = require("fs-extra");
|
|
5
5
|
const os = require("os");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const shell = require("shelljs");
|
|
7
8
|
const stitch_1 = require("../actions/stitch");
|
|
8
9
|
exports.default = async (source, options = {
|
|
@@ -17,11 +18,13 @@ exports.default = async (source, options = {
|
|
|
17
18
|
extensions = await response.text();
|
|
18
19
|
}
|
|
19
20
|
const stitched = stitch_1.default(source);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
21
|
+
const index = path.join(stitched, 'index.graphql');
|
|
22
|
+
const graphql = fs.readFileSync(index, 'utf8');
|
|
23
|
+
const tmp = path.join(os.tmpdir(), `stepzen-lint-${Date.now()}`);
|
|
22
24
|
fs.ensureDirSync(tmp);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const lintFile = path.join(tmp, 'index.graphql');
|
|
26
|
+
fs.writeFileSync(lintFile, `${extensions}${os.EOL}${os.EOL}${graphql}`);
|
|
27
|
+
shell.exec(`npx graphql-schema-linter ${lintFile}`, { silent: true }, (code, stdout, stderr) => {
|
|
25
28
|
console.log(stdout);
|
|
26
29
|
fs.removeSync(tmp);
|
|
27
30
|
});
|
package/lib/actions/merge.js
CHANGED
|
@@ -5,6 +5,7 @@ const glob = require("glob");
|
|
|
5
5
|
const merge_1 = require("@graphql-tools/merge");
|
|
6
6
|
const graphql_1 = require("graphql");
|
|
7
7
|
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
8
9
|
const merge_helpers_1 = require("../utils/merge-helpers");
|
|
9
10
|
const print_1 = require("./print");
|
|
10
11
|
const set_files_in_sdl_1 = require("../utils/set-files-in-sdl");
|
|
@@ -27,9 +28,14 @@ exports.default = async (original, imported, options = {
|
|
|
27
28
|
if (!options.answers)
|
|
28
29
|
options.answers = {};
|
|
29
30
|
if (!options.output)
|
|
30
|
-
options.output =
|
|
31
|
+
options.output = `stepzen-tmp-${Date.now()}`;
|
|
31
32
|
if (!options.silent)
|
|
32
33
|
options.silent = false;
|
|
34
|
+
// To stop things like
|
|
35
|
+
// C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
|
|
36
|
+
const regex = new RegExp(os.tmpdir(), 'gi');
|
|
37
|
+
options.output = options.output.replace(regex, '');
|
|
38
|
+
options.output = path.join(os.tmpdir(), options.output);
|
|
33
39
|
// Ensure original, importing and output directories exist
|
|
34
40
|
if (!fs.existsSync(original))
|
|
35
41
|
throw new Error(`Cannot find original directory ${original}`);
|
|
@@ -39,8 +45,9 @@ exports.default = async (original, imported, options = {
|
|
|
39
45
|
// Copy the original into the output.
|
|
40
46
|
fs.copySync(original, options.output);
|
|
41
47
|
// Ensure an index.graphql exists
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
const outputIndex = path.join(options.output, 'index.graphql');
|
|
49
|
+
if (!fs.existsSync(outputIndex)) {
|
|
50
|
+
fs.writeFileSync(outputIndex, BLANK_INDEX_TEMPLATE);
|
|
44
51
|
}
|
|
45
52
|
const merged = merge_1.mergeTypeDefs([
|
|
46
53
|
await merge_helpers_1.getSchema(options.output),
|
|
@@ -100,19 +107,24 @@ exports.default = async (original, imported, options = {
|
|
|
100
107
|
};
|
|
101
108
|
// Write the files to the output directory
|
|
102
109
|
cleaned.original.forEach((a) => {
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
// eslint-disable-next-line
|
|
111
|
+
const file = path.join(options.output, a.file);
|
|
112
|
+
fs.ensureFileSync(file);
|
|
113
|
+
fs.writeFileSync(file, print_1.default(a.ast));
|
|
105
114
|
});
|
|
106
115
|
cleaned.imported.forEach((a) => {
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
// eslint-disable-next-line
|
|
117
|
+
const file = path.join(options.output, imported.name, a.file);
|
|
118
|
+
fs.ensureFileSync(file);
|
|
119
|
+
fs.writeFileSync(file, print_1.default(a.ast));
|
|
109
120
|
});
|
|
110
121
|
// Make sure all files are referenced in @sdl
|
|
111
122
|
set_files_in_sdl_1.default(options.output);
|
|
112
123
|
// Generate configuration
|
|
113
124
|
const config = await merge_helpers_1.getConfiguration([options.output, imported.source], options.silent, options.answers);
|
|
114
125
|
if (config) {
|
|
115
|
-
|
|
126
|
+
const configFile = path.join(options.output, 'config.yaml');
|
|
127
|
+
fs.writeFileSync(configFile, config);
|
|
116
128
|
}
|
|
117
129
|
// Return a merged schema!
|
|
118
130
|
return options.output;
|
package/lib/actions/stitch.js
CHANGED
|
@@ -5,9 +5,10 @@ const graphql_1 = require("graphql");
|
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const glob = require("glob");
|
|
7
7
|
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
8
9
|
const prettier = require("prettier");
|
|
9
10
|
const dedupe_query_and_mutation_types_1 = require("../utils/dedupe-query-and-mutation-types");
|
|
10
|
-
exports.default = (source, output =
|
|
11
|
+
exports.default = (source, output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)) => {
|
|
11
12
|
// Ensure source and output directories exist
|
|
12
13
|
if (!fs.existsSync(source))
|
|
13
14
|
throw new Error(`Cannot find source directory ${source}`);
|
|
@@ -16,8 +17,9 @@ exports.default = (source, output = `${os.tmpdir()}/stepzen-tmp-${Date.now()}`)
|
|
|
16
17
|
let ast;
|
|
17
18
|
let files = [];
|
|
18
19
|
// If there's an index.graphQL - get files argument in @sdl directive
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const sourceIndex = path.join(source, 'index.graphql');
|
|
21
|
+
if (fs.existsSync(sourceIndex)) {
|
|
22
|
+
const index = fs.readFileSync(sourceIndex, "utf8");
|
|
21
23
|
ast = graphql_1.parse(index);
|
|
22
24
|
ast = graphql_1.visit(ast, {
|
|
23
25
|
Directive(node) {
|
|
@@ -45,7 +47,7 @@ exports.default = (source, output = `${os.tmpdir()}/stepzen-tmp-${Date.now()}`)
|
|
|
45
47
|
const graphql = fs.readFileSync(`${source}/${file}`, "utf8");
|
|
46
48
|
return graphql;
|
|
47
49
|
});
|
|
48
|
-
ast = graphql_1.parse(content.join(
|
|
50
|
+
ast = graphql_1.parse(content.join(os.EOL));
|
|
49
51
|
}
|
|
50
52
|
// Strip @sdl directive
|
|
51
53
|
ast = graphql_1.visit(ast, {
|
|
@@ -56,26 +58,31 @@ exports.default = (source, output = `${os.tmpdir()}/stepzen-tmp-${Date.now()}`)
|
|
|
56
58
|
});
|
|
57
59
|
// Check all the files exist
|
|
58
60
|
for (const file of files) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const find = path.join(source, file);
|
|
62
|
+
if (!fs.existsSync(find)) {
|
|
63
|
+
throw new Error(`Cannot find file ${find}`);
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
// Get all the files and stitch
|
|
64
67
|
const printed = graphql_1.print(ast);
|
|
65
|
-
let stitched = `${printed}
|
|
68
|
+
let stitched = `${printed}${os.EOL}`;
|
|
66
69
|
for (const file of files) {
|
|
67
|
-
const
|
|
68
|
-
|
|
70
|
+
const find = path.join(source, file);
|
|
71
|
+
const content = fs.readFileSync(find, "utf8");
|
|
72
|
+
stitched += `${content}${os.EOL}`;
|
|
69
73
|
}
|
|
70
74
|
// Dedupe Query and Mutation types
|
|
71
75
|
stitched = dedupe_query_and_mutation_types_1.default(stitched);
|
|
72
76
|
// Format
|
|
73
77
|
stitched = prettier.format(stitched, { parser: "graphql" });
|
|
74
78
|
// Write to output folder
|
|
75
|
-
|
|
79
|
+
const outputIndex = path.join(output, 'index.graphql');
|
|
80
|
+
fs.writeFileSync(outputIndex, stitched);
|
|
76
81
|
// Copy config if exists, too
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
const sourceConfig = path.join(source, 'config.yaml');
|
|
83
|
+
const outputConfig = path.join(output, 'config.yaml');
|
|
84
|
+
if (fs.existsSync(sourceConfig)) {
|
|
85
|
+
fs.copyFileSync(sourceConfig, outputConfig);
|
|
79
86
|
}
|
|
80
87
|
// Return output folder
|
|
81
88
|
return output;
|
package/lib/actions/transpile.js
CHANGED
|
@@ -49,7 +49,8 @@ exports.default = async (source) => {
|
|
|
49
49
|
let mutated = '';
|
|
50
50
|
if (graphqlFiles.length > 0) {
|
|
51
51
|
const stitched = await stitch_1.default(source);
|
|
52
|
-
const
|
|
52
|
+
const index = path.join(stitched, 'index.graphql');
|
|
53
|
+
const graphql = fs.readFileSync(index, "utf8");
|
|
53
54
|
let ast = graphql_1.parse(graphql);
|
|
54
55
|
original = graphql_1.parse(graphql);
|
|
55
56
|
// you can transpile schema ast here
|
package/lib/actions/validate.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const graphql_1 = require("graphql");
|
|
4
4
|
const fs = require("fs-extra");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const path = require("path");
|
|
5
7
|
const ensure_query_and_mutation_types_1 = require("../utils/ensure-query-and-mutation-types");
|
|
6
8
|
const constants_1 = require("../utils/constants");
|
|
7
9
|
const validators_1 = require("../validators");
|
|
@@ -17,9 +19,10 @@ exports.default = (source, options = {
|
|
|
17
19
|
throw new Error(`Cannot find index.graphql in ${source}`);
|
|
18
20
|
}
|
|
19
21
|
// Get the index.graphql file
|
|
20
|
-
const
|
|
22
|
+
const file = path.join(source, 'index.graphql');
|
|
23
|
+
const index = fs.readFileSync(file, "utf8");
|
|
21
24
|
// Parse
|
|
22
|
-
let ast = graphql_1.parse(`${constants_1.EXPERIMENTAL_EXTENSIONS}
|
|
25
|
+
let ast = graphql_1.parse(`${constants_1.EXPERIMENTAL_EXTENSIONS}${os.EOL}${options.extensions}${os.EOL}${index}`, {
|
|
23
26
|
noLocation: true,
|
|
24
27
|
});
|
|
25
28
|
// We make an exception for 'no type Query' or 'no type Mutation'
|
|
@@ -7,6 +7,7 @@ const node_fetch_1 = require("node-fetch");
|
|
|
7
7
|
const fs = require("fs-extra");
|
|
8
8
|
const glob = require("glob");
|
|
9
9
|
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
10
11
|
const graphql_helpers_1 = require("../utils/graphql-helpers");
|
|
11
12
|
const constants_1 = require("./constants");
|
|
12
13
|
const configure_1 = require("../actions/configure");
|
|
@@ -46,7 +47,7 @@ const findTypeInSchema = (name, files) => {
|
|
|
46
47
|
};
|
|
47
48
|
exports.findTypeInSchema = findTypeInSchema;
|
|
48
49
|
const getConfiguration = async (directories, silent = false, answers = {}) => {
|
|
49
|
-
const tmp =
|
|
50
|
+
const tmp = path.join(os.tmpdir(), `stepzen-tmp-config-${Date.now()}`);
|
|
50
51
|
fs.ensureDirSync(tmp);
|
|
51
52
|
for (const directory of directories) {
|
|
52
53
|
const configs = [
|
|
@@ -54,9 +55,11 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
|
|
|
54
55
|
...glob.sync("**/stepzen.config.json", { cwd: directory }),
|
|
55
56
|
];
|
|
56
57
|
for (const config of configs) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
fs.
|
|
58
|
+
const configFolder = path.join(directory, config);
|
|
59
|
+
const writeFolder = path.join(tmp, directory, config);
|
|
60
|
+
const content = fs.readFileSync(configFolder, "utf8");
|
|
61
|
+
fs.ensureFileSync(writeFolder);
|
|
62
|
+
fs.writeFileSync(writeFolder, content);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
const configuration = await configure_1.default(tmp, silent, answers);
|
|
@@ -74,7 +77,7 @@ exports.getExtensions = getExtensions;
|
|
|
74
77
|
const getSchema = async (directory) => {
|
|
75
78
|
const extensions = await exports.getExtensions();
|
|
76
79
|
const transpiled = await transpile_1.default(directory);
|
|
77
|
-
return utilities_1.buildSchema(`${extensions}
|
|
80
|
+
return utilities_1.buildSchema(`${extensions}${os.EOL}${transpiled.schema}`);
|
|
78
81
|
};
|
|
79
82
|
exports.getSchema = getSchema;
|
|
80
83
|
const mergeQueryMutationIntoSchema = (type, files) => {
|
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const glob = require("glob");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const graphql_helpers_1 = require("./graphql-helpers");
|
|
7
8
|
const print_1 = require("../actions/print");
|
|
8
9
|
exports.default = (source) => {
|
|
9
10
|
const files = glob
|
|
10
11
|
.sync("**/*.graphql", { cwd: source })
|
|
11
12
|
.filter((file) => file !== "index.graphql");
|
|
12
|
-
const
|
|
13
|
+
const output = path.join(source, 'index.graphql');
|
|
14
|
+
const index = fs.readFileSync(output, "utf8");
|
|
13
15
|
let ast = graphql_1.parse(index);
|
|
14
16
|
ast = graphql_1.visit(ast, {
|
|
15
17
|
Directive(node) {
|
|
@@ -28,5 +30,5 @@ exports.default = (source) => {
|
|
|
28
30
|
}
|
|
29
31
|
},
|
|
30
32
|
});
|
|
31
|
-
fs.writeFileSync(
|
|
33
|
+
fs.writeFileSync(output, print_1.default(ast));
|
|
32
34
|
};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const graphql_1 = require("graphql");
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const yaml = require("yaml");
|
|
7
8
|
const STEPZEN_DEFAULTS = [
|
|
8
9
|
'fedex_default',
|
|
@@ -27,10 +28,11 @@ exports.default = (ast, source) => {
|
|
|
27
28
|
configs = lodash_1.uniq(configs);
|
|
28
29
|
configs = lodash_1.filter(configs, (config) => !STEPZEN_DEFAULTS.includes(config));
|
|
29
30
|
if (configs.length > 0) {
|
|
30
|
-
|
|
31
|
+
const sourceConfig = path.join(source, 'config.yaml');
|
|
32
|
+
if (!fs.existsSync(sourceConfig)) {
|
|
31
33
|
throw new Error('No config.yaml found');
|
|
32
34
|
}
|
|
33
|
-
const content = fs.readFileSync(
|
|
35
|
+
const content = fs.readFileSync(sourceConfig, 'utf8');
|
|
34
36
|
const asYaml = yaml.parse(content);
|
|
35
37
|
for (const config of configs) {
|
|
36
38
|
const found = (_a = asYaml === null || asYaml === void 0 ? void 0 : asYaml.configurationset) === null || _a === void 0 ? void 0 : _a.find((c) => {
|