@amritk/mjst 0.25.0 → 0.25.1
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.js +20 -11
- package/package.json +10 -10
package/dist/cli.js
CHANGED
|
@@ -3,21 +3,14 @@ import { execFile } from "node:child_process";
|
|
|
3
3
|
import { readdir, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
-
import { extractAsyncApi, listMessageSchemas } from "@amritk/asyncapi";
|
|
7
6
|
import { deriveRootTypeName } from "@amritk/helpers/derive-root-type-name";
|
|
8
7
|
const execFileAsync = promisify(execFile);
|
|
9
|
-
import { combineGeneratedFiles } from "./combine-files.js";
|
|
10
8
|
import { createOutputWriter } from "./create-output-writer.js";
|
|
11
9
|
import { detectHelpersMode } from "./detect-helpers-mode.js";
|
|
12
|
-
import { emitExamples } from "./emit-examples.js";
|
|
13
|
-
import { CONTRACTS_DIR, CONTRACTS_PEER, emitMessageContracts } from "./emit-message-contracts.js";
|
|
14
10
|
import { ensureOutputDir } from "./ensure-output-dir.js";
|
|
15
|
-
import { generateFiles } from "./generate-files.js";
|
|
16
11
|
import { HELP_TEXT } from "./help-text.js";
|
|
17
12
|
import { isDependencyDeclared } from "./is-dependency-declared.js";
|
|
18
|
-
import { loadAsyncApiDocument } from "./load-asyncapi-document.js";
|
|
19
13
|
import { loadConfig } from "./load-config.js";
|
|
20
|
-
import { loadSchema } from "./load-schema.js";
|
|
21
14
|
import { parseCliArgs } from "./parse-cli-args.js";
|
|
22
15
|
import { parseMetaRequest } from "./parse-meta-request.js";
|
|
23
16
|
import { readVersion } from "./read-version.js";
|
|
@@ -32,6 +25,10 @@ const resolveHelpersMode = (config, outputDir) => {
|
|
|
32
25
|
}
|
|
33
26
|
return helpersMode;
|
|
34
27
|
};
|
|
28
|
+
const loadGenerationPipeline = async () => {
|
|
29
|
+
const [{ loadSchema }, { generateFiles }] = await Promise.all([import("./load-schema.js"), import("./generate-files.js")]);
|
|
30
|
+
return { loadSchema, generateFiles };
|
|
31
|
+
};
|
|
35
32
|
const extractConfigPath = (args) => {
|
|
36
33
|
for (let i = 0; i < args.length; i++) {
|
|
37
34
|
const arg = args[i];
|
|
@@ -65,6 +62,7 @@ const commitOrDiscard = async (writer, stageAll) => {
|
|
|
65
62
|
return writer.commit();
|
|
66
63
|
};
|
|
67
64
|
const runExamples = async (config, outputDir, tasks) => {
|
|
65
|
+
const { emitExamples } = await import("./emit-examples.js");
|
|
68
66
|
const writer = await createOutputWriter(outputDir);
|
|
69
67
|
const written = await commitOrDiscard(writer, async () => {
|
|
70
68
|
for (const task of tasks) {
|
|
@@ -137,6 +135,7 @@ const findJsonSchemas = async (dir) => {
|
|
|
137
135
|
return results;
|
|
138
136
|
};
|
|
139
137
|
const runSingle = async (config, schemaPath, outputDir) => {
|
|
138
|
+
const { loadSchema, generateFiles } = await loadGenerationPipeline();
|
|
140
139
|
const schema = await loadSchema(config, schemaPath);
|
|
141
140
|
await ensureOutputDir(outputDir);
|
|
142
141
|
const helpersMode = resolveHelpersMode(config, outputDir);
|
|
@@ -164,6 +163,8 @@ Total files generated: ${written.length}`);
|
|
|
164
163
|
}
|
|
165
164
|
};
|
|
166
165
|
const runSingleFile = async (config, schemaPath, outFilePath) => {
|
|
166
|
+
const { loadSchema, generateFiles } = await loadGenerationPipeline();
|
|
167
|
+
const { combineGeneratedFiles } = await import("./combine-files.js");
|
|
167
168
|
const schema = await loadSchema(config, schemaPath);
|
|
168
169
|
const outputDir = dirname(outFilePath);
|
|
169
170
|
await ensureOutputDir(outputDir);
|
|
@@ -194,6 +195,7 @@ const runRecursive = async (config, schemaDir, outputDir) => {
|
|
|
194
195
|
process.exit(1);
|
|
195
196
|
}
|
|
196
197
|
const schemaFiles = await findJsonSchemas(schemaDir);
|
|
198
|
+
const { loadSchema, generateFiles } = await loadGenerationPipeline();
|
|
197
199
|
if (schemaFiles.length === 0) {
|
|
198
200
|
console.error(`Error: no .json schema files found under ${schemaDir}.`);
|
|
199
201
|
process.exit(1);
|
|
@@ -245,12 +247,19 @@ ${relPath} \u2192 ${relNoExt}/ (root type: ${rootTypeName})`);
|
|
|
245
247
|
Total files generated: ${writtenTsFiles.length}`);
|
|
246
248
|
}
|
|
247
249
|
};
|
|
248
|
-
const reportContractsPeer = (outputDir) => {
|
|
249
|
-
if (isDependencyDeclared(outputDir,
|
|
250
|
+
const reportContractsPeer = (outputDir, peer) => {
|
|
251
|
+
if (isDependencyDeclared(outputDir, peer))
|
|
250
252
|
return;
|
|
251
|
-
console.log(`Tip: the generated contracts import ${
|
|
253
|
+
console.log(`Tip: the generated contracts import ${peer}, which is not a declared dependency of the project at ${outputDir}. Install it there (it is a peer of the generated code, not of the mjst CLI).`);
|
|
252
254
|
};
|
|
253
255
|
const runAsyncApi = async (config, documentPath, outputDir) => {
|
|
256
|
+
const [{ loadAsyncApiDocument }, { extractAsyncApi, listMessageSchemas }, { generateFiles }, contractsModule] = await Promise.all([
|
|
257
|
+
import("./load-asyncapi-document.js"),
|
|
258
|
+
import("@amritk/asyncapi"),
|
|
259
|
+
import("./generate-files.js"),
|
|
260
|
+
import("./emit-message-contracts.js")
|
|
261
|
+
]);
|
|
262
|
+
const { CONTRACTS_DIR, CONTRACTS_PEER, emitMessageContracts } = contractsModule;
|
|
254
263
|
const document = await loadAsyncApiDocument(config, documentPath);
|
|
255
264
|
const model = extractAsyncApi(document);
|
|
256
265
|
const schemas = listMessageSchemas(model);
|
|
@@ -323,7 +332,7 @@ ${subDir}/ (root type: ${rootTypeName})`);
|
|
|
323
332
|
if (config.messageContracts) {
|
|
324
333
|
console.log(`
|
|
325
334
|
Message contracts: ${contractMessageCount} message(s) across ${contractChannelCount} channel(s)`);
|
|
326
|
-
reportContractsPeer(outputDir);
|
|
335
|
+
reportContractsPeer(outputDir, CONTRACTS_PEER);
|
|
327
336
|
}
|
|
328
337
|
if (exampleTasks.length > 0) {
|
|
329
338
|
await runExamples(config, outputDir, exampleTasks);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/mjst",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -49,16 +49,16 @@
|
|
|
49
49
|
"./package.json": "./package.json"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@amritk/adapters": "^0.6.
|
|
53
|
-
"@amritk/api": "^0.16.
|
|
54
|
-
"@amritk/asyncapi": "^0.3.
|
|
55
|
-
"@amritk/generate-examples": "^0.8.
|
|
52
|
+
"@amritk/adapters": "^0.6.7",
|
|
53
|
+
"@amritk/api": "^0.16.6",
|
|
54
|
+
"@amritk/asyncapi": "^0.3.5",
|
|
55
|
+
"@amritk/generate-examples": "^0.8.9",
|
|
56
56
|
"@amritk/generate-markdown": "^0.11.0",
|
|
57
|
-
"@amritk/helpers": "^0.23.
|
|
58
|
-
"@amritk/lint": "^0.6.
|
|
59
|
-
"@amritk/validation": "^0.3.
|
|
60
|
-
"@amritk/resolve-refs": "^0.
|
|
61
|
-
"@amritk/yaml": "^0.7.
|
|
57
|
+
"@amritk/helpers": "^0.23.3",
|
|
58
|
+
"@amritk/lint": "^0.6.2",
|
|
59
|
+
"@amritk/validation": "^0.3.2",
|
|
60
|
+
"@amritk/resolve-refs": "^0.8.0",
|
|
61
|
+
"@amritk/yaml": "^0.7.3",
|
|
62
62
|
"fast-glob": "^3.3.2",
|
|
63
63
|
"json-schema-typed": "^8.0.1",
|
|
64
64
|
"yargs": "^17.7.2"
|