openxiangda 1.0.25 → 1.0.27

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.
@@ -8,10 +8,23 @@ import { fileURLToPath } from "node:url";
8
8
  import { build } from "vite";
9
9
 
10
10
  const rootDir = fileURLToPath(new URL("..", import.meta.url));
11
- const sourceRoot = path.join(rootDir, "src", "js-code-nodes");
12
- const outputRoot = path.join(rootDir, "dist", "js-code-nodes");
13
11
  const args = process.argv.slice(2);
14
12
 
13
+ const sourceKinds = {
14
+ "js-code-nodes": {
15
+ name: "js-code-nodes",
16
+ sourceRoot: path.join(rootDir, "src", "js-code-nodes"),
17
+ outputRoot: path.join(rootDir, "dist", "js-code-nodes"),
18
+ label: "JS_CODE",
19
+ },
20
+ automations: {
21
+ name: "automations",
22
+ sourceRoot: path.join(rootDir, "src", "automations"),
23
+ outputRoot: path.join(rootDir, "dist", "automations"),
24
+ label: "automation code",
25
+ },
26
+ };
27
+
15
28
  function readArg(name) {
16
29
  const prefix = `--${name}=`;
17
30
  const inline = args.find((arg) => arg.startsWith(prefix));
@@ -20,12 +33,12 @@ function readArg(name) {
20
33
  return index >= 0 ? args[index + 1] : undefined;
21
34
  }
22
35
 
23
- async function listScriptCodes() {
24
- if (!existsSync(sourceRoot)) return [];
25
- const entries = await readdir(sourceRoot);
36
+ async function listScriptCodes(kind) {
37
+ if (!existsSync(kind.sourceRoot)) return [];
38
+ const entries = await readdir(kind.sourceRoot);
26
39
  const result = [];
27
40
  for (const entry of entries) {
28
- const entryDir = path.join(sourceRoot, entry);
41
+ const entryDir = path.join(kind.sourceRoot, entry);
29
42
  const entryStat = await stat(entryDir);
30
43
  if (!entryStat.isDirectory()) continue;
31
44
  if (existsSync(path.join(entryDir, "index.ts"))) result.push(entry);
@@ -45,11 +58,11 @@ function typecheckScripts() {
45
58
  if (result.status !== 0) throw new Error("JS_CODE TypeScript validation failed");
46
59
  }
47
60
 
48
- async function buildScript(scriptCode) {
49
- const entry = path.join(sourceRoot, scriptCode, "index.ts");
50
- if (!existsSync(entry)) throw new Error(`JS_CODE script not found: ${entry}`);
61
+ async function buildScript(kind, scriptCode) {
62
+ const entry = path.join(kind.sourceRoot, scriptCode, "index.ts");
63
+ if (!existsSync(entry)) throw new Error(`${kind.label} script not found: ${entry}`);
51
64
 
52
- const outDir = path.join(outputRoot, scriptCode);
65
+ const outDir = path.join(kind.outputRoot, scriptCode);
53
66
  const external = Array.from(
54
67
  new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]),
55
68
  );
@@ -82,19 +95,46 @@ async function buildScript(scriptCode) {
82
95
  },
83
96
  });
84
97
 
85
- console.log(`built ${scriptCode} -> ${path.relative(rootDir, path.join(outDir, "index.cjs"))}`);
98
+ console.log(`built ${kind.name}/${scriptCode} -> ${path.relative(rootDir, path.join(outDir, "index.cjs"))}`);
86
99
  }
87
100
 
88
101
  const onlyScript = readArg("script");
89
- const scriptCodes = onlyScript ? [onlyScript] : await listScriptCodes();
102
+ const sourceArg = readArg("source");
103
+ const selectedKind = sourceArg ? sourceKinds[sourceArg] : undefined;
104
+ if (sourceArg && !selectedKind) {
105
+ throw new Error(`unsupported source: ${sourceArg}. Expected js-code-nodes or automations`);
106
+ }
107
+
108
+ async function resolveBuildTargets() {
109
+ if (onlyScript) {
110
+ if (selectedKind) return [{ kind: selectedKind, scriptCode: onlyScript }];
111
+ for (const kind of Object.values(sourceKinds)) {
112
+ if (existsSync(path.join(kind.sourceRoot, onlyScript, "index.ts"))) {
113
+ return [{ kind, scriptCode: onlyScript }];
114
+ }
115
+ }
116
+ return [{ kind: sourceKinds["js-code-nodes"], scriptCode: onlyScript }];
117
+ }
118
+
119
+ const kinds = selectedKind ? [selectedKind] : Object.values(sourceKinds);
120
+ const targets = [];
121
+ for (const kind of kinds) {
122
+ for (const scriptCode of await listScriptCodes(kind)) {
123
+ targets.push({ kind, scriptCode });
124
+ }
125
+ }
126
+ return targets;
127
+ }
128
+
129
+ const targets = await resolveBuildTargets();
90
130
 
91
- if (scriptCodes.length === 0) {
92
- console.log("no JS_CODE scripts found under src/js-code-nodes/<scriptCode>/index.ts");
131
+ if (targets.length === 0) {
132
+ console.log("no JS_CODE scripts found under src/js-code-nodes/<scriptCode>/index.ts or src/automations/<scriptCode>/index.ts");
93
133
  process.exit(0);
94
134
  }
95
135
 
96
136
  typecheckScripts();
97
137
 
98
- for (const scriptCode of scriptCodes) {
99
- await buildScript(scriptCode);
138
+ for (const target of targets) {
139
+ await buildScript(target.kind, target.scriptCode);
100
140
  }
@@ -11,5 +11,5 @@
11
11
  "@/*": ["src/*"]
12
12
  }
13
13
  },
14
- "include": ["src/js-code-nodes/**/*.ts"]
14
+ "include": ["src/js-code-nodes/**/*.ts", "src/automations/**/*.ts"]
15
15
  }