@voltx/cli 0.3.3 → 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 +68 -14
- 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-4T26KROZ.mjs +456 -0
- package/dist/chunk-5DVBIJXU.mjs +84 -0
- package/dist/chunk-5RN2FYST.mjs +494 -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-CFWXMM7Q.mjs +450 -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-EXMRIKIX.mjs +404 -0
- package/dist/chunk-FI2W4L4S.mjs +205 -0
- package/dist/chunk-FN7KZJ6H.mjs +363 -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-P5FSO2UH.mjs +497 -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-UO43CY7Y.mjs +497 -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 +1023 -306
- package/dist/cli.mjs +7 -6
- package/dist/create.d.mts +1 -0
- package/dist/create.d.ts +1 -0
- package/dist/create.js +813 -189
- 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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1010 -294
- package/dist/index.mjs +6 -7
- 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,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
|
+
};
|