@stepzen/transpiler 0.21.0-beta.1 → 0.21.0-beta.4
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.d.ts +9 -0
- package/lib/actions/configure.d.ts.map +1 -1
- package/lib/actions/configure.js +67 -42
- package/lib/actions/configure.js.map +1 -1
- package/lib/actions/transpile.d.ts +2 -2
- package/lib/actions/transpile.d.ts.map +1 -1
- package/lib/actions/transpile.js +8 -12
- package/lib/actions/transpile.js.map +1 -1
- package/lib/mutations/config/envvars.d.ts.map +1 -1
- package/lib/mutations/config/envvars.js +10 -1
- package/lib/mutations/config/envvars.js.map +1 -1
- package/lib/utils/constants.d.ts.map +1 -1
- package/lib/utils/constants.js +2 -0
- package/lib/utils/constants.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/configure.ts +93 -50
- package/src/actions/transpile.ts +13 -19
- package/src/mutations/config/envvars.ts +17 -1
- package/src/utils/constants.ts +4 -0
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get effective StepZen endpoint configuration for a directory:
|
|
3
|
+
* Traverse the file system starting at `source` and
|
|
4
|
+
* - merge all `config.yaml` files (discarding unrecognized properties)
|
|
5
|
+
* - merge all `config` sections from `stepzen.config.json` files
|
|
6
|
+
*
|
|
7
|
+
* Possibly, interactive: if `silent` is `false` and there are non-empty
|
|
8
|
+
* `config` sections in `stepzen.config.json` files.
|
|
9
|
+
*/
|
|
1
10
|
declare const _default: (source: string, silent?: boolean, answers?: any) => Promise<string | false>;
|
|
2
11
|
export default _default;
|
|
3
12
|
//# sourceMappingURL=configure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;iCAC2B,MAAM,8BAA2B,GAAG;AAAlE,wBA+JC"}
|
package/lib/actions/configure.js
CHANGED
|
@@ -6,45 +6,68 @@ const glob = require("glob");
|
|
|
6
6
|
const inquirer = require("inquirer");
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const yaml = require("yaml");
|
|
9
|
+
/**
|
|
10
|
+
* Get effective StepZen endpoint configuration for a directory:
|
|
11
|
+
* Traverse the file system starting at `source` and
|
|
12
|
+
* - merge all `config.yaml` files (discarding unrecognized properties)
|
|
13
|
+
* - merge all `config` sections from `stepzen.config.json` files
|
|
14
|
+
*
|
|
15
|
+
* Possibly, interactive: if `silent` is `false` and there are non-empty
|
|
16
|
+
* `config` sections in `stepzen.config.json` files.
|
|
17
|
+
*/
|
|
9
18
|
exports.default = async (source, silent = false, answers = {}) => {
|
|
10
|
-
|
|
19
|
+
const config = {
|
|
11
20
|
configurationset: [],
|
|
12
21
|
ruleset: [],
|
|
22
|
+
access: undefined,
|
|
23
|
+
deployment: undefined,
|
|
13
24
|
};
|
|
25
|
+
debug('stepzen:transpiler:config')(`getting effective config for ${source}`);
|
|
14
26
|
// Now let's parse and add any config.yamls
|
|
27
|
+
let configYamlCount = 0;
|
|
15
28
|
for (const y of glob.sync('**/config.yaml', { cwd: source })) {
|
|
16
29
|
const filePath = path.join(source, y);
|
|
17
30
|
const file = fs.readFileSync(filePath, 'utf8');
|
|
18
31
|
let asYAML;
|
|
19
32
|
try {
|
|
20
|
-
asYAML = yaml.parse(file);
|
|
33
|
+
asYAML = yaml.parse(file, { schema: 'failsafe' });
|
|
21
34
|
}
|
|
22
35
|
catch (error) {
|
|
23
|
-
debug('stepzen:transpiler')(`
|
|
36
|
+
debug('stepzen:transpiler:config')(`Ignoring an invalid config.yaml ${filePath}.` +
|
|
37
|
+
` YAML parse error: ${error}`);
|
|
24
38
|
continue;
|
|
25
39
|
}
|
|
26
40
|
if (!asYAML) {
|
|
27
|
-
debug('stepzen:transpiler')(`
|
|
41
|
+
debug('stepzen:transpiler:config')(`ignoring an empty config.yaml ${filePath}`);
|
|
28
42
|
continue;
|
|
29
43
|
}
|
|
30
|
-
|
|
31
|
-
debug('stepzen:transpiler')(`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
configYamlCount += 1;
|
|
45
|
+
debug('stepzen:transpiler:config')(`adding config.yaml ${filePath}:\n${JSON.stringify(asYAML, null, 2)}`);
|
|
46
|
+
// strip away any non-recognized properties
|
|
47
|
+
Object.entries(asYAML).forEach(([keyAsAny, value]) => {
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(config, keyAsAny)) {
|
|
49
|
+
const key = keyAsAny;
|
|
50
|
+
config[key] = Array.isArray(config[key])
|
|
51
|
+
? config[key].concat(value)
|
|
52
|
+
: value;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
debug('stepzen:transpiler:config')(`ignoring unrecognized config property ${keyAsAny}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
38
58
|
}
|
|
59
|
+
debug('stepzen:transpiler:config')(`done adding **/config.yaml files (processed: ${configYamlCount})`);
|
|
39
60
|
// Now let's build configs from questions
|
|
61
|
+
let configJsonCount = 0;
|
|
40
62
|
for await (const j of glob.sync('**/stepzen.config.json', {
|
|
41
63
|
cwd: source,
|
|
42
64
|
})) {
|
|
43
65
|
const filePath = path.join(source, j);
|
|
44
66
|
const file = fs.readFileSync(filePath, 'utf8');
|
|
45
67
|
const asJSON = JSON.parse(file);
|
|
46
|
-
|
|
47
|
-
debug('stepzen:transpiler')(`
|
|
68
|
+
configJsonCount += 1;
|
|
69
|
+
debug('stepzen:transpiler:config')(`adding stepzen.config.json ${filePath}:` +
|
|
70
|
+
`\n${JSON.stringify(asJSON, null, 2)}`);
|
|
48
71
|
if (asJSON.config?.questions) {
|
|
49
72
|
for await (const question of asJSON.config?.questions) {
|
|
50
73
|
const [name, key] = question.name.split('.');
|
|
@@ -66,44 +89,46 @@ exports.default = async (source, silent = false, answers = {}) => {
|
|
|
66
89
|
[key]: answer[name][key],
|
|
67
90
|
},
|
|
68
91
|
};
|
|
69
|
-
debug('stepzen:transpiler')(`
|
|
70
|
-
debug('stepzen:transpiler')(`
|
|
92
|
+
debug('stepzen:transpiler:config')(`question: ${JSON.stringify(question, null, 2)}`);
|
|
93
|
+
debug('stepzen:transpiler:config')(`answer: ${JSON.stringify(configset, null, 2)}`);
|
|
71
94
|
config.configurationset.push({ ...configset });
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
}
|
|
75
|
-
debug('stepzen:transpiler')(`
|
|
98
|
+
debug('stepzen:transpiler:config')(`done adding **/stepzen.config.json files (processed: ${configJsonCount})`);
|
|
99
|
+
debug('stepzen:transpiler:config')(`combined content of all config files:` +
|
|
100
|
+
`\n${JSON.stringify(config, null, 2)}`);
|
|
76
101
|
// OK now let's collate everything into shared configurations
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
const configurationset = [];
|
|
103
|
+
{
|
|
104
|
+
const obj = {};
|
|
105
|
+
for (const c of config.configurationset) {
|
|
106
|
+
const name = c.configuration.name;
|
|
107
|
+
if (!obj[name])
|
|
108
|
+
obj[name] = {};
|
|
109
|
+
for (const [key, value] of Object.entries(c.configuration)) {
|
|
110
|
+
if (key === name)
|
|
111
|
+
continue;
|
|
112
|
+
obj[name][key] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const configuration of Object.keys(obj)) {
|
|
116
|
+
configurationset.push({
|
|
117
|
+
configuration: { ...obj[configuration] },
|
|
118
|
+
});
|
|
86
119
|
}
|
|
87
120
|
}
|
|
88
121
|
// Now convert back into StepZen format
|
|
89
|
-
const structured = {
|
|
90
|
-
configurationset: [],
|
|
91
|
-
ruleset: [],
|
|
92
|
-
};
|
|
93
|
-
for (const configuration of Object.keys(obj)) {
|
|
94
|
-
structured.configurationset.push({
|
|
95
|
-
configuration: { ...obj[configuration] },
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
structured.ruleset = [...config.ruleset];
|
|
122
|
+
const structured = Object.fromEntries(Object.entries({ ...config, configurationset }).filter(([_key, value]) => Array.isArray(value) ? value.length > 0 : value !== undefined));
|
|
99
123
|
// Return YAML, if appropriate
|
|
100
|
-
if (structured.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (structured.configurationset || structured.ruleset) {
|
|
105
|
-
return yaml.stringify(structured);
|
|
124
|
+
if (Object.keys(structured).length > 0) {
|
|
125
|
+
const configYamlStr = yaml.stringify(structured);
|
|
126
|
+
debug('stepzen:transpiler:config')(`effective config:\n${configYamlStr}`);
|
|
127
|
+
return configYamlStr;
|
|
106
128
|
}
|
|
129
|
+
debug('stepzen:transpiler:config')(`Could not find any of the supported properties in the config:` +
|
|
130
|
+
` [ '${Object.keys(config).join(`', '`)}' ].` +
|
|
131
|
+
` Retuning 'false' meaning 'effective config is empty'.`);
|
|
107
132
|
return false;
|
|
108
133
|
};
|
|
109
134
|
//# sourceMappingURL=configure.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.js","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,+BAA8B;AAC9B,6BAA4B;AAC5B,qCAAoC;AACpC,6BAA4B;AAC5B,6BAA4B;AAE5B,kBAAe,KAAK,EAAE,MAAc,EAAE,MAAM,GAAG,KAAK,EAAE,UAAe,EAAE,EAAE,EAAE;IACzE,
|
|
1
|
+
{"version":3,"file":"configure.js","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,+BAA8B;AAC9B,6BAA4B;AAC5B,qCAAoC;AACpC,6BAA4B;AAC5B,6BAA4B;AAE5B;;;;;;;;GAQG;AACH,kBAAe,KAAK,EAAE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GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QAChD,KAAK,CAAC,2BAA2B,CAAC,CAAC,sBAAsB,aAAa,EAAE,CAAC,CAAA;QACzE,OAAO,aAAa,CAAA;KACrB;IAED,KAAK,CAAC,2BAA2B,CAAC,CAChC,+DAA+D;QAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;QAC7C,wDAAwD,CAC3D,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":"iCAa8B,MAAM;;;;;AAApC,wBAkDC"}
|
package/lib/actions/transpile.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const graphql_1 = require("graphql");
|
|
4
4
|
const dotenv = require("dotenv");
|
|
5
|
+
const debug = require("debug");
|
|
5
6
|
const fs = require("fs");
|
|
6
7
|
const glob = require("glob");
|
|
7
8
|
const path = require("path");
|
|
@@ -15,11 +16,13 @@ exports.default = async (source) => {
|
|
|
15
16
|
throw new Error(`Cannot find source directory ${source}`);
|
|
16
17
|
}
|
|
17
18
|
// Load env vars, from working and source directories
|
|
19
|
+
debug('stepzen:dotenv')(`loading .env from ${process.cwd()}, at transpiler/src/actions/transpile.ts:24`);
|
|
18
20
|
dotenv.config();
|
|
21
|
+
debug('stepzen:dotenv')(`loading .env from ${path.resolve(source)}` +
|
|
22
|
+
`, at transpiler/src/actions/transpile.ts:29`);
|
|
19
23
|
dotenv.config({ path: path.resolve(source, '.env') });
|
|
20
24
|
// State of whether we've transpiled or not
|
|
21
25
|
let transpiledConfig = false;
|
|
22
|
-
let transpiledGraphQL = false;
|
|
23
26
|
// See whether to transpile config
|
|
24
27
|
let config = await (0, configure_1.default)(source, true);
|
|
25
28
|
const configCopy = config;
|
|
@@ -33,24 +36,17 @@ exports.default = async (source) => {
|
|
|
33
36
|
}
|
|
34
37
|
// See whether to transpile GraphQL
|
|
35
38
|
const graphqlFiles = glob.sync('**/*.graphql', { cwd: source });
|
|
36
|
-
let
|
|
37
|
-
let mutated = '';
|
|
39
|
+
let schema = '';
|
|
38
40
|
if (graphqlFiles.length > 0) {
|
|
39
41
|
const stitched = await (0, stitch_1.default)(source);
|
|
40
42
|
const index = path.join(stitched, 'index.graphql');
|
|
41
43
|
const graphql = fs.readFileSync(index, 'utf8');
|
|
42
|
-
|
|
43
|
-
original = (0, graphql_1.parse)(graphql);
|
|
44
|
-
// you can transpile schema ast here
|
|
45
|
-
mutated = (0, print_1.default)(ast);
|
|
46
|
-
if ((0, print_1.default)(original) !== mutated) {
|
|
47
|
-
transpiledGraphQL = true;
|
|
48
|
-
}
|
|
44
|
+
schema = (0, print_1.default)((0, graphql_1.parse)(graphql));
|
|
49
45
|
}
|
|
50
46
|
return {
|
|
51
47
|
config,
|
|
52
|
-
schema
|
|
53
|
-
transpiled: transpiledConfig
|
|
48
|
+
schema,
|
|
49
|
+
transpiled: transpiledConfig,
|
|
54
50
|
};
|
|
55
51
|
};
|
|
56
52
|
//# sourceMappingURL=transpile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile.js","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAC3C,iCAAgC;AAChC,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,4CAAoC;AACpC,8CAAsC;AACtC,2CAAmC;AAEnC,gDAAiD;AAEjD,kBAAe,KAAK,EAAE,MAAc,EAAE,EAAE;IACtC,6CAA6C;IAC7C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAA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AC1C,MAAM,UAAU,GAAG,MAAM,CAAA;IAEzB,IAAI,MAAM,EAAE;QACV,IAAI,KAAK,EAAE,MAAM,QAAQ,IAAI,gBAAe,EAAE;YAC5C,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAA;SAChC;KACF;IAED,IAAI,UAAU,KAAK,MAAM,EAAE;QACzB,gBAAgB,GAAG,IAAI,CAAA;KACxB;IAED,mCAAmC;IACnC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,CAAC,CAAA;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,MAAM,QAAQ,GAAG,MAAM,IAAA,gBAAM,EAAC,MAAM,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAClD,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC9C,MAAM,GAAG,IAAA,eAAK,EAAC,IAAA,eAAK,EAAC,OAAO,CAAC,CAAC,CAAA;KAC/B;IAED,OAAO;QACL,MAAM;QACN,MAAM;QACN,UAAU,EAAE,gBAAgB;KAC7B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envvars.d.ts","sourceRoot":"","sources":["../../../src/mutations/config/envvars.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"envvars.d.ts","sourceRoot":"","sources":["../../../src/mutations/config/envvars.ts"],"names":[],"mappings":"iCAE8B,MAAM,KAAG,QAAQ,MAAM,CAAC;AAAtD,wBA8BC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const debug = require("debug");
|
|
3
4
|
exports.default = async (config) => {
|
|
4
5
|
const envvars = Object.keys(process.env)
|
|
5
6
|
.filter(key => {
|
|
@@ -9,10 +10,18 @@ exports.default = async (config) => {
|
|
|
9
10
|
obj[key] = process.env[key];
|
|
10
11
|
return obj;
|
|
11
12
|
}, {});
|
|
13
|
+
let replacements = 0;
|
|
14
|
+
debug('stepzen:transpiler:config')(`STEPZEN_* env vars available for replacement:` +
|
|
15
|
+
` ${JSON.stringify(envvars, undefined, 2)}`);
|
|
12
16
|
for (const [key, value] of Object.entries(envvars)) {
|
|
13
17
|
const regex = new RegExp(key, 'g');
|
|
14
|
-
config = config.replace(regex,
|
|
18
|
+
config = config.replace(regex, (match, offset) => {
|
|
19
|
+
replacements += 1;
|
|
20
|
+
debug('stepzen:transpiler:config')(`replacing ${match} at offset ${offset}`);
|
|
21
|
+
return `${value}`;
|
|
22
|
+
});
|
|
15
23
|
}
|
|
24
|
+
debug('stepzen:transpiler:config')(`total replacements made: ${replacements}`);
|
|
16
25
|
return config;
|
|
17
26
|
};
|
|
18
27
|
//# sourceMappingURL=envvars.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envvars.js","sourceRoot":"","sources":["../../../src/mutations/config/envvars.ts"],"names":[],"mappings":";;AAAA,kBAAe,KAAK,EAAE,MAAc,EAAmB,EAAE;IACvD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;SACrC,MAAM,CAAC,GAAG,CAAC,EAAE;QACZ,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACnC,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,GAAQ,EAAE,GAAG,EAAE,EAAE;QACxB,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;IAER,KAAK,MAAM,CAAC,GAAG,EA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AC,CAChC,aAAa,KAAK,cAAc,MAAM,EAAE,CACzC,CAAA;YACD,OAAO,GAAG,KAAK,EAAE,CAAA;QACnB,CAAC,CAAC,CAAA;KACH;IAED,KAAK,CAAC,2BAA2B,CAAC,CAAC,4BAA4B,YAAY,EAAE,CAAC,CAAA;IAE9E,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,uBAAuB,yIAOnC,CAAA;AAED,eAAO,MAAM,cAAc,QAAyC,CAAA"}
|
package/lib/utils/constants.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.STEPZEN_DOMAIN = exports.EXPERIMENTAL_EXTENSIONS = void 0;
|
|
4
4
|
const dotenv = require("dotenv");
|
|
5
|
+
const debug = require("debug");
|
|
6
|
+
debug('stepzen:dotenv')(`loading .env from ${process.cwd()}, at transpiler/src/utils/constants.ts`);
|
|
5
7
|
dotenv.config();
|
|
6
8
|
const { STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN } = process.env;
|
|
7
9
|
exports.EXPERIMENTAL_EXTENSIONS = `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,+BAA8B;AAE9B,KAAK,CAAC,gBAAgB,CAAC,CACrB,qBAAqB,OAAO,CAAC,GAAG,EAAE,wCAAwC,CAC3E,CAAA;AACD,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,EAAC,cAAc,EAAE,sBAAsB,EAAC,GAAG,OAAO,CAAC,GAAG,CAAA;AAE/C,QAAA,uBAAuB,GAAG;;;;;;;CAOtC,CAAA;AAEY,QAAA,cAAc,GAAG,sBAAsB,IAAI,YAAY,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.21.0-beta.
|
|
4
|
+
"version": "0.21.0-beta.4",
|
|
5
5
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"nyc": "^14.1.1",
|
|
54
54
|
"ts-node": "^10.8.2"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "8213b0cc66702658ce49cccbc9d4b21bc25c101d"
|
|
57
57
|
}
|
package/src/actions/configure.ts
CHANGED
|
@@ -5,47 +5,75 @@ import * as inquirer from 'inquirer'
|
|
|
5
5
|
import * as path from 'path'
|
|
6
6
|
import * as yaml from 'yaml'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Get effective StepZen endpoint configuration for a directory:
|
|
10
|
+
* Traverse the file system starting at `source` and
|
|
11
|
+
* - merge all `config.yaml` files (discarding unrecognized properties)
|
|
12
|
+
* - merge all `config` sections from `stepzen.config.json` files
|
|
13
|
+
*
|
|
14
|
+
* Possibly, interactive: if `silent` is `false` and there are non-empty
|
|
15
|
+
* `config` sections in `stepzen.config.json` files.
|
|
16
|
+
*/
|
|
8
17
|
export default async (source: string, silent = false, answers: any = {}) => {
|
|
9
|
-
|
|
10
|
-
configurationset: [],
|
|
11
|
-
ruleset: [],
|
|
18
|
+
const config = {
|
|
19
|
+
configurationset: [] as any[],
|
|
20
|
+
ruleset: [] as any[],
|
|
21
|
+
access: undefined as any,
|
|
22
|
+
deployment: undefined as any,
|
|
12
23
|
}
|
|
13
24
|
|
|
25
|
+
debug('stepzen:transpiler:config')(`getting effective config for ${source}`)
|
|
26
|
+
|
|
14
27
|
// Now let's parse and add any config.yamls
|
|
28
|
+
let configYamlCount = 0
|
|
15
29
|
for (const y of glob.sync('**/config.yaml', {cwd: source})) {
|
|
16
30
|
const filePath = path.join(source, y)
|
|
17
31
|
|
|
18
32
|
const file = fs.readFileSync(filePath, 'utf8')
|
|
19
33
|
let asYAML
|
|
20
34
|
try {
|
|
21
|
-
asYAML = yaml.parse(file)
|
|
35
|
+
asYAML = yaml.parse(file, {schema: 'failsafe'})
|
|
22
36
|
} catch (error) {
|
|
23
|
-
debug('stepzen:transpiler')(
|
|
24
|
-
`
|
|
37
|
+
debug('stepzen:transpiler:config')(
|
|
38
|
+
`Ignoring an invalid config.yaml ${filePath}.` +
|
|
39
|
+
` YAML parse error: ${error}`,
|
|
25
40
|
)
|
|
26
41
|
continue
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
if (!asYAML) {
|
|
30
|
-
debug('stepzen:transpiler')(
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
debug('stepzen:transpiler')(`Adding config.yaml ${filePath}`)
|
|
35
|
-
debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asYAML, null, 2)}`)
|
|
36
|
-
|
|
37
|
-
if (asYAML.configurationset) {
|
|
38
|
-
config.configurationset = config.configurationset.concat(
|
|
39
|
-
asYAML.configurationset,
|
|
45
|
+
debug('stepzen:transpiler:config')(
|
|
46
|
+
`ignoring an empty config.yaml ${filePath}`,
|
|
40
47
|
)
|
|
48
|
+
continue
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
configYamlCount += 1
|
|
52
|
+
debug('stepzen:transpiler:config')(
|
|
53
|
+
`adding config.yaml ${filePath}:\n${JSON.stringify(asYAML, null, 2)}`,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
// strip away any non-recognized properties
|
|
57
|
+
Object.entries(asYAML).forEach(([keyAsAny, value]) => {
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(config, keyAsAny)) {
|
|
59
|
+
const key = keyAsAny as keyof typeof config
|
|
60
|
+
config[key] = Array.isArray(config[key])
|
|
61
|
+
? config[key].concat(value)
|
|
62
|
+
: value
|
|
63
|
+
} else {
|
|
64
|
+
debug('stepzen:transpiler:config')(
|
|
65
|
+
`ignoring unrecognized config property ${keyAsAny}`,
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
46
69
|
}
|
|
47
70
|
|
|
71
|
+
debug('stepzen:transpiler:config')(
|
|
72
|
+
`done adding **/config.yaml files (processed: ${configYamlCount})`,
|
|
73
|
+
)
|
|
74
|
+
|
|
48
75
|
// Now let's build configs from questions
|
|
76
|
+
let configJsonCount = 0
|
|
49
77
|
for await (const j of glob.sync('**/stepzen.config.json', {
|
|
50
78
|
cwd: source,
|
|
51
79
|
})) {
|
|
@@ -54,8 +82,11 @@ export default async (source: string, silent = false, answers: any = {}) => {
|
|
|
54
82
|
const file = fs.readFileSync(filePath, 'utf8')
|
|
55
83
|
const asJSON = JSON.parse(file)
|
|
56
84
|
|
|
57
|
-
|
|
58
|
-
debug('stepzen:transpiler')(
|
|
85
|
+
configJsonCount += 1
|
|
86
|
+
debug('stepzen:transpiler:config')(
|
|
87
|
+
`adding stepzen.config.json ${filePath}:` +
|
|
88
|
+
`\n${JSON.stringify(asJSON, null, 2)}`,
|
|
89
|
+
)
|
|
59
90
|
|
|
60
91
|
if (asJSON.config?.questions) {
|
|
61
92
|
for await (const question of asJSON.config?.questions) {
|
|
@@ -81,11 +112,11 @@ export default async (source: string, silent = false, answers: any = {}) => {
|
|
|
81
112
|
},
|
|
82
113
|
}
|
|
83
114
|
|
|
84
|
-
debug('stepzen:transpiler')(
|
|
85
|
-
`
|
|
115
|
+
debug('stepzen:transpiler:config')(
|
|
116
|
+
`question: ${JSON.stringify(question, null, 2)}`,
|
|
86
117
|
)
|
|
87
|
-
debug('stepzen:transpiler')(
|
|
88
|
-
`
|
|
118
|
+
debug('stepzen:transpiler:config')(
|
|
119
|
+
`answer: ${JSON.stringify(configset, null, 2)}`,
|
|
89
120
|
)
|
|
90
121
|
|
|
91
122
|
config.configurationset.push({...configset})
|
|
@@ -93,41 +124,53 @@ export default async (source: string, silent = false, answers: any = {}) => {
|
|
|
93
124
|
}
|
|
94
125
|
}
|
|
95
126
|
|
|
96
|
-
debug('stepzen:transpiler')(
|
|
97
|
-
`
|
|
127
|
+
debug('stepzen:transpiler:config')(
|
|
128
|
+
`done adding **/stepzen.config.json files (processed: ${configJsonCount})`,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
debug('stepzen:transpiler:config')(
|
|
132
|
+
`combined content of all config files:` +
|
|
133
|
+
`\n${JSON.stringify(config, null, 2)}`,
|
|
98
134
|
)
|
|
99
135
|
|
|
100
136
|
// OK now let's collate everything into shared configurations
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
137
|
+
const configurationset = []
|
|
138
|
+
{
|
|
139
|
+
const obj: any = {}
|
|
140
|
+
for (const c of config.configurationset) {
|
|
141
|
+
const name = c.configuration.name
|
|
142
|
+
if (!obj[name]) obj[name] = {}
|
|
143
|
+
for (const [key, value] of Object.entries(c.configuration)) {
|
|
144
|
+
if (key === name) continue
|
|
145
|
+
obj[name][key] = value
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const configuration of Object.keys(obj)) {
|
|
150
|
+
configurationset.push({
|
|
151
|
+
configuration: {...obj[configuration]},
|
|
152
|
+
})
|
|
108
153
|
}
|
|
109
154
|
}
|
|
110
155
|
|
|
111
156
|
// Now convert back into StepZen format
|
|
112
|
-
const structured
|
|
113
|
-
configurationset
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
structured.configurationset.push({
|
|
118
|
-
configuration: {...obj[configuration]},
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
structured.ruleset = [...config.ruleset]
|
|
157
|
+
const structured = Object.fromEntries(
|
|
158
|
+
Object.entries({...config, configurationset}).filter(([_key, value]) =>
|
|
159
|
+
Array.isArray(value) ? value.length > 0 : value !== undefined,
|
|
160
|
+
),
|
|
161
|
+
)
|
|
122
162
|
|
|
123
163
|
// Return YAML, if appropriate
|
|
124
|
-
if (structured.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (structured.configurationset || structured.ruleset) {
|
|
129
|
-
return yaml.stringify(structured)
|
|
164
|
+
if (Object.keys(structured).length > 0) {
|
|
165
|
+
const configYamlStr = yaml.stringify(structured)
|
|
166
|
+
debug('stepzen:transpiler:config')(`effective config:\n${configYamlStr}`)
|
|
167
|
+
return configYamlStr
|
|
130
168
|
}
|
|
131
169
|
|
|
170
|
+
debug('stepzen:transpiler:config')(
|
|
171
|
+
`Could not find any of the supported properties in the config:` +
|
|
172
|
+
` [ '${Object.keys(config).join(`', '`)}' ].` +
|
|
173
|
+
` Retuning 'false' meaning 'effective config is empty'.`,
|
|
174
|
+
)
|
|
132
175
|
return false
|
|
133
176
|
}
|
package/src/actions/transpile.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {DocumentNode, parse} from 'graphql'
|
|
2
2
|
import * as dotenv from 'dotenv'
|
|
3
|
+
import * as debug from 'debug'
|
|
3
4
|
import * as fs from 'fs'
|
|
4
5
|
import * as glob from 'glob'
|
|
5
6
|
import * as path from 'path'
|
|
@@ -17,15 +18,21 @@ export default async (source: string) => {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
// Load env vars, from working and source directories
|
|
21
|
+
debug('stepzen:dotenv')(
|
|
22
|
+
`loading .env from ${process.cwd()}, at transpiler/src/actions/transpile.ts:24`,
|
|
23
|
+
)
|
|
20
24
|
dotenv.config()
|
|
25
|
+
debug('stepzen:dotenv')(
|
|
26
|
+
`loading .env from ${path.resolve(source)}` +
|
|
27
|
+
`, at transpiler/src/actions/transpile.ts:29`,
|
|
28
|
+
)
|
|
21
29
|
dotenv.config({path: path.resolve(source, '.env')})
|
|
22
30
|
|
|
23
31
|
// State of whether we've transpiled or not
|
|
24
32
|
let transpiledConfig = false
|
|
25
|
-
let transpiledGraphQL = false
|
|
26
33
|
|
|
27
34
|
// See whether to transpile config
|
|
28
|
-
let config
|
|
35
|
+
let config = await configure(source, true)
|
|
29
36
|
const configCopy = config
|
|
30
37
|
|
|
31
38
|
if (config) {
|
|
@@ -40,31 +47,18 @@ export default async (source: string) => {
|
|
|
40
47
|
|
|
41
48
|
// See whether to transpile GraphQL
|
|
42
49
|
const graphqlFiles = glob.sync('**/*.graphql', {cwd: source})
|
|
43
|
-
let
|
|
44
|
-
let mutated: any = ''
|
|
50
|
+
let schema = ''
|
|
45
51
|
|
|
46
52
|
if (graphqlFiles.length > 0) {
|
|
47
53
|
const stitched = await stitch(source)
|
|
48
|
-
|
|
49
54
|
const index = path.join(stitched, 'index.graphql')
|
|
50
|
-
|
|
51
55
|
const graphql = fs.readFileSync(index, 'utf8')
|
|
52
|
-
|
|
53
|
-
let ast: DocumentNode = parse(graphql)
|
|
54
|
-
original = parse(graphql)
|
|
55
|
-
|
|
56
|
-
// you can transpile schema ast here
|
|
57
|
-
|
|
58
|
-
mutated = print(ast)
|
|
59
|
-
|
|
60
|
-
if (print(original) !== mutated) {
|
|
61
|
-
transpiledGraphQL = true
|
|
62
|
-
}
|
|
56
|
+
schema = print(parse(graphql))
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
return {
|
|
66
60
|
config,
|
|
67
|
-
schema
|
|
68
|
-
transpiled: transpiledConfig
|
|
61
|
+
schema,
|
|
62
|
+
transpiled: transpiledConfig,
|
|
69
63
|
}
|
|
70
64
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as debug from 'debug'
|
|
2
|
+
|
|
1
3
|
export default async (config: string): Promise<string> => {
|
|
2
4
|
const envvars = Object.keys(process.env)
|
|
3
5
|
.filter(key => {
|
|
@@ -8,10 +10,24 @@ export default async (config: string): Promise<string> => {
|
|
|
8
10
|
return obj
|
|
9
11
|
}, {})
|
|
10
12
|
|
|
13
|
+
let replacements = 0
|
|
14
|
+
debug('stepzen:transpiler:config')(
|
|
15
|
+
`STEPZEN_* env vars available for replacement:` +
|
|
16
|
+
` ${JSON.stringify(envvars, undefined, 2)}`,
|
|
17
|
+
)
|
|
18
|
+
|
|
11
19
|
for (const [key, value] of Object.entries(envvars)) {
|
|
12
20
|
const regex = new RegExp(key, 'g')
|
|
13
|
-
config = config.replace(regex,
|
|
21
|
+
config = config.replace(regex, (match, offset) => {
|
|
22
|
+
replacements += 1
|
|
23
|
+
debug('stepzen:transpiler:config')(
|
|
24
|
+
`replacing ${match} at offset ${offset}`,
|
|
25
|
+
)
|
|
26
|
+
return `${value}`
|
|
27
|
+
})
|
|
14
28
|
}
|
|
15
29
|
|
|
30
|
+
debug('stepzen:transpiler:config')(`total replacements made: ${replacements}`)
|
|
31
|
+
|
|
16
32
|
return config
|
|
17
33
|
}
|
package/src/utils/constants.ts
CHANGED