@stepzen/transpiler 0.0.29 → 0.0.33

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.
@@ -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('stepzen:transpiler')(`Adding config.yaml ${filePath}`);
23
- debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asYAML, null, 2)}`);
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('stepzen:transpiler')(`Adding stepzen.config.json ${filePath}`);
41
- debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asJSON, null, 2)}`);
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 = { [name]: { [key]: ((_e = answers[name]) === null || _e === void 0 ? void 0 : _e[key]) ? (_f = answers[name]) === null || _f === void 0 ? void 0 : _f[key] : "" } };
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('stepzen:transpiler')(`Question: ${JSON.stringify(question, null, 2)}`);
61
- debug('stepzen:transpiler')(`Answer: ${JSON.stringify(configset, null, 2)}`);
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('stepzen:transpiler')(`Configuration: ${JSON.stringify(config, null, 2)}`);
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) {
@@ -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('https://www.steprz.net/directives.graphql');
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, 'index.graphql');
22
- const graphql = fs.readFileSync(index, 'utf8');
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, 'index.graphql');
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);
@@ -33,8 +33,7 @@ exports.default = async (original, imported, options = {
33
33
  options.silent = false;
34
34
  // To stop things like
35
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 = path.join(os.tmpdir(), options.output.replace(regex, ''));
36
+ options.output = merge_helpers_1.dedupeTempFolder(options.output);
38
37
  // Ensure original, importing and output directories exist
39
38
  if (!fs.existsSync(original))
40
39
  throw new Error(`Cannot find original directory ${original}`);
@@ -44,7 +43,7 @@ exports.default = async (original, imported, options = {
44
43
  // Copy the original into the output.
45
44
  fs.copySync(original, options.output);
46
45
  // Ensure an index.graphql exists
47
- const outputIndex = path.join(options.output, 'index.graphql');
46
+ const outputIndex = path.join(options.output, "index.graphql");
48
47
  if (!fs.existsSync(outputIndex)) {
49
48
  fs.writeFileSync(outputIndex, BLANK_INDEX_TEMPLATE);
50
49
  }
@@ -108,21 +107,23 @@ exports.default = async (original, imported, options = {
108
107
  cleaned.original.forEach((a) => {
109
108
  // eslint-disable-next-line
110
109
  const file = path.join(options.output, a.file);
111
- fs.ensureFileSync(file);
112
- fs.writeFileSync(file, print_1.default(a.ast));
110
+ const deduped = merge_helpers_1.dedupeTempFolder(file);
111
+ fs.ensureFileSync(deduped);
112
+ fs.writeFileSync(deduped, print_1.default(a.ast));
113
113
  });
114
114
  cleaned.imported.forEach((a) => {
115
115
  // eslint-disable-next-line
116
116
  const file = path.join(options.output, imported.name, a.file);
117
- fs.ensureFileSync(file);
118
- fs.writeFileSync(file, print_1.default(a.ast));
117
+ const deduped = merge_helpers_1.dedupeTempFolder(file);
118
+ fs.ensureFileSync(deduped);
119
+ fs.writeFileSync(deduped, print_1.default(a.ast));
119
120
  });
120
121
  // Make sure all files are referenced in @sdl
121
122
  set_files_in_sdl_1.default(options.output);
122
123
  // Generate configuration
123
124
  const config = await merge_helpers_1.getConfiguration([options.output, imported.source], options.silent, options.answers);
124
125
  if (config) {
125
- const configFile = path.join(options.output, 'config.yaml');
126
+ const configFile = path.join(options.output, "config.yaml");
126
127
  fs.writeFileSync(configFile, config);
127
128
  }
128
129
  // Return a merged schema!
@@ -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, 'index.graphql');
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, 'index.graphql');
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, 'config.yaml');
83
- const outputConfig = path.join(output, 'config.yaml');
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
  }
@@ -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, 'index.graphql');
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
  };
@@ -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, 'index.graphql');
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, 'g');
13
+ const regex = new RegExp(key, "g");
14
14
  config = config.replace(regex, `${value}`);
15
15
  }
