@axinom/mosaic-cli 0.54.0-rc.4 → 0.54.0

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 (113) hide show
  1. package/dist/cli/index.js +6 -6
  2. package/dist/cli/index.js.map +1 -1
  3. package/dist/commands/apply-templates/apply-templates.js +12 -11
  4. package/dist/commands/apply-templates/apply-templates.js.map +1 -1
  5. package/dist/commands/apply-templates/bitwarden-vault.js.map +1 -1
  6. package/dist/commands/create/command.js +26 -11
  7. package/dist/commands/create/command.js.map +1 -1
  8. package/dist/commands/create/createSolution.js +31 -31
  9. package/dist/commands/create/createSolution.js.map +1 -1
  10. package/dist/commands/create/helpers/git.d.ts +1 -1
  11. package/dist/commands/create/helpers/git.js +8 -9
  12. package/dist/commands/create/helpers/git.js.map +1 -1
  13. package/dist/commands/create/helpers/logger.js +8 -7
  14. package/dist/commands/create/helpers/logger.js.map +1 -1
  15. package/dist/commands/create/runQuestionaire.js +18 -18
  16. package/dist/commands/create/runQuestionaire.js.map +1 -1
  17. package/dist/commands/create-extension-config/create-extension-config.js +14 -14
  18. package/dist/commands/create-extension-config/create-extension-config.js.map +1 -1
  19. package/dist/commands/create-extension-config/index.js +2 -1
  20. package/dist/commands/create-extension-config/index.js.map +1 -1
  21. package/dist/commands/get-access-token/get-dev-access-token.js +3 -4
  22. package/dist/commands/get-access-token/get-dev-access-token.js.map +1 -1
  23. package/dist/commands/get-access-token/index.js +6 -6
  24. package/dist/commands/get-access-token/index.js.map +1 -1
  25. package/dist/commands/graphql-diff.js +44 -46
  26. package/dist/commands/graphql-diff.js.map +1 -1
  27. package/dist/commands/hosting/manifest/manifest-commands.js +3 -4
  28. package/dist/commands/hosting/manifest/manifest-commands.js.map +1 -1
  29. package/dist/commands/hosting/manifest/upload-manifest.js +7 -7
  30. package/dist/commands/hosting/manifest/upload-manifest.js.map +1 -1
  31. package/dist/commands/hosting/pilet/pilet-commands.js +3 -4
  32. package/dist/commands/hosting/pilet/pilet-commands.js.map +1 -1
  33. package/dist/commands/hosting/pilet/register-pilet.js +13 -10
  34. package/dist/commands/hosting/pilet/register-pilet.js.map +1 -1
  35. package/dist/commands/hosting/service/deploy/service-deploy-command.js +3 -4
  36. package/dist/commands/hosting/service/deploy/service-deploy-command.js.map +1 -1
  37. package/dist/commands/hosting/service/deploy/service-deploy.js +14 -14
  38. package/dist/commands/hosting/service/deploy/service-deploy.js.map +1 -1
  39. package/dist/commands/hosting/service/undeploy/service-undeploy-command.js +3 -4
  40. package/dist/commands/hosting/service/undeploy/service-undeploy-command.js.map +1 -1
  41. package/dist/commands/hosting/service/undeploy/service-undeploy.js +11 -11
  42. package/dist/commands/hosting/service/undeploy/service-undeploy.js.map +1 -1
  43. package/dist/commands/msg-codegen/codegen.js +326 -322
  44. package/dist/commands/msg-codegen/codegen.js.map +1 -1
  45. package/dist/commands/msg-codegen/index.js +4 -5
  46. package/dist/commands/msg-codegen/index.js.map +1 -1
  47. package/dist/commands/msg-codegen/lint.js +55 -60
  48. package/dist/commands/msg-codegen/lint.js.map +1 -1
  49. package/dist/commands/msg-codegen/presets.js +10 -1
  50. package/dist/commands/msg-codegen/presets.js.map +1 -1
  51. package/dist/commands/msg-codegen/utils.d.ts +1 -0
  52. package/dist/commands/msg-codegen/utils.js +38 -26
  53. package/dist/commands/msg-codegen/utils.js.map +1 -1
  54. package/dist/commands/msg-diff/git-checkout-tmp.js +7 -6
  55. package/dist/commands/msg-diff/git-checkout-tmp.js.map +1 -1
  56. package/dist/commands/msg-diff/index.js +4 -4
  57. package/dist/commands/msg-diff/index.js.map +1 -1
  58. package/dist/commands/msg-diff/msg-diff.js +188 -198
  59. package/dist/commands/msg-diff/msg-diff.js.map +1 -1
  60. package/dist/commands/pg-dump/generate.js +5 -4
  61. package/dist/commands/pg-dump/generate.js.map +1 -1
  62. package/dist/commands/publish-schema-to-db/content-entity-model.js.map +1 -1
  63. package/dist/commands/publish-schema-to-db/generate.js +45 -45
  64. package/dist/commands/publish-schema-to-db/generate.js.map +1 -1
  65. package/dist/commands/publish-schema-to-db/index.js +3 -4
  66. package/dist/commands/publish-schema-to-db/index.js.map +1 -1
  67. package/dist/commands/publish-schema-to-db/pg-models/columns/pk-column.js.map +1 -1
  68. package/dist/commands/publish-schema-to-db/pg-models/columns/primitive-column.js.map +1 -1
  69. package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js +18 -22
  70. package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js.map +1 -1
  71. package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js +26 -29
  72. package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js.map +1 -1
  73. package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js +11 -11
  74. package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js.map +1 -1
  75. package/dist/commands/publish-schema-to-db/pg-models/tables/content-entity-table.js.map +1 -1
  76. package/dist/commands/publish-schema-to-db/pg-models/tables/object-property-table.js.map +1 -1
  77. package/dist/commands/publish-schema-to-db/pg-models/tables/relations-table.js.map +1 -1
  78. package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js +2 -3
  79. package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js.map +1 -1
  80. package/dist/commands/service/purge-permissions/purge-permissions-command.js +3 -4
  81. package/dist/commands/service/purge-permissions/purge-permissions-command.js.map +1 -1
  82. package/dist/commands/service/purge-permissions/purge-permissions.js +4 -5
  83. package/dist/commands/service/purge-permissions/purge-permissions.js.map +1 -1
  84. package/dist/commands/service/sync-permissions/sync-permission-command.js +3 -4
  85. package/dist/commands/service/sync-permissions/sync-permission-command.js.map +1 -1
  86. package/dist/commands/service/sync-permissions/sync-permissions.js +5 -5
  87. package/dist/commands/service/sync-permissions/sync-permissions.js.map +1 -1
  88. package/dist/commands/unpublish-pilet/index.js +7 -7
  89. package/dist/commands/unpublish-pilet/index.js.map +1 -1
  90. package/dist/commands/unpublish-pilet/unpublish-pilet.js +4 -4
  91. package/dist/commands/unpublish-pilet/unpublish-pilet.js.map +1 -1
  92. package/package.json +18 -13
  93. package/src/commands/apply-templates/apply-templates.spec.ts +20 -11
  94. package/src/commands/apply-templates/apply-templates.ts +1 -1
  95. package/src/commands/create/helpers/logger.ts +1 -1
  96. package/src/commands/create-extension-config/create-extension-config.ts +1 -1
  97. package/src/commands/get-access-token/index.ts +1 -1
  98. package/src/commands/hosting/pilet/register-pilet.ts +1 -1
  99. package/src/commands/msg-codegen/codegen.ts +34 -6
  100. package/src/commands/msg-codegen/presets.ts +12 -0
  101. package/src/commands/msg-codegen/utils.ts +14 -1
  102. package/src/commands/msg-diff/msg-diff.spec.ts +6 -9
  103. package/src/commands/pg-dump/generate.ts +1 -1
  104. package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.spec.ts +18 -14
  105. package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.spec.ts +11 -7
  106. package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.spec.ts +1 -0
  107. package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.spec.ts +1 -0
  108. package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.spec.ts +2 -1
  109. package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.spec.ts +1 -0
  110. package/src/commands/publish-schema-to-db/pg-models/pgl-utils.spec.ts +1 -0
  111. package/src/commands/unpublish-pilet/index.ts +1 -1
  112. package/src/types/find-nearest-file.d.ts +11 -0
  113. package/src/commands/publish-schema-to-db/jest.config.js +0 -9
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Codegen = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const modelina_1 = require("@asyncapi/modelina");
7
- const parser_1 = require("@asyncapi/parser");
8
- const endent_1 = require("endent");
9
- const fs = require("fs");
10
- const path = require("path");
7
+ const parser_1 = tslib_1.__importStar(require("@asyncapi/parser"));
8
+ const endent_1 = tslib_1.__importDefault(require("endent"));
9
+ const fs = tslib_1.__importStar(require("fs"));
10
+ const path = tslib_1.__importStar(require("path"));
11
11
  const common_1 = require("../../common");
