@voltx/cli 0.3.4 → 0.3.5
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/README.md +54 -22
- package/dist/build.d.mts +4 -3
- package/dist/build.d.ts +4 -3
- package/dist/build.js +56 -27
- package/dist/build.mjs +1 -2
- package/dist/chunk-2LHDOMF2.mjs +680 -0
- package/dist/chunk-5DVBIJXU.mjs +84 -0
- package/dist/chunk-65PVXS4D.mjs +894 -0
- package/dist/chunk-7JVIEGSA.mjs +141 -0
- package/dist/chunk-A4NA4AJN.mjs +786 -0
- package/dist/chunk-AAAHANST.mjs +839 -0
- package/dist/chunk-AD3WMFZF.mjs +205 -0
- package/dist/chunk-CSSHLVYS.mjs +83 -0
- package/dist/chunk-CWOSNV5O.mjs +150 -0
- package/dist/chunk-EI6XBYKB.mjs +84 -0
- package/dist/chunk-FI2W4L4S.mjs +205 -0
- package/dist/chunk-G2INQCCJ.mjs +907 -0
- package/dist/chunk-H2DTIOEO.mjs +150 -0
- package/dist/chunk-IS2WTE3C.mjs +138 -0
- package/dist/chunk-JECCDBYI.mjs +730 -0
- package/dist/chunk-KX2MRJUO.mjs +795 -0
- package/dist/chunk-LTGMHAZS.mjs +147 -0
- package/dist/chunk-OPO6RUFP.mjs +698 -0
- package/dist/chunk-PWQSKYAM.mjs +682 -0
- package/dist/chunk-Q5XCFN7L.mjs +1026 -0
- package/dist/chunk-QSU6FZC7.mjs +497 -0
- package/dist/chunk-RYWRFHEC.mjs +83 -0
- package/dist/chunk-SU4Q3PTH.mjs +201 -0
- package/dist/chunk-UXI3QSDN.mjs +121 -0
- package/dist/chunk-VD3CNPNP.mjs +123 -0
- package/dist/chunk-X6VOAPRJ.mjs +756 -0
- package/dist/cli.js +932 -307
- package/dist/cli.mjs +7 -6
- package/dist/create.d.mts +1 -0
- package/dist/create.d.ts +1 -0
- package/dist/create.js +723 -191
- package/dist/create.mjs +1 -2
- package/dist/dev.d.mts +6 -4
- package/dist/dev.d.ts +6 -4
- package/dist/dev.js +119 -46
- package/dist/dev.mjs +1 -2
- package/dist/generate.js +13 -13
- package/dist/generate.mjs +1 -2
- package/dist/index.js +919 -295
- package/dist/index.mjs +5 -6
- package/dist/start.js +7 -17
- package/dist/start.mjs +1 -2
- package/dist/welcome.mjs +0 -1
- package/package.json +11 -3
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/dev.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { resolve, join } from "path";
|
|
4
|
+
import { existsSync, writeFileSync, unlinkSync } from "fs";
|
|
5
|
+
import { loadEnv } from "@voltx/core";
|
|
6
|
+
async function runDev(options = {}) {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const {
|
|
9
|
+
port,
|
|
10
|
+
entry = findEntryPoint(cwd),
|
|
11
|
+
clearScreen = true
|
|
12
|
+
} = options;
|
|
13
|
+
if (!entry) {
|
|
14
|
+
console.error("[voltx] Could not find entry point. Expected src/index.ts or src/index.js");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const entryPath = resolve(cwd, entry);
|
|
18
|
+
if (!existsSync(entryPath)) {
|
|
19
|
+
console.error(`[voltx] Entry file not found: ${entry}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
loadEnv("development", cwd);
|
|
23
|
+
const hasFrontend = existsSync(resolve(cwd, "src", "frontend"));
|
|
24
|
+
if (hasFrontend) {
|
|
25
|
+
await startViteDevServer(cwd, port, entry, options);
|
|
26
|
+
} else {
|
|
27
|
+
await startTsxWatch(cwd, port, entry, options);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function startViteDevServer(cwd, port, entry, options) {
|
|
31
|
+
const resolvedPort = port ?? (Number(process.env.PORT) || 3e3);
|
|
32
|
+
printDevBanner(entry, resolvedPort, true);
|
|
33
|
+
const userViteConfig = resolve(cwd, "vite.config.ts");
|
|
34
|
+
const hasUserViteConfig = existsSync(userViteConfig);
|
|
35
|
+
let tempConfigPath = null;
|
|
36
|
+
if (!hasUserViteConfig) {
|
|
37
|
+
tempConfigPath = resolve(cwd, "vite.config.voltx.ts");
|
|
38
|
+
const viteConfigContent = generateViteConfig(entry, resolvedPort);
|
|
39
|
+
writeFileSync(tempConfigPath, viteConfigContent, "utf-8");
|
|
40
|
+
}
|
|
41
|
+
const env = {
|
|
42
|
+
...process.env,
|
|
43
|
+
NODE_ENV: "development"
|
|
44
|
+
};
|
|
45
|
+
if (port) {
|
|
46
|
+
env.PORT = String(port);
|
|
47
|
+
}
|
|
48
|
+
const viteBin = findBin(cwd, "vite");
|
|
49
|
+
const viteArgs = ["dev"];
|
|
50
|
+
if (tempConfigPath) {
|
|
51
|
+
viteArgs.push("--config", tempConfigPath);
|
|
52
|
+
}
|
|
53
|
+
viteArgs.push("--port", String(resolvedPort));
|
|
54
|
+
let child;
|
|
55
|
+
if (viteBin) {
|
|
56
|
+
child = spawn(viteBin, viteArgs, { cwd, env, stdio: "inherit" });
|
|
57
|
+
} else {
|
|
58
|
+
child = spawn("npx", ["vite", ...viteArgs], { cwd, env, stdio: "inherit" });
|
|
59
|
+
}
|
|
60
|
+
const cleanup = () => {
|
|
61
|
+
if (tempConfigPath && existsSync(tempConfigPath)) {
|
|
62
|
+
try {
|
|
63
|
+
unlinkSync(tempConfigPath);
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
69
|
+
for (const signal of signals) {
|
|
70
|
+
process.on(signal, () => {
|
|
71
|
+
cleanup();
|
|
72
|
+
child.kill(signal);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
child.on("error", (err) => {
|
|
76
|
+
cleanup();
|
|
77
|
+
if (err.code === "ENOENT") {
|
|
78
|
+
console.error("[voltx] vite not found. Install it with: npm install -D vite @hono/vite-dev-server");
|
|
79
|
+
} else {
|
|
80
|
+
console.error("[voltx] Dev server error:", err.message);
|
|
81
|
+
}
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
child.on("exit", (code) => {
|
|
85
|
+
cleanup();
|
|
86
|
+
process.exit(code ?? 0);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function generateViteConfig(entry, port) {
|
|
90
|
+
return `// Auto-generated by VoltX \u2014 do not commit this file
|
|
91
|
+
import { defineConfig } from "vite";
|
|
92
|
+
import devServer from "@hono/vite-dev-server";
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
server: {
|
|
96
|
+
port: ${port},
|
|
97
|
+
},
|
|
98
|
+
plugins: [
|
|
99
|
+
devServer({
|
|
100
|
+
entry: "${entry}",
|
|
101
|
+
exclude: [
|
|
102
|
+
/.*\\.tsx?($|\\?)/,
|
|
103
|
+
/.*\\.(s?css|less)($|\\?)/,
|
|
104
|
+
/.*\\.(svg|png|jpg|jpeg|gif|webp|ico)($|\\?)/,
|
|
105
|
+
/^\\/@.+$/,
|
|
106
|
+
/^\\/favicon\\.ico$/,
|
|
107
|
+
/^\\/node_modules\\/.*/,
|
|
108
|
+
/^\\/src\\/frontend\\/.*/,
|
|
109
|
+
],
|
|
110
|
+
injectClientScript: false,
|
|
111
|
+
}),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
async function startTsxWatch(cwd, port, entry, options) {
|
|
117
|
+
const resolvedPort = port ?? (Number(process.env.PORT) || 3e3);
|
|
118
|
+
printDevBanner(entry, resolvedPort, false);
|
|
119
|
+
const env = {
|
|
120
|
+
...process.env,
|
|
121
|
+
NODE_ENV: "development"
|
|
122
|
+
};
|
|
123
|
+
if (port) {
|
|
124
|
+
env.PORT = String(port);
|
|
125
|
+
}
|
|
126
|
+
const tsxArgs = ["watch"];
|
|
127
|
+
if (options.clearScreen ?? true) {
|
|
128
|
+
tsxArgs.push("--clear-screen=false");
|
|
129
|
+
}
|
|
130
|
+
tsxArgs.push("--ignore=node_modules", "--ignore=dist", "--ignore=.turbo");
|
|
131
|
+
tsxArgs.push(entry);
|
|
132
|
+
const tsxBin = findBin(cwd, "tsx");
|
|
133
|
+
let child;
|
|
134
|
+
if (tsxBin) {
|
|
135
|
+
child = spawn(tsxBin, tsxArgs, { cwd, env, stdio: "inherit" });
|
|
136
|
+
} else {
|
|
137
|
+
child = spawn("npx", ["tsx", ...tsxArgs], { cwd, env, stdio: "inherit" });
|
|
138
|
+
}
|
|
139
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
140
|
+
for (const signal of signals) {
|
|
141
|
+
process.on(signal, () => {
|
|
142
|
+
child.kill(signal);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
child.on("error", (err) => {
|
|
146
|
+
if (err.code === "ENOENT") {
|
|
147
|
+
console.error("[voltx] tsx not found. Install it with: npm install -D tsx");
|
|
148
|
+
} else {
|
|
149
|
+
console.error("[voltx] Dev server error:", err.message);
|
|
150
|
+
}
|
|
151
|
+
process.exit(1);
|
|
152
|
+
});
|
|
153
|
+
child.on("exit", (code) => {
|
|
154
|
+
process.exit(code ?? 0);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function findEntryPoint(cwd) {
|
|
158
|
+
const candidates = [
|
|
159
|
+
"src/index.ts",
|
|
160
|
+
"src/index.js",
|
|
161
|
+
"src/index.mts",
|
|
162
|
+
"src/main.ts",
|
|
163
|
+
"src/main.js",
|
|
164
|
+
"index.ts",
|
|
165
|
+
"index.js"
|
|
166
|
+
];
|
|
167
|
+
for (const candidate of candidates) {
|
|
168
|
+
if (existsSync(join(cwd, candidate))) {
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function findBin(cwd, name) {
|
|
175
|
+
const paths = [
|
|
176
|
+
join(cwd, "node_modules", ".bin", name),
|
|
177
|
+
join(cwd, "..", "node_modules", ".bin", name),
|
|
178
|
+
join(cwd, "..", "..", "node_modules", ".bin", name)
|
|
179
|
+
];
|
|
180
|
+
for (const p of paths) {
|
|
181
|
+
if (existsSync(p)) return p;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
function printDevBanner(entry, port, fullStack) {
|
|
186
|
+
console.log("");
|
|
187
|
+
console.log(" \u26A1 VoltX Dev Server");
|
|
188
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
189
|
+
console.log(` Entry: ${entry}`);
|
|
190
|
+
console.log(` Port: ${port}`);
|
|
191
|
+
console.log(` Mode: ${fullStack ? "full-stack (Vite + Hono)" : "API-only (tsx watch)"}`);
|
|
192
|
+
if (fullStack) {
|
|
193
|
+
console.log(` HMR: enabled (frontend + backend)`);
|
|
194
|
+
}
|
|
195
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
196
|
+
console.log("");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export {
|
|
200
|
+
runDev
|
|
201
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// src/dev.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { resolve, join } from "path";
|
|
4
|
+
import { existsSync } from "fs";
|
|
5
|
+
import { loadEnv } from "@voltx/core";
|
|
6
|
+
async function runDev(options = {}) {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const {
|
|
9
|
+
port,
|
|
10
|
+
entry = findEntryPoint(cwd),
|
|
11
|
+
clearScreen = true
|
|
12
|
+
} = options;
|
|
13
|
+
if (!entry) {
|
|
14
|
+
console.error("[voltx] Could not find entry point. Expected src/index.ts or src/index.js");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const entryPath = resolve(cwd, entry);
|
|
18
|
+
if (!existsSync(entryPath)) {
|
|
19
|
+
console.error(`[voltx] Entry file not found: ${entry}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
loadEnv("development", cwd);
|
|
23
|
+
const env = {
|
|
24
|
+
...process.env,
|
|
25
|
+
NODE_ENV: "development"
|
|
26
|
+
};
|
|
27
|
+
if (port) {
|
|
28
|
+
env.PORT = String(port);
|
|
29
|
+
}
|
|
30
|
+
printDevBanner(entry, port);
|
|
31
|
+
const tsxArgs = ["watch"];
|
|
32
|
+
if (clearScreen) {
|
|
33
|
+
tsxArgs.push("--clear-screen=false");
|
|
34
|
+
}
|
|
35
|
+
const watchDirs = [
|
|
36
|
+
"src/routes",
|
|
37
|
+
"src/agents",
|
|
38
|
+
"src/tools",
|
|
39
|
+
"src/jobs",
|
|
40
|
+
"src/lib",
|
|
41
|
+
"voltx.config.ts",
|
|
42
|
+
...options.watch ?? []
|
|
43
|
+
];
|
|
44
|
+
tsxArgs.push("--ignore=node_modules", "--ignore=dist", "--ignore=.turbo");
|
|
45
|
+
tsxArgs.push(entry);
|
|
46
|
+
const tsxBin = findTsxBin(cwd);
|
|
47
|
+
let child;
|
|
48
|
+
if (tsxBin) {
|
|
49
|
+
child = spawn(tsxBin, tsxArgs, {
|
|
50
|
+
cwd,
|
|
51
|
+
env,
|
|
52
|
+
stdio: "inherit"
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
child = spawn("npx", ["tsx", ...tsxArgs], {
|
|
56
|
+
cwd,
|
|
57
|
+
env,
|
|
58
|
+
stdio: "inherit"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
62
|
+
for (const signal of signals) {
|
|
63
|
+
process.on(signal, () => {
|
|
64
|
+
child.kill(signal);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
child.on("error", (err) => {
|
|
68
|
+
if (err.code === "ENOENT") {
|
|
69
|
+
console.error("[voltx] tsx not found. Install it with: npm install -D tsx");
|
|
70
|
+
console.error("[voltx] Or run your app directly: npx tsx watch src/index.ts");
|
|
71
|
+
} else {
|
|
72
|
+
console.error("[voltx] Dev server error:", err.message);
|
|
73
|
+
}
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
|
76
|
+
child.on("exit", (code) => {
|
|
77
|
+
process.exit(code ?? 0);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function findEntryPoint(cwd) {
|
|
81
|
+
const candidates = [
|
|
82
|
+
"src/index.ts",
|
|
83
|
+
"src/index.js",
|
|
84
|
+
"src/index.mts",
|
|
85
|
+
"src/main.ts",
|
|
86
|
+
"src/main.js",
|
|
87
|
+
"index.ts",
|
|
88
|
+
"index.js"
|
|
89
|
+
];
|
|
90
|
+
for (const candidate of candidates) {
|
|
91
|
+
if (existsSync(join(cwd, candidate))) {
|
|
92
|
+
return candidate;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function findTsxBin(cwd) {
|
|
98
|
+
const localBin = join(cwd, "node_modules", ".bin", "tsx");
|
|
99
|
+
if (existsSync(localBin)) return localBin;
|
|
100
|
+
const parentBin = join(cwd, "..", "node_modules", ".bin", "tsx");
|
|
101
|
+
if (existsSync(parentBin)) return parentBin;
|
|
102
|
+
const rootBin = join(cwd, "..", "..", "node_modules", ".bin", "tsx");
|
|
103
|
+
if (existsSync(rootBin)) return rootBin;
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function printDevBanner(entry, port) {
|
|
107
|
+
console.log("");
|
|
108
|
+
console.log(" \u26A1 VoltX Dev Server");
|
|
109
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
110
|
+
console.log(` Entry: ${entry}`);
|
|
111
|
+
if (port) {
|
|
112
|
+
console.log(` Port: ${port}`);
|
|
113
|
+
}
|
|
114
|
+
console.log(` Mode: development (hot reload)`);
|
|
115
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
116
|
+
console.log("");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
runDev
|
|
121
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// src/build.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { resolve, join } from "path";
|
|
4
|
+
import { existsSync, mkdirSync } from "fs";
|
|
5
|
+
import { loadEnv } from "@voltx/core";
|
|
6
|
+
async function runBuild(options = {}) {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const {
|
|
9
|
+
entry = findEntryPoint(cwd),
|
|
10
|
+
outDir = "dist",
|
|
11
|
+
minify = true,
|
|
12
|
+
sourcemap = false
|
|
13
|
+
} = options;
|
|
14
|
+
if (!entry) {
|
|
15
|
+
console.error("[voltx] Could not find entry point. Expected src/index.ts");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
const entryPath = resolve(cwd, entry);
|
|
19
|
+
if (!existsSync(entryPath)) {
|
|
20
|
+
console.error(`[voltx] Entry file not found: ${entry}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
console.log("");
|
|
24
|
+
console.log(" \u26A1 VoltX Build");
|
|
25
|
+
loadEnv("production", cwd);
|
|
26
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
27
|
+
console.log(` Entry: ${entry}`);
|
|
28
|
+
console.log(` Output: ${outDir}/`);
|
|
29
|
+
console.log(` Minify: ${minify}`);
|
|
30
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
31
|
+
console.log("");
|
|
32
|
+
mkdirSync(resolve(cwd, outDir), { recursive: true });
|
|
33
|
+
console.log(" [1/2] Building server...");
|
|
34
|
+
const tsupArgs = [
|
|
35
|
+
entry,
|
|
36
|
+
"--format",
|
|
37
|
+
"esm",
|
|
38
|
+
"--out-dir",
|
|
39
|
+
outDir,
|
|
40
|
+
"--clean",
|
|
41
|
+
"--target",
|
|
42
|
+
"node20"
|
|
43
|
+
];
|
|
44
|
+
if (minify) tsupArgs.push("--minify");
|
|
45
|
+
if (sourcemap) tsupArgs.push("--sourcemap");
|
|
46
|
+
tsupArgs.push("--no-splitting");
|
|
47
|
+
const tsupBin = findBin(cwd, "tsup");
|
|
48
|
+
await runCommand(
|
|
49
|
+
tsupBin ?? "npx",
|
|
50
|
+
tsupBin ? tsupArgs : ["tsup", ...tsupArgs],
|
|
51
|
+
cwd
|
|
52
|
+
);
|
|
53
|
+
console.log(" \u2713 Server built successfully");
|
|
54
|
+
const frontendDir = resolve(cwd, "src", "frontend");
|
|
55
|
+
const viteConfig = resolve(cwd, "vite.config.ts");
|
|
56
|
+
const hasFrontend = existsSync(frontendDir) || existsSync(viteConfig);
|
|
57
|
+
if (hasFrontend) {
|
|
58
|
+
console.log(" [2/2] Building frontend...");
|
|
59
|
+
const viteBin = findBin(cwd, "vite");
|
|
60
|
+
const viteArgs = ["build", "--outDir", join(outDir, "public")];
|
|
61
|
+
await runCommand(
|
|
62
|
+
viteBin ?? "npx",
|
|
63
|
+
viteBin ? viteArgs : ["vite", ...viteArgs],
|
|
64
|
+
cwd
|
|
65
|
+
);
|
|
66
|
+
console.log(" \u2713 Frontend built successfully");
|
|
67
|
+
} else {
|
|
68
|
+
console.log(" [2/2] No frontend found, skipping...");
|
|
69
|
+
}
|
|
70
|
+
console.log("");
|
|
71
|
+
console.log(" \u26A1 Build complete!");
|
|
72
|
+
console.log(` Run \`voltx start\` to start the production server.`);
|
|
73
|
+
console.log("");
|
|
74
|
+
}
|
|
75
|
+
function findEntryPoint(cwd) {
|
|
76
|
+
const candidates = [
|
|
77
|
+
"src/index.ts",
|
|
78
|
+
"src/index.js",
|
|
79
|
+
"src/index.mts",
|
|
80
|
+
"src/main.ts",
|
|
81
|
+
"src/main.js"
|
|
82
|
+
];
|
|
83
|
+
for (const candidate of candidates) {
|
|
84
|
+
if (existsSync(join(cwd, candidate))) {
|
|
85
|
+
return candidate;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function findBin(cwd, name) {
|
|
91
|
+
const paths = [
|
|
92
|
+
join(cwd, "node_modules", ".bin", name),
|
|
93
|
+
join(cwd, "..", "node_modules", ".bin", name),
|
|
94
|
+
join(cwd, "..", "..", "node_modules", ".bin", name)
|
|
95
|
+
];
|
|
96
|
+
for (const p of paths) {
|
|
97
|
+
if (existsSync(p)) return p;
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function runCommand(cmd, args, cwd) {
|
|
102
|
+
return new Promise((resolve2, reject) => {
|
|
103
|
+
const child = spawn(cmd, args, {
|
|
104
|
+
cwd,
|
|
105
|
+
stdio: "inherit",
|
|
106
|
+
env: { ...process.env, NODE_ENV: "production" }
|
|
107
|
+
});
|
|
108
|
+
child.on("error", (err) => {
|
|
109
|
+
if (err.code === "ENOENT") {
|
|
110
|
+
console.error(`[voltx] ${cmd} not found. Install it with: npm install -D ${cmd}`);
|
|
111
|
+
}
|
|
112
|
+
reject(err);
|
|
113
|
+
});
|
|
114
|
+
child.on("exit", (code) => {
|
|
115
|
+
if (code === 0) resolve2();
|
|
116
|
+
else reject(new Error(`${cmd} exited with code ${code}`));
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export {
|
|
122
|
+
runBuild
|
|
123
|
+
};
|