@stepzen/transpiler 0.0.31 → 0.0.32
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 +10 -8
- package/lib/actions/lint.js +4 -4
- package/lib/actions/merge.js +8 -6
- package/lib/actions/stitch.js +4 -4
- package/lib/actions/transpile.js +4 -4
- package/lib/actions/validate.js +1 -1
- package/lib/mutations/config/envvars.js +2 -2
- package/lib/mutations/config/index.js +1 -3
- package/lib/utils/constants.js +2 -2
- package/lib/utils/merge-helpers.js +3 -3
- package/lib/utils/set-files-in-sdl.js +1 -1
- package/lib/validators/config-exists/index.js +8 -8
- package/lib/validators/index.js +1 -3
- package/package.json +1 -1
package/lib/actions/configure.js
CHANGED
|
@@ -19,8 +19,8 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
19
19
|
const filePath = path.join(source, y);
|
|
20
20
|
const file = fs.readFileSync(filePath, "utf8");
|
|
21
21
|
const asYAML = yaml.parse(file);
|
|
22
|
-
debug(
|
|
23
|
-
debug(
|
|
22
|
+
debug("stepzen:transpiler")(`Adding config.yaml ${filePath}`);
|
|
23
|
+
debug("stepzen:transpiler")(`Contents: ${JSON.stringify(asYAML, null, 2)}`);
|
|
24
24
|
if (asYAML.configurationset) {
|
|
25
25
|
config.configurationset = config.configurationset.concat(asYAML.configurationset);
|
|
26
26
|
}
|
|
@@ -37,8 +37,8 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
37
37
|
const filePath = path.join(source, j);
|
|
38
38
|
const file = fs.readFileSync(filePath, "utf8");
|
|
39
39
|
const asJSON = JSON.parse(file);
|
|
40
|
-
debug(
|
|
41
|
-
debug(
|
|
40
|
+
debug("stepzen:transpiler")(`Adding stepzen.config.json ${filePath}`);
|
|
41
|
+
debug("stepzen:transpiler")(`Contents: ${JSON.stringify(asJSON, null, 2)}`);
|
|
42
42
|
if ((_c = asJSON.config) === null || _c === void 0 ? void 0 : _c.questions) {
|
|
43
43
|
try {
|
|
44
44
|
for (var _j = (e_2 = void 0, tslib_1.__asyncValues((_d = asJSON.config) === null || _d === void 0 ? void 0 : _d.questions)), _k; _k = await _j.next(), !_k.done;) {
|
|
@@ -46,7 +46,9 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
46
46
|
const [name, key] = question.name.split(".");
|
|
47
47
|
let answer = {};
|
|
48
48
|
if (silent) {
|
|
49
|
-
answer = {
|
|
49
|
+
answer = {
|
|
50
|
+
[name]: { [key]: ((_e = answers[name]) === null || _e === void 0 ? void 0 : _e[key]) ? (_f = answers[name]) === null || _f === void 0 ? void 0 : _f[key] : "" },
|
|
51
|
+
};
|
|
50
52
|
}
|
|
51
53
|
else {
|
|
52
54
|
answer = await inquirer.prompt(Object.assign({ type: "password" }, question));
|
|
@@ -57,8 +59,8 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
57
59
|
[key]: answer[name][key],
|
|
58
60
|
},
|
|
59
61
|
};
|
|
60
|
-
debug(
|
|
61
|
-
debug(
|
|
62
|
+
debug("stepzen:transpiler")(`Question: ${JSON.stringify(question, null, 2)}`);
|
|
63
|
+
debug("stepzen:transpiler")(`Answer: ${JSON.stringify(configset, null, 2)}`);
|
|
62
64
|
config.configurationset.push(Object.assign({}, configset));
|
|
63
65
|
}
|
|
64
66
|
}
|
|
@@ -79,7 +81,7 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
79
81
|
}
|
|
80
82
|
finally { if (e_1) throw e_1.error; }
|
|
81
83
|
}
|
|
82
|
-
debug(
|
|
84
|
+
debug("stepzen:transpiler")(`Configuration: ${JSON.stringify(config, null, 2)}`);
|
|
83
85
|
// OK now let's collate everything into shared configurations
|
|
84
86
|
const obj = {};
|
|
85
87
|
for (const c of config.configurationset) {
|
package/lib/actions/lint.js
CHANGED
|
@@ -14,15 +14,15 @@ exports.default = async (source, options = {
|
|
|
14
14
|
}
|
|
15
15
|
let extensions = options.extensions;
|
|
16
16
|
if (!extensions) {
|
|
17
|
-
const response = await node_fetch_1.default(
|
|
17
|
+
const response = await node_fetch_1.default("https://www.steprz.net/directives.graphql");
|
|
18
18
|
extensions = await response.text();
|
|
19
19
|
}
|
|
20
20
|
const stitched = stitch_1.default(source);
|
|
21
|
-
const index = path.join(stitched,
|
|
22
|
-
const graphql = fs.readFileSync(index,
|
|
21
|
+
const index = path.join(stitched, "index.graphql");
|
|
22
|
+
const graphql = fs.readFileSync(index, "utf8");
|
|
23
23
|
const tmp = path.join(os.tmpdir(), `stepzen-lint-${Date.now()}`);
|
|
24
24
|
fs.ensureDirSync(tmp);
|
|
25
|
-
const lintFile = path.join(tmp,
|
|
25
|
+
const lintFile = path.join(tmp, "index.graphql");
|
|
26
26
|
fs.writeFileSync(lintFile, `${extensions}${os.EOL}${os.EOL}${graphql}`);
|
|
27
27
|
shell.exec(`npx graphql-schema-linter ${lintFile}`, { silent: true }, (code, stdout, stderr) => {
|
|
28
28
|
console.log(stdout);
|
package/lib/actions/merge.js
CHANGED
|
@@ -43,7 +43,7 @@ exports.default = async (original, imported, options = {
|
|
|
43
43
|
// Copy the original into the output.
|
|
44
44
|
fs.copySync(original, options.output);
|
|
45
45
|
// Ensure an index.graphql exists
|
|
46
|
-
const outputIndex = path.join(options.output,
|
|
46
|
+
const outputIndex = path.join(options.output, "index.graphql");
|
|
47
47
|
if (!fs.existsSync(outputIndex)) {
|
|
48
48
|
fs.writeFileSync(outputIndex, BLANK_INDEX_TEMPLATE);
|
|
49
49
|
}
|
|
@@ -107,21 +107,23 @@ exports.default = async (original, imported, options = {
|
|
|
107
107
|
cleaned.original.forEach((a) => {
|
|
108
108
|
// eslint-disable-next-line
|
|
109
109
|
const file = path.join(options.output, a.file);
|
|
110
|
-
|
|
111
|
-
fs.
|
|
110
|
+
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
111
|
+
fs.ensureFileSync(deduped);
|
|
112
|
+
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
112
113
|
});
|
|
113
114
|
cleaned.imported.forEach((a) => {
|
|
114
115
|
// eslint-disable-next-line
|
|
115
116
|
const file = path.join(options.output, imported.name, a.file);
|
|
116
|
-
|
|
117
|
-
fs.
|
|
117
|
+
const deduped = merge_helpers_1.dedupeTempFolder(file);
|
|
118
|
+
fs.ensureFileSync(deduped);
|
|
119
|
+
fs.writeFileSync(deduped, print_1.default(a.ast));
|
|
118
120
|
});
|
|
119
121
|
// Make sure all files are referenced in @sdl
|
|
120
122
|
set_files_in_sdl_1.default(options.output);
|
|
121
123
|
// Generate configuration
|
|
122
124
|
const config = await merge_helpers_1.getConfiguration([options.output, imported.source], options.silent, options.answers);
|
|
123
125
|
if (config) {
|
|
124
|
-
const configFile = path.join(options.output,
|
|
126
|
+
const configFile = path.join(options.output, "config.yaml");
|
|
125
127
|
fs.writeFileSync(configFile, config);
|
|
126
128
|
}
|
|
127
129
|
// Return a merged schema!
|
package/lib/actions/stitch.js
CHANGED
|
@@ -17,7 +17,7 @@ exports.default = (source, output = path.join(os.tmpdir(), `stepzen-tmp-${Date.n
|
|
|
17
17
|
let ast;
|
|
18
18
|
let files = [];
|
|
19
19
|
// If there's an index.graphQL - get files argument in @sdl directive
|
|
20
|
-
const sourceIndex = path.join(source,
|
|
20
|
+
const sourceIndex = path.join(source, "index.graphql");
|
|
21
21
|
if (fs.existsSync(sourceIndex)) {
|
|
22
22
|
const index = fs.readFileSync(sourceIndex, "utf8");
|
|
23
23
|
ast = graphql_1.parse(index);
|
|
@@ -76,11 +76,11 @@ exports.default = (source, output = path.join(os.tmpdir(), `stepzen-tmp-${Date.n
|
|
|
76
76
|
// Format
|
|
77
77
|
stitched = prettier.format(stitched, { parser: "graphql" });
|
|
78
78
|
// Write to output folder
|
|
79
|
-
const outputIndex = path.join(output,
|
|
79
|
+
const outputIndex = path.join(output, "index.graphql");
|
|
80
80
|
fs.writeFileSync(outputIndex, stitched);
|
|
81
81
|
// Copy config if exists, too
|
|
82
|
-
const sourceConfig = path.join(source,
|
|
83
|
-
const outputConfig = path.join(output,
|
|
82
|
+
const sourceConfig = path.join(source, "config.yaml");
|
|
83
|
+
const outputConfig = path.join(output, "config.yaml");
|
|
84
84
|
if (fs.existsSync(sourceConfig)) {
|
|
85
85
|
fs.copyFileSync(sourceConfig, outputConfig);
|
|
86
86
|
}
|
package/lib/actions/transpile.js
CHANGED
|
@@ -45,11 +45,11 @@ exports.default = async (source) => {
|
|
|
45
45
|
}
|
|
46
46
|
// See whether to transpile GraphQL
|
|
47
47
|
const graphqlFiles = glob.sync("**/*.graphql", { cwd: source });
|
|
48
|
-
let original =
|
|
49
|
-
let mutated =
|
|
48
|
+
let original = "";
|
|
49
|
+
let mutated = "";
|
|
50
50
|
if (graphqlFiles.length > 0) {
|
|
51
51
|
const stitched = await stitch_1.default(source);
|
|
52
|
-
const index = path.join(stitched,
|
|
52
|
+
const index = path.join(stitched, "index.graphql");
|
|
53
53
|
const graphql = fs.readFileSync(index, "utf8");
|
|
54
54
|
let ast = graphql_1.parse(graphql);
|
|
55
55
|
original = graphql_1.parse(graphql);
|
|
@@ -62,6 +62,6 @@ exports.default = async (source) => {
|
|
|
62
62
|
return {
|
|
63
63
|
config,
|
|
64
64
|
schema: mutated,
|
|
65
|
-
transpiled: transpiledConfig || transpiledGraphQL
|
|
65
|
+
transpiled: transpiledConfig || transpiledGraphQL,
|
|
66
66
|
};
|
|
67
67
|
};
|
package/lib/actions/validate.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.default = (source, options = {
|
|
|
19
19
|
throw new Error(`Cannot find index.graphql in ${source}`);
|
|
20
20
|
}
|
|
21
21
|
// Get the index.graphql file
|
|
22
|
-
const file = path.join(source,
|
|
22
|
+
const file = path.join(source, "index.graphql");
|
|
23
23
|
const index = fs.readFileSync(file, "utf8");
|
|
24
24
|
// Parse
|
|
25
25
|
let ast = graphql_1.parse(`${constants_1.EXPERIMENTAL_EXTENSIONS}${os.EOL}${options.extensions}${os.EOL}${index}`, {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = async (config) => {
|
|
4
4
|
const envvars = Object.keys(process.env)
|
|
5
|
-
.filter(key => {
|
|
5
|
+
.filter((key) => {
|
|
6
6
|
return key.startsWith(`STEPZEN_`);
|
|
7
7
|
})
|
|
8
8
|
.reduce((obj, key) => {
|
|
@@ -10,7 +10,7 @@ exports.default = async (config) => {
|
|
|
10
10
|
return obj;
|
|
11
11
|
}, {});
|
|
12
12
|
for (const [key, value] of Object.entries(envvars)) {
|
|
13
|
-
const regex = new RegExp(key,
|
|
13
|
+
const regex = new RegExp(key, "g");
|
|
14
14
|
config = config.replace(regex, `${value}`);
|
|
15
15
|
}
|
|
16
16
|
return config;
|
package/lib/utils/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.STEPZEN_DOMAIN = exports.EXPERIMENTAL_EXTENSIONS = void 0;
|
|
4
4
|
const dotenv = require("dotenv");
|
|
5
5
|
dotenv.config();
|
|
6
|
-
const { STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN
|
|
6
|
+
const { STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN } = process.env;
|
|
7
7
|
exports.EXPERIMENTAL_EXTENSIONS = `
|
|
8
8
|
directive @experimental(
|
|
9
9
|
debug: Boolean
|
|
@@ -12,4 +12,4 @@ directive @experimental(
|
|
|
12
12
|
setter: String
|
|
13
13
|
) on OBJECT | FIELD_DEFINITION
|
|
14
14
|
`;
|
|
15
|
-
exports.STEPZEN_DOMAIN = ENV_VAR_STEPZEN_DOMAIN ||
|
|
15
|
+
exports.STEPZEN_DOMAIN = ENV_VAR_STEPZEN_DOMAIN || "stepzen.io";
|
|
@@ -13,8 +13,8 @@ const constants_1 = require("./constants");
|
|
|
13
13
|
const configure_1 = require("../actions/configure");
|
|
14
14
|
const transpile_1 = require("../actions/transpile");
|
|
15
15
|
const dedupeTempFolder = (dirpath) => {
|
|
16
|
-
const regex = new RegExp(os.tmpdir(),
|
|
17
|
-
dirpath = dirpath.replace(regex,
|
|
16
|
+
const regex = new RegExp(os.tmpdir(), "gi");
|
|
17
|
+
dirpath = dirpath.replace(regex, "");
|
|
18
18
|
dirpath = path.join(os.tmpdir(), dirpath);
|
|
19
19
|
return dirpath;
|
|
20
20
|
};
|
|
@@ -76,7 +76,7 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
|
|
|
76
76
|
};
|
|
77
77
|
exports.getConfiguration = getConfiguration;
|
|
78
78
|
const getExtensions = async () => {
|
|
79
|
-
const domain = constants_1.STEPZEN_DOMAIN.replace(
|
|
79
|
+
const domain = constants_1.STEPZEN_DOMAIN.replace(".io", ".net");
|
|
80
80
|
const response = await node_fetch_1.default(`https://www.${domain}/directives.graphql`);
|
|
81
81
|
const text = await response.text();
|
|
82
82
|
return text;
|
|
@@ -10,7 +10,7 @@ exports.default = (source) => {
|
|
|
10
10
|
const files = glob
|
|
11
11
|
.sync("**/*.graphql", { cwd: source })
|
|
12
12
|
.filter((file) => file !== "index.graphql");
|
|
13
|
-
const output = path.join(source,
|
|
13
|
+
const output = path.join(source, "index.graphql");
|
|
14
14
|
const index = fs.readFileSync(output, "utf8");
|
|
15
15
|
let ast = graphql_1.parse(index);
|
|
16
16
|
ast = graphql_1.visit(ast, {
|
|
@@ -6,11 +6,11 @@ const fs = require("fs");
|
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const yaml = require("yaml");
|
|
8
8
|
const STEPZEN_DEFAULTS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
"fedex_default",
|
|
10
|
+
"holidayapi_default",
|
|
11
|
+
"ipapi_default",
|
|
12
|
+
"owm_default",
|
|
13
|
+
"ups_default",
|
|
14
14
|
];
|
|
15
15
|
exports.default = (ast, source) => {
|
|
16
16
|
var _a;
|
|
@@ -28,11 +28,11 @@ exports.default = (ast, source) => {
|
|
|
28
28
|
configs = lodash_1.uniq(configs);
|
|
29
29
|
configs = lodash_1.filter(configs, (config) => !STEPZEN_DEFAULTS.includes(config));
|
|
30
30
|
if (configs.length > 0) {
|
|
31
|
-
const sourceConfig = path.join(source,
|
|
31
|
+
const sourceConfig = path.join(source, "config.yaml");
|
|
32
32
|
if (!fs.existsSync(sourceConfig)) {
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error("No config.yaml found");
|
|
34
34
|
}
|
|
35
|
-
const content = fs.readFileSync(sourceConfig,
|
|
35
|
+
const content = fs.readFileSync(sourceConfig, "utf8");
|
|
36
36
|
const asYaml = yaml.parse(content);
|
|
37
37
|
for (const config of configs) {
|
|
38
38
|
const found = (_a = asYaml === null || asYaml === void 0 ? void 0 : asYaml.configurationset) === null || _a === void 0 ? void 0 : _a.find((c) => {
|
package/lib/validators/index.js
CHANGED