12
12
  const presets_1 = require("./presets");
13
13
  const utils_1 = require("./utils");
@@ -36,60 +36,56 @@ class Codegen {
36
36
  this.schemasOutputRoot = path.join(this.outputRoot, 'schemas');
37
37
  this.messagingSettingsOutputRoot = path.join(this.outputRoot, 'config');
38
38
  }
39
- run() {
40
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
41
- console.log('Running message codegen.');
42
- console.log(`* schema root: ${this.schemaRoot}`);
43
- console.log(`* output root: ${this.outputRoot}`);
44
- try {
45
- yield this.walk(this.schemaRoot);
46
- yield this.barrelExportTs([], [
47
- this.typesOutputRoot,
48
- this.schemasOutputRoot,
49
- this.messagingSettingsOutputRoot,
50
- ], path.join(this.outputRoot, 'index.ts'));
51
- }
52
- catch (e) {
53
- console.log(e);
54
- process.exit(common_1.exitCode);
55
- }
56
- });
39
+ async run() {
40
+ console.log('Running message codegen.');
41
+ console.log(`* schema root: ${this.schemaRoot}`);
42
+ console.log(`* output root: ${this.outputRoot}`);
43
+ try {
44
+ await this.walk(this.schemaRoot);
45
+ await this.barrelExportTs([], [
46
+ this.typesOutputRoot,
47
+ this.schemasOutputRoot,
48
+ this.messagingSettingsOutputRoot,
49
+ ], path.join(this.outputRoot, 'index.ts'));
50
+ }
51
+ catch (e) {
52
+ console.log(e);
53
+ process.exit(common_1.exitCode);
54
+ }
57
55
  }
58
56
  /**
59
57
  * Recursively walks a schemas directory and generates TS + bundled JSON schema files.
60
58
  * @param dir - Directory to walk.
61
59
  */
