@stepzen/transpiler 0.0.32 → 0.0.35

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.
Files changed (65) hide show
  1. package/LICENSE +1 -1
  2. package/lib/actions/configure.js +15 -14
  3. package/lib/actions/configure.js.map +1 -0
  4. package/lib/actions/lint.js +6 -5
  5. package/lib/actions/lint.js.map +1 -0
  6. package/lib/actions/merge.js +14 -15
  7. package/lib/actions/merge.js.map +1 -0
  8. package/lib/actions/print.d.ts +1 -1
  9. package/lib/actions/print.js +2 -1
  10. package/lib/actions/print.js.map +1 -0
  11. package/lib/actions/stitch.js +14 -13
  12. package/lib/actions/stitch.js.map +1 -0
  13. package/lib/actions/transpile.js +7 -6
  14. package/lib/actions/transpile.js.map +1 -0
  15. package/lib/actions/validate.js +4 -3
  16. package/lib/actions/validate.js.map +1 -0
  17. package/lib/index.d.ts +7 -1
  18. package/lib/index.js +16 -16
  19. package/lib/index.js.map +1 -0
  20. package/lib/mutations/config/envvars.js +3 -2
  21. package/lib/mutations/config/envvars.js.map +1 -0
  22. package/lib/mutations/config/index.js +1 -0
  23. package/lib/mutations/config/index.js.map +1 -0
  24. package/lib/utils/constants.js +2 -1
  25. package/lib/utils/constants.js.map +1 -0
  26. package/lib/utils/dedupe-query-and-mutation-types.js +7 -6
  27. package/lib/utils/dedupe-query-and-mutation-types.js.map +1 -0
  28. package/lib/utils/ensure-query-and-mutation-types.d.ts +1 -1
  29. package/lib/utils/ensure-query-and-mutation-types.js +7 -6
  30. package/lib/utils/ensure-query-and-mutation-types.js.map +1 -0
  31. package/lib/utils/graphql-helpers.js +1 -0
  32. package/lib/utils/graphql-helpers.js.map +1 -0
  33. package/lib/utils/merge-helpers.d.ts +1 -1
  34. package/lib/utils/merge-helpers.js +9 -6
  35. package/lib/utils/merge-helpers.js.map +1 -0
  36. package/lib/utils/set-files-in-sdl.js +9 -8
  37. package/lib/utils/set-files-in-sdl.js.map +1 -0
  38. package/lib/utils/strip-empty-queries-and-mutations.d.ts +1 -1
  39. package/lib/utils/strip-empty-queries-and-mutations.js +7 -6
  40. package/lib/utils/strip-empty-queries-and-mutations.js.map +1 -0
  41. package/lib/validators/config-exists/index.d.ts +1 -1
  42. package/lib/validators/config-exists/index.js +11 -10
  43. package/lib/validators/config-exists/index.js.map +1 -0
  44. package/lib/validators/index.js +1 -0
  45. package/lib/validators/index.js.map +1 -0
  46. package/package.json +24 -16
  47. package/src/actions/configure.ts +120 -0
  48. package/src/actions/lint.ts +45 -0
  49. package/src/actions/merge.ts +186 -0
  50. package/src/actions/print.ts +8 -0
  51. package/src/actions/stitch.ts +105 -0
  52. package/src/actions/transpile.ts +70 -0
  53. package/src/actions/validate.ts +54 -0
  54. package/src/index.ts +7 -0
  55. package/src/mutations/config/envvars.ts +17 -0
  56. package/src/mutations/config/index.ts +3 -0
  57. package/src/utils/constants.ts +16 -0
  58. package/src/utils/dedupe-query-and-mutation-types.ts +74 -0
  59. package/src/utils/ensure-query-and-mutation-types.ts +52 -0
  60. package/src/utils/graphql-helpers.ts +3 -0
  61. package/src/utils/merge-helpers.ts +176 -0
  62. package/src/utils/set-files-in-sdl.ts +40 -0
  63. package/src/utils/strip-empty-queries-and-mutations.ts +43 -0
  64. package/src/validators/config-exists/index.ts +54 -0
  65. package/src/validators/index.ts +3 -0
