@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.
- package/dist/cli/index.js +6 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/apply-templates/apply-templates.js +12 -11
- package/dist/commands/apply-templates/apply-templates.js.map +1 -1
- package/dist/commands/apply-templates/bitwarden-vault.js.map +1 -1
- package/dist/commands/create/command.js +26 -11
- package/dist/commands/create/command.js.map +1 -1
- package/dist/commands/create/createSolution.js +31 -31
- package/dist/commands/create/createSolution.js.map +1 -1
- package/dist/commands/create/helpers/git.d.ts +1 -1
- package/dist/commands/create/helpers/git.js +8 -9
- package/dist/commands/create/helpers/git.js.map +1 -1
- package/dist/commands/create/helpers/logger.js +8 -7
- package/dist/commands/create/helpers/logger.js.map +1 -1
- package/dist/commands/create/runQuestionaire.js +18 -18
- package/dist/commands/create/runQuestionaire.js.map +1 -1
- package/dist/commands/create-extension-config/create-extension-config.js +14 -14
- package/dist/commands/create-extension-config/create-extension-config.js.map +1 -1
- package/dist/commands/create-extension-config/index.js +2 -1
- package/dist/commands/create-extension-config/index.js.map +1 -1
- package/dist/commands/get-access-token/get-dev-access-token.js +3 -4
- package/dist/commands/get-access-token/get-dev-access-token.js.map +1 -1
- package/dist/commands/get-access-token/index.js +6 -6
- package/dist/commands/get-access-token/index.js.map +1 -1
- package/dist/commands/graphql-diff.js +44 -46
- package/dist/commands/graphql-diff.js.map +1 -1
- package/dist/commands/hosting/manifest/manifest-commands.js +3 -4
- package/dist/commands/hosting/manifest/manifest-commands.js.map +1 -1
- package/dist/commands/hosting/manifest/upload-manifest.js +7 -7
- package/dist/commands/hosting/manifest/upload-manifest.js.map +1 -1
- package/dist/commands/hosting/pilet/pilet-commands.js +3 -4
- package/dist/commands/hosting/pilet/pilet-commands.js.map +1 -1
- package/dist/commands/hosting/pilet/register-pilet.js +13 -10
- package/dist/commands/hosting/pilet/register-pilet.js.map +1 -1
- package/dist/commands/hosting/service/deploy/service-deploy-command.js +3 -4
- package/dist/commands/hosting/service/deploy/service-deploy-command.js.map +1 -1
- package/dist/commands/hosting/service/deploy/service-deploy.js +14 -14
- package/dist/commands/hosting/service/deploy/service-deploy.js.map +1 -1
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js +3 -4
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js.map +1 -1
- package/dist/commands/hosting/service/undeploy/service-undeploy.js +11 -11
- package/dist/commands/hosting/service/undeploy/service-undeploy.js.map +1 -1
- package/dist/commands/msg-codegen/codegen.js +326 -322
- package/dist/commands/msg-codegen/codegen.js.map +1 -1
- package/dist/commands/msg-codegen/index.js +4 -5
- package/dist/commands/msg-codegen/index.js.map +1 -1
- package/dist/commands/msg-codegen/lint.js +55 -60
- package/dist/commands/msg-codegen/lint.js.map +1 -1
- package/dist/commands/msg-codegen/presets.js +10 -1
- package/dist/commands/msg-codegen/presets.js.map +1 -1
- package/dist/commands/msg-codegen/utils.d.ts +1 -0
- package/dist/commands/msg-codegen/utils.js +38 -26
- package/dist/commands/msg-codegen/utils.js.map +1 -1
- package/dist/commands/msg-diff/git-checkout-tmp.js +7 -6
- package/dist/commands/msg-diff/git-checkout-tmp.js.map +1 -1
- package/dist/commands/msg-diff/index.js +4 -4
- package/dist/commands/msg-diff/index.js.map +1 -1
- package/dist/commands/msg-diff/msg-diff.js +188 -198
- package/dist/commands/msg-diff/msg-diff.js.map +1 -1
- package/dist/commands/pg-dump/generate.js +5 -4
- package/dist/commands/pg-dump/generate.js.map +1 -1
- package/dist/commands/publish-schema-to-db/content-entity-model.js.map +1 -1
- package/dist/commands/publish-schema-to-db/generate.js +45 -45
- package/dist/commands/publish-schema-to-db/generate.js.map +1 -1
- package/dist/commands/publish-schema-to-db/index.js +3 -4
- package/dist/commands/publish-schema-to-db/index.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/columns/pk-column.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/columns/primitive-column.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js +18 -22
- package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js +26 -29
- package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js +11 -11
- package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/content-entity-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/object-property-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/relations-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js +2 -3
- package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js.map +1 -1
- package/dist/commands/service/purge-permissions/purge-permissions-command.js +3 -4
- package/dist/commands/service/purge-permissions/purge-permissions-command.js.map +1 -1
- package/dist/commands/service/purge-permissions/purge-permissions.js +4 -5
- package/dist/commands/service/purge-permissions/purge-permissions.js.map +1 -1
- package/dist/commands/service/sync-permissions/sync-permission-command.js +3 -4
- package/dist/commands/service/sync-permissions/sync-permission-command.js.map +1 -1
- package/dist/commands/service/sync-permissions/sync-permissions.js +5 -5
- package/dist/commands/service/sync-permissions/sync-permissions.js.map +1 -1
- package/dist/commands/unpublish-pilet/index.js +7 -7
- package/dist/commands/unpublish-pilet/index.js.map +1 -1
- package/dist/commands/unpublish-pilet/unpublish-pilet.js +4 -4
- package/dist/commands/unpublish-pilet/unpublish-pilet.js.map +1 -1
- package/package.json +18 -13
- package/src/commands/apply-templates/apply-templates.spec.ts +20 -11
- package/src/commands/apply-templates/apply-templates.ts +1 -1
- package/src/commands/create/helpers/logger.ts +1 -1
- package/src/commands/create-extension-config/create-extension-config.ts +1 -1
- package/src/commands/get-access-token/index.ts +1 -1
- package/src/commands/hosting/pilet/register-pilet.ts +1 -1
- package/src/commands/msg-codegen/codegen.ts +34 -6
- package/src/commands/msg-codegen/presets.ts +12 -0
- package/src/commands/msg-codegen/utils.ts +14 -1
- package/src/commands/msg-diff/msg-diff.spec.ts +6 -9
- package/src/commands/pg-dump/generate.ts +1 -1
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.spec.ts +18 -14
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.spec.ts +11 -7
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.spec.ts +2 -1
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.spec.ts +1 -0
- package/src/commands/unpublish-pilet/index.ts +1 -1
- package/src/types/find-nearest-file.d.ts +11 -0
- 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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
327
|
-
|
|
339
|
+
? `super(serviceId, messageType, queue, routingKey, action, aggregateType);`
|
|
340
|
+
: ''}
|
|
328
341
|
}`
|
|
329
|
-
|
|
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
|
-
|
|
338
|
-
|
|
350
|
+
? `super('${serviceId}', messageType, queue, routingKey, action, aggregateType);`
|
|
351
|
+
: ''}
|
|
339
352
|
}`;
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
425
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
476
|
-
|
|
484
|
+
.map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(f))}'`)
|
|
485
|
+
.join(',\n')}
|
|
477
486
|
}`;
|
|
478
|
-
|
|
487
|
+
typeNamesEnum = (0, endent_1.default) `
|
|
479
488
|
export enum ${enumNameBase}Types {
|
|
480
489
|
${sortedFiles
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
496
|
+
}
|
|
497
|
+
const contents = (0, endent_1.default) `
|
|
489
498
|
${exports}
|
|
490
499
|
|
|
491
500
|
${schemaEnum}
|
|
492
501
|
|
|
493
502
|
${typeNamesEnum}
|
|
494
503
|
`;
|
|
495
|
-
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
532
|
+
}
|
|
533
|
+
contents += (0, endent_1.default) `\n
|
|
527
534
|
${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
|
|
528
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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
|
-
|
|
566
|
+
}
|
|
567
|
+
contents += (0, endent_1.default) `\n
|
|
563
568
|
${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
|
|
564
|
-
|
|
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.
|