62
- walk(dir) {
63
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
64
- const items = yield fs.promises.readdir(dir);
65
- const fullPathItems = items.map((i) => path.join(dir, i));
66
- const dirs = fullPathItems.filter((i) => fs.statSync(i).isDirectory());
67
- const files = fullPathItems.filter((i) => fs.statSync(i).isFile() && this.filePattern.test(i));
68
- if ([...files, ...dirs].length === 0) {
69
- return;
70
- }
71
- for (const asyncApiFile of files) {
72
- console.log(`Processing ${asyncApiFile}.`);
73
- yield this.processAsyncAPIDocument(asyncApiFile);
74
- }
75
- for (const directory of dirs) {
76
- yield this.walk(directory);
77
- }
78
- if (files.length === 0) {
79
- //Calculate correct TS output related directories for barrel exports.
80
- const tsDirs = dirs.map((d) => path.join(this.typesOutputRoot, path.relative(this.schemaRoot, d)));
81
- const tsIndexOutPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
82
- yield this.barrelExportTs([], tsDirs, tsIndexOutPath);
83
- // Calculate correct JSON schema output related directories for barrel exports.
84
- const schemaDirs = dirs.map((d) => path.join(this.schemasOutputRoot, path.relative(this.schemaRoot, d)));
85
- const schemaIndexOutPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
86
- yield this.barrelExportSchema([], schemaDirs, schemaIndexOutPath);
87
- // Calculate correct Message Settings output related directories for barrel exports.
88
- const settingsDirs = dirs.map((d) => path.join(this.messagingSettingsOutputRoot, path.relative(this.schemaRoot, d)));
89
- const messagingIndexOutPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
90
- yield this.barrelExportSettings([], settingsDirs, messagingIndexOutPath);
91
- }
92
- });
60
+ async walk(dir) {
61
+ const items = await fs.promises.readdir(dir);
62
+ const fullPathItems = items.map((i) => path.join(dir, i));
63
+ const dirs = fullPathItems.filter((i) => fs.statSync(i).isDirectory());
64
+ const files = fullPathItems.filter((i) => fs.statSync(i).isFile() && this.filePattern.test(i));
65
+ if ([...files, ...dirs].length === 0) {
66
+ return;
67
+ }
68
+ for (const asyncApiFile of files) {
69
+ console.log(`Processing ${asyncApiFile}.`);
70
+ await this.processAsyncAPIDocument(asyncApiFile);
71
+ }
72
+ for (const directory of dirs) {
73
+ await this.walk(directory);
74
+ }
75
+ if (files.length === 0) {
76
+ //Calculate correct TS output related directories for barrel exports.
77
+ const tsDirs = dirs.map((d) => path.join(this.typesOutputRoot, path.relative(this.schemaRoot, d)));
78
+ const tsIndexOutPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
79
+ await this.barrelExportTs([], tsDirs, tsIndexOutPath);
80
+ // Calculate correct JSON schema output related directories for barrel exports.
81
+ const schemaDirs = dirs.map((d) => path.join(this.schemasOutputRoot, path.relative(this.schemaRoot, d)));
82
+ const schemaIndexOutPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
83
+ await this.barrelExportSchema([], schemaDirs, schemaIndexOutPath);
84
+ // Calculate correct Message Settings output related directories for barrel exports.
85
+ const settingsDirs = dirs.map((d) => path.join(this.messagingSettingsOutputRoot, path.relative(this.schemaRoot, d)));
86
+ const messagingIndexOutPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
87
+ await this.barrelExportSettings([], settingsDirs, messagingIndexOutPath);
88
+ }
93
89
  }
94
90
  /**
95
91
  * Builds a path for the generated TS file from an input JSON schema path, retains directory structure.
@@ -111,170 +107,190 @@ class Codegen {
111
107
  * Generates TS interfaces and JSON schemas from AsyncAPI schema.
112
108
  * @param asyncApiFile - path to AsyncAPI document
113
109
  */
114
- processAsyncAPIDocument(asyncApiFile) {
115
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
116
- const parser = new parser_1.default();
117
- const { document, diagnostics } = yield (0, parser_1.fromFile)(parser, asyncApiFile).parse();
118
- if (document === undefined) {
119
- console.error(`Failed to parse ${asyncApiFile}.`);
120
- console.error(diagnostics);
121
- process.exit(1);
122
- }
123
- //export Typescript models
124
- const tsModelsOutputPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
125
- yield this.exportTsModels(document, tsModelsOutputPath);
126
- //export JSON Schemas
127
- const schemasOutputPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
128
- yield this.exportSchemas(document, schemasOutputPath);
129
- //export message settings
130
- const messagingSettingsOutputPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
131
- yield this.exportSettings(document, messagingSettingsOutputPath);
132
- });
110
+ async processAsyncAPIDocument(asyncApiFile) {
111
+ const parser = new parser_1.default();
112
+ const { document, diagnostics } = await (0, parser_1.fromFile)(parser, asyncApiFile).parse();
113
+ if (document === undefined) {
114
+ console.error(`Failed to parse ${asyncApiFile}.`);
115
+ console.error(diagnostics);
116
+ process.exit(1);
117
+ }
118
+ //export Typescript models
119
+ const tsModelsOutputPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
120
+ await this.exportTsModels(document, tsModelsOutputPath);
121
+ //export JSON Schemas
122
+ const schemasOutputPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
123
+ await this.exportSchemas(document, schemasOutputPath);
124
+ //export message settings
125
+ const messagingSettingsOutputPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
126
+ await this.exportSettings(document, messagingSettingsOutputPath);
133
127
  }
134
128
  /**
135
129
  * Export all TS models from AsyncAPI document
136
130
  * @param asyncAPIDocument - AsyncAPI Document object
137
131
  * @param outputPath - output path for generated files
138
132
  */
