@voltx/cli 0.3.4 → 0.3.6
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-TFVNHM7S.mjs +1028 -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 +935 -308
- package/dist/cli.mjs +7 -6
- package/dist/create.d.mts +1 -0
- package/dist/create.d.ts +1 -0
- package/dist/create.js +726 -192
- 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 +922 -296
- 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,147 @@
|
|
|
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
|
+
loadEnv("production", cwd);
|
|
24
|
+
const hasFrontend = existsSync(resolve(cwd, "src", "frontend"));
|
|
25
|
+
console.log("");
|
|
26
|
+
console.log(" \u26A1 VoltX Build");
|
|
27
|
+
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");
|
|
28
|
+
console.log(` Entry: ${entry}`);
|
|
29
|
+
console.log(` Output: ${outDir}/`);
|
|
30
|
+
console.log(` Mode: ${hasFrontend ? "full-stack" : "API-only"}`);
|
|
31
|
+
console.log(` Minify: ${minify}`);
|
|
32
|
+
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");
|
|
33
|
+
console.log("");
|
|
34
|
+
mkdirSync(resolve(cwd, outDir), { recursive: true });
|
|
35
|
+
if (hasFrontend) {
|
|
36
|
+
await buildFullStack(cwd, entry, outDir, minify, sourcemap);
|
|
37
|
+
} else {
|
|
38
|
+
await buildApiOnly(cwd, entry, outDir, minify, sourcemap);
|
|
39
|
+
}
|
|
40
|
+
console.log("");
|
|
41
|
+
console.log(" \u26A1 Build complete!");
|
|
42
|
+
console.log(` Run \`voltx start\` to start the production server.`);
|
|
43
|
+
console.log("");
|
|
44
|
+
}
|
|
45
|
+
async function buildFullStack(cwd, entry, outDir, minify, sourcemap) {
|
|
46
|
+
const totalSteps = 3;
|
|
47
|
+
console.log(` [1/${totalSteps}] Building client...`);
|
|
48
|
+
const viteBin = findBin(cwd, "vite");
|
|
49
|
+
const clientOutDir = join(outDir, "client");
|
|
50
|
+
await runCommand(
|
|
51
|
+
viteBin ?? "npx",
|
|
52
|
+
viteBin ? ["build", "--outDir", clientOutDir, "--ssrManifest"] : ["vite", "build", "--outDir", clientOutDir, "--ssrManifest"],
|
|
53
|
+
cwd
|
|
54
|
+
);
|
|
55
|
+
console.log(" \u2713 Client built");
|
|
56
|
+
console.log(` [2/${totalSteps}] Building SSR bundle...`);
|
|
57
|
+
const ssrEntry = resolve(cwd, "src", "frontend", "entry-server.tsx");
|
|
58
|
+
const serverOutDir = join(outDir, "server");
|
|
59
|
+
if (existsSync(ssrEntry)) {
|
|
60
|
+
await runCommand(
|
|
61
|
+
viteBin ?? "npx",
|
|
62
|
+
viteBin ? ["build", "--outDir", serverOutDir, "--ssr", ssrEntry] : ["vite", "build", "--outDir", serverOutDir, "--ssr", ssrEntry],
|
|
63
|
+
cwd
|
|
64
|
+
);
|
|
65
|
+
console.log(" \u2713 SSR bundle built");
|
|
66
|
+
} else {
|
|
67
|
+
console.log(" \u26A0 No entry-server.tsx found, skipping SSR bundle");
|
|
68
|
+
}
|
|
69
|
+
console.log(` [3/${totalSteps}] Building server...`);
|
|
70
|
+
await buildServer(cwd, entry, outDir, minify, sourcemap);
|
|
71
|
+
console.log(" \u2713 Server built");
|
|
72
|
+
}
|
|
73
|
+
async function buildApiOnly(cwd, entry, outDir, minify, sourcemap) {
|
|
74
|
+
console.log(" [1/1] Building server...");
|
|
75
|
+
await buildServer(cwd, entry, outDir, minify, sourcemap);
|
|
76
|
+
console.log(" \u2713 Server built");
|
|
77
|
+
}
|
|
78
|
+
async function buildServer(cwd, entry, outDir, minify, sourcemap) {
|
|
79
|
+
const tsupBin = findBin(cwd, "tsup");
|
|
80
|
+
const tsupArgs = [
|
|
81
|
+
entry,
|
|
82
|
+
"--format",
|
|
83
|
+
"esm",
|
|
84
|
+
"--out-dir",
|
|
85
|
+
outDir,
|
|
86
|
+
"--clean",
|
|
87
|
+
"--target",
|
|
88
|
+
"node20",
|
|
89
|
+
"--no-splitting"
|
|
90
|
+
];
|
|
91
|
+
if (minify) tsupArgs.push("--minify");
|
|
92
|
+
if (sourcemap) tsupArgs.push("--sourcemap");
|
|
93
|
+
await runCommand(
|
|
94
|
+
tsupBin ?? "npx",
|
|
95
|
+
tsupBin ? tsupArgs : ["tsup", ...tsupArgs],
|
|
96
|
+
cwd
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function findEntryPoint(cwd) {
|
|
100
|
+
const candidates = [
|
|
101
|
+
"src/index.ts",
|
|
102
|
+
"src/index.js",
|
|
103
|
+
"src/index.mts",
|
|
104
|
+
"src/main.ts",
|
|
105
|
+
"src/main.js"
|
|
106
|
+
];
|
|
107
|
+
for (const candidate of candidates) {
|
|
108
|
+
if (existsSync(join(cwd, candidate))) {
|
|
109
|
+
return candidate;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
function findBin(cwd, name) {
|
|
115
|
+
const paths = [
|
|
116
|
+
join(cwd, "node_modules", ".bin", name),
|
|
117
|
+
join(cwd, "..", "node_modules", ".bin", name),
|
|
118
|
+
join(cwd, "..", "..", "node_modules", ".bin", name)
|
|
119
|
+
];
|
|
120
|
+
for (const p of paths) {
|
|
121
|
+
if (existsSync(p)) return p;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function runCommand(cmd, args, cwd) {
|
|
126
|
+
return new Promise((resolve2, reject) => {
|
|
127
|
+
const child = spawn(cmd, args, {
|
|
128
|
+
cwd,
|
|
129
|
+
stdio: "inherit",
|
|
130
|
+
env: { ...process.env, NODE_ENV: "production" }
|
|
131
|
+
});
|
|
132
|
+
child.on("error", (err) => {
|
|
133
|
+
if (err.code === "ENOENT") {
|
|
134
|
+
console.error(`[voltx] ${cmd} not found. Install it with: npm install -D ${cmd}`);
|
|
135
|
+
}
|
|
136
|
+
reject(err);
|
|
137
|
+
});
|
|
138
|
+
child.on("exit", (code) => {
|
|
139
|
+
if (code === 0) resolve2();
|
|
140
|
+
else reject(new Error(`${cmd} exited with code ${code}`));
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
runBuild
|
|
147
|
+
};
|