@stepzen/transpiler 0.21.0-beta.1 → 0.21.0-beta.2

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.
@@ -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":"iCAO8B,MAAM,8BAA2B,GAAG;AAAlE,wBA6HC"}
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;iCAC2B,MAAM,8BAA2B,GAAG;AAAlE,wBA+JC"}
@@ -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
- let config = {
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')(`error parsing ${filePath}: ${error} -> ignoring this file`);
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')(`Ignoring an empty config.yaml ${filePath}`);
41
+ debug('stepzen:transpiler:config')(`ignoring an empty config.yaml ${filePath}`);
28
42
  continue;
29
43
  }
30
- debug('stepzen:transpiler')(`Adding config.yaml ${filePath}`);
31
- debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asYAML, null, 2)}`);
32
- if (asYAML.configurationset) {
33
- config.configurationset = config.configurationset.concat(asYAML.configurationset);
34
- }
35
- if (asYAML.ruleset) {
36
- config.ruleset = config.ruleset.concat(asYAML.ruleset);
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
- debug('stepzen:transpiler')(`Adding stepzen.config.json ${filePath}`);
47
- debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asJSON, null, 2)}`);
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')(`Question: ${JSON.stringify(question, null, 2)}`);
70
- debug('stepzen:transpiler')(`Answer: ${JSON.stringify(configset, null, 2)}`);
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')(`Configuration: ${JSON.stringify(config, null, 2)}`);
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 obj = {};
78
- for (const c of config.configurationset) {
79
- const name = c.configuration.name;
80
- if (!obj[name])
81
- obj[name] = {};
82
- for (const [key, value] of Object.entries(c.configuration)) {
83
- if (key === name)
84
- continue;
85
- obj[name][key] = value;
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.configurationset.length === 0)
101
- delete structured.configurationset;
102
- if (structured.ruleset.length === 0)
103
- delete structured.ruleset;
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,IAAI,MAAM,GAAQ;QAChB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,EAAE;KACZ,CAAA;IAED,2CAA2C;IAC3C,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,I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ACF;QAED,KAAK,MAAM,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC5C,gBAAgB,CAAC,IAAI,CAAC;gBACpB,aAAa,EAAE,EAAC,GAAG,GAAG,CAAC,aAAa,CAAC,EAAC;aACvC,CAAC,CAAA;SACH;KACF;IAED,uCAAuC;IACvC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,EAAC,GAAG,MAAM,EAAE,gBAAgB,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CACrE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAC9D,CACF,CAAA;IAED,8BAA8B;IAC9B,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACtC,MAAM,aAAa,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,6 +1,6 @@
1
1
  declare const _default: (source: string) => Promise<{
2
- config: any;
3
- schema: any;
2
+ config: string | false;
3
+ schema: string;
4
4
  transpiled: boolean;
5
5
  }>;
6
6
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":"iCAY8B,MAAM;;;;;AAApC,wBAyDC"}
1
+ {"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":"iCAa8B,MAAM;;;;;AAApC,wBAkDC"}
@@ -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 original = '';
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
- let ast = (0, graphql_1.parse)(graphql);
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: mutated,
53
- transpiled: transpiledConfig || transpiledGraphQL,
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,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAA;KAC1D;IAED,qDAAqD;IACrD,MAAM,CAAC,MAAM,EAAE,CAAA;IACf,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAC,CAAC,CAAA;IAEnD,2CAA2C;IAC3C,IAAI,gBAAgB,GAAG,KAAK,CAAA;IAC5B,IAAI,iBAAiB,GAAG,KAAK,CAAA;IAE7B,kCAAkC;IAClC,IAAI,MAAM,GAAQ,MAAM,IAAA,mBAAS,EAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC/C,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,MAA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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":"iCAA8B,MAAM,KAAG,QAAQ,MAAM,CAAC;AAAtD,wBAgBC"}
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, `${value}`);
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;S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OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAC9C,CAAA;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAClD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAClC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC/C,YAAY,IAAI,CAAC,CAAA;YACjB,KAAK,CAAC,2BAA2B,CAAC,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":"AAMA,eAAO,MAAM,uBAAuB,yIAOnC,CAAA;AAED,eAAO,MAAM,cAAc,QAAyC,CAAA"}
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"}
@@ -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;AAEhC,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"}
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.1",
4
+ "version": "0.21.0-beta.2",
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": "6dddebabddbbd69adb07b5e7c816125ae5dc3430"
56
+ "gitHead": "58b85cc37fa990639bf7170d4224cf51cc1f7ad1"
57
57
  }
@@ -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
- let config: any = {
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
- `error parsing ${filePath}: ${error} -> ignoring this file`,
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')(`Ignoring an empty config.yaml ${filePath}`)
31
- continue
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
- if (asYAML.ruleset) {
44
- config.ruleset = config.ruleset.concat(asYAML.ruleset)
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
- debug('stepzen:transpiler')(`Adding stepzen.config.json ${filePath}`)
58
- debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asJSON, null, 2)}`)
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
- `Question: ${JSON.stringify(question, null, 2)}`,
115
+ debug('stepzen:transpiler:config')(
116
+ `question: ${JSON.stringify(question, null, 2)}`,
86
117
  )
87
- debug('stepzen:transpiler')(
88
- `Answer: ${JSON.stringify(configset, null, 2)}`,
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
- `Configuration: ${JSON.stringify(config, null, 2)}`,
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 obj: any = {}
102
- for (const c of config.configurationset) {
103
- const name = c.configuration.name
104
- if (!obj[name]) obj[name] = {}
105
- for (const [key, value] of Object.entries(c.configuration)) {
106
- if (key === name) continue
107
- obj[name][key] = value
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: any = {
113
- configurationset: [],
114
- ruleset: [],
115
- }
116
- for (const configuration of Object.keys(obj)) {
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.configurationset.length === 0)
125
- delete structured.configurationset
126
- if (structured.ruleset.length === 0) delete structured.ruleset
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
  }
@@ -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: any = await configure(source, true)
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 original: any = ''
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: mutated,
68
- transpiled: transpiledConfig || transpiledGraphQL,
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, `${value}`)
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
  }
@@ -1,5 +1,9 @@
1
1
  import * as dotenv from 'dotenv'
2
+ import * as debug from 'debug'
2
3
 
4
+ debug('stepzen:dotenv')(
5
+ `loading .env from ${process.cwd()}, at transpiler/src/utils/constants.ts`,
6
+ )
3
7
  dotenv.config()
4
8
 
5
9
  const {STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN} = process.env