@rvct/asyncapi 1.0.0-beta.1 → 1.0.0-beta.2
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/generate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadConfig } from "./config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { runGeneration } from "./runtime/runGeneration.js";
|
|
3
3
|
import { writeArtifacts } from "./runtime/writeArtifacts.js";
|
|
4
4
|
export async function generate(options = {}) {
|
|
5
5
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -9,25 +9,19 @@ export async function generate(options = {}) {
|
|
|
9
9
|
input: options.input,
|
|
10
10
|
out: options.out,
|
|
11
11
|
});
|
|
12
|
-
const
|
|
13
|
-
const context = {
|
|
12
|
+
const result = await runGeneration({
|
|
14
13
|
cwd,
|
|
15
14
|
config,
|
|
16
|
-
|
|
17
|
-
graph: null,
|
|
18
|
-
diagnostics: [],
|
|
19
|
-
artifacts: [],
|
|
20
|
-
};
|
|
21
|
-
await pluginManager.run(context);
|
|
15
|
+
});
|
|
22
16
|
const outDir = await writeArtifacts({
|
|
23
|
-
cwd,
|
|
24
|
-
outDir: config.output.path,
|
|
25
|
-
artifacts:
|
|
17
|
+
cwd: result.cwd,
|
|
18
|
+
outDir: result.config.output.path,
|
|
19
|
+
artifacts: result.artifacts,
|
|
26
20
|
});
|
|
27
21
|
return {
|
|
28
|
-
total:
|
|
22
|
+
total: result.artifacts.length,
|
|
29
23
|
outDir,
|
|
30
|
-
diagnostics:
|
|
31
|
-
artifacts:
|
|
24
|
+
diagnostics: result.diagnostics,
|
|
25
|
+
artifacts: result.artifacts,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PluginManager } from "../runtime/PluginManager.js";
|
|
2
|
+
export async function runGeneration({ cwd = process.cwd(), config, }) {
|
|
3
|
+
const pluginManager = new PluginManager(config);
|
|
4
|
+
const context = {
|
|
5
|
+
cwd,
|
|
6
|
+
config,
|
|
7
|
+
asyncapi: null,
|
|
8
|
+
graph: null,
|
|
9
|
+
diagnostics: [],
|
|
10
|
+
artifacts: [],
|
|
11
|
+
};
|
|
12
|
+
await pluginManager.run(context);
|
|
13
|
+
return {
|
|
14
|
+
cwd,
|
|
15
|
+
config,
|
|
16
|
+
diagnostics: context.diagnostics,
|
|
17
|
+
artifacts: context.artifacts,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dirname, join, resolve } from "node:path";
|
|
2
2
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import prettier from "prettier";
|
|
4
|
+
const GENERATED_GITATTRIBUTES = "* linguist-generated=true\n**/* linguist-generated=true\n";
|
|
4
5
|
function toPosixPath(value) {
|
|
5
6
|
return value.replaceAll("\\", "/");
|
|
6
7
|
}
|
|
@@ -60,13 +61,18 @@ export async function writeArtifacts({ cwd, outDir, artifacts, }) {
|
|
|
60
61
|
for (const artifact of artifacts) {
|
|
61
62
|
files.set(artifact.filePath, artifact.code);
|
|
62
63
|
}
|
|
64
|
+
if (files.size > 0) {
|
|
65
|
+
files.set(".gitattributes", GENERATED_GITATTRIBUTES);
|
|
66
|
+
}
|
|
63
67
|
for (const [relativePath, code] of [...files.entries()].sort(([left], [right]) => left.localeCompare(right))) {
|
|
64
68
|
const absolutePath = resolve(resolvedOutDir, relativePath);
|
|
65
69
|
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
66
|
-
const formatted =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const formatted = relativePath === ".gitattributes"
|
|
71
|
+
? code
|
|
72
|
+
: await prettier.format(code, {
|
|
73
|
+
...(prettierConfig ?? {}),
|
|
74
|
+
filepath: absolutePath,
|
|
75
|
+
});
|
|
70
76
|
writeFileSync(absolutePath, formatted);
|
|
71
77
|
}
|
|
72
78
|
return resolvedOutDir;
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,16 @@ export interface UserConfig {
|
|
|
37
37
|
};
|
|
38
38
|
plugins?: PluginInstance[];
|
|
39
39
|
}
|
|
40
|
+
export interface RunGenerationOptions {
|
|
41
|
+
cwd?: string;
|
|
42
|
+
config: UserConfig;
|
|
43
|
+
}
|
|
44
|
+
export interface RunGenerationResult {
|
|
45
|
+
cwd: string;
|
|
46
|
+
config: UserConfig;
|
|
47
|
+
diagnostics: Diagnostic[];
|
|
48
|
+
artifacts: GeneratedArtifact[];
|
|
49
|
+
}
|
|
40
50
|
export interface GenerateOptions {
|
|
41
51
|
cwd?: string;
|
|
42
52
|
config?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rvct/asyncapi",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist && tsc -p tsconfig.json && tsc-alias -p tsconfig.json -f",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"format.check": "eslint . && prettier --check .",
|
|
10
10
|
"test": "npm run test:unit && npm run test:smoke",
|
|
11
11
|
"test:unit": "vitest run --project unit",
|
|
12
|
-
"test:smoke": "
|
|
12
|
+
"test:smoke": "vitest run --project smoke"
|
|
13
13
|
},
|
|
14
14
|
"description": "Config-driven AsyncAPI to JSON Schema, TypeScript, and Zod generator",
|
|
15
15
|
"repository": {
|