@@ -1,4 +1,4 @@
1
- import { GraphQLSchema } from "graphql";
1
+ import { GraphQLSchema } from 'graphql';
2
2
  export declare const dedupeTempFolder: (dirpath: string) => string;
3
3
  export declare const findQueryMutationInSchema: (name: string, files: any) => Boolean;
4
4
  export declare const findTypeInSchema: (name: string, files: any) => Boolean;
@@ -8,13 +8,15 @@ 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");
15
16
  const dedupeTempFolder = (dirpath) => {
16
- const regex = new RegExp(os.tmpdir(), "gi");
17
- dirpath = dirpath.replace(regex, "");
17
+ do {
18
+ dirpath = lodash_1.replace(dirpath, os.tmpdir(), '');
19
+ } while (dirpath.includes(os.tmpdir()));
18
20
  dirpath = path.join(os.tmpdir(), dirpath);
19
21
  return dirpath;
20
22
  };
@@ -58,14 +60,14 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
58
60
  fs.ensureDirSync(tmp);
59
61
  for (const directory of directories) {
60
62
  const configs = [
61
- ...glob.sync("**/config.yaml", { cwd: directory }),
62
- ...glob.sync("**/stepzen.config.json", { cwd: directory }),
63
+ ...glob.sync('**/config.yaml', { cwd: directory }),
64
+ ...glob.sync('**/stepzen.config.json', { cwd: directory }),
63
65
  ];
64
66
  for (const config of configs) {
65
67
  const configFolder = path.join(directory, config);
66
68
  let writeFolder = path.join(tmp, directory, config);
67
69
  writeFolder = exports.dedupeTempFolder(writeFolder);
68
- const content = fs.readFileSync(configFolder, "utf8");
70
+ const content = fs.readFileSync(configFolder, 'utf8');
69
71
  fs.ensureFileSync(writeFolder);
70
72
  fs.writeFileSync(writeFolder, content);
71
73
  }
@@ -76,7 +78,7 @@ const getConfiguration = async (directories, silent = false, answers = {}) => {
76
78
  };
77
79
  exports.getConfiguration = getConfiguration;
78
80
  const getExtensions = async () => {
79
- const domain = constants_1.STEPZEN_DOMAIN.replace(".io", ".net");
81
+ const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
80
82
  const response = await node_fetch_1.default(`https://www.${domain}/directives.graphql`);
81
83
  const text = await response.text();
82
84
  return text;
@@ -148,3 +150,4 @@ const removeTypeFromSchema = (name, files) => {
148
150
  return files;
149
151
  };
150
152
  exports.removeTypeFromSchema = removeTypeFromSchema;
153
+ //# sourceMappingURL=merge-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-helpers.js","sourceRoot":"","sources":["../../src/utils/merge-helpers.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AAE,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE;gBACnB,eAAe,CAAC,IAAI;oBAClB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;wBAC5B,OAAO,IAAI,CAAA;qBACZ;gBACH,CAAC;aACF,CAAC,IACH;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAdY,QAAA,6BAA6B,iCAczC;AAEM,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,KAAU,EAAE,EAAE;IAC/D,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;QAC9B,uCACK,IAAI,KACP,GAAG,EAAE,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE;gBACnB,oBAAoB,CAAC,IAAI;oBACvB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;wBAC5B,OAAO,IAAI,CAAA;qBACZ;gBACH,CAAC;aACF,CAAC,IACH;IACH,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAdY,QAAA,oBAAoB,wBAchC"}
@@ -8,19 +8,19 @@ const graphql_helpers_1 = require("./graphql-helpers");
8
8
  const print_1 = require("../actions/print");
9
9
  exports.default = (source) => {
10
10
  const files = glob
11
- .sync("**/*.graphql", { cwd: source })
12
- .filter((file) => file !== "index.graphql");
13
- const output = path.join(source, "index.graphql");
14
- const index = fs.readFileSync(output, "utf8");
11
+ .sync('**/*.graphql', { cwd: source })
12
+ .filter(file => file !== 'index.graphql');
13
+ const output = path.join(source, 'index.graphql');
14
+ const index = fs.readFileSync(output, 'utf8');
15
15
  let ast = graphql_1.parse(index);
16
16
  ast = graphql_1.visit(ast, {
17
17
  Directive(node) {
18
- if (node.name.value === "sdl") {
18
+ if (node.name.value === 'sdl') {
19
19
  const mutated = graphql_helpers_1.cloneDeep(node);
20
20
  mutated.arguments = mutated.arguments.map((arg) => {
21
- if (arg.name.value === "files") {
22
- arg.value.values = files.map((file) => ({
23
- kind: "StringValue",
21
+ if (arg.name.value === 'files') {
22
+ arg.value.values = files.map(file => ({
23
+ kind: 'StringValue',
24
24
  value: file,
25
25
  }));
26
26
  }
@@ -32,3 +32,4 @@ exports.default = (source) => {
32
32
  });
33
33
  fs.writeFileSync(output, print_1.default(ast));
34
34
  };
35
+ //# sourceMappingURL=set-files-in-sdl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-files-in-sdl.js","sourceRoot":"","sources":["../../src/utils/set-files-in-sdl.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AACxB,6BAA4B;AAC5B,qCAAoC;AACpC,6BAA4B;AAE5B,uDAA2C;AAC3C,4CAAoC;AAEpC,kBAAe,CAAC,MAAc,EAAE,EAAE;IAChC,MAAM,KAAK,GAAG,IAAI;SACf,IAAI,CAAC,cAAc,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,CAAC;SACnC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,eAAe,CAAC,CAAA;IAE3C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAEjD,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE7C,IAAI,GAAG,GAAG,eAAK,CAAC,KAAK,CAAC,CAAA;IACtB,GAAG,GAAG,eAAK,CAAC,GAAG,EAAE;QACf,SAAS,CAAC,IAAI;YACZ,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE;gBAC7B,MAAM,OAAO,GAAQ,2BAAS,CAAC,IAAI,CAAC,CAAA;gBAEpC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE;oBACrD,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;wBAC9B,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;4BACpC,IAAI,EAAE,aAAa;4BACnB,KAAK,EAAE,IAAI;yBACZ,CAAC,CAAC,CAAA;qBACJ;oBACD,OAAO,GAAG,CAAA;gBACZ,CAAC,CAAC,CAAA;gBAEF,OAAO,OAAO,CAAA;aACf;QACH,CAAC;KACF,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,eAAK,CAAC,GAAG,CAAC,CAAC,CAAA;AACtC,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
- import { DocumentNode } from "graphql";
1
+ import { DocumentNode } from 'graphql';
2
2
  declare const _default: (ast: DocumentNode) => DocumentNode;
3
3
  export default _default;
@@ -7,17 +7,17 @@ exports.default = (ast) => {
7
7
  ast = graphql_1.visit(ast, {
8
8
  ObjectTypeDefinition: {
9
9
  enter(node) {
10
- if (node.name.kind === "Name" && node.name.value === "Query") {
10
+ if (node.name.kind === 'Name' && node.name.value === 'Query') {
11
11
  const mutated = graphql_helpers_1.cloneDeep(node);
12
12
  mutated.fields = mutated.fields.filter((field) => {
13
- return field.name.value !== "__query";
13
+ return field.name.value !== '__query';
14
14
  });
15
15
  return mutated;
16
16
  }
17
- if (node.name.kind === "Name" && node.name.value === "Mutation") {
17
+ if (node.name.kind === 'Name' && node.name.value === 'Mutation') {
18
18
  const mutated = graphql_helpers_1.cloneDeep(node);
19
19
  mutated.fields = mutated.fields.filter((field) => {
20
- return field.name.value !== "__mutated";
20
+ return field.name.value !== '__mutated';
21
21
  });
22
22
  return mutated;
23
23
  }
@@ -29,11 +29,11 @@ exports.default = (ast) => {
29
29
  ObjectTypeDefinition: {
30
30
  enter(node) {
31
31
  var _a, _b;
32
- if (node.name.kind === "Name" && node.name.value === "Query") {
32
+ if (node.name.kind === 'Name' && node.name.value === 'Query') {
33
33
  if (((_a = node.fields) === null || _a === void 0 ? void 0 : _a.length) === 0)
34
34
  return null;
35
35
  }
36
- if (node.name.kind === "Name" && node.name.value === "Mutation") {
36
+ if (node.name.kind === 'Name' && node.name.value === 'Mutation') {
37
37
  if (((_b = node.fields) === null || _b === void 0 ? void 0 : _b.length) === 0)
38
38
  return null;
39
39
  }
@@ -42,3 +42,4 @@ exports.default = (ast) => {
42
42
  });
43
43
  return ast;
44
44
  };
45
+ //# sourceMappingURL=strip-empty-queries-and-mutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-empty-queries-and-mutations.js","sourceRoot":"","sources":["../../src/utils/strip-empty-queries-and-mutations.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAE3C,uDAA2C;AAE3C,kBAAe,CAAC,GAAiB,EAAgB,EAAE;IACjD,iEAAiE;IACjE,GAAG,GAAG,eAAK,CAAC,GAAG,EAAE;QACf,oBAAoB,EAAE;YACpB,KAAK,CAAC,IAAI;gBACR,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;oBAC5D,MAAM,OAAO,GAAQ,2BAAS,CAAC,IAAI,CAAC,CAAA;oBACpC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE;wBACpD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAA;oBACvC,CAAC,CAAC,CAAA;oBACF,OAAO,OAAO,CAAA;iBACf;gBACD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,UAAU,EAAE;oBAC/D,MAAM,OAAO,GAAQ,2BAAS,CAAC,IAAI,CAAC,CAAA;oBACpC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE;wBACpD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,WAAW,CAAA;oBACzC,CAAC,CAAC,CAAA;oBACF,OAAO,OAAO,CAAA;iBACf;YACH,CAAC;SACF;KACF,CAAC,CAAA;IAEF,gDAAgD;IAChD,GAAG,GAAG,eAAK,CAAC,GAAG,EAAE;QACf,oBAAoB,EAAE;YACpB,KAAK,CAAC,IAAI;;gBACR,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;oBAC5D,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,MAAK,CAAC;wBAAE,OAAO,IAAI,CAAA;iBAC3C;gBACD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,UAAU,EAAE;oBAC/D,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,MAAK,CAAC;wBAAE,OAAO,IAAI,CAAA;iBAC3C;YACH,CAAC;SACF;KACF,CAAC,CAAA;IAEF,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
- import { DocumentNode } from "graphql";
1
+ import { DocumentNode } from 'graphql';
2
2
  declare const _default: (ast: DocumentNode, source: string) => boolean;
3
3
  export default _default;
@@ -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;
@@ -20,19 +20,19 @@ exports.default = (ast, source) => {
20
20
  var _a, _b;
21
21
  const name = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;
22
22
  const value = (_b = node.value) === null || _b === void 0 ? void 0 : _b.value;
23
- if (name === "configuration") {
23
+ if (name === 'configuration') {
24
24
  configs = configs.concat(value);
25
25
  }
26
26
  },
27
27
  });
28
28
  configs = lodash_1.uniq(configs);
29
- configs = lodash_1.filter(configs, (config) => !STEPZEN_DEFAULTS.includes(config));
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) => {
@@ -46,3 +46,4 @@ exports.default = (ast, source) => {
46
46
  }
47
47
  return true;
48
48
  };
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/config-exists/index.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAC3C,mCAAmC;AACnC,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,MAAM,gBAAgB,GAAG;IACvB,eAAe;IACf,oBAAoB;IACpB,eAAe;IACf,aAAa;IACb,aAAa;CACd,CAAA;AAED,kBAAe,CAAC,GAAiB,EAAE,MAAc,EAAE,EAAE;;IACnD,IAAI,OAAO,GAAQ,EAAE,CAAA;IAErB,eAAK,CAAC,GAAG,EAAE;QACT,QAAQ,CAAC,IAAS;;YAChB,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAA;YAC7B,MAAM,KAAK,GAAG,MAAA,IAAI,CAAC,KAAK,0CA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4
  exports.default = [config_exists_1.default];
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";;AAAA,mDAA0C;AAE1C,kBAAe,CAAC,uBAAY,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,53 +1,61 @@
1
1
  {
2
2
  "name": "@stepzen/transpiler",
3
3
  "description": "The StepZen transpiler",
4
- "version": "0.0.32",
4
+ "version": "0.0.35",
5
5
  "author": "Darren Waddell <darren@stepzen.com>",
6
6
  "license": "MIT",
7
7
  "files": [
8
- "lib/**/*"
8
+ "lib/**/*",
9
+ "src/**/*"
9
10
  ],
10
11
  "main": "lib/index.js",
12
+ "types": "lib/index.d.ts",
11
13
  "engines": {
12
14
  "node": ">=14.0.1",
13
15
  "npm": ">=6.14"
14
16
  },
15
17
  "scripts": {
16
- "test": "rm -rf lib && tsc -b && nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\""
18
+ "prepare": "husky install",
19
+ "test": "rm -rf lib && tsc -b && nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
20
+ "posttest": "prettier . --check"
17
21
  },
18
22
  "dependencies": {
19
- "@graphql-tools/merge": "^6.2.13",
20
- "debug": "^4.3.1",
23
+ "@graphql-tools/merge": "^6.2.17",
24
+ "debug": "^4.3.3",
21
25
  "dotenv": "^10.0.0",
22
26
  "fs-extra": "^9.1.0",
23
- "glob": "^7.1.6",
24
- "graphql": "^15.5.0",
25
- "has-flag": "^5.0.0",
26
- "inquirer": "^8.0.0",
27
+ "glob": "^7.2.0",
28
+ "graphql": "^15.8.0",
29
+ "inquirer": "^8.2.0",
27
30
  "lodash": "^4.17.21",
28
- "node-fetch": "^2.6.1",
29
- "prettier": "^2.2.1",
30
- "shelljs": "^0.8.4",
31
+ "node-fetch": "^2.6.7",
32
+ "prettier": "^2.5.1",
33
+ "shelljs": "^0.8.5",
31
34
  "yaml": "^1.10.2"
32
35
  },
33
36
  "devDependencies": {
34
- "@types/debug": "^4.1.5",
37
+ "@types/debug": "^4.1.7",
35
38
  "@types/fs-extra": "^9.0.11",
36
- "@types/glob": "^7.1.3",
39
+ "@types/glob": "^7.2.0",
37
40
  "@types/inquirer": "^7.3.1",
38
41
  "@types/lodash": "^4.14.168",
39
42
  "@types/mocha": "^8.2.2",
40
43
  "@types/mock-fs": "^4.13.0",
41
- "@types/node-fetch": "^2.5.10",
42
- "@types/prettier": "^2.2.3",
44
+ "@types/node-fetch": "^2.6.1",
45
+ "@types/prettier": "^2.4.4",
43
46
  "@types/shelljs": "^0.8.9",
44
47
  "chai": "^4.3.4",
45
48
  "fancy-test": "^1.4.10",
49
+ "husky": "^7.0.4",
50
+ "lint-staged": "^12.3.4",
46
51
  "mocha": "^9.0.1",
47
52
  "mock-fs": "^4.13.0",
48
53
  "node-ts": "^5.1.1",
49
54
  "nyc": "^14.1.1",
50
55
  "ts-node": "^9.1.1",
51
56
  "typescript": "^4.2.4"
57
+ },
58
+ "lint-staged": {
59
+ "*.{ts,js,css,md,yaml,json}": "prettier --write"
52
60
  }
53
61
  }
@@ -0,0 +1,120 @@
1
+ import * as debug from 'debug'
2
+ import * as fs from 'fs-extra'
3
+ import * as glob from 'glob'
4
+ import * as inquirer from 'inquirer'
5
+ import * as path from 'path'
6
+ import * as yaml from 'yaml'
7
+
8
+ export default async (source: string, silent = false, answers: any = {}) => {
9
+ let config: any = {
10
+ configurationset: [],
11
+ ruleset: [],
12
+ }
13
+
14
+ // Now let's parse and add any config.yamls
15
+ for (const y of glob.sync('**/config.yaml', {cwd: source})) {
16
+ const filePath = path.join(source, y)
17
+
18
+ const file = fs.readFileSync(filePath, 'utf8')
19
+ const asYAML = yaml.parse(file)
20
+
21
+ debug('stepzen:transpiler')(`Adding config.yaml ${filePath}`)
22
+ debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asYAML, null, 2)}`)
23
+
24
+ if (asYAML.configurationset) {
25
+ config.configurationset = config.configurationset.concat(
26
+ asYAML.configurationset,
27
+ )
28
+ }
29
+
30
+ if (asYAML.ruleset) {
31
+ config.ruleset = config.ruleset.concat(asYAML.ruleset)
32
+ }
33
+ }
34
+
35
+ // Now let's build configs from questions
36
+ for await (const j of glob.sync('**/stepzen.config.json', {
37
+ cwd: source,
38
+ })) {
39
+ const filePath = path.join(source, j)
40
+
41
+ const file = fs.readFileSync(filePath, 'utf8')
42
+ const asJSON = JSON.parse(file)
43
+
44
+ debug('stepzen:transpiler')(`Adding stepzen.config.json ${filePath}`)
45
+ debug('stepzen:transpiler')(`Contents: ${JSON.stringify(asJSON, null, 2)}`)
46
+
47
+ if (asJSON.config?.questions) {
48
+ for await (const question of asJSON.config?.questions) {
49
+ const [name, key] = question.name.split('.')
50
+
51
+ let answer: any = {}
52
+
53
+ if (silent) {
54
+ answer = {
55
+ [name]: {[key]: answers[name]?.[key] ? answers[name]?.[key] : ''},
56
+ }
57
+ } else {
58
+ answer = await inquirer.prompt({
59
+ type: 'password',
60
+ ...question,
61
+ })
62
+ }
63
+
64
+ const configset = {
65
+ configuration: {
66
+ name,
67
+ [key]: answer[name][key],
68
+ },
69
+ }
70
+
71
+ debug('stepzen:transpiler')(
72
+ `Question: ${JSON.stringify(question, null, 2)}`,
73
+ )
74
+ debug('stepzen:transpiler')(
75
+ `Answer: ${JSON.stringify(configset, null, 2)}`,
76
+ )
77
+
78
+ config.configurationset.push({...configset})
79
+ }
80
+ }
81
+ }
82
+
83
+ debug('stepzen:transpiler')(
84
+ `Configuration: ${JSON.stringify(config, null, 2)}`,
85
+ )
86
+
87
+ // OK now let's collate everything into shared configurations
88
+ const obj: any = {}
89
+ for (const c of config.configurationset) {
90
+ const name = c.configuration.name
91
+ if (!obj[name]) obj[name] = {}
92
+ for (const [key, value] of Object.entries(c.configuration)) {
93
+ if (key === name) continue
94
+ obj[name][key] = value
95
+ }
96
+ }
97
+
98
+ // Now convert back into StepZen format
99
+ const structured: any = {
100
+ configurationset: [],
101
+ ruleset: [],
102
+ }
103
+ for (const configuration of Object.keys(obj)) {
104
+ structured.configurationset.push({
105
+ configuration: {...obj[configuration]},
106
+ })
107
+ }
108
+ structured.ruleset = [...config.ruleset]
109
+
110
+ // Return YAML, if appropriate
111
+ if (structured.configurationset.length === 0)
112
+ delete structured.configurationset
113
+ if (structured.ruleset.length === 0) delete structured.ruleset
114
+
115
+ if (structured.configurationset || structured.ruleset) {
116
+ return yaml.stringify(structured)
117
+ }
118
+
119
+ return false
120
+ }
@@ -0,0 +1,45 @@
1
+ import fetch from 'node-fetch'
2
+ import * as fs from 'fs-extra'
3
+ import * as os from 'os'
4
+ import * as path from 'path'
5
+ import * as shell from 'shelljs'
6
+
7
+ import stitch from '../actions/stitch'
8
+
9
+ export default async (
10
+ source: string,
11
+ options: {
12
+ extensions: string
13
+ } = {
14
+ extensions: '',
15
+ },
16
+ ) => {
17
+ if (!fs.existsSync(source)) {
18
+ throw new Error(`Cannot find source directory ${source}`)
19
+ }
20
+
21
+ let extensions = options.extensions
22
+
23
+ if (!extensions) {
24
+ const response = await fetch('https://www.steprz.net/directives.graphql')
25
+ extensions = await response.text()
26
+ }
27
+
28
+ const stitched = stitch(source)
29
+ const index = path.join(stitched, 'index.graphql')
30
+ const graphql = fs.readFileSync(index, 'utf8')
31
+
32
+ const tmp = path.join(os.tmpdir(), `stepzen-lint-${Date.now()}`)
33
+ fs.ensureDirSync(tmp)
34
+ const lintFile = path.join(tmp, 'index.graphql')
35
+ fs.writeFileSync(lintFile, `${extensions}${os.EOL}${os.EOL}${graphql}`)
36
+
37
+ shell.exec(
38
+ `npx graphql-schema-linter ${lintFile}`,
39
+ {silent: true},
40
+ (code, stdout, stderr) => {
41
+ console.log(stdout)
42
+ fs.removeSync(tmp)
43
+ },
44
+ )
45
+ }
@@ -0,0 +1,186 @@
1
+ import * as fs from 'fs-extra'
2
+ import * as glob from 'glob'
3
+ import {mergeTypeDefs} from '@graphql-tools/merge'
4
+ import {parse, visit} from 'graphql'
5
+ import * as os from 'os'
6
+ import * as path from 'path'
7
+
8
+ import {
9
+ dedupeTempFolder,
10
+ findQueryMutationInSchema,
11
+ findTypeInSchema,
12
+ getSchema,
13
+ mergeQueryMutationIntoSchema,
14
+ removeQueryMutationFromSchema,
15
+ mergeTypeIntoSchema,
16
+ removeTypeFromSchema,
17
+ getConfiguration,
18
+ } from '../utils/merge-helpers'
19
+ import print from './print'
20
+ import setFilesInSDL from '../utils/set-files-in-sdl'
21
+ import stripEmptyQueriesAndMutations from '../utils/strip-empty-queries-and-mutations'
22
+
23
+ const BLANK_INDEX_TEMPLATE = `
24
+ schema @sdl(files: []) {
25
+ query: Query
26
+ }
27
+
28
+ type Query {
29
+ __query: String
30
+ }
31
+ `.trim()
32
+
33
+ export default async (
34
+ original: string,
35
+ imported: {
36
+ name: string
37
+ source: string
38
+ },
39
+ options: {
40
+ answers: any
41
+ output: string | null
42
+ silent: boolean
43
+ } = {
44
+ answers: {},
45
+ output: null,
46
+ silent: false,
47
+ },
48
+ ) => {
49
+ // Make sure there is an output directory
50
+ if (!options.answers) options.answers = {}
51
+ if (!options.output)
52
+ options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)
53
+ if (!options.silent) options.silent = false
54
+
55
+ // To stop things like
56
+ // C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
57
+ options.output = dedupeTempFolder(options.output)
58
+
59
+ // Ensure original, importing and output directories exist
60
+ if (!fs.existsSync(original))
61
+ throw new Error(`Cannot find original directory ${original}`)
62
+ if (!fs.existsSync(imported.source))
63
+ throw new Error(`Cannot find imported source directory ${imported.source}`)
64
+ fs.ensureDirSync(options.output)
65
+
66
+ // Copy the original into the output.
67
+ fs.copySync(original, options.output)
68
+
69
+ // Ensure an index.graphql exists
70
+ const outputIndex = path.join(options.output, 'index.graphql')
71
+ if (!fs.existsSync(outputIndex)) {
72
+ fs.writeFileSync(outputIndex, BLANK_INDEX_TEMPLATE)
73
+ }
74
+
75
+ const merged = mergeTypeDefs([
76
+ await getSchema(options.output),
77
+ await getSchema(imported.source),
78
+ ])
79
+
80
+ let queries: any[] = []
81
+ let mutations: any[] = []
82
+ let types: any[] = []
83
+
84
+ visit(merged, {
85
+ ObjectTypeDefinition(node) {
86
+ if (node.name.value === 'Query') queries = queries.concat(node.fields)
87
+ else if (node.name.value === 'Mutation')
88
+ mutations = mutations.concat(node.fields)
89
+ else types = types.concat(node)
90
+ },
91
+ })
92
+
93
+ const details = {
94
+ original: glob.sync('**/*.graphql', {cwd: options.output}).map(file => {
95
+ const content = fs.readFileSync(`${options.output}/${file}`, 'utf8')
96
+ return {ast: parse(content), file}
97
+ }),
98
+ imported: glob.sync('**/*.graphql', {cwd: imported.source}).map(file => {
99
+ const content = fs.readFileSync(`${imported.source}/${file}`, 'utf8')
100
+ return {ast: parse(content), file}
101
+ }),
102
+ }
103
+
104
+ // Merge Queries and Mutations
105
+ for (const type of [...queries, ...mutations]) {
106
+ const isInOriginal = findQueryMutationInSchema(
107
+ type.name.value,
108
+ details.original,
109
+ )
110
+ const isInImported = findQueryMutationInSchema(
111
+ type.name.value,
112
+ details.imported,
113
+ )
114
+
115
+ if (isInOriginal && isInImported) {
116
+ details.original = mergeQueryMutationIntoSchema(type, details.original)
117
+ details.imported = removeQueryMutationFromSchema(
118
+ type.name.value,
119
+ details.imported,
120
+ )
121
+ }
122
+ }
123
+
124
+ // Merge Types
125
+ for (const type of types) {
126
+ const isInOriginal = findTypeInSchema(type.name.value, details.original)
127
+ const isInImported = findTypeInSchema(type.name.value, details.imported)
128
+
129
+ if (isInOriginal && isInImported) {
130
+ details.original = mergeTypeIntoSchema(type, details.original)
131
+ details.imported = removeTypeFromSchema(type.name.value, details.imported)
132
+ }
133
+ }
134
+
135
+ // Clean up the files. Remove empty Query / Mutation types, filter out now-empty files
136
+ const cleaned = {
137
+ original: details.original
138
+ .map(item => ({
139
+ ...item,
140
+ ast: stripEmptyQueriesAndMutations(item.ast),
141
+ }))
142
+ .filter(item => item.ast.definitions.length > 0),
143
+ imported: details.imported
144
+ .map(item => ({
145
+ ...item,
146
+ ast: stripEmptyQueriesAndMutations(item.ast),
147
+ }))
148
+ .filter(item => item.ast.definitions.length > 0),
149
+ }
150
+
151
+ // Write the files to the output directory
152
+ cleaned.original.forEach((a: any) => {
153
+ // eslint-disable-next-line
154
+ const file = path.join(options.output as any, a.file)
155
+ const deduped = dedupeTempFolder(file)
156
+
157
+ fs.ensureFileSync(deduped)
158
+ fs.writeFileSync(deduped, print(a.ast))
159
+ })
160
+
161
+ cleaned.imported.forEach(a => {
162
+ // eslint-disable-next-line
163
+ const file = path.join(options.output as any, imported.name, a.file)
164
+ const deduped = dedupeTempFolder(file)
165
+
166
+ fs.ensureFileSync(deduped)
167
+ fs.writeFileSync(deduped, print(a.ast))
168
+ })
169
+
170
+ // Make sure all files are referenced in @sdl
171
+ setFilesInSDL(options.output)
172
+
173
+ // Generate configuration
174
+ const config = await getConfiguration(
175
+ [options.output, imported.source],
176
+ options.silent,
177
+ options.answers,
178
+ )
179
+ if (config) {
180
+ const configFile = path.join(options.output, 'config.yaml')
181
+ fs.writeFileSync(configFile, config as string)
182
+ }
183
+
184
+ // Return a merged schema!
185
+ return options.output
186
+ }