@atlassian/clientside-extensions-schema 2.4.1 → 2.5.0-84fa90d-kwd5ix2w

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 (95) hide show
  1. package/dist/cjs/bin/generate-from-schema.js +15 -15
  2. package/dist/cjs/bin/generate-from-schema.js.map +1 -1
  3. package/dist/cjs/bin/generate-graphql-definitions.js +5 -5
  4. package/dist/cjs/bin/generate-graphql-definitions.js.map +1 -1
  5. package/dist/cjs/bin/generate-module-definitions-file.js +5 -5
  6. package/dist/cjs/bin/generate-module-definitions-file.js.map +1 -1
  7. package/dist/cjs/code-generator/code-generator.js +13 -13
  8. package/dist/cjs/code-generator/code-generator.js.map +1 -1
  9. package/dist/cjs/code-generator/type-definitions.js +5 -5
  10. package/dist/cjs/code-generator/type-definitions.js.map +1 -1
  11. package/dist/cjs/graphql-definition.js +4 -4
  12. package/dist/cjs/graphql-definition.js.map +1 -1
  13. package/dist/cjs/loader/schema-loader.js +12 -11
  14. package/dist/cjs/loader/schema-loader.js.map +1 -1
  15. package/dist/cjs/providedTypes/index.js +2 -2
  16. package/dist/cjs/providedTypes/index.js.map +1 -1
  17. package/dist/cjs/scalars/extensions/ModalOnAction.js +1 -1
  18. package/dist/cjs/scalars/extensions/ModalOnAction.js.map +1 -1
  19. package/dist/cjs/scalars/extensions/PanelOnAction.js +1 -1
  20. package/dist/cjs/scalars/extensions/PanelOnAction.js.map +1 -1
  21. package/dist/cjs/scalars/index.js +15 -15
  22. package/dist/cjs/scalars/index.js.map +1 -1
  23. package/dist/cjs/utils/ast-utils.js +34 -26
  24. package/dist/cjs/utils/ast-utils.js.map +1 -1
  25. package/dist/cjs/utils/create-schema.js +13 -10
  26. package/dist/cjs/utils/create-schema.js.map +1 -1
  27. package/dist/cjs/utils/default-resolvers.js +1 -1
  28. package/dist/cjs/utils/default-resolvers.js.map +1 -1
  29. package/dist/cjs/utils/inject-built-in-scalars.js +1 -1
  30. package/dist/cjs/utils/inject-built-in-scalars.js.map +1 -1
  31. package/dist/cjs/utils/inject-provided-types.js +3 -3
  32. package/dist/cjs/utils/inject-provided-types.js.map +1 -1
  33. package/dist/cjs/utils/pascal-case.js +2 -2
  34. package/dist/cjs/utils/pascal-case.js.map +1 -1
  35. package/dist/cjs/utils/schema-document-populator.js +12 -11
  36. package/dist/cjs/utils/schema-document-populator.js.map +1 -1
  37. package/dist/cjs/utils/schema-document-serializer.js +4 -3
  38. package/dist/cjs/utils/schema-document-serializer.js.map +1 -1
  39. package/dist/cjs/utils/schema.js +3 -2
  40. package/dist/cjs/utils/schema.js.map +1 -1
  41. package/dist/cjs/utils/validator-checks.js +28 -14
  42. package/dist/cjs/utils/validator-checks.js.map +1 -1
  43. package/dist/cjs/utils/validator-generator.js +26 -25
  44. package/dist/cjs/utils/validator-generator.js.map +1 -1
  45. package/dist/esm/code-generator/code-generator.js +1 -1
  46. package/dist/esm/code-generator/code-generator.js.map +1 -1
  47. package/dist/esm/loader/schema-loader.js +3 -2
  48. package/dist/esm/loader/schema-loader.js.map +1 -1
  49. package/dist/esm/scalars/extensions/ModalOnAction.js +1 -1
  50. package/dist/esm/scalars/extensions/ModalOnAction.js.map +1 -1
  51. package/dist/esm/scalars/extensions/PanelOnAction.js +1 -1
  52. package/dist/esm/scalars/extensions/PanelOnAction.js.map +1 -1
  53. package/dist/esm/utils/create-schema.js +3 -2
  54. package/dist/esm/utils/create-schema.js.map +1 -1
  55. package/dist/types/code-generator/code-generator.d.ts +3 -2
  56. package/dist/types/code-generator/code-generator.d.ts.map +1 -1
  57. package/dist/types/loader/schema-loader.d.ts.map +1 -1
  58. package/dist/types/utils/ast-utils.d.ts +1 -1
  59. package/dist/types/utils/ast-utils.d.ts.map +1 -1
  60. package/dist/types/utils/create-schema.d.ts.map +1 -1
  61. package/lib/code-generator/code-generator.ts +9 -7
  62. package/lib/loader/schema-loader.ts +4 -2
  63. package/lib/utils/create-schema.ts +4 -2
  64. package/lib/utils/validator-generator.test.ts +6 -6
  65. package/package.json +12 -10
  66. package/dist/cjs/code-generator/type-definitions.test.js +0 -22
  67. package/dist/cjs/code-generator/type-definitions.test.js.map +0 -1
  68. package/dist/cjs/loader/schema-loader.test.js +0 -52
  69. package/dist/cjs/loader/schema-loader.test.js.map +0 -1
  70. package/dist/cjs/utils/ast-utils.test.js +0 -67
  71. package/dist/cjs/utils/ast-utils.test.js.map +0 -1
  72. package/dist/cjs/utils/schema-document-populator.test.js +0 -117
  73. package/dist/cjs/utils/schema-document-populator.test.js.map +0 -1
  74. package/dist/cjs/utils/validator-generator.test.js +0 -1144
  75. package/dist/cjs/utils/validator-generator.test.js.map +0 -1
  76. package/dist/esm/code-generator/type-definitions.test.js +0 -19
  77. package/dist/esm/code-generator/type-definitions.test.js.map +0 -1
  78. package/dist/esm/loader/schema-loader.test.js +0 -49
  79. package/dist/esm/loader/schema-loader.test.js.map +0 -1
  80. package/dist/esm/utils/ast-utils.test.js +0 -65
  81. package/dist/esm/utils/ast-utils.test.js.map +0 -1
  82. package/dist/esm/utils/schema-document-populator.test.js +0 -114
  83. package/dist/esm/utils/schema-document-populator.test.js.map +0 -1
  84. package/dist/esm/utils/validator-generator.test.js +0 -1141
  85. package/dist/esm/utils/validator-generator.test.js.map +0 -1
  86. package/dist/types/code-generator/type-definitions.test.d.ts +0 -2
  87. package/dist/types/code-generator/type-definitions.test.d.ts.map +0 -1
  88. package/dist/types/loader/schema-loader.test.d.ts +0 -2
  89. package/dist/types/loader/schema-loader.test.d.ts.map +0 -1
  90. package/dist/types/utils/ast-utils.test.d.ts +0 -2
  91. package/dist/types/utils/ast-utils.test.d.ts.map +0 -1
  92. package/dist/types/utils/schema-document-populator.test.d.ts +0 -2
  93. package/dist/types/utils/schema-document-populator.test.d.ts.map +0 -1
  94. package/dist/types/utils/validator-generator.test.d.ts +0 -3
  95. package/dist/types/utils/validator-generator.test.d.ts.map +0 -1
@@ -2,19 +2,19 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
- const glob_1 = tslib_1.__importDefault(require("glob"));
5
+ const glob_1 = (0, tslib_1.__importDefault)(require("glob"));
6
6
  const util_1 = require("util");
7
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
8
- const path_1 = tslib_1.__importDefault(require("path"));
9
- const fs_1 = tslib_1.__importDefault(require("fs"));
10
- const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
11
- const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
12
- const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
13
- const lodash_snakecase_1 = tslib_1.__importDefault(require("lodash.snakecase"));
14
- const code_generator_1 = tslib_1.__importDefault(require("../code-generator/code-generator"));
7
+ const yargs_1 = (0, tslib_1.__importDefault)(require("yargs"));
8
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
9
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
10
+ const mkdirp_1 = (0, tslib_1.__importDefault)(require("mkdirp"));
11
+ const rimraf_1 = (0, tslib_1.__importDefault)(require("rimraf"));
12
+ const chokidar_1 = (0, tslib_1.__importDefault)(require("chokidar"));
13
+ const lodash_snakecase_1 = (0, tslib_1.__importDefault)(require("lodash.snakecase"));
14
+ const code_generator_1 = (0, tslib_1.__importDefault)(require("../code-generator/code-generator"));
15
15
  const schema_1 = require("../utils/schema");
16
- const globPromise = util_1.promisify(glob_1.default);
17
- const rimrafPromise = util_1.promisify(rimraf_1.default);
16
+ const globPromise = (0, util_1.promisify)(glob_1.default);
17
+ const rimrafPromise = (0, util_1.promisify)(rimraf_1.default);
18
18
  const appendExtension = (baseFileName, extension) => {
19
19
  return `${baseFileName}.${extension}`;
20
20
  };
@@ -22,7 +22,7 @@ const getGeneratorTargetDirectory = (filePath) => {
22
22
  return path_1.default.join(path_1.default.dirname(filePath), 'generated');
23
23
  };
24
24
  const ensureFileName = (name) => {
25
- return lodash_snakecase_1.default(name);
25
+ return (0, lodash_snakecase_1.default)(name);
26
26
  };