139
- exportTsModels(asyncAPIDocument, outputPath) {
140
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
141
- const generator = new modelina_1.TypeScriptGenerator({
142
- modelType: 'interface',
143
- enumType: 'union',
144
- mapType: 'indexedObject',
145
- constraints: {
146
- propertyKey: (0, modelina_1.typeScriptDefaultPropertyKeyConstraints)({
147
- NAMING_FORMATTER: (name) => modelina_1.FormatHelpers.toSnakeCase(name),
148
- NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
149
- }),
150
- modelName: (0, modelina_1.typeScriptDefaultModelNameConstraints)({
151
- NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
152
- }),
153
- },
154
- // Order of presets matters!
155
- presets: [
156
- presets_1.NULLABLE_PROPERTY_TO_UNION_PRESET,
157
- presets_1.ANY_TO_UNKNOWN_PRESET,
158
- presets_1.ADDITIONAL_PROPERTIES_PRESET,
159
- presets_1.EXPORT_TYPES_PRESET,
160
- modelina_1.TS_DESCRIPTION_PRESET,
161
- presets_1.IMPORTS_PRESET,
162
- ],
163
- });
164
- let outputModels = yield generator.generate(asyncAPIDocument);
165
- for (const schema of asyncAPIDocument.components().schemas()) {
166
- const referencedModels = yield generator.generate(schema.json());
167
- outputModels = outputModels.map((om) => referencedModels.find((rm) => om.modelName === rm.modelName) || om);
133
+ async exportTsModels(asyncAPIDocument, outputPath) {
134
+ const generator = new modelina_1.TypeScriptGenerator({
135
+ modelType: 'interface',
136
+ enumType: 'union',
137
+ mapType: 'indexedObject',
138
+ constraints: {
139
+ propertyKey: (0, modelina_1.typeScriptDefaultPropertyKeyConstraints)({
140
+ NAMING_FORMATTER: (name) => modelina_1.FormatHelpers.toSnakeCase(name),
141
+ NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
142
+ }),
143
+ modelName: (0, modelina_1.typeScriptDefaultModelNameConstraints)({
144
+ NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
145
+ }),
146
+ },
147
+ // Order of presets matters!
148
+ presets: [
149
+ presets_1.NULLABLE_PROPERTY_TO_UNION_PRESET,
150
+ presets_1.ANY_TO_UNKNOWN_PRESET,
151
+ presets_1.ADDITIONAL_PROPERTIES_PRESET,
152
+ presets_1.EXPORT_TYPES_PRESET,
153
+ modelina_1.TS_DESCRIPTION_PRESET,
154
+ presets_1.IMPORTS_PRESET,
155
+ ],
156
+ });
157
+ let outputModels = await generator.generate(asyncAPIDocument);
158
+ for (const schema of asyncAPIDocument.components().schemas()) {
159
+ const referencedModels = await generator.generate(schema.json());
160
+ outputModels = outputModels.map((om) => referencedModels.find((rm) => om.modelName === rm.modelName) || om);
161
+ }
162
+ const groupedModels = {};
163
+ outputModels.map((outModel) => {
164
+ const modelPathPrefix = (0, utils_1.getModelPathPrefix)(outModel.modelName);
165
+ if (groupedModels[modelPathPrefix] === undefined) {
166
+ groupedModels[modelPathPrefix] = [];
168
167
  }
169
- const groupedModels = {};
170
- outputModels.map((outModel) => {
171
- const modelPathPrefix = (0, utils_1.getModelPathPrefix)(outModel.modelName);
172
- if (groupedModels[modelPathPrefix] === undefined) {
173
- groupedModels[modelPathPrefix] = [];
174
- }
175
- groupedModels[modelPathPrefix].push(outModel);
176
- });
177
- const tsDirs = [];
178
- for (const pathPrefix in groupedModels) {
179
- const models = groupedModels[pathPrefix];
180
- const groupOutPutPath = path.join(outputPath, pathPrefix);
181
- if (pathPrefix) {
182
- tsDirs.push(groupOutPutPath);
183
- }
184
- yield fs.promises.mkdir(groupOutPutPath, {
185
- recursive: true,
186
- });
187
- const tsFiles = [];
188
- for (const outputModel of models) {
189
- const outputFilePath = this.buildTsOutPath(groupOutPutPath, outputModel.modelName);
190
- yield fs.promises.writeFile(outputFilePath, outputModel.result);
191
- tsFiles.push(outputFilePath);
192
- }
193
- //generate barrel export for all model in AsyncAPI document
194
- const tsIndexOutPath = path.join(groupOutPutPath, 'index.ts');
195
- yield this.barrelExportTs(tsFiles, [], tsIndexOutPath);
168
+ groupedModels[modelPathPrefix].push(outModel);
169
+ });
170
+ const tsDirs = [];
171
+ for (const pathPrefix in groupedModels) {
172
+ const models = groupedModels[pathPrefix];
173
+ const groupOutPutPath = path.join(outputPath, pathPrefix);
174
+ if (pathPrefix) {
175
+ tsDirs.push(groupOutPutPath);
196
176
  }
197
- if (tsDirs.length > 0) {
198
- const tsIndexOutPath = path.join(outputPath, 'index.ts');
199
- yield this.barrelExportTs([], tsDirs, tsIndexOutPath);
177
+ await fs.promises.mkdir(groupOutPutPath, {
178
+ recursive: true,
179
+ });
180
+ const tsFiles = [];
181
+ for (const outputModel of models) {
182
+ const outputFilePath = this.buildTsOutPath(groupOutPutPath, outputModel.modelName);
183
+ await fs.promises.writeFile(outputFilePath, outputModel.result);
184
+ tsFiles.push(outputFilePath);
200
185
  }
201
- });
186
+ //generate barrel export for all model in AsyncAPI document
187
+ const tsIndexOutPath = path.join(groupOutPutPath, 'index.ts');
188
+ const existingTsFiles = fs.existsSync(groupOutPutPath)
189
+ ? (await fs.promises.readdir(groupOutPutPath))
190
+ .filter((f) => f.endsWith('.ts') && f !== 'index.ts')
191
+ .map((f) => path.join(groupOutPutPath, f))
192
+ : [];
193
+ const mergedTsFiles = [...new Set([...tsFiles, ...existingTsFiles])];
194
+ await this.barrelExportTs(mergedTsFiles, [], tsIndexOutPath);
195
+ }
196
+ if (tsDirs.length > 0) {
197
+ const tsIndexOutPath = path.join(outputPath, 'index.ts');
198
+ const existingDirs = fs.existsSync(outputPath)
199
+ ? (await fs.promises.readdir(outputPath, { withFileTypes: true }))
200
+ .filter((d) => d.isDirectory())
201
+ .map((d) => path.join(outputPath, d.name))
202
+ : [];
203
+ const mergedDirs = [...new Set([...tsDirs, ...existingDirs])];
204
+ await this.barrelExportTs([], mergedDirs, tsIndexOutPath);
205
+ }
202
206
  }
203
207
  /**
204
208
  * Export all JSON Schemas from AsyncAPI document
205
209
  * @param asyncAPIDocument - AsyncAPI Document object
206
210
  * @param outputPath - output path for generated files
207
211
  */
208
- exportSchemas(asyncAPIDocument, outputPath) {
209
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
210
- const groupedSchemas = {};
211
- for (const message of asyncAPIDocument.allMessages()) {
212
- const schemaPathPrefix = (0, utils_1.getModelPathPrefix)((0, utils_1.getMessageTitle)(message));
213
- if (groupedSchemas[schemaPathPrefix] === undefined) {
214
- groupedSchemas[schemaPathPrefix] = [];
215
- }
216
- groupedSchemas[schemaPathPrefix].push(message);
212
+ async exportSchemas(asyncAPIDocument, outputPath) {
213
+ const groupedSchemas = {};
214
+ for (const message of asyncAPIDocument.allMessages()) {
215
+ const schemaPathPrefix = (0, utils_1.getModelPathPrefix)((0, utils_1.getMessageTitle)(message));
216
+ if (groupedSchemas[schemaPathPrefix] === undefined) {
217
+ groupedSchemas[schemaPathPrefix] = [];
217
218
  }
218
- const schemaDirs = [];
219
- for (const pathPrefix in groupedSchemas) {
220
- const messages = groupedSchemas[pathPrefix];
221
- const schemaFiles = [];
222
- const groupOutPutPath = path.join(outputPath, pathPrefix);
223
- if (pathPrefix) {
224
- schemaDirs.push(groupOutPutPath);
225
- }
226
- yield fs.promises.mkdir(groupOutPutPath, {
227
- recursive: true,
228
- });
229
- for (const msg of messages) {
230
- const payload = msg.payload();
231
- if (payload !== undefined && payload.json() !== undefined) {
232
- const filteredPayload = (0, utils_1.removeXParserProperties)(payload.json());
233
- const outputSchemaPath = this.buildSchemaOutPath(groupOutPutPath, (0, utils_1.getMessageTitle)(msg));
234
- yield this.bundleSchema(filteredPayload, outputSchemaPath);
235
- schemaFiles.push(outputSchemaPath);
236
- }
219
+ groupedSchemas[schemaPathPrefix].push(message);
220
+ }
221
+ const schemaDirs = [];
222
+ for (const pathPrefix in groupedSchemas) {
223
+ const messages = groupedSchemas[pathPrefix];
224
+ const schemaFiles = [];
225
+ const groupOutPutPath = path.join(outputPath, pathPrefix);
226
+ if (pathPrefix) {
227
+ schemaDirs.push(groupOutPutPath);
228
+ }
229
+ await fs.promises.mkdir(groupOutPutPath, {
230
+ recursive: true,
231
+ });
232
+ for (const msg of messages) {
233
+ const payload = msg.payload();
234
+ if (payload !== undefined && payload.json() !== undefined) {
235
+ const filteredPayload = (0, utils_1.removeXParserProperties)(payload.json());
236
+ const outputSchemaPath = this.buildSchemaOutPath(groupOutPutPath, (0, utils_1.getMessageTitle)(msg));
237
+ await this.bundleSchema(filteredPayload, outputSchemaPath);
238
+ schemaFiles.push(outputSchemaPath);
237
239
  }
238
- //generate barrel export for all model in AsyncAPI document
239
- const schemasIndexOutPath = path.join(groupOutPutPath, 'index.ts');
240
- yield this.barrelExportSchema(schemaFiles, [], schemasIndexOutPath);
241
240
  }
242
- const schemaIndexOutPath = path.join(outputPath, 'index.ts');
243
- yield this.barrelExportSchema([], schemaDirs, schemaIndexOutPath);
244
- });
241
+ //generate barrel export for all model in AsyncAPI document
242
+ const schemasIndexOutPath = path.join(groupOutPutPath, 'index.ts');
243
+ const existingSchemaFiles = fs.existsSync(groupOutPutPath)
244
+ ? (await fs.promises.readdir(groupOutPutPath))
245
+ .filter((f) => f.endsWith('.json'))
246
+ .map((f) => path.join(groupOutPutPath, f))
247
+ : [];
248
+ const mergedSchemaFiles = [
249
+ ...new Set([...schemaFiles, ...existingSchemaFiles]),
250
+ ];
251
+ await this.barrelExportSchema(mergedSchemaFiles, [], schemasIndexOutPath);
252
+ }
253
+ const schemaIndexOutPath = path.join(outputPath, 'index.ts');
254
+ const existingSchemaDirs = fs.existsSync(outputPath)
255
+ ? (await fs.promises.readdir(outputPath, { withFileTypes: true }))
256
+ .filter((d) => d.isDirectory())
257
+ .map((d) => path.join(outputPath, d.name))
258
+ : [];
259
+ const mergedSchemaDirs = [
260
+ ...new Set([...schemaDirs, ...existingSchemaDirs]),
261
+ ];
262
+ await this.barrelExportSchema([], mergedSchemaDirs, schemaIndexOutPath);
245
263
  }
246
264
  /**
247
265
  * Export all AsyncAPI document channels to Messaging Settings
248
266
  * @param asyncAPIDocument - AsyncAPI Document object
249
267
  * @param outputPath - output path for generated files
250
268
  */
251
- exportSettings(asyncAPIDocument, outputPath) {
269
+ async exportSettings(asyncAPIDocument, outputPath) {
252
270
  var _a, _b;
253
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
254
- const serviceTitle = (0, utils_1.getServiceTitle)(asyncAPIDocument);
255
- const serviceId = (0, utils_1.getServiceId)(asyncAPIDocument);
256
- const channelsData = [];
257
- for (const channel of asyncAPIDocument.channels()) {
258
- const queueName = (_a = channel.bindings().get('amqp')) === null || _a === void 0 ? void 0 : _a.value().queue.name;
259
- if (queueName !== undefined) {
260
- const routingKey = channel.address();
261
- const action = (0, utils_1.getChannelAction)(channel);
262
- const payloadName = (_b = (0, utils_1.getPayloadTitle)(channel)) !== null && _b !== void 0 ? _b : 'undefined';
263
- const aggregateType = (0, utils_1.getChannelAggregateType)(channel);
264
- const aggregateIdField = (0, utils_1.getChannelAggregateIdField)(channel);
265
- channelsData.push({
266
- routingKey,
267
- queueName,
268
- payloadName,
269
- acceptedAction: action,
270
- isMultiTenant: routingKey.includes('*.*'),
271
- aggregateType,
272
- aggregateIdField,
273
- });
274
- }
271
+ const serviceTitle = (0, utils_1.getServiceTitle)(asyncAPIDocument);
272
+ const serviceId = (0, utils_1.getServiceId)(asyncAPIDocument);
273
+ const channelsData = [];
274
+ for (const channel of asyncAPIDocument.channels()) {
275
+ const queueName = (_a = channel.bindings().get('amqp')) === null || _a === void 0 ? void 0 : _a.value().queue.name;
276
+ const routingKey = channel.address();
277
+ if (queueName !== undefined && routingKey != null) {
278
+ const action = (0, utils_1.getChannelAction)(channel);
279
+ const payloadName = (_b = (0, utils_1.getPayloadTitle)(channel)) !== null && _b !== void 0 ? _b : 'undefined';
280
+ const aggregateType = (0, utils_1.getChannelAggregateType)(channel);
281
+ const aggregateIdField = (0, utils_1.getChannelAggregateIdField)(channel);
282
+ channelsData.push({
283
+ routingKey,
284
+ queueName,
285
+ payloadName,
286
+ acceptedAction: action,
287
+ isMultiTenant: routingKey.includes('*.*'),
288
+ aggregateType,
289
+ aggregateIdField,
290
+ });
275
291
  }
276
- yield this.generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath);
277
- });
292
+ }
293
+ await this.generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath);
278
294
  }
279
295
  /**
280
296
  * Generate Messaging Settings based on Channels data.
@@ -283,15 +299,13 @@ class Codegen {
283
299
  * @param channelsData - AsyncAPI channels information
284
300
  * @param outputPath - output path for generated files
285
301
  */
286
- generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath) {
287
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
288
- const messagingSettingFiles = [];
289
- messagingSettingFiles.push(yield this.createMessagingSettingFile(true, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === true), outputPath));
290
- messagingSettingFiles.push(yield this.createMessagingSettingFile(false, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === false), outputPath));
291
- //barrel export for messaging settings
292
- const schemaIndexOutPath = path.join(outputPath, 'index.ts');
293
- yield this.barrelExportSettings(messagingSettingFiles.filter((f) => f), [], schemaIndexOutPath);
294
- });
302
+ async generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath) {
303
+ const messagingSettingFiles = [];
304
+ messagingSettingFiles.push(await this.createMessagingSettingFile(true, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === true), outputPath));
305
+ messagingSettingFiles.push(await this.createMessagingSettingFile(false, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === false), outputPath));
306
+ //barrel export for messaging settings
307
+ const schemaIndexOutPath = path.join(outputPath, 'index.ts');
308
+ await this.barrelExportSettings(messagingSettingFiles.filter((f) => f), [], schemaIndexOutPath);
295
309
  }