16
16
  return config;
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const envvars_1 = require("./envvars");
4
- exports.default = [
5
- envvars_1.default,
6
- ];
4
+ exports.default = [envvars_1.default];
@@ -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, } = process.env;
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 || 'stepzen.io';
15
+ exports.STEPZEN_DOMAIN = ENV_VAR_STEPZEN_DOMAIN || "stepzen.io";
@@ -1,4 +1,5 @@
1
1
  import { GraphQLSchema } from "graphql";
2
+ export declare const dedupeTempFolder: (dirpath: string) => string;
2
3
  export declare const findQueryMutationInSchema: (name: string, files: any) => Boolean;
3
4
  export declare const findTypeInSchema: (name: string, files: any) => Boolean;
4
5
  export declare const getConfiguration: (directories: string[], silent?: boolean, answers?: any) => Promise<string | boolean>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeTypeFromSchema = exports.removeQueryMutationFromSchema = exports.mergeTypeIntoSchema = exports.mergeQueryMutationIntoSchema = exports.getSchema = exports.getExtensions = exports.getConfiguration = exports.findTypeInSchema = exports.findQueryMutationInSchema = void 0;
3
+ exports.removeTypeFromSchema = exports.removeQueryMutationFromSchema = exports.mergeTypeIntoSchema = exports.mergeQueryMutationIntoSchema = exports.getSchema = exports.getExtensions = exports.getConfiguration = exports.findTypeInSchema = exports.findQueryMutationInSchema = exports.dedupeTempFolder = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const utilities_1 = require("graphql/utilities");
6
6
  const node_fetch_1 = require("node-fetch");
@@ -8,10 +8,19 @@ const fs = require("fs-extra");
8
8
  const glob = require("glob");
9
9
  const os = require("os");
10
10
  const path = require("path");
11
+ const lodash_1 = require("lodash");
11
12
  const graphql_helpers_1 = require("../utils/graphql-helpers");
12
13
  const constants_1 = require("./constants");
13
14
  const configure_1 = require("../actions/configure");
14
15
  const transpile_1 = require("../actions/transpile");
16
+ const dedupeTempFolder = (dirpath) => {
17
+ do {
18
+ dirpath = lodash_1.replace(dirpath, os.tmpdir(), '');
19
+ } while (dirpath.includes(os.tmpdir()));
20
+ dirpath = path.join(os.tmpdir(), dirpath);
21
+ return dirpath;
22
+ };
23
+ exports.dedupeTempFolder = dedupeTempFolder;
15
24
  const findQueryMutationInSchema = (name, files) => {
16
25
  for (const file of files) {
17
26
  let found = false;
@@ -56,7 +65,8 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
56
65
  ];
57
66
  for (const config of configs) {
58
67
  const configFolder = path.join(directory, config);
59
- const writeFolder = path.join(tmp, directory, config);
68
+ let writeFolder = path.join(tmp, directory, config);
69
+ writeFolder = exports.dedupeTempFolder(writeFolder);
60
70
  const content = fs.readFileSync(configFolder, "utf8");
61
71
  fs.ensureFileSync(writeFolder);
62
72
  fs.writeFileSync(writeFolder, content);
@@ -68,7 +78,7 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
68
78
  };
69
79
  exports.getConfiguration = getConfiguration;
70
80
  const getExtensions = async () => {
71
- const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
81
+ const domain = constants_1.STEPZEN_DOMAIN.replace(".io", ".net");
72
82
  const response = await node_fetch_1.default(`https://www.${domain}/directives.graphql`);
73
83
  const text = await response.text();
74
84
  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, 'index.graphql');
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
- 'fedex_default',
10
- 'holidayapi_default',
11
- 'ipapi_default',
12
- 'owm_default',
13
- 'ups_default',
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, 'config.yaml');
31
+ const sourceConfig = path.join(source, "config.yaml");
32
32
  if (!fs.existsSync(sourceConfig)) {
33
- throw new Error('No config.yaml found');
33
+ throw new Error("No config.yaml found");
34
34
  }
35
- const content = fs.readFileSync(sourceConfig, 'utf8');
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) => {
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_exists_1 = require("./config-exists");
4
- exports.default = [
5
- config_exists_1.default,
6
- ];
4
+ exports.default = [config_exists_1.default];
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.29",
4
+ "version": "0.0.33",
5
5
  "author": "Darren Waddell <darren@stepzen.com>",
6
6
  "license": "MIT",
7
7
  "files": [