27
27
  const bustCacheForFile = (filePath) => {
28
28
  delete require.cache[require.resolve(filePath)]; // watch mode cache busting
@@ -37,20 +37,20 @@ const writeContentsToFile = (targetDirectory) => async (baseIdentifier, typescri
37
37
  const baseFilename = ensureFileName(baseIdentifier);
38
38
  const wrapperFileNameTs = path_1.default.join(targetDirectory, appendExtension(baseFilename, 'ts'));
39
39
  const wrapperFileNameJs = path_1.default.join(targetDirectory, appendExtension(baseFilename, 'js'));
40
- await mkdirp_1.default(path_1.default.dirname(wrapperFileNameTs));
40
+ await (0, mkdirp_1.default)(path_1.default.dirname(wrapperFileNameTs));
41
41
  await fs_1.default.promises.writeFile(wrapperFileNameTs, typescriptCode, 'utf8');
42
42
  await fs_1.default.promises.writeFile(wrapperFileNameJs, javascriptCode, 'utf8');
43
43
  return toRelativeIfExists(baseFilename);
44
44
  };
45
45
  const generateContentForSchemaFile = async (filePath, generatorOptions) => {
46
46
  bustCacheForFile(filePath);
47
- const schemaData = await schema_1.loadSchema(filePath);
47
+ const schemaData = await (0, schema_1.loadSchema)(filePath);
48
48
  if (!schemaData) {
49
49
  return;
50
50
  }
51
51
  const targetDirectory = getGeneratorTargetDirectory(filePath);
52
52
  try {
53
- await code_generator_1.default(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);
53
+ await (0, code_generator_1.default)(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);
54
54
  }
55
55
  catch (e) {
56
56
  console.error(`Something went wrong trying to generate the hooks for your extension point specified at "${filePath}".
@@ -1 +1 @@
1
- {"version":3,"file":"generate-from-schema.js","sourceRoot":"","sources":["../../../lib/bin/generate-from-schema.ts"],"names":[],"mappings":";;;;AACA,wDAAwB;AACxB,+BAAiC;AACjC,0DAA0B;AAC1B,wDAAwB;AACxB,oDAAoB;AACpB,4DAA4B;AAC5B,4DAA4B;AAC5B,gEAAgC;AAChC,gFAAyC;AACzC,8FAA4D;AAC5D,4CAA6C;AAI7C,MAAM,WAAW,GAAG,gBAAS,C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B;QACzC,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACrB,CAAC;SACD,MAAM,CAAC,aAAa,EAAE;QACnB,QAAQ,EAAE,gCAAgC;QAC1C,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;KAChB,CAAC;SACD,MAAM,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE;KACd,CAAC;QACF,mBAAmB;SAClB,MAAM,CAAC,gBAAgB,EAAE;QACtB,QAAQ,EAAE,sDAAsD;QAChE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QACb,QAAQ,EAAE,iDAAiD;QAC3D,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACX,QAAQ,EAAE,+EAA+E;QACzF,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;KACzB,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport glob from 'glob';\nimport { promisify } from 'util';\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport rimraf from 'rimraf';\nimport chokidar from 'chokidar';\nimport snakeCase from 'lodash.snakecase';\nimport generateCode from '../code-generator/code-generator';\nimport { loadSchema } from '../utils/schema';\n\nimport type { FileWriter, GeneratorOptions } from '../code-generator/code-generator';\n\nconst globPromise = promisify(glob);\nconst rimrafPromise = promisify(rimraf);\n\nconst appendExtension = (baseFileName: string, extension: string) => {\n return `${baseFileName}.${extension}`;\n};\n\nconst getGeneratorTargetDirectory = (filePath: string) => {\n return path.join(path.dirname(filePath), 'generated');\n};\n\nconst ensureFileName = (name: string) => {\n return snakeCase(name) as string;\n};\n\nconst bustCacheForFile = (filePath: string) => {\n delete require.cache[require.resolve(filePath)]; // watch mode cache busting\n};\n\nconst toRelativeIfExists = (filePath: string) => {\n if (!filePath) {\n return null;\n }\n\n return `./${filePath}`;\n};\n\nconst writeContentsToFile =\n (targetDirectory: string): FileWriter =>\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const baseFilename = ensureFileName(baseIdentifier);\n const wrapperFileNameTs = path.join(targetDirectory, appendExtension(baseFilename, 'ts'));\n const wrapperFileNameJs = path.join(targetDirectory, appendExtension(baseFilename, 'js'));\n await mkdirp(path.dirname(wrapperFileNameTs));\n await fs.promises.writeFile(wrapperFileNameTs, typescriptCode, 'utf8');\n await fs.promises.writeFile(wrapperFileNameJs, javascriptCode, 'utf8');\n\n return toRelativeIfExists(baseFilename);\n };\n\nconst generateContentForSchemaFile = async (filePath: string, generatorOptions: GeneratorOptions) => {\n bustCacheForFile(filePath);\n const schemaData = await loadSchema(filePath);\n if (!schemaData) {\n return;\n }\n const targetDirectory = getGeneratorTargetDirectory(filePath);\n try {\n await generateCode(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);\n } catch (e) {\n console.error(`Something went wrong trying to generate the hooks for your extension point specified at \"${filePath}\".\nIf this persists, feel free to raise an issue with us at: https://bitbucket.org/atlassian/atlassian-clientside-extensions/issues\n\nProvided Schema:\n${schemaData}\nOriginal Error:\n${e}`);\n }\n};\n\nconst cleanupTargetDir = async (targetDir: string) => {\n await rimrafPromise(targetDir);\n};\n\ntype Options = yargs.Arguments<{\n glob: string;\n cwd: string;\n watch: boolean;\n providedTypes: string;\n strictMode: boolean;\n validatorOnly: boolean;\n}>;\n\nconst getProvidedTypesPaths = async (options: Options): Promise<string[]> => {\n let paths: string[] = [];\n const { providedTypes: pattern, cwd } = options;\n\n if (pattern) {\n paths = await globPromise(pattern, { cwd, ignore: '**/node_modules/**' });\n\n if (!paths.length) {\n console.warn(`Schema code generator: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n }\n\n return paths;\n};\n\nconst generate = async (options: Options, providedTypesPaths: string[]) => {\n const { glob: pattern, cwd, strictMode, validatorOnly } = options;\n\n // TODO: Extract all this\n const resultFiles = await globPromise(pattern, { cwd, ignore: '**/node_modules/**' });\n const absoluteFilePaths = resultFiles.map((filePath) => path.resolve(path.join(cwd, filePath)));\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n // we have to run this first to remove all preexisting directories before generating any files\n // eslint-disable-next-line no-await-in-loop\n await cleanupTargetDir(getGeneratorTargetDirectory(absolutePath));\n }\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode,\n validatorOnly,\n };\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n bustCacheForFile(absolutePath);\n // eslint-disable-next-line no-await-in-loop\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n};\n\nconst run = async (options: Options) => {\n // TODO: Refactor this part to be more smart about watching changes in provided types\n let providedTypesPaths = await getProvidedTypesPaths(options);\n\n await generate(options, providedTypesPaths);\n\n if (options.watch) {\n console.log('Schema code generator watching for changes....');\n chokidar\n .watch([options.glob, options.providedTypes], {\n cwd: options.cwd,\n ignored: (changedFilePath: string) => {\n return changedFilePath.includes('node_modules');\n },\n })\n .on('all', async (eventName: string, filePath: string) => {\n // eslint-disable-next-line no-console\n console.log(`Schema code generator detected changes. Rebuilding \"${filePath}\"...`);\n const absolutePath = path.resolve(path.join(options.cwd, filePath));\n if (eventName !== 'unlink') {\n bustCacheForFile(absolutePath);\n\n // TODO: Refactor this part to be more smart about watching changes in provided types\n providedTypesPaths = await getProvidedTypesPaths(options);\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode: options.strictMode,\n validatorOnly: options.validatorOnly,\n };\n\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n });\n }\n};\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [options]',\n 'Generate hooks and other related code based on provided schema.',\n (builder) => {\n builder\n .option('glob', {\n describe: `Glob pattern to find schemas.`,\n type: 'string',\n demandOption: true,\n })\n .option('strict-mode', {\n describe: 'Toggles validation strict mode',\n type: 'boolean',\n default: true,\n })\n .option('provided-types', {\n describe: `Glob pattern to find provided types for schemas.`,\n type: 'string',\n default: '',\n })\n /** @since 2.1.0 */\n .option('validator-only', {\n describe: `Only generate validators for the given schema files.`,\n type: 'boolean',\n default: false,\n })\n .option('watch', {\n describe: `Continuously watch for and generate on changes.`,\n type: 'boolean',\n default: false,\n })\n .option('cwd', {\n describe: `The cwd in which the glob is searching for schemas. Defaults to process.cwd()`,\n type: 'string',\n default: process.cwd(),\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
1
+ {"version":3,"file":"generate-from-schema.js","sourceRoot":"","sources":["../../../lib/bin/generate-from-schema.ts"],"names":[],"mappings":";;;;AACA,6DAAwB;AACxB,+BAAiC;AACjC,+DAA0B;AAC1B,6DAAwB;AACxB,yDAAoB;AACpB,iEAA4B;AAC5B,iEAA4B;AAC5B,qEAAgC;AAChC,qFAAyC;AACzC,mGAA4D;AAC5D,4CAA6C;AAI7C,MAAM,WAAW,GAAG,IAAA,gBAAS,EAAC,cAAI,CAAC,CAAC;AACpC,MAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,gBAAM,CAAC,CAAC;AAExC,MAAM,eAAe,GAAG,CAAC,YAAoB,EAAE,SAAiB,EAAE,EAAE;IAChE,OAAO,GAAG,YAAY,IAAI,SAAS,EAAE,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,EAAE;IACrD,OAAO,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,EAAE;IACp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,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QACb,QAAQ,EAAE,iDAAiD;QAC3D,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACX,QAAQ,EAAE,+EAA+E;QACzF,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;KACzB,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport glob from 'glob';\nimport { promisify } from 'util';\nimport yargs from 'yargs';\nimport path from 'path';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp';\nimport rimraf from 'rimraf';\nimport chokidar from 'chokidar';\nimport snakeCase from 'lodash.snakecase';\nimport generateCode from '../code-generator/code-generator';\nimport { loadSchema } from '../utils/schema';\n\nimport type { FileWriter, GeneratorOptions } from '../code-generator/code-generator';\n\nconst globPromise = promisify(glob);\nconst rimrafPromise = promisify(rimraf);\n\nconst appendExtension = (baseFileName: string, extension: string) => {\n return `${baseFileName}.${extension}`;\n};\n\nconst getGeneratorTargetDirectory = (filePath: string) => {\n return path.join(path.dirname(filePath), 'generated');\n};\n\nconst ensureFileName = (name: string) => {\n return snakeCase(name) as string;\n};\n\nconst bustCacheForFile = (filePath: string) => {\n delete require.cache[require.resolve(filePath)]; // watch mode cache busting\n};\n\nconst toRelativeIfExists = (filePath: string) => {\n if (!filePath) {\n return null;\n }\n\n return `./${filePath}`;\n};\n\nconst writeContentsToFile =\n (targetDirectory: string): FileWriter =>\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const baseFilename = ensureFileName(baseIdentifier);\n const wrapperFileNameTs = path.join(targetDirectory, appendExtension(baseFilename, 'ts'));\n const wrapperFileNameJs = path.join(targetDirectory, appendExtension(baseFilename, 'js'));\n await mkdirp(path.dirname(wrapperFileNameTs));\n await fs.promises.writeFile(wrapperFileNameTs, typescriptCode, 'utf8');\n await fs.promises.writeFile(wrapperFileNameJs, javascriptCode, 'utf8');\n\n return toRelativeIfExists(baseFilename);\n };\n\nconst generateContentForSchemaFile = async (filePath: string, generatorOptions: GeneratorOptions) => {\n bustCacheForFile(filePath);\n const schemaData = await loadSchema(filePath);\n if (!schemaData) {\n return;\n }\n const targetDirectory = getGeneratorTargetDirectory(filePath);\n try {\n await generateCode(schemaData, generatorOptions, writeContentsToFile(targetDirectory), true);\n } catch (e) {\n console.error(`Something went wrong trying to generate the hooks for your extension point specified at \"${filePath}\".\nIf this persists, feel free to raise an issue with us at: https://bitbucket.org/atlassian/atlassian-clientside-extensions/issues\n\nProvided Schema:\n${schemaData}\nOriginal Error:\n${e}`);\n }\n};\n\nconst cleanupTargetDir = async (targetDir: string) => {\n await rimrafPromise(targetDir);\n};\n\ntype Options = yargs.Arguments<{\n glob: string;\n cwd: string;\n watch: boolean;\n providedTypes: string;\n strictMode: boolean;\n validatorOnly: boolean;\n}>;\n\nconst getProvidedTypesPaths = async (options: Options): Promise<string[]> => {\n let paths: string[] = [];\n const { providedTypes: pattern, cwd } = options;\n\n if (pattern) {\n paths = await globPromise(pattern, { cwd, ignore: '**/node_modules/**' });\n\n if (!paths.length) {\n console.warn(`Schema code generator: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n }\n\n return paths;\n};\n\nconst generate = async (options: Options, providedTypesPaths: string[]) => {\n const { glob: pattern, cwd, strictMode, validatorOnly } = options;\n\n // TODO: Extract all this\n const resultFiles = await globPromise(pattern, { cwd, ignore: '**/node_modules/**' });\n const absoluteFilePaths = resultFiles.map((filePath) => path.resolve(path.join(cwd, filePath)));\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n // we have to run this first to remove all preexisting directories before generating any files\n // eslint-disable-next-line no-await-in-loop\n await cleanupTargetDir(getGeneratorTargetDirectory(absolutePath));\n }\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode,\n validatorOnly,\n };\n\n // eslint-disable-next-line no-restricted-syntax\n for (const absolutePath of absoluteFilePaths) {\n bustCacheForFile(absolutePath);\n // eslint-disable-next-line no-await-in-loop\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n};\n\nconst run = async (options: Options) => {\n // TODO: Refactor this part to be more smart about watching changes in provided types\n let providedTypesPaths = await getProvidedTypesPaths(options);\n\n await generate(options, providedTypesPaths);\n\n if (options.watch) {\n console.log('Schema code generator watching for changes....');\n chokidar\n .watch([options.glob, options.providedTypes], {\n cwd: options.cwd,\n ignored: (changedFilePath: string) => {\n return changedFilePath.includes('node_modules');\n },\n })\n .on('all', async (eventName: string, filePath: string) => {\n // eslint-disable-next-line no-console\n console.log(`Schema code generator detected changes. Rebuilding \"${filePath}\"...`);\n const absolutePath = path.resolve(path.join(options.cwd, filePath));\n if (eventName !== 'unlink') {\n bustCacheForFile(absolutePath);\n\n // TODO: Refactor this part to be more smart about watching changes in provided types\n providedTypesPaths = await getProvidedTypesPaths(options);\n\n const generatorOptions: GeneratorOptions = {\n providedTypesPaths,\n strictMode: options.strictMode,\n validatorOnly: options.validatorOnly,\n };\n\n await generateContentForSchemaFile(absolutePath, generatorOptions);\n }\n });\n }\n};\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [options]',\n 'Generate hooks and other related code based on provided schema.',\n (builder) => {\n builder\n .option('glob', {\n describe: `Glob pattern to find schemas.`,\n type: 'string',\n demandOption: true,\n })\n .option('strict-mode', {\n describe: 'Toggles validation strict mode',\n type: 'boolean',\n default: true,\n })\n .option('provided-types', {\n describe: `Glob pattern to find provided types for schemas.`,\n type: 'string',\n default: '',\n })\n /** @since 2.1.0 */\n .option('validator-only', {\n describe: `Only generate validators for the given schema files.`,\n type: 'boolean',\n default: false,\n })\n .option('watch', {\n describe: `Continuously watch for and generate on changes.`,\n type: 'boolean',\n default: false,\n })\n .option('cwd', {\n describe: `The cwd in which the glob is searching for schemas. Defaults to process.cwd()`,\n type: 'string',\n default: process.cwd(),\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
@@ -2,12 +2,12 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
6
- const fs_1 = tslib_1.__importDefault(require("fs"));
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const graphql_definition_1 = tslib_1.__importDefault(require("../graphql-definition"));
5
+ const yargs_1 = (0, tslib_1.__importDefault)(require("yargs"));
6
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
7
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
8
+ const graphql_definition_1 = (0, tslib_1.__importDefault)(require("../graphql-definition"));
9
9
  const run = async (options) => {
10
- const definitions = await graphql_definition_1.default();
10
+ const definitions = await (0, graphql_definition_1.default)();
11
11
  if (!options.path) {
12
12
  console.log(definitions);
13
13
  process.exit(0);
@@ -1 +1 @@
1
- {"version":3,"file":"generate-graphql-definitions.js","sourceRoot":"","sources":["../../../lib/bin/generate-graphql-definitions.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAC1B,oDAAoB;AACpB,wDAAwB;AACxB,uFAAuD;AAKvD,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,MAAM,4BAAkB,EAAE,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,MAAM,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACvG,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,WAAW,EACX,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE;QACvB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAC;AACP,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport path from 'path';\nimport graphqlDefinitions from '../graphql-definition';\n\ntype Options = {\n path?: string;\n};\nconst run = async (options: Options) => {\n const definitions = await graphqlDefinitions();\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n const filePath = path.isAbsolute(options.path) ? options.path : path.join(process.cwd(), options.path);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder.positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
1
+ {"version":3,"file":"generate-graphql-definitions.js","sourceRoot":"","sources":["../../../lib/bin/generate-graphql-definitions.ts"],"names":[],"mappings":";;;;AACA,+DAA0B;AAC1B,yDAAoB;AACpB,6DAAwB;AACxB,4FAAuD;AAKvD,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAkB,GAAE,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,MAAM,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACvG,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,WAAW,EACX,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE;QACvB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAC;AACP,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport path from 'path';\nimport graphqlDefinitions from '../graphql-definition';\n\ntype Options = {\n path?: string;\n};\nconst run = async (options: Options) => {\n const definitions = await graphqlDefinitions();\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n const filePath = path.isAbsolute(options.path) ? options.path : path.join(process.cwd(), options.path);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder.positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
@@ -3,18 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const path_1 = require("path");
6
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
7
- const fs_1 = tslib_1.__importDefault(require("fs"));
8
- const type_definitions_1 = tslib_1.__importDefault(require("../code-generator/type-definitions"));
6
+ const yargs_1 = (0, tslib_1.__importDefault)(require("yargs"));
7
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
8
+ const type_definitions_1 = (0, tslib_1.__importDefault)(require("../code-generator/type-definitions"));
9
9
  const run = async (options) => {
10
- const definitions = type_definitions_1.default(options.moduleGlob);
10
+ const definitions = (0, type_definitions_1.default)(options.moduleGlob);
11
11
  if (!options.path) {
12
12
  console.log(definitions);
13
13
  process.exit(0);
14
14
  }
15
15
  // we now know it exists!
16
16
  const optionPath = options.path;
17
- const filePath = path_1.isAbsolute(optionPath) ? optionPath : path_1.join(process.cwd(), optionPath);
17
+ const filePath = (0, path_1.isAbsolute)(optionPath) ? optionPath : (0, path_1.join)(process.cwd(), optionPath);
18
18
  try {
19
19
  await fs_1.default.promises.writeFile(filePath, definitions, 'utf8');
20
20
  console.log(`Successfully wrote definitions to
@@ -1 +1 @@
1
- {"version":3,"file":"generate-module-definitions-file.js","sourceRoot":"","sources":["../../../lib/bin/generate-module-definitions-file.ts"],"names":[],"mappings":";;;;AACA,+BAAwC;AACxC,0DAA0B;AAC1B,oDAAoB;AACpB,kGAAgE;AAOhE,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,0BAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,yBAAyB;IACzB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAK,CAAC;IAEjC,MAAM,QAAQ,GAAG,iBAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IACvF,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,qBAAqB,EACrB,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO;SACF,UAAU,CAAC,MAAM,EAAE;QAChB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC;SAED,MAAM,CAAC,aAAa,EAAE;QACnB,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,uFAAuF;QACjG,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,eAAe;KAC3B,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport { isAbsolute, join } from 'path';\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport getDefinitions from '../code-generator/type-definitions';\n\ntype Options = {\n path?: string;\n moduleGlob: string;\n};\n\nconst run = async (options: Options) => {\n const definitions = getDefinitions(options.moduleGlob);\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n // we now know it exists!\n const optionPath = options.path!;\n\n const filePath = isAbsolute(optionPath) ? optionPath : join(process.cwd(), optionPath);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path] [options]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder\n .positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n })\n\n .option('module-glob', {\n alias: 'mg',\n describe: 'The name of the module the definitions are generated for. Defaults to \"*.cse.graphql\"',\n type: 'string',\n default: '*.cse.graphql',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
1
+ {"version":3,"file":"generate-module-definitions-file.js","sourceRoot":"","sources":["../../../lib/bin/generate-module-definitions-file.ts"],"names":[],"mappings":";;;;AACA,+BAAwC;AACxC,+DAA0B;AAC1B,yDAAoB;AACpB,uGAAgE;AAOhE,MAAM,GAAG,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,IAAA,0BAAc,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,yBAAyB;IACzB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAK,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAA,iBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IACvF,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC;EAClB,QAAQ,EAAE,CAAC,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACL,CAAC,CAAC;AAEF,oEAAoE;AACpE,eAAK;KACA,OAAO,CACJ,qBAAqB,EACrB,0GAA0G,EAC1G,CAAC,OAAO,EAAE,EAAE;IACR,OAAO;SACF,UAAU,CAAC,MAAM,EAAE;QAChB,QAAQ,EAAE,mCAAmC;QAC7C,IAAI,EAAE,QAAQ;KACjB,CAAC;SAED,MAAM,CAAC,aAAa,EAAE;QACnB,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,uFAAuF;QACjG,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,eAAe;KAC3B,CAAC,CAAC;AACX,CAAC,EACD,GAAG,CACN;KACA,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,4BAA4B","sourcesContent":["#!/usr/bin/env node\nimport { isAbsolute, join } from 'path';\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport getDefinitions from '../code-generator/type-definitions';\n\ntype Options = {\n path?: string;\n moduleGlob: string;\n};\n\nconst run = async (options: Options) => {\n const definitions = getDefinitions(options.moduleGlob);\n\n if (!options.path) {\n console.log(definitions);\n process.exit(0);\n }\n\n // we now know it exists!\n const optionPath = options.path!;\n\n const filePath = isAbsolute(optionPath) ? optionPath : join(process.cwd(), optionPath);\n try {\n await fs.promises.writeFile(filePath, definitions, 'utf8');\n console.log(`Successfully wrote definitions to\n${filePath}`);\n process.exit(0);\n } catch (e) {\n console.error(`Failed to write definitions to ${filePath}.`, e);\n process.exit(1);\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-expressions\nyargs\n .command(\n '$0 [path] [options]',\n 'Generate a definition file of available Scalars, Enums and Union types baked into clientside extensions.',\n (builder) => {\n builder\n .positional('path', {\n describe: `Filepath to store definitions in.`,\n type: 'string',\n })\n\n .option('module-glob', {\n alias: 'mg',\n describe: 'The name of the module the definitions are generated for. Defaults to \"*.cse.graphql\"',\n type: 'string',\n default: '*.cse.graphql',\n });\n },\n run,\n )\n .help().argv; // for --help and -h to work\n"]}
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const ts = tslib_1.__importStar(require("typescript"));
4
+ const ts = (0, tslib_1.__importStar)(require("typescript"));
5
5
  const schema_document_populator_1 = require("../utils/schema-document-populator");
6
6
  const create_schema_1 = require("../utils/create-schema");
7
7
  const validator_generator_1 = require("../utils/validator-generator");
8
8
  const schema_document_serializer_1 = require("../utils/schema-document-serializer");
9
- const SchemaDocument_1 = tslib_1.__importDefault(require("../utils/SchemaDocument"));
10
- const injcect_types_1 = tslib_1.__importDefault(require("../utils/injcect-types"));
9
+ const SchemaDocument_1 = (0, tslib_1.__importDefault)(require("../utils/SchemaDocument"));
10
+ const injcect_types_1 = (0, tslib_1.__importDefault)(require("../utils/injcect-types"));
11
11
  const schema_1 = require("../utils/schema");
12
12
  const utils_1 = require("../utils");
13
- const react_1 = tslib_1.__importDefault(require("./react"));
13
+ const react_1 = (0, tslib_1.__importDefault)(require("./react"));
14
14
  const generateJavascript = (source) => {
15
15
  const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });
16
16
  return result.outputText;
17
17
  };
18
18
  const schemaToDocument = (schemaString, baseTypeName) => {
19
- const schema = create_schema_1.getSchemaObject(schemaString, baseTypeName);
19
+ const schema = (0, create_schema_1.getSchemaObject)(schemaString, baseTypeName);
20
20
  const schemaDocument = new SchemaDocument_1.default();
21
- schema_document_populator_1.populateDocument(schemaDocument, schema);
21
+ (0, schema_document_populator_1.populateDocument)(schemaDocument, schema);
22
22
  return schemaDocument;
23
23
  };
24
24
  const getExtensionPointName = (schemaString) => {
@@ -27,12 +27,12 @@ const getExtensionPointName = (schemaString) => {
27
27
  return (_b = (_a = document.getObjectType('Schema')) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.extensionPoint;
28
28
  };
29
29
  const createValidatorForSchema = (schemaString, baseTypeName, options) => {
30
- return validator_generator_1.createValidator(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);
30
+ return (0, validator_generator_1.createValidator)(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);
31
31
  };
32
32
  const generateValidators = async (extensionPoint, schema, fileWriter, options) => {
33
33
  const attributeValidationOptions = {
34
34
  ...options,
35
- checkExcessiveKeys: false,
35
+ checkExcessiveKeys: false, // TODO: This should be enabled in the future
36
36
  };
37
37
  const attributeValidatorTypescript = createValidatorForSchema(schema, 'Schema', attributeValidationOptions);
38
38
  const validatorFile = await fileWriter(`${extensionPoint}_validator`, attributeValidatorTypescript, generateJavascript(attributeValidatorTypescript));
@@ -64,8 +64,8 @@ const contextSchemaDocument: SerializedDocument = ${contextSchemaDocument}
64
64
  export {schemaDocument, contextSchemaDocument }
65
65
  `;
66
66
  const generateSchemaDocuments = async (extensionPoint, schema, fileWriter) => {
67
- const schemaDocument = schema_document_serializer_1.serializeSchemaDocument(extensionPoint, schema, 'Schema');
68
- const contextSchemaDocument = schema_document_serializer_1.serializeSchemaDocument(extensionPoint, schema, 'ContextSchema');
67
+ const schemaDocument = (0, schema_document_serializer_1.serializeSchemaDocument)(extensionPoint, schema, 'Schema');
68
+ const contextSchemaDocument = (0, schema_document_serializer_1.serializeSchemaDocument)(extensionPoint, schema, 'ContextSchema');
69
69
  const schemaDocumentsTypescript = getSchemaDocumentContent(JSON.stringify(schemaDocument, null, 4), JSON.stringify(contextSchemaDocument, null, 4));
70
70
  const schemaDocumentsFile = await fileWriter(`${extensionPoint}_schema_documents`, schemaDocumentsTypescript, generateJavascript(schemaDocumentsTypescript));
71
71
  return schemaDocumentsFile;
@@ -77,7 +77,7 @@ const defaultOptions = {
77
77
  };
78
78
  const getGeneratedCode = async (attributeValidatorLocation, contextValidatorLocation, extensionPoint, schema, fileWriter) => {
79
79
  const schemaDocumentsFile = await generateSchemaDocuments(extensionPoint, schema, fileWriter);
80
- return react_1.default(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);
80
+ return (0, react_1.default)(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);
81
81
  };
82
82
  async function generateCode(schema, options, fileWriter, writeBase) {
83
83
  const { providedTypesPaths, strictMode, validatorOnly } = { ...defaultOptions, ...options };
@@ -85,9 +85,9 @@ async function generateCode(schema, options, fileWriter, writeBase) {
85
85
  throw new Error('The "validatorOnly" option is not available when "writeBase" is not true!');
86
86
  }
87
87
  // Extend schema with custom provided types
88
- const maybeProvidedTypesSchema = await Promise.all(providedTypesPaths.map((filePath) => schema_1.loadSchema(filePath)));
88
+ const maybeProvidedTypesSchema = await Promise.all(providedTypesPaths.map((filePath) => (0, schema_1.loadSchema)(filePath)));
89
89
  const providedTypesSchema = maybeProvidedTypesSchema.filter(utils_1.isNotNull);
90
- const baseSchema = injcect_types_1.default(schema, providedTypesSchema);
90
+ const baseSchema = (0, injcect_types_1.default)(schema, providedTypesSchema);
91
91
  // Read the extension point
92
92
  const extensionPoint = getExtensionPointName(baseSchema);
93
93
  if (!extensionPoint) {
@@ -1 +1 @@
1
- {"version":3,"file":"code-generator.js","sourceRoot":"","sources":["../../../lib/code-generator/code-generator.ts"],"names":[],"mappings":";;;AAAA,uDAAiC;AACjC,kFAAsE;AACtE,0DAAuF;AACvF,sEAA+D;AAC/D,oFAA8E;AAC9E,qFAAqD;AACrD,mFAAiD;AACjD,4CAA6C;AAC7C,oCAAqC;AAErC,4DAAoD;AAEpD,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,MAAM,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnG,OAAO,MAAM,CAAC,UAAU,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,EAAE;IACpE,MAAM,MAAM,GAAG,+BAAe,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,IAAI,wBAAc,EAAE,CAAC;IAC5C,4CAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACzC,OAAO,cAAc,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,qB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Aa,CAAC,CAAC,CAAC;QACnF,OAAO,SAAkC,CAAC;KAC7C;IAED,OAAO,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAA0B,CAAC;AACvG,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { populateDocument } from '../utils/schema-document-populator';\nimport { getSchemaObject, SchemaDefinitionMissingError } from '../utils/create-schema';\nimport { createValidator } from '../utils/validator-generator';\nimport { serializeSchemaDocument } from '../utils/schema-document-serializer';\nimport SchemaDocument from '../utils/SchemaDocument';\nimport injectTypes from '../utils/injcect-types';\nimport { loadSchema } from '../utils/schema';\nimport { isNotNull } from '../utils';\nimport type { ValidationOptions } from '../utils/validator-types';\nimport generateReactExtensionWrapper from './react';\n\nconst generateJavascript = (source: string) => {\n const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });\n return result.outputText;\n};\n\nconst schemaToDocument = (schemaString: string, baseTypeName: string) => {\n const schema = getSchemaObject(schemaString, baseTypeName);\n const schemaDocument = new SchemaDocument();\n populateDocument(schemaDocument, schema);\n return schemaDocument;\n};\n\nconst getExtensionPointName = (schemaString: string): string | undefined => {\n const document = schemaToDocument(schemaString, 'Schema');\n return document.getObjectType('Schema')?.meta?.extensionPoint as string;\n};\n\nconst createValidatorForSchema = (schemaString: string, baseTypeName: string, options: ValidationOptions) => {\n return createValidator(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);\n};\n\ntype ValidatorGeneratorOptions = {\n strictMode: boolean;\n};\n\nconst generateValidators = async (extensionPoint: string, schema: string, fileWriter: FileWriter, options: ValidatorGeneratorOptions) => {\n const attributeValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: false, // TODO: This should be enabled in the future\n };\n const attributeValidatorTypescript = createValidatorForSchema(schema, 'Schema', attributeValidationOptions);\n\n const validatorFile = await fileWriter(\n `${extensionPoint}_validator`,\n attributeValidatorTypescript,\n generateJavascript(attributeValidatorTypescript),\n );\n\n try {\n const contextValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: true,\n };\n const contextValidatorTypescript = createValidatorForSchema(schema, 'ContextSchema', contextValidationOptions);\n const contextValidatorFile = await fileWriter(\n `${extensionPoint}_validator_context`,\n contextValidatorTypescript,\n generateJavascript(contextValidatorTypescript),\n );\n return [validatorFile, contextValidatorFile];\n } catch (e) {\n // we allow for a missing context schema, as not all extension points have a context\n if (e instanceof SchemaDefinitionMissingError) {\n return [validatorFile];\n }\n\n // else rethrow\n throw e;\n }\n};\n\nconst getSchemaDocumentContent = (schemaDocument: string, contextSchemaDocument: string) => `\nimport { SerializedDocument } from '@atlassian/clientside-extensions-schema';\n\nconst schemaDocument: SerializedDocument = ${schemaDocument};\n\nconst contextSchemaDocument: SerializedDocument = ${contextSchemaDocument}\n\nexport {schemaDocument, contextSchemaDocument }\n`;\n\nconst generateSchemaDocuments = async (extensionPoint: string, schema: string, fileWriter: FileWriter) => {\n const schemaDocument = serializeSchemaDocument(extensionPoint, schema, 'Schema');\n const contextSchemaDocument = serializeSchemaDocument(extensionPoint, schema, 'ContextSchema');\n\n const schemaDocumentsTypescript = getSchemaDocumentContent(\n JSON.stringify(schemaDocument, null, 4),\n JSON.stringify(contextSchemaDocument, null, 4),\n );\n const schemaDocumentsFile = await fileWriter(\n `${extensionPoint}_schema_documents`,\n schemaDocumentsTypescript,\n generateJavascript(schemaDocumentsTypescript),\n );\n\n return schemaDocumentsFile as string;\n};\n\nexport type FileWriter = (baseFilename: string, typescriptCode: string, javascriptCode: string) => Promise<string | null>;\n\nexport interface GeneratorOptions {\n providedTypesPaths: string[];\n strictMode: boolean;\n validatorOnly: boolean;\n}\n\nconst defaultOptions: GeneratorOptions = {\n providedTypesPaths: [],\n strictMode: true,\n validatorOnly: false,\n};\n\nconst getGeneratedCode = async (\n attributeValidatorLocation: string | null,\n contextValidatorLocation: string | null,\n extensionPoint: string,\n schema: string,\n fileWriter: FileWriter,\n) => {\n const schemaDocumentsFile = await generateSchemaDocuments(extensionPoint, schema, fileWriter);\n return generateReactExtensionWrapper(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);\n};\n\ntype ReturnWithoutWrite<B extends boolean> = B extends true ? void : [string, string, string];\n\nasync function generateCode<B extends boolean>(\n schema: string,\n options: Partial<GeneratorOptions>,\n fileWriter: FileWriter,\n writeBase: B,\n): Promise<ReturnWithoutWrite<B>> {\n const { providedTypesPaths, strictMode, validatorOnly }: GeneratorOptions = { ...defaultOptions, ...options };\n if (!writeBase && validatorOnly) {\n throw new Error('The \"validatorOnly\" option is not available when \"writeBase\" is not true!');\n }\n\n // Extend schema with custom provided types\n const maybeProvidedTypesSchema: (string | null)[] = await Promise.all(providedTypesPaths.map((filePath) => loadSchema(filePath)));\n const providedTypesSchema: string[] = maybeProvidedTypesSchema.filter(isNotNull);\n const baseSchema = injectTypes(schema, providedTypesSchema);\n\n // Read the extension point\n const extensionPoint = getExtensionPointName(baseSchema);\n\n if (!extensionPoint) {\n throw new Error(`Could not extract the extension point from your provided schema.\nPlease ensure you specify the extensionPoint as part of the meta data within the description of your Schema.\n\nExample:\n\n\"\"\"\n---\nextensionPoint: specify-your-extension-point-name-here\n---\nThis is the description of your Schema\n\"\"\"\ntype Schema {\n // content of your schema…\n}\n`);\n }\n\n const validatorGeneratorOptions: ValidatorGeneratorOptions = {\n strictMode,\n };\n\n const [validatorFile, contextValidatorFile] = await generateValidators(\n extensionPoint,\n baseSchema,\n fileWriter,\n validatorGeneratorOptions,\n );\n\n if (validatorOnly) {\n return undefined as ReturnWithoutWrite<B>;\n }\n\n const generatedCode = await getGeneratedCode(validatorFile, contextValidatorFile, extensionPoint, baseSchema, fileWriter);\n\n if (writeBase) {\n await fileWriter(extensionPoint, generatedCode, generateJavascript(generatedCode));\n return undefined as ReturnWithoutWrite<B>;\n }\n\n return [extensionPoint, generatedCode, generateJavascript(generatedCode)] as ReturnWithoutWrite<B>;\n}\n\nexport default generateCode;\n"]}
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C,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClI,MAAM,mBAAmB,GAAa,wBAAwB,CAAC,MAAM,CAAC,iBAAS,CAAC,CAAC;IACjF,MAAM,UAAU,GAAG,IAAA,uBAAW,EAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAE5D,2BAA2B;IAC3B,MAAM,cAAc,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAEzD,IAAI,CAAC,cAAc,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;CAcvB,CAAC,CAAC;KACE;IAED,MAAM,yBAAyB,GAA8B;QACzD,UAAU;KACb,CAAC;IAEF,MAAM,CAAC,aAAa,EAAE,oBAAoB,CAAC,GAAG,MAAM,kBAAkB,CAClE,cAAc,EACd,UAAU,EACV,UAAU,EACV,yBAAyB,CAC5B,CAAC;IAEF,IAAI,aAAa,EAAE;QACf,OAAO,SAA2C,CAAC;KACtD;IAED,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE1H,IAAI,SAAS,EAAE;QACX,MAAM,UAAU,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;QACnF,OAAO,SAA2C,CAAC;KACtD;IAED,OAAO,CAAC,cAAc,EAAE,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAmC,CAAC;AAChH,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { populateDocument } from '../utils/schema-document-populator';\nimport { getSchemaObject, SchemaDefinitionMissingError } from '../utils/create-schema';\nimport { createValidator } from '../utils/validator-generator';\nimport { serializeSchemaDocument } from '../utils/schema-document-serializer';\nimport SchemaDocument from '../utils/SchemaDocument';\nimport injectTypes from '../utils/injcect-types';\nimport { loadSchema } from '../utils/schema';\nimport { isNotNull } from '../utils';\nimport type { ValidationOptions } from '../utils/validator-types';\nimport generateReactExtensionWrapper from './react';\n\nconst generateJavascript = (source: string) => {\n const result = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } });\n return result.outputText;\n};\n\nconst schemaToDocument = (schemaString: string, baseTypeName: string) => {\n const schema = getSchemaObject(schemaString, baseTypeName);\n const schemaDocument = new SchemaDocument();\n populateDocument(schemaDocument, schema);\n return schemaDocument;\n};\n\nconst getExtensionPointName = (schemaString: string): string | undefined => {\n const document = schemaToDocument(schemaString, 'Schema');\n return document.getObjectType('Schema')?.meta?.extensionPoint as string;\n};\n\nconst createValidatorForSchema = (schemaString: string, baseTypeName: string, options: ValidationOptions) => {\n return createValidator(schemaToDocument(schemaString, baseTypeName), baseTypeName, options);\n};\n\ntype ValidatorGeneratorOptions = {\n strictMode: boolean;\n};\n\nconst generateValidators = async (extensionPoint: string, schema: string, fileWriter: FileWriter, options: ValidatorGeneratorOptions) => {\n const attributeValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: false, // TODO: This should be enabled in the future\n };\n const attributeValidatorTypescript = createValidatorForSchema(schema, 'Schema', attributeValidationOptions);\n\n const validatorFile = await fileWriter(\n `${extensionPoint}_validator`,\n attributeValidatorTypescript,\n generateJavascript(attributeValidatorTypescript),\n );\n\n try {\n const contextValidationOptions: ValidationOptions = {\n ...options,\n checkExcessiveKeys: true,\n };\n const contextValidatorTypescript = createValidatorForSchema(schema, 'ContextSchema', contextValidationOptions);\n const contextValidatorFile = await fileWriter(\n `${extensionPoint}_validator_context`,\n contextValidatorTypescript,\n generateJavascript(contextValidatorTypescript),\n );\n return [validatorFile, contextValidatorFile];\n } catch (e) {\n // we allow for a missing context schema, as not all extension points have a context\n if (e instanceof SchemaDefinitionMissingError) {\n return [validatorFile];\n }\n\n // else rethrow\n throw e;\n }\n};\n\nconst getSchemaDocumentContent = (schemaDocument: string, contextSchemaDocument: string) => `\nimport { SerializedDocument } from '@atlassian/clientside-extensions-schema';\n\nconst schemaDocument: SerializedDocument = ${schemaDocument};\n\nconst contextSchemaDocument: SerializedDocument = ${contextSchemaDocument}\n\nexport {schemaDocument, contextSchemaDocument }\n`;\n\nconst generateSchemaDocuments = async (extensionPoint: string, schema: string, fileWriter: FileWriter) => {\n const schemaDocument = serializeSchemaDocument(extensionPoint, schema, 'Schema');\n const contextSchemaDocument = serializeSchemaDocument(extensionPoint, schema, 'ContextSchema');\n\n const schemaDocumentsTypescript = getSchemaDocumentContent(\n JSON.stringify(schemaDocument, null, 4),\n JSON.stringify(contextSchemaDocument, null, 4),\n );\n const schemaDocumentsFile = await fileWriter(\n `${extensionPoint}_schema_documents`,\n schemaDocumentsTypescript,\n generateJavascript(schemaDocumentsTypescript),\n );\n\n return schemaDocumentsFile as string;\n};\n\nexport type FileWriter = (baseFilename: string, typescriptCode: string, javascriptCode: string) => Promise<string | null>;\n\nexport interface GeneratorOptions {\n providedTypesPaths: string[];\n strictMode: boolean;\n validatorOnly: boolean;\n}\n\nconst defaultOptions: GeneratorOptions = {\n providedTypesPaths: [],\n strictMode: true,\n validatorOnly: false,\n};\n\nconst getGeneratedCode = async (\n attributeValidatorLocation: string | null,\n contextValidatorLocation: string | null,\n extensionPoint: string,\n schema: string,\n fileWriter: FileWriter,\n) => {\n const schemaDocumentsFile = await generateSchemaDocuments(extensionPoint, schema, fileWriter);\n return generateReactExtensionWrapper(attributeValidatorLocation, contextValidatorLocation, extensionPoint, schemaDocumentsFile);\n};\n\ntype GeneratedReturnType = [extensionPoint: string, generatedTsCdode: string, generatedJsCode: string];\n\ntype ReturnWithoutWrite<WriteBaseT extends boolean> = WriteBaseT extends true ? void : GeneratedReturnType;\n\nasync function generateCode<WriteBaseT extends boolean>(\n schema: string,\n options: Partial<GeneratorOptions>,\n fileWriter: FileWriter,\n writeBase: WriteBaseT,\n): Promise<ReturnWithoutWrite<WriteBaseT>> {\n const { providedTypesPaths, strictMode, validatorOnly }: GeneratorOptions = { ...defaultOptions, ...options };\n if (!writeBase && validatorOnly) {\n throw new Error('The \"validatorOnly\" option is not available when \"writeBase\" is not true!');\n }\n\n // Extend schema with custom provided types\n const maybeProvidedTypesSchema: (string | null)[] = await Promise.all(providedTypesPaths.map((filePath) => loadSchema(filePath)));\n const providedTypesSchema: string[] = maybeProvidedTypesSchema.filter(isNotNull);\n const baseSchema = injectTypes(schema, providedTypesSchema);\n\n // Read the extension point\n const extensionPoint = getExtensionPointName(baseSchema);\n\n if (!extensionPoint) {\n throw new Error(`Could not extract the extension point from your provided schema.\nPlease ensure you specify the extensionPoint as part of the meta data within the description of your Schema.\n\nExample:\n\n\"\"\"\n---\nextensionPoint: specify-your-extension-point-name-here\n---\nThis is the description of your Schema\n\"\"\"\ntype Schema {\n // content of your schema…\n}\n`);\n }\n\n const validatorGeneratorOptions: ValidatorGeneratorOptions = {\n strictMode,\n };\n\n const [validatorFile, contextValidatorFile] = await generateValidators(\n extensionPoint,\n baseSchema,\n fileWriter,\n validatorGeneratorOptions,\n );\n\n if (validatorOnly) {\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n const generatedCode = await getGeneratedCode(validatorFile, contextValidatorFile, extensionPoint, baseSchema, fileWriter);\n\n if (writeBase) {\n await fileWriter(extensionPoint, generatedCode, generateJavascript(generatedCode));\n return undefined as ReturnWithoutWrite<WriteBaseT>;\n }\n\n return [extensionPoint, generatedCode, generateJavascript(generatedCode)] as ReturnWithoutWrite<WriteBaseT>;\n}\n\nexport default generateCode;\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const typescript_1 = tslib_1.__importDefault(require("typescript"));
4
+ const typescript_1 = (0, tslib_1.__importDefault)(require("typescript"));
5
5
  const path_1 = require("path");
6
- const react_1 = tslib_1.__importDefault(require("./react"));
6
+ const react_1 = (0, tslib_1.__importDefault)(require("./react"));
7
7
  const removeNestedDeclareKeywords = (definitions) => {
8
8
  const declareConstRegExp = /export declare const/g;
9
9
  const declareConstReplacer = 'export const';
@@ -43,13 +43,13 @@ const generateModuleDescriptor = (code) => {
43
43
  const host = typescript_1.default.createCompilerHost(compilerOptions);
44
44
  const oldRead = host.readFile;
45
45
  host.readFile = (fileName) => {
46
- if (baseFilename === path_1.basename(fileName, path_1.extname(fileName))) {
46
+ if (baseFilename === (0, path_1.basename)(fileName, (0, path_1.extname)(fileName))) {
47
47
  return code;
48
48
  }
49
49
  return oldRead(fileName);
50
50
  };
51
51
  host.writeFile = (fileName, contents) => {
52
- if (path_1.basename(fileName).startsWith(baseFilename) && fileName.endsWith('.d.ts')) {
52
+ if ((0, path_1.basename)(fileName).startsWith(baseFilename) && fileName.endsWith('.d.ts')) {
53
53
  definition = contents;
54
54
  }
55
55
  };
@@ -59,7 +59,7 @@ const generateModuleDescriptor = (code) => {
59
59
  return definition;
60
60
  };
61
61
  const getReactDefinitions = () => {
62
- return generateModuleDescriptor(react_1.default(null, null, null, null));
62
+ return generateModuleDescriptor((0, react_1.default)(null, null, null, null));
63
63
  };
64
64
  // Generate a fake wrapper and make typescript generate typings for it
65
65
  function getDefinitions(moduleGlob) {
@@ -1 +1 @@
1
- {"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":";;;AACA,oEAA4B;AAC5B,+BAAyC;AACzC,4DAAoD;AAEpD,MAAM,2BAA2B,GAAG,CAAC,WAAmB,EAAU,EAAE;IAChE,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,MAAM,oBAAoB,GAAG,cAAc,CAAC;IAE5C,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC1C,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,MAAM,OAAO,GAAuB;QAChC,CAAC,kBAAkB,EAAE,oBAAoB,CAAC;QAC1C,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KAC3C,CAAC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,IAAI,CAAC,SAAS,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAE;QACpD,IAAI,eAAQ,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3E,UAAU,GAAG,QAAQ,CAAC;SACzB;IACL,CAAC,CAAC;IAEF,kCAAkC;IAClC,MAAM,OAAO,GAAG,oBAAE,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;IACxE,OAAO,CAAC,IAAI,EAAE,CAAC;IAEf,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC7B,OAAO,wBAAwB,CAAC,eAA6B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3F,CAAC,CAAC;AAEF,sEAAsE;AACtE,SAAwB,cAAc,CAAC,UAAkB;IACrD,OAAO,sBAAsB,CAAC,mBAAmB,EAAE,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC;AAFD,iCAEC","sourcesContent":["import type { CompilerOptions } from 'typescript';\nimport ts from 'typescript';\nimport { basename, extname } from 'path';\nimport generateReactExtensionWrapper from './react';\n\nconst removeNestedDeclareKeywords = (definitions: string): string => {\n const declareConstRegExp = /export declare const/g;\n const declareConstReplacer = 'export const';\n\n const declareTypeRegExp = /declare type/g;\n const declareTypeReplacer = 'type';\n\n const regExps: [RegExp, string][] = [\n [declareConstRegExp, declareConstReplacer],\n [declareTypeRegExp, declareTypeReplacer],\n ];\n\n for (const [regExp, replacer] of regExps) {\n definitions = definitions.replace(regExp, replacer);\n }\n\n return definitions;\n};\n\nconst wrapInModuleDefinition = (definitions: string, moduleGlob: string) => {\n return `declare module '${moduleGlob}' {\n${removeNestedDeclareKeywords(definitions).replace(/^/gm, ' '.repeat(4))}\n}\n`;\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nconst generateModuleDescriptor = (code: string) => {\n const baseFilename = `FAKE_NAME${Math.floor(Math.random() * 1000)}`;\n\n let definition = '';\n\n const compilerOptions: CompilerOptions = {\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n strict: true,\n\n // We don't want to check the declarations files at this point,\n // https://github.com/microsoft/TypeScript/wiki/Performance#skipping-dts-checking\n skipLibCheck: true,\n\n // We don't want to put all the types definitions by default\n // https://github.com/microsoft/TypeScript/wiki/Performance#controlling-types-inclusion\n types: [],\n };\n\n const host = ts.createCompilerHost(compilerOptions);\n const oldRead = host.readFile;\n host.readFile = (fileName: string) => {\n if (baseFilename === basename(fileName, extname(fileName))) {\n return code;\n }\n return oldRead(fileName);\n };\n host.writeFile = (fileName: string, contents: string) => {\n if (basename(fileName).startsWith(baseFilename) && fileName.endsWith('.d.ts')) {\n definition = contents;\n }\n };\n\n // Prepare and emit the d.ts files\n const program = ts.createProgram([baseFilename], compilerOptions, host);\n program.emit();\n\n return definition;\n};\n\nconst getReactDefinitions = () => {\n return generateModuleDescriptor(generateReactExtensionWrapper(null, null, null, null));\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nexport default function getDefinitions(moduleGlob: string) {\n return wrapInModuleDefinition(getReactDefinitions(), moduleGlob);\n}\n"]}
1
+ {"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../lib/code-generator/type-definitions.ts"],"names":[],"mappings":";;;AACA,yEAA4B;AAC5B,+BAAyC;AACzC,iEAAoD;AAEpD,MAAM,2BAA2B,GAAG,CAAC,WAAmB,EAAU,EAAE;IAChE,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,MAAM,oBAAoB,GAAG,cAAc,CAAC;IAE5C,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC1C,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,MAAM,OAAO,GAAuB;QAChC,CAAC,kBAAkB,EAAE,oBAAoB,CAAC;QAC1C,CAA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,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,IAAI,CAAC,SAAS,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAE;QACpD,IAAI,IAAA,eAAQ,EAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3E,UAAU,GAAG,QAAQ,CAAC;SACzB;IACL,CAAC,CAAC;IAEF,kCAAkC;IAClC,MAAM,OAAO,GAAG,oBAAE,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;IACxE,OAAO,CAAC,IAAI,EAAE,CAAC;IAEf,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC7B,OAAO,wBAAwB,CAAC,IAAA,eAA6B,EAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3F,CAAC,CAAC;AAEF,sEAAsE;AACtE,SAAwB,cAAc,CAAC,UAAkB;IACrD,OAAO,sBAAsB,CAAC,mBAAmB,EAAE,EAAE,UAAU,CAAC,CAAC;AACrE,CAAC;AAFD,iCAEC","sourcesContent":["import type { CompilerOptions } from 'typescript';\nimport ts from 'typescript';\nimport { basename, extname } from 'path';\nimport generateReactExtensionWrapper from './react';\n\nconst removeNestedDeclareKeywords = (definitions: string): string => {\n const declareConstRegExp = /export declare const/g;\n const declareConstReplacer = 'export const';\n\n const declareTypeRegExp = /declare type/g;\n const declareTypeReplacer = 'type';\n\n const regExps: [RegExp, string][] = [\n [declareConstRegExp, declareConstReplacer],\n [declareTypeRegExp, declareTypeReplacer],\n ];\n\n for (const [regExp, replacer] of regExps) {\n definitions = definitions.replace(regExp, replacer);\n }\n\n return definitions;\n};\n\nconst wrapInModuleDefinition = (definitions: string, moduleGlob: string) => {\n return `declare module '${moduleGlob}' {\n${removeNestedDeclareKeywords(definitions).replace(/^/gm, ' '.repeat(4))}\n}\n`;\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nconst generateModuleDescriptor = (code: string) => {\n const baseFilename = `FAKE_NAME${Math.floor(Math.random() * 1000)}`;\n\n let definition = '';\n\n const compilerOptions: CompilerOptions = {\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n strict: true,\n\n // We don't want to check the declarations files at this point,\n // https://github.com/microsoft/TypeScript/wiki/Performance#skipping-dts-checking\n skipLibCheck: true,\n\n // We don't want to put all the types definitions by default\n // https://github.com/microsoft/TypeScript/wiki/Performance#controlling-types-inclusion\n types: [],\n };\n\n const host = ts.createCompilerHost(compilerOptions);\n const oldRead = host.readFile;\n host.readFile = (fileName: string) => {\n if (baseFilename === basename(fileName, extname(fileName))) {\n return code;\n }\n return oldRead(fileName);\n };\n host.writeFile = (fileName: string, contents: string) => {\n if (basename(fileName).startsWith(baseFilename) && fileName.endsWith('.d.ts')) {\n definition = contents;\n }\n };\n\n // Prepare and emit the d.ts files\n const program = ts.createProgram([baseFilename], compilerOptions, host);\n program.emit();\n\n return definition;\n};\n\nconst getReactDefinitions = () => {\n return generateModuleDescriptor(generateReactExtensionWrapper(null, null, null, null));\n};\n\n// Generate a fake wrapper and make typescript generate typings for it\nexport default function getDefinitions(moduleGlob: string) {\n return wrapInModuleDefinition(getReactDefinitions(), moduleGlob);\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const glob_1 = tslib_1.__importDefault(require("glob"));
4
+ const glob_1 = (0, tslib_1.__importDefault)(require("glob"));
5
5
  const util_1 = require("util");
6
- const globPromise = util_1.promisify(glob_1.default);
6
+ const globPromise = (0, util_1.promisify)(glob_1.default);
7
7
  const scalarToDefinitionString = (scalar) => {
8
8
  return `
9
9
  """
@@ -16,14 +16,14 @@ scalar ${scalar.name}
16
16
  const getScalars = async () => {
17
17
  const scalarFiles = await globPromise('./scalars/**/*.js', { cwd: __dirname });
18
18
  const scalars = (await Promise.all(scalarFiles.map(async (filePath) => {
19
- return (await Promise.resolve().then(() => tslib_1.__importStar(require(filePath)))).default;
19
+ return (await Promise.resolve().then(() => (0, tslib_1.__importStar)(require(filePath)))).default;
20
20
  }))).filter(Boolean);
21
21
  return scalars.map(scalarToDefinitionString).join('\n\n');
22
22
  };
23
23
  const getProvidedTypes = async () => {
24
24
  const providedTypesFiles = await globPromise('./providedTypes/*.js', { cwd: __dirname });
25
25
  const providedTypes = await Promise.all(providedTypesFiles.map(async (filePath) => {
26
- return (await Promise.resolve().then(() => tslib_1.__importStar(require(filePath)))).default;
26
+ return (await Promise.resolve().then(() => (0, tslib_1.__importStar)(require(filePath)))).default;
27
27
  }));
28
28
  return providedTypes.join('\n\n');
29
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-definition.js","sourceRoot":"","sources":["../../lib/graphql-definition.ts"],"names":[],"mappings":";;;AAAA,wDAAwB;AACxB,+BAAiC;AAGjC,MAAM,WAAW,GAAG,gBAAS,CAAC,cAAI,CAAC,CAAC;AAEpC,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,EAAE;IAChD,OAAO;;EAET,MAAM,CAAC,WAAW;WACT,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc;;SAE3G,MAAM,CAAC,IAAI;CACnB,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC1B,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,mBAAmB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,CACZ,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/B,OAAO,CAAC,gEAAa,QAAQ,GAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CACJ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IAChC,MAAM,kBAAkB,GAAG,MAAM,WAAW,CAAC,sBAAsB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IACzF,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACnC,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACtC,OAAO,CAAC,gEAAa,QAAQ,GAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,kBAAe,KAAK,IAAI,EAAE;IACtB,MAAM,iBAAiB,GAAG,MAAM,UAAU,EAAE,CAAC;IAC7C,MAAM,wBAAwB,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAE1D,OAAO;;;;EAIT,iBAAiB;;;;;EAKjB,wBAAwB;CACzB,CAAC;AACF,CAAC,CAAC","sourcesContent":["import glob from 'glob';\nimport { promisify } from 'util';\nimport type { Scalar } from './scalars/types';\n\nconst globPromise = promisify(glob);\n\nconst scalarToDefinitionString = (scalar: Scalar) => {\n return `\n\"\"\"\n${scalar.description}\nExample: ${typeof scalar.defaultExample === 'string' ? JSON.stringify(scalar.defaultExample) : scalar.defaultExample}\n\"\"\"\nscalar ${scalar.name}\n`;\n};\n\nconst getScalars = async () => {\n const scalarFiles = await globPromise('./scalars/**/*.js', { cwd: __dirname });\n const scalars = (\n await Promise.all(\n scalarFiles.map(async (filePath) => {\n return (await import(filePath)).default as Scalar;\n }),\n )\n ).filter(Boolean);\n\n return scalars.map(scalarToDefinitionString).join('\\n\\n');\n};\n\nconst getProvidedTypes = async () => {\n const providedTypesFiles = await globPromise('./providedTypes/*.js', { cwd: __dirname });\n const providedTypes = await Promise.all(\n providedTypesFiles.map(async (filePath) => {\n return (await import(filePath)).default as string;\n }),\n );\n\n return providedTypes.join('\\n\\n');\n};\n\nexport default async () => {\n const scalarDefinitions = await getScalars();\n const providedTypesDefinitions = await getProvidedTypes();\n\n return `\n###########################################################\n# GENERATED: Scalar definitions for clientside extensions #\n###########################################################\n${scalarDefinitions}\n\n############################################################################\n# GENERATED: Other provided types, enums, unions for clientside extensions #\n############################################################################\n${providedTypesDefinitions}\n`;\n};\n"]}
1
+ {"version":3,"file":"graphql-definition.js","sourceRoot":"","sources":["../../lib/graphql-definition.ts"],"names":[],"mappings":";;;AAAA,6DAAwB;AACxB,+BAAiC;AAGjC,MAAM,WAAW,GAAG,IAAA,gBAAS,EAAC,cAAI,CAAC,CAAC;AAEpC,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,EAAE;IAChD,OAAO;;EAET,MAAM,CAAC,WAAW;WACT,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc;;SAE3G,MAAM,CAAC,IAAI;CACnB,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC1B,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,mBAAmB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,CACZ,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/B,OAAO,CAAC,qEAAa,QAAQ,GAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CACJ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,OAAO,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IAChC,MAAM,kBAAkB,GAAG,MAAM,WAAW,CAAC,sBAAsB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IACzF,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACnC,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACtC,OAAO,CAAC,qEAAa,QAAQ,GAAC,CAAC,CAAC,OAAiB,CAAC;IACtD,CAAC,CAAC,CACL,CAAC;IAEF,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,kBAAe,KAAK,IAAI,EAAE;IACtB,MAAM,iBAAiB,GAAG,MAAM,UAAU,EAAE,CAAC;IAC7C,MAAM,wBAAwB,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAE1D,OAAO;;;;EAIT,iBAAiB;;;;;EAKjB,wBAAwB;CACzB,CAAC;AACF,CAAC,CAAC","sourcesContent":["import glob from 'glob';\nimport { promisify } from 'util';\nimport type { Scalar } from './scalars/types';\n\nconst globPromise = promisify(glob);\n\nconst scalarToDefinitionString = (scalar: Scalar) => {\n return `\n\"\"\"\n${scalar.description}\nExample: ${typeof scalar.defaultExample === 'string' ? JSON.stringify(scalar.defaultExample) : scalar.defaultExample}\n\"\"\"\nscalar ${scalar.name}\n`;\n};\n\nconst getScalars = async () => {\n const scalarFiles = await globPromise('./scalars/**/*.js', { cwd: __dirname });\n const scalars = (\n await Promise.all(\n scalarFiles.map(async (filePath) => {\n return (await import(filePath)).default as Scalar;\n }),\n )\n ).filter(Boolean);\n\n return scalars.map(scalarToDefinitionString).join('\\n\\n');\n};\n\nconst getProvidedTypes = async () => {\n const providedTypesFiles = await globPromise('./providedTypes/*.js', { cwd: __dirname });\n const providedTypes = await Promise.all(\n providedTypesFiles.map(async (filePath) => {\n return (await import(filePath)).default as string;\n }),\n );\n\n return providedTypes.join('\\n\\n');\n};\n\nexport default async () => {\n const scalarDefinitions = await getScalars();\n const providedTypesDefinitions = await getProvidedTypes();\n\n return `\n###########################################################\n# GENERATED: Scalar definitions for clientside extensions #\n###########################################################\n${scalarDefinitions}\n\n############################################################################\n# GENERATED: Other provided types, enums, unions for clientside extensions #\n############################################################################\n${providedTypesDefinitions}\n`;\n};\n"]}
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const loader_utils_1 = require("loader-utils");
5
- const glob_1 = tslib_1.__importDefault(require("glob"));
5
+ const glob_1 = (0, tslib_1.__importDefault)(require("glob"));
6
6
  const schema_utils_1 = require("schema-utils");
7
7
  const util_1 = require("util");
8
- const code_generator_1 = tslib_1.__importDefault(require("../code-generator/code-generator"));
9
- const loader_schema_json_1 = tslib_1.__importDefault(require("./loader-schema.json"));
10
- const globPromise = util_1.promisify(glob_1.default);
11
- const toFilename = (loaderContext, identifier, content) => loader_utils_1.interpolateName(loaderContext, `${identifier}.[contenthash].js`, {
8
+ const code_generator_1 = (0, tslib_1.__importDefault)(require("../code-generator/code-generator"));
9
+ const loader_schema_json_1 = (0, tslib_1.__importDefault)(require("./loader-schema.json"));
10
+ const globPromise = (0, util_1.promisify)(glob_1.default);
11
+ const toFilename = (loaderContext, identifier, content) => (0, loader_utils_1.interpolateName)(loaderContext, `${identifier}.[contenthash].js`, {
12
12
  context: loaderContext.rootContext,
13
13
  content,
14
14
  });
@@ -41,8 +41,8 @@ const defaultLoaderOptions = {
41
41
  async function schemaLoader(content) {
42
42
  const callback = this.async();
43
43
  // Get and validate loader options
44
- const loaderOptions = loader_utils_1.getOptions(this);
45
- schema_utils_1.validate(loader_schema_json_1.default, loaderOptions, { name: 'CSE schema-loader' });
44
+ const loaderOptions = (0, loader_utils_1.getOptions)(this);
45
+ (0, schema_utils_1.validate)(loader_schema_json_1.default, loaderOptions, { name: 'CSE schema-loader' });
46
46
  const { providedTypes: providedTypesPattern, strictMode } = { ...defaultLoaderOptions, ...loaderOptions };
47
47
  // Get provided types
48
48
  let providedTypesPaths = [];
@@ -54,7 +54,7 @@ async function schemaLoader(content) {
54
54
  // Run schema compiler
55
55
  const loaderContext = this;
56
56
  if (this.resourceQuery) {
57
- const rqOptions = loader_utils_1.parseQuery(this.resourceQuery);
57
+ const rqOptions = (0, loader_utils_1.parseQuery)(this.resourceQuery);
58
58
  if (rqOptions.subfile && fileStore.has(rqOptions.subfile)) {
59
59
  callback(null, fileStore.get(rqOptions.subfile));
60
60
  return;
@@ -67,7 +67,7 @@ async function schemaLoader(content) {
67
67
  providedTypesPaths,
68
68
  strictMode,
69
69
  };
70
- const [, , generatedJavascript] = await code_generator_1.default(content, generatorOptions, async (baseIdentifier, typescriptCode, javascriptCode) => {
70
+ const [, , generatedJavascript] = await (0, code_generator_1.default)(content, generatorOptions, async (baseIdentifier, typescriptCode, javascriptCode) => {
71
71
  const filename = toFilename(loaderContext, baseIdentifier, javascriptCode);
72
72
  fileStore.set(filename, javascriptCode);
73
73
  const resourcePath = serializePath(loaderContext.resourcePath);
@@ -75,8 +75,9 @@ async function schemaLoader(content) {
75
75
  }, false);
76
76
  callback(null, generatedJavascript);
77
77
  }
78
- catch (e) {
79
- callback(e);
78
+ catch (err) {
79
+ const error = err;
80
+ callback(error);
80
81
  }
81
82
  }
82
83
  exports.default = schemaLoader;
@@ -1 +1 @@
1
- {"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../lib/loader/schema-loader.ts"],"names":[],"mappings":";;;AAAA,+CAAuE;AACvE,wDAAwB;AACxB,+CAAwC;AAGxC,+BAAiC;AAEjC,8FAA4D;AAC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AAE,cAAc,CAAC,CAAC;YAC3E,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAExC,MAAM,YAAY,GAAG,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;YAE/D,OAAO,KAAK,iBAAiB,IAAI,YAAY,YAAY,QAAQ,EAAE,CAAC;QACxE,CAAC,EACD,KAAK,CACR,CAAC;QACF,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;KACvC;IAAC,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,CAAC,CAAC,CAAC;KACf;AACL,CAAC;AA1DD,+BA0DC","sourcesContent":["import { getOptions, interpolateName, parseQuery } from 'loader-utils';\nimport glob from 'glob';\nimport { validate } from 'schema-utils';\n\nimport type { Schema } from 'schema-utils/declarations/validate';\nimport { promisify } from 'util';\nimport type { GeneratorOptions } from '../code-generator/code-generator';\nimport generateCode from '../code-generator/code-generator';\nimport schema from './loader-schema.json';\nimport type { LoaderOptions, LoaderContext, LoaderCallback, QueryObject } from './types';\n\nconst globPromise = promisify(glob);\n\nconst toFilename = (loaderContext: LoaderContext, identifier: string, content: string) =>\n interpolateName(loaderContext, `${identifier}.[contenthash].js`, {\n context: loaderContext.rootContext,\n content,\n });\n\nconst fileStore = new Map<string, string>();\n\nconst findProvidedTypes = async (pattern: string, cwd?: string): Promise<string[]> => {\n const providedTypes = await globPromise(pattern, {\n ignore: '**/node_modules/**',\n absolute: true,\n cwd,\n });\n\n if (!providedTypes.length) {\n console.warn(`CSE schema-loader: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n\n return providedTypes;\n};\n\n// We need a way to serialize and convert Windows OS style path before outputting it as a string. The webpack loader had issues when the \"\\\"\n// directory separator character was not escaped and as a result the file path end-up glued together e.g. \"C:foobarfile.graphql\".\n// The solution is either to convert this path \"C:\\foo\\bar\\file.graphql\" to \"C:\\\\foo\\\\bar\\\\file.graphql\"\n// or to a unix style \"C:/foo/bar/file.graphql\"\nconst serializePath = (filePath: string): string => {\n return filePath.replace(/\\\\/g, '\\\\\\\\');\n};\n\n// The full name of the webpack GraphQL loader we are referencing in the generated code\nconst graphqlLoaderPath = '@atlassian/clientside-extensions-schema/loader';\n\nconst defaultLoaderOptions: LoaderOptions = {\n providedTypes: '',\n strictMode: true,\n};\n\n// get's a \"this\" context so !MUST! be a \"function\" and !NOT! an arrow-function\nexport default async function schemaLoader(this: LoaderContext, content: string) {\n const callback = this.async() as LoaderCallback;\n\n // Get and validate loader options\n const loaderOptions: Readonly<LoaderOptions> = getOptions(this);\n\n validate(schema as Schema, loaderOptions, { name: 'CSE schema-loader' });\n\n const { providedTypes: providedTypesPattern, strictMode }: LoaderOptions = { ...defaultLoaderOptions, ...loaderOptions };\n\n // Get provided types\n let providedTypesPaths: string[] = [];\n\n if (providedTypesPattern) {\n providedTypesPaths = await findProvidedTypes(providedTypesPattern, loaderOptions.cwd);\n\n // Track custom type files\n providedTypesPaths.forEach((file: string) => this.addDependency(file));\n }\n\n // Run schema compiler\n const loaderContext = this as LoaderContext;\n\n if (this.resourceQuery) {\n const rqOptions = parseQuery(this.resourceQuery) as QueryObject;\n\n if (rqOptions.subfile && fileStore.has(rqOptions.subfile)) {\n callback(null, fileStore.get(rqOptions.subfile));\n return;\n }\n\n callback(new Error(`CSE Schema-loader: Unknown subfile ${rqOptions.subfile} requested.`));\n return;\n }\n\n try {\n const generatorOptions: Partial<GeneratorOptions> = {\n providedTypesPaths,\n strictMode,\n };\n\n const [, , generatedJavascript] = await generateCode(\n content,\n generatorOptions,\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const filename = toFilename(loaderContext, baseIdentifier, javascriptCode);\n fileStore.set(filename, javascriptCode);\n\n const resourcePath = serializePath(loaderContext.resourcePath);\n\n return `!!${graphqlLoaderPath}!${resourcePath}?subfile=${filename}`;\n },\n false,\n );\n callback(null, generatedJavascript);\n } catch (e) {\n callback(e);\n }\n}\n"]}
1
+ {"version":3,"file":"schema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AC,GAAG,MAAM,IAAA,wBAAY,EAChD,OAAO,EACP,gBAAgB,EAChB,KAAK,EAAE,cAAsB,EAAE,cAAsB,EAAE,cAAsB,EAAE,EAAE;YAC7E,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;YAC3E,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAExC,MAAM,YAAY,GAAG,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;YAE/D,OAAO,KAAK,iBAAiB,IAAI,YAAY,YAAY,QAAQ,EAAE,CAAC;QACxE,CAAC,EACD,KAAK,CACR,CAAC;QACF,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;KACvC;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,GAAY,CAAC;QAE3B,QAAQ,CAAC,KAAK,CAAC,CAAC;KACnB;AACL,CAAC;AA5DD,+BA4DC","sourcesContent":["import { getOptions, interpolateName, parseQuery } from 'loader-utils';\nimport glob from 'glob';\nimport { validate } from 'schema-utils';\n\nimport type { Schema } from 'schema-utils/declarations/validate';\nimport { promisify } from 'util';\nimport type { GeneratorOptions } from '../code-generator/code-generator';\nimport generateCode from '../code-generator/code-generator';\nimport schema from './loader-schema.json';\nimport type { LoaderOptions, LoaderContext, LoaderCallback, QueryObject } from './types';\n\nconst globPromise = promisify(glob);\n\nconst toFilename = (loaderContext: LoaderContext, identifier: string, content: string) =>\n interpolateName(loaderContext, `${identifier}.[contenthash].js`, {\n context: loaderContext.rootContext,\n content,\n });\n\nconst fileStore = new Map<string, string>();\n\nconst findProvidedTypes = async (pattern: string, cwd?: string): Promise<string[]> => {\n const providedTypes = await globPromise(pattern, {\n ignore: '**/node_modules/**',\n absolute: true,\n cwd,\n });\n\n if (!providedTypes.length) {\n console.warn(`CSE schema-loader: Provided pattern \"${pattern}\" could not find any files with GraphQL provided types`);\n }\n\n return providedTypes;\n};\n\n// We need a way to serialize and convert Windows OS style path before outputting it as a string. The webpack loader had issues when the \"\\\"\n// directory separator character was not escaped and as a result the file path end-up glued together e.g. \"C:foobarfile.graphql\".\n// The solution is either to convert this path \"C:\\foo\\bar\\file.graphql\" to \"C:\\\\foo\\\\bar\\\\file.graphql\"\n// or to a unix style \"C:/foo/bar/file.graphql\"\nconst serializePath = (filePath: string): string => {\n return filePath.replace(/\\\\/g, '\\\\\\\\');\n};\n\n// The full name of the webpack GraphQL loader we are referencing in the generated code\nconst graphqlLoaderPath = '@atlassian/clientside-extensions-schema/loader';\n\nconst defaultLoaderOptions: LoaderOptions = {\n providedTypes: '',\n strictMode: true,\n};\n\n// get's a \"this\" context so !MUST! be a \"function\" and !NOT! an arrow-function\nexport default async function schemaLoader(this: LoaderContext, content: string) {\n const callback = this.async() as LoaderCallback;\n\n // Get and validate loader options\n const loaderOptions: Readonly<LoaderOptions> = getOptions(this);\n\n validate(schema as Schema, loaderOptions, { name: 'CSE schema-loader' });\n\n const { providedTypes: providedTypesPattern, strictMode }: LoaderOptions = { ...defaultLoaderOptions, ...loaderOptions };\n\n // Get provided types\n let providedTypesPaths: string[] = [];\n\n if (providedTypesPattern) {\n providedTypesPaths = await findProvidedTypes(providedTypesPattern, loaderOptions.cwd);\n\n // Track custom type files\n providedTypesPaths.forEach((file: string) => this.addDependency(file));\n }\n\n // Run schema compiler\n const loaderContext = this as LoaderContext;\n\n if (this.resourceQuery) {\n const rqOptions = parseQuery(this.resourceQuery) as QueryObject;\n\n if (rqOptions.subfile && fileStore.has(rqOptions.subfile)) {\n callback(null, fileStore.get(rqOptions.subfile));\n return;\n }\n\n callback(new Error(`CSE Schema-loader: Unknown subfile ${rqOptions.subfile} requested.`));\n return;\n }\n\n try {\n const generatorOptions: Partial<GeneratorOptions> = {\n providedTypesPaths,\n strictMode,\n };\n\n const [, , generatedJavascript] = await generateCode(\n content,\n generatorOptions,\n async (baseIdentifier: string, typescriptCode: string, javascriptCode: string) => {\n const filename = toFilename(loaderContext, baseIdentifier, javascriptCode);\n fileStore.set(filename, javascriptCode);\n\n const resourcePath = serializePath(loaderContext.resourcePath);\n\n return `!!${graphqlLoaderPath}!${resourcePath}?subfile=${filename}`;\n },\n false,\n );\n callback(null, generatedJavascript);\n } catch (err) {\n const error = err as Error;\n\n callback(error);\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const IconGlyph_1 = tslib_1.__importDefault(require("./IconGlyph"));
5
- const Icon_1 = tslib_1.__importDefault(require("./Icon"));
4
+ const IconGlyph_1 = (0, tslib_1.__importDefault)(require("./IconGlyph"));
5
+ const Icon_1 = (0, tslib_1.__importDefault)(require("./Icon"));
6
6
  const providedTypes = [IconGlyph_1.default, Icon_1.default];
7
7
  exports.default = providedTypes;
8
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/providedTypes/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,0DAA8B;AAE9B,MAAM,aAAa,GAAG,CAAC,mBAAe,EAAE,cAAQ,CAAC,CAAC;AAElD,kBAAe,aAAa,CAAC","sourcesContent":["import IconGlyphScalar from './IconGlyph';\nimport IconType from './Icon';\n\nconst providedTypes = [IconGlyphScalar, IconType];\n\nexport default providedTypes;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/providedTypes/index.ts"],"names":[],"mappings":";;;AAAA,yEAA0C;AAC1C,+DAA8B;AAE9B,MAAM,aAAa,GAAG,CAAC,mBAAe,EAAE,cAAQ,CAAC,CAAC;AAElD,kBAAe,aAAa,CAAC","sourcesContent":["import IconGlyphScalar from './IconGlyph';\nimport IconType from './Icon';\n\nconst providedTypes = [IconGlyphScalar, IconType];\n\nexport default providedTypes;\n"]}
@@ -6,7 +6,7 @@ const ModalOnActionScalar = {
6
6
  description: 'The value should be a callback function expecting to receive the Modal-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/modal-api/',
7
7
  validationType: types_1.ValidationTypes.function,
8
8
  typescriptType: 'Function',
9
- defaultExample: () => { },
9
+ defaultExample: () => { }, // TODO: example this better
10
10
  };
11
11
  exports.default = ModalOnActionScalar;
12
12
  //# sourceMappingURL=ModalOnAction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModalOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/ModalOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU;IAC1B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;CAC3B,CAAC;AAEF,kBAAe,mBAAmB,CAAC","sourcesContent":["import type { Scalar } from '../types';\nimport { ValidationTypes } from '../types';\n\nconst ModalOnActionScalar: Scalar = {\n name: 'ModalOnAction',\n description:\n 'The value should be a callback function expecting to receive the Modal-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/modal-api/',\n validationType: ValidationTypes.function,\n typescriptType: 'Function', // TODO: type this better\n defaultExample: () => {}, // TODO: example this better\n};\n\nexport default ModalOnActionScalar;\n"]}
1
+ {"version":3,"file":"ModalOnAction.js","sourceRoot":"","sources":["../../../../lib/scalars/extensions/ModalOnAction.ts"],"names":[],"mappings":";;AACA,oCAA2C;AAE3C,MAAM,mBAAmB,GAAW;IAChC,IAAI,EAAE,eAAe;IACrB,WAAW,EACP,iLAAiL;IACrL,cAAc,EAAE,uBAAe,CAAC,QAAQ;IACxC,cAAc,EAAE,UAAU;IAC1B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,4BAA4B;CACzD,CAAC;AAEF,kBAAe,mBAAmB,CAAC","sourcesContent":["import type { Scalar } from '../types';\nimport { ValidationTypes } from '../types';\n\nconst ModalOnActionScalar: Scalar = {\n name: 'ModalOnAction',\n description:\n 'The value should be a callback function expecting to receive the Modal-API. See https://developer.atlassian.com/server/framework/clientside-extensions/reference/api/modal-api/',\n validationType: ValidationTypes.function,\n typescriptType: 'Function', // TODO: type this better\n defaultExample: () => {}, // TODO: example this better\n};\n\nexport default ModalOnActionScalar;\n"]}