296
310
  /**
297
311
  * Create new Messaging Settings file.
@@ -301,20 +315,19 @@ class Codegen {
301
315
  * @param channelsData - AsyncAPI channels information
302
316
  * @param outputPath - output path for generated files
303
317
  */
304
- createMessagingSettingFile(isMultiTenant, serviceId, serviceTitle, channelsData, outputPath) {
305
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
306
- if (channelsData.length === 0) {
307
- return ``;
308
- }
309
- const baseClass = isMultiTenant
310
- ? `MultiTenantMessagingSettings`
311
- : `MessagingSettings`;
312
- const className = `${modelina_1.FormatHelpers.toPascalCase(serviceTitle)}${baseClass}`;
313
- const action = isMultiTenant ? 'extends' : 'implements';
314
- const visibility = isMultiTenant ? '' : 'public readonly ';
315
- const toStringOverride = isMultiTenant ? ' override' : '';
316
- const constructor = serviceId === AX_COMMON_SERVICE_ID
317
- ? (0, endent_1.default) `private constructor(
318
+ async createMessagingSettingFile(isMultiTenant, serviceId, serviceTitle, channelsData, outputPath) {
319
+ if (channelsData.length === 0) {
320
+ return ``;
321
+ }
322
+ const baseClass = isMultiTenant
323
+ ? `MultiTenantMessagingSettings`
324
+ : `MessagingSettings`;
325
+ const className = `${modelina_1.FormatHelpers.toPascalCase(serviceTitle)}${baseClass}`;
326
+ const action = isMultiTenant ? 'extends' : 'implements';
327
+ const visibility = isMultiTenant ? '' : 'public readonly ';
328
+ const toStringOverride = isMultiTenant ? ' override' : '';
329
+ const constructor = serviceId === AX_COMMON_SERVICE_ID
330
+ ? (0, endent_1.default) `private constructor(
318
331
  ${visibility}serviceId: string,
319
332
  ${visibility}messageType: string,
320
333
  ${visibility}queue: string,
@@ -323,10 +336,10 @@ class Codegen {
323
336
  ${visibility}aggregateType: string,
324
337
  ) {
325
338
  ${isMultiTenant
326
- ? `super(serviceId, messageType, queue, routingKey, action, aggregateType);`
327
- : ''}
339
+ ? `super(serviceId, messageType, queue, routingKey, action, aggregateType);`
340
+ : ''}
328
341
  }`
329
- : (0, endent_1.default) `private constructor(
342
+ : (0, endent_1.default) `private constructor(
330
343
  ${visibility}messageType: string,
331
344
  ${visibility}queue: string,
332
345
  ${visibility}routingKey: string,
@@ -334,30 +347,29 @@ class Codegen {
334
347
  ${visibility}aggregateType: string,
335
348
  ) {
336
349
  ${isMultiTenant
337
- ? `super('${serviceId}', messageType, queue, routingKey, action, aggregateType);`
338
- : ''}
350
+ ? `super('${serviceId}', messageType, queue, routingKey, action, aggregateType);`
351
+ : ''}
339
352
  }`;
340
- const properties = channelsData.map((data) => this.createMessagingSettingProperty(data, className, serviceId === AX_COMMON_SERVICE_ID));
341
- const content = (0, endent_1.default) `import { ${baseClass} } from '@axinom/mosaic-message-bus-abstractions';
353
+ const properties = channelsData.map((data) => this.createMessagingSettingProperty(data, className, serviceId === AX_COMMON_SERVICE_ID));
354
+ const content = (0, endent_1.default) `import { ${baseClass} } from '@axinom/mosaic-message-bus-abstractions';
342
355
 
343
356
  export class ${className} ${action} ${baseClass} {
344
357
  ${properties.join(`\n`)}
345
358
  ${isMultiTenant || serviceId === AX_COMMON_SERVICE_ID
346
- ? ``
347
- : `\npublic readonly serviceId = '${serviceId}';\n`}
359
+ ? ``
360
+ : `\npublic readonly serviceId = '${serviceId}';\n`}
348
361
  ${constructor}
349
362
 
350
363
  public${toStringOverride} toString = (): string => {
351
364
  return this.messageType;
352
365
  };
353
366
  }`;
354
- const filePath = path.join(outputPath, `${modelina_1.FormatHelpers.toParamCase(className)}.ts`);
355
- yield fs.promises.mkdir(path.dirname(filePath), {
356
- recursive: true,
357
- });
358
- yield fs.promises.writeFile(filePath, content);
359
- return filePath;
367
+ const filePath = path.join(outputPath, `${modelina_1.FormatHelpers.toParamCase(className)}.ts`);
368
+ await fs.promises.mkdir(path.dirname(filePath), {
369
+ recursive: true,
360
370
  });
371
+ await fs.promises.writeFile(filePath, content);
372
+ return filePath;
361
373
  }
362
374
  /**
363
375
  * Create Messaging Settings property from Channel Data.
@@ -420,11 +432,9 @@ class Codegen {
420
432
  * @param jsonSchema - Schema object.
421
433
  * @param outPath - Output JSON schema path.
422
434
  */
423
- bundleSchema(jsonSchema, outPath) {
424
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
425
- yield fs.promises.mkdir(path.dirname(outPath), { recursive: true });
426
- yield fs.promises.writeFile(outPath, JSON.stringify(jsonSchema, null, 2));
427
- });
435
+ async bundleSchema(jsonSchema, outPath) {
436
+ await fs.promises.mkdir(path.dirname(outPath), { recursive: true });
437
+ await fs.promises.writeFile(outPath, JSON.stringify(jsonSchema, null, 2));
428
438
  }
429
439
  // TODO: Consider doing named exports based on message groups to not just put all messages in one namespace.
430
440
  // TODO: Maybe some templating engine would be better than just building strings.
@@ -435,65 +445,63 @@ class Codegen {
435
445
  * @param dirs - Directories to roll up.
436
446
  * @param outPath - Path where to write `index.ts`.
437
447
  */
438
- barrelExportTs(files, dirs, outPath) {
439
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
440
- console.log(`Rolling up TS exports to ${outPath}.`);
441
- const items = [
442
- ...files.map((f) => path.basename(f, '.ts')),
443
- ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
444
- ];
445
- if (items.length < 1) {
446
- return;
447
- }
448
- const exports = `${items
449
- .sort()
450
- .map((p) => `export * from './${p}';`)
451
- .join('\n')}`;
452
- let schemaEnum = '';
453
- let typeNamesEnum = '';
454
- // TODO: Break this up into smaller pieces.
455
- // TODO: Consider adding docstring to generated enums.
456
- if (files.length > 0) {
457
- const sortedFiles = files.sort();
458
- // TODO: Message envelope is handled separately, we could remove this entirely.
459
- // If message-envelope requires some special handling.
460
- if (files.length === 1 && files[0].endsWith('message-envelope.ts')) {
461
- const file = files[0];
462
- schemaEnum = (0, endent_1.default) `
448
+ async barrelExportTs(files, dirs, outPath) {
449
+ console.log(`Rolling up TS exports to ${outPath}.`);
450
+ const items = [
451
+ ...files.map((f) => path.basename(f, '.ts')),
452
+ ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
453
+ ];
454
+ if (items.length < 1) {
455
+ return;
456
+ }
457
+ const exports = `${items
458
+ .sort()
459
+ .map((p) => `export * from './${p}';`)
460
+ .join('\n')}`;
461
+ let schemaEnum = '';
462
+ let typeNamesEnum = '';
463
+ // TODO: Break this up into smaller pieces.
464
+ // TODO: Consider adding docstring to generated enums.
465
+ if (files.length > 0) {
466
+ const sortedFiles = files.sort();
467
+ // TODO: Message envelope is handled separately, we could remove this entirely.
468
+ // If message-envelope requires some special handling.
469
+ if (files.length === 1 && files[0].endsWith('message-envelope.ts')) {
470
+ const file = files[0];
471
+ schemaEnum = (0, endent_1.default) `
463
472
  export enum MessageEnvelopeSchema {
464
473
  MessageEnvelope = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(file))}'
465
474
  }
466
475
  `;
467
- }
468
- else {
469
- let enumNameBase = modelina_1.FormatHelpers.toPascalCase((0, utils_1.getRelativeDir)(this.typesOutputRoot, path.dirname(outPath)));
470
- if (!enumNameBase.includes('Types')) {
471
- enumNameBase = enumNameBase.replace('Payloads', ''); // Remove the Payloads prefix to reduce noise
472
- schemaEnum = (0, endent_1.default) `
476
+ }
477
+ else {
478
+ let enumNameBase = modelina_1.FormatHelpers.toPascalCase((0, utils_1.getRelativeDir)(this.typesOutputRoot, path.dirname(outPath)));
479
+ if (!enumNameBase.includes('Types')) {
480
+ enumNameBase = enumNameBase.replace('Payloads', ''); // Remove the Payloads prefix to reduce noise
481
+ schemaEnum = (0, endent_1.default) `
473
482
  export enum ${enumNameBase}Schemas {
474
483
  ${sortedFiles
475
- .map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(f))}'`)
476
- .join(',\n')}
484
+ .map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(f))}'`)
485
+ .join(',\n')}
477
486
  }`;
478
- typeNamesEnum = (0, endent_1.default) `
487
+ typeNamesEnum = (0, endent_1.default) `
479
488
  export enum ${enumNameBase}Types {
480
489
  ${sortedFiles
481
- .sort()
482
- .map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))}'`)
483
- .join(',\n')}
490
+ .sort()
491
+ .map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))}'`)
492
+ .join(',\n')}
484
493
  }`;
485
- }
486
494
  }
487
495
  }
488
- const contents = (0, endent_1.default) `
496
+ }
497
+ const contents = (0, endent_1.default) `
489
498
  ${exports}
490
499
 
491
500
  ${schemaEnum}
492
501
 
493
502
  ${typeNamesEnum}
494
503
  `;
