design-embed 0.1.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/LICENSE +9 -0
- package/README.md +5 -0
- package/dist/args.js +36 -0
- package/dist/cli.js +35 -0
- package/dist/commands/check.js +4 -0
- package/dist/commands/compile.js +157 -0
- package/dist/commands/generateTests.js +113 -0
- package/dist/commands/init.js +102 -0
- package/dist/commands/plugin.js +68 -0
- package/dist/index.js +2 -0
- package/node_modules/@design-embed/config/README.md +5 -0
- package/node_modules/@design-embed/config/dist/index.js +283 -0
- package/node_modules/@design-embed/config/package.json +19 -0
- package/node_modules/@design-embed/config/src/index.ts +518 -0
- package/node_modules/@design-embed/core/README.md +5 -0
- package/node_modules/@design-embed/core/dist/diagnostics/diagnostic.js +3 -0
- package/node_modules/@design-embed/core/dist/diagnostics/jsonDiagnostic.js +35 -0
- package/node_modules/@design-embed/core/dist/index.js +351 -0
- package/node_modules/@design-embed/core/dist/pipeline/checkMode.js +29 -0
- package/node_modules/@design-embed/core/dist/plugins/pluginApi.js +1 -0
- package/node_modules/@design-embed/core/dist/plugins/pluginRegistry.js +25 -0
- package/node_modules/@design-embed/core/package.json +19 -0
- package/node_modules/@design-embed/core/src/diagnostics/diagnostic.ts +18 -0
- package/node_modules/@design-embed/core/src/diagnostics/jsonDiagnostic.ts +51 -0
- package/node_modules/@design-embed/core/src/index.ts +591 -0
- package/node_modules/@design-embed/core/src/pipeline/checkMode.ts +46 -0
- package/node_modules/@design-embed/core/src/plugins/pluginApi.ts +78 -0
- package/node_modules/@design-embed/core/src/plugins/pluginRegistry.ts +37 -0
- package/package.json +42 -0
- package/src/args.ts +57 -0
- package/src/cli.ts +42 -0
- package/src/commands/check.ts +7 -0
- package/src/commands/compile.ts +198 -0
- package/src/commands/generateTests.ts +140 -0
- package/src/commands/init.ts +114 -0
- package/src/commands/plugin.ts +89 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { loadConfig, type PluginDefinition } from "@design-embed/config";
|
|
4
|
+
import type { SourcePlugin } from "@design-embed/core";
|
|
5
|
+
import { getStringFlag } from "../args.ts";
|
|
6
|
+
|
|
7
|
+
export async function runPluginCommand(
|
|
8
|
+
_name: string | undefined,
|
|
9
|
+
flags: Record<string, string | boolean>,
|
|
10
|
+
): Promise<number> {
|
|
11
|
+
const configPath = getStringFlag(flags, "--config");
|
|
12
|
+
if (!configPath) {
|
|
13
|
+
console.error("Error: --config is required.");
|
|
14
|
+
return 2;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
const configResult = await loadConfig(configPath, cwd);
|
|
19
|
+
for (const diagnostic of configResult.diagnostics) {
|
|
20
|
+
if (diagnostic.severity === "error") {
|
|
21
|
+
console.error(`error: ${diagnostic.code}: ${diagnostic.message}`);
|
|
22
|
+
} else {
|
|
23
|
+
console.warn(
|
|
24
|
+
`${diagnostic.severity}: ${diagnostic.code}: ${diagnostic.message}`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (configResult.diagnostics.some((d) => d.severity === "error")) {
|
|
29
|
+
return 2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const outPath = getStringFlag(flags, "--out");
|
|
33
|
+
if (!outPath) {
|
|
34
|
+
console.error("Error: --out is required.");
|
|
35
|
+
return 2;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const plugin = findSourcePlugin(configResult.config?.plugins);
|
|
39
|
+
if (!plugin) {
|
|
40
|
+
console.error(
|
|
41
|
+
"Error: config must include a source plugin instance in the plugins array (e.g. new FigmaHtmlPlugin({ ... })).",
|
|
42
|
+
);
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const result = await plugin.run({ cwd, args: {} });
|
|
47
|
+
|
|
48
|
+
for (const diagnostic of result.diagnostics) {
|
|
49
|
+
const output = `${diagnostic.severity}: ${diagnostic.code}: ${diagnostic.message}`;
|
|
50
|
+
if (diagnostic.severity === "error") {
|
|
51
|
+
console.error(output);
|
|
52
|
+
} else {
|
|
53
|
+
console.warn(output);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (result.diagnostics.some((d) => d.severity === "error")) {
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!result.html) {
|
|
62
|
+
console.error("Error: source plugin produced no HTML.");
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const resolvedOutPath = resolve(cwd, outPath);
|
|
67
|
+
mkdirSync(dirname(resolvedOutPath), { recursive: true });
|
|
68
|
+
writeFileSync(resolvedOutPath, result.html, "utf-8");
|
|
69
|
+
console.log(`Wrote ${outPath}`);
|
|
70
|
+
|
|
71
|
+
for (const file of result.files ?? []) {
|
|
72
|
+
const resolvedPath = resolve(cwd, file.path);
|
|
73
|
+
mkdirSync(dirname(resolvedPath), { recursive: true });
|
|
74
|
+
writeFileSync(resolvedPath, file.contents, "utf-8");
|
|
75
|
+
console.log(`Wrote ${file.path}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isSourcePlugin(plugin: PluginDefinition): plugin is SourcePlugin {
|
|
82
|
+
return typeof (plugin as SourcePlugin).run === "function";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function findSourcePlugin(
|
|
86
|
+
plugins: PluginDefinition[] | undefined,
|
|
87
|
+
): SourcePlugin | undefined {
|
|
88
|
+
return plugins?.find(isSourcePlugin);
|
|
89
|
+
}
|
package/src/index.ts
ADDED