495
- yield fs.promises.writeFile(outPath, contents);
496
- });
504
+ await fs.promises.writeFile(outPath, contents);
497
505
  }
498
506
  /**
499
507
  * Generates a barrel index.ts for all Messaging Settings inside `outPath`.
@@ -501,32 +509,30 @@ class Codegen {
501
509
  * @param dirs - Directories to roll up.
502
510
  * @param outPath - Path where to write `index.ts`.
503
511
  */
504
- barrelExportSettings(files, dirs, outPath) {
505
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
506
- console.log(`Rolling up Messaging Settings exports to ${outPath}.`);
507
- const items = [
508
- ...files.map((f) => path.basename(f, '.ts')),
509
- ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
510
- ];
511
- const dirExports = dirs
512
- .sort()
513
- .filter((d) => fs.existsSync(d))
514
- .map((d) => path.basename(d));
515
- if (items.length < 1) {
516
- return;
517
- }
518
- let contents = '';
519
- if (files.length > 0) {
520
- const baseNames = files.map((f) => path.basename(f, '.ts')).sort();
521
- const messagingImports = baseNames.map((n) => `export * from './${n}';`);
522
- contents = (0, endent_1.default) `
512
+ async barrelExportSettings(files, dirs, outPath) {
513
+ console.log(`Rolling up Messaging Settings exports to ${outPath}.`);
514
+ const items = [
515
+ ...files.map((f) => path.basename(f, '.ts')),
516
+ ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
517
+ ];
518
+ const dirExports = dirs
519
+ .sort()
520
+ .filter((d) => fs.existsSync(d))
521
+ .map((d) => path.basename(d));
522
+ if (items.length < 1) {
523
+ return;
524
+ }
525
+ let contents = '';
526
+ if (files.length > 0) {
527
+ const baseNames = files.map((f) => path.basename(f, '.ts')).sort();
528
+ const messagingImports = baseNames.map((n) => `export * from './${n}';`);
529
+ contents = (0, endent_1.default) `
523
530
  ${messagingImports.join('\n')}
524
531
  `;
525
- }
526
- contents += (0, endent_1.default) `\n
532
+ }
533
+ contents += (0, endent_1.default) `\n
527
534
  ${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
528
- yield fs.promises.writeFile(outPath, contents);
529
- });
535
+ await fs.promises.writeFile(outPath, contents);
530
536
  }
531
537
  /**
532
538
  * Generates a barrel index.ts for all JSON schemas inside `outPath`.
@@ -534,35 +540,33 @@ class Codegen {
534
540
  * @param dirs - Directories to roll up.
535
541
  * @param outPath - Path where to write `index.ts`.
536
542
  */
537
- barrelExportSchema(files, dirs, outPath) {
538
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
539
- console.log(`Rolling up JSON exports to ${outPath}.`);
540
- const items = [
541
- ...files.map((f) => path.basename(f, '.json')),
542
- ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
543
- ];
544
- const dirExports = dirs
545
- .sort()
546
- .filter((d) => fs.existsSync(d))
547
- .map((d) => path.basename(d));
548
- if (items.length < 1) {
549
- return;
550
- }
551
- let contents = '';
552
- if (files.length > 0) {
553
- const baseNames = files.map((f) => path.basename(f, '.json')).sort();
554
- const schemaImports = baseNames.map((n) => `import * as ${modelina_1.FormatHelpers.toPascalCase(n)} from './${n}.json';`);
555
- const schemaExports = baseNames.map((n) => `export const ${modelina_1.FormatHelpers.toPascalCase(n)}Schema = ${modelina_1.FormatHelpers.toPascalCase(n)};`);
556
- contents = (0, endent_1.default) `
543
+ async barrelExportSchema(files, dirs, outPath) {
544
+ console.log(`Rolling up JSON exports to ${outPath}.`);
545
+ const items = [
546
+ ...files.map((f) => path.basename(f, '.json')),
547
+ ...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
548
+ ];
549
+ const dirExports = dirs
550
+ .sort()
551
+ .filter((d) => fs.existsSync(d))
552
+ .map((d) => path.basename(d));
553
+ if (items.length < 1) {
554
+ return;
555
+ }
556
+ let contents = '';
557
+ if (files.length > 0) {
558
+ const baseNames = files.map((f) => path.basename(f, '.json')).sort();
559
+ const schemaImports = baseNames.map((n) => `import * as ${modelina_1.FormatHelpers.toPascalCase(n)} from './${n}.json';`);
560
+ const schemaExports = baseNames.map((n) => `export const ${modelina_1.FormatHelpers.toPascalCase(n)}Schema = ${modelina_1.FormatHelpers.toPascalCase(n)};`);
561
+ contents = (0, endent_1.default) `
557
562
  ${schemaImports.join('\n')}
558
563
 
559
564
  ${schemaExports.join('\n')}
560
565
  `;
561
- }
562
- contents += (0, endent_1.default) `\n
566
+ }
567
+ contents += (0, endent_1.default) `\n
563
568
  ${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
564
- yield fs.promises.writeFile(outPath, contents);
565
- });
569
+ await fs.promises.writeFile(outPath, contents);
566
570
  }
567
571
  /**
568
572
  * Converts a generated TS path to a corresponding JSON schema path.