@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.
Files changed (50) hide show
  1. package/README.md +54 -22
  2. package/dist/build.d.mts +4 -3
  3. package/dist/build.d.ts +4 -3
  4. package/dist/build.js +56 -27
  5. package/dist/build.mjs +1 -2
  6. package/dist/chunk-2LHDOMF2.mjs +680 -0
  7. package/dist/chunk-5DVBIJXU.mjs +84 -0
  8. package/dist/chunk-65PVXS4D.mjs +894 -0
  9. package/dist/chunk-7JVIEGSA.mjs +141 -0
  10. package/dist/chunk-A4NA4AJN.mjs +786 -0
  11. package/dist/chunk-AAAHANST.mjs +839 -0
  12. package/dist/chunk-AD3WMFZF.mjs +205 -0
  13. package/dist/chunk-CSSHLVYS.mjs +83 -0
  14. package/dist/chunk-CWOSNV5O.mjs +150 -0
  15. package/dist/chunk-EI6XBYKB.mjs +84 -0
  16. package/dist/chunk-FI2W4L4S.mjs +205 -0
  17. package/dist/chunk-G2INQCCJ.mjs +907 -0
  18. package/dist/chunk-H2DTIOEO.mjs +150 -0
  19. package/dist/chunk-IS2WTE3C.mjs +138 -0
  20. package/dist/chunk-JECCDBYI.mjs +730 -0
  21. package/dist/chunk-KX2MRJUO.mjs +795 -0
  22. package/dist/chunk-LTGMHAZS.mjs +147 -0
  23. package/dist/chunk-OPO6RUFP.mjs +698 -0
  24. package/dist/chunk-PWQSKYAM.mjs +682 -0
  25. package/dist/chunk-Q5XCFN7L.mjs +1026 -0
  26. package/dist/chunk-QSU6FZC7.mjs +497 -0
  27. package/dist/chunk-RYWRFHEC.mjs +83 -0
  28. package/dist/chunk-SU4Q3PTH.mjs +201 -0
  29. package/dist/chunk-TFVNHM7S.mjs +1028 -0
  30. package/dist/chunk-UXI3QSDN.mjs +121 -0
  31. package/dist/chunk-VD3CNPNP.mjs +123 -0
  32. package/dist/chunk-X6VOAPRJ.mjs +756 -0
  33. package/dist/cli.js +935 -308
  34. package/dist/cli.mjs +7 -6
  35. package/dist/create.d.mts +1 -0
  36. package/dist/create.d.ts +1 -0
  37. package/dist/create.js +726 -192
  38. package/dist/create.mjs +1 -2
  39. package/dist/dev.d.mts +6 -4
  40. package/dist/dev.d.ts +6 -4
  41. package/dist/dev.js +119 -46
  42. package/dist/dev.mjs +1 -2
  43. package/dist/generate.js +13 -13
  44. package/dist/generate.mjs +1 -2
  45. package/dist/index.js +922 -296
  46. package/dist/index.mjs +5 -6
  47. package/dist/start.js +7 -17
  48. package/dist/start.mjs +1 -2
  49. package/dist/welcome.mjs +0 -1
  50. package/package.json +11 -3
@@ -0,0 +1,150 @@
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 server.ts or 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 hasViteConfig = existsSync(resolve(cwd, "vite.config.ts"));
25
+ const hasServerEntry = existsSync(resolve(cwd, "server.ts"));
26
+ const isFullStack = hasViteConfig || hasServerEntry;
27
+ console.log("");
28
+ console.log(" \u26A1 VoltX Build");
29
+ 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");
30
+ console.log(` Entry: ${entry}`);
31
+ console.log(` Output: ${outDir}/`);
32
+ console.log(` Mode: ${isFullStack ? "full-stack" : "API-only"}`);
33
+ console.log(` Minify: ${minify}`);
34
+ 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");
35
+ console.log("");
36
+ mkdirSync(resolve(cwd, outDir), { recursive: true });
37
+ if (isFullStack) {
38
+ await buildFullStack(cwd, entry, outDir, minify, sourcemap);
39
+ } else {
40
+ await buildApiOnly(cwd, entry, outDir, minify, sourcemap);
41
+ }
42
+ console.log("");
43
+ console.log(" \u26A1 Build complete!");
44
+ console.log(` Run \`voltx start\` to start the production server.`);
45
+ console.log("");
46
+ }
47
+ async function buildFullStack(cwd, entry, outDir, minify, sourcemap) {
48
+ const ssrEntry = existsSync(join(cwd, "src", "entry-server.tsx")) ? "src/entry-server.tsx" : null;
49
+ const totalSteps = ssrEntry ? 3 : 2;
50
+ console.log(` [1/${totalSteps}] Building client...`);
51
+ const viteBin = findBin(cwd, "vite");
52
+ const clientOutDir = join(outDir, "client");
53
+ await runCommand(
54
+ viteBin ?? "npx",
55
+ viteBin ? ["build", "--outDir", clientOutDir] : ["vite", "build", "--outDir", clientOutDir],
56
+ cwd
57
+ );
58
+ console.log(" \u2713 Client built");
59
+ if (ssrEntry) {
60
+ console.log(` [2/${totalSteps}] Building SSR bundle...`);
61
+ const serverOutDir = join(outDir, "server");
62
+ await runCommand(
63
+ viteBin ?? "npx",
64
+ viteBin ? ["build", "--ssr", ssrEntry, "--outDir", serverOutDir] : ["vite", "build", "--ssr", ssrEntry, "--outDir", serverOutDir],
65
+ cwd
66
+ );
67
+ console.log(" \u2713 SSR bundle built");
68
+ }
69
+ const serverStep = ssrEntry ? 3 : 2;
70
+ console.log(` [${serverStep}/${totalSteps}] Building server...`);
71
+ await buildServer(cwd, entry, outDir, minify, sourcemap, false);
72
+ console.log(" \u2713 Server built");
73
+ }
74
+ async function buildApiOnly(cwd, entry, outDir, minify, sourcemap) {
75
+ console.log(" [1/1] Building server...");
76
+ await buildServer(cwd, entry, outDir, minify, sourcemap);
77
+ console.log(" \u2713 Server built");
78
+ }
79
+ async function buildServer(cwd, entry, outDir, minify, sourcemap, clean = true) {
80
+ const tsupBin = findBin(cwd, "tsup");
81
+ const tsupArgs = [
82
+ entry,
83
+ "--format",
84
+ "esm",
85
+ "--out-dir",
86
+ outDir,
87
+ "--target",
88
+ "node20",
89
+ "--no-splitting"
90
+ ];
91
+ if (clean) tsupArgs.push("--clean");
92
+ if (minify) tsupArgs.push("--minify");
93
+ if (sourcemap) tsupArgs.push("--sourcemap");
94
+ await runCommand(
95
+ tsupBin ?? "npx",
96
+ tsupBin ? tsupArgs : ["tsup", ...tsupArgs],
97
+ cwd
98
+ );
99
+ }
100
+ function findEntryPoint(cwd) {
101
+ const candidates = [
102
+ "server.ts",
103
+ "server.js",
104
+ "src/index.ts",
105
+ "src/index.js",
106
+ "src/index.mts",
107
+ "src/main.ts",
108
+ "src/main.js"
109
+ ];
110
+ for (const candidate of candidates) {
111
+ if (existsSync(join(cwd, candidate))) {
112
+ return candidate;
113
+ }
114
+ }
115
+ return null;
116
+ }
117
+ function findBin(cwd, name) {
118
+ const paths = [
119
+ join(cwd, "node_modules", ".bin", name),
120
+ join(cwd, "..", "node_modules", ".bin", name),
121
+ join(cwd, "..", "..", "node_modules", ".bin", name)
122
+ ];
123
+ for (const p of paths) {
124
+ if (existsSync(p)) return p;
125
+ }
126
+ return null;
127
+ }
128
+ function runCommand(cmd, args, cwd) {
129
+ return new Promise((resolve2, reject) => {
130
+ const child = spawn(cmd, args, {
131
+ cwd,
132
+ stdio: "inherit",
133
+ env: { ...process.env, NODE_ENV: "production" }
134
+ });
135
+ child.on("error", (err) => {
136
+ if (err.code === "ENOENT") {
137
+ console.error(`[voltx] ${cmd} not found. Install it with: npm install -D ${cmd}`);
138
+ }
139
+ reject(err);
140
+ });
141
+ child.on("exit", (code) => {
142
+ if (code === 0) resolve2();
143
+ else reject(new Error(`${cmd} exited with code ${code}`));
144
+ });
145
+ });
146
+ }
147
+
148
+ export {
149
+ runBuild
150
+ };
@@ -0,0 +1,138 @@
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 server.ts or 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 hasViteConfig = existsSync(resolve(cwd, "vite.config.ts"));
25
+ const hasServerEntry = existsSync(resolve(cwd, "server.ts"));
26
+ const isFullStack = hasViteConfig || hasServerEntry;
27
+ console.log("");
28
+ console.log(" \u26A1 VoltX Build");
29
+ 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");
30
+ console.log(` Entry: ${entry}`);
31
+ console.log(` Output: ${outDir}/`);
32
+ console.log(` Mode: ${isFullStack ? "full-stack" : "API-only"}`);
33
+ console.log(` Minify: ${minify}`);
34
+ 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");
35
+ console.log("");
36
+ mkdirSync(resolve(cwd, outDir), { recursive: true });
37
+ if (isFullStack) {
38
+ await buildFullStack(cwd, entry, outDir, minify, sourcemap);
39
+ } else {
40
+ await buildApiOnly(cwd, entry, outDir, minify, sourcemap);
41
+ }
42
+ console.log("");
43
+ console.log(" \u26A1 Build complete!");
44
+ console.log(` Run \`voltx start\` to start the production server.`);
45
+ console.log("");
46
+ }
47
+ async function buildFullStack(cwd, entry, outDir, minify, sourcemap) {
48
+ const totalSteps = 2;
49
+ console.log(` [1/${totalSteps}] Building client...`);
50
+ const viteBin = findBin(cwd, "vite");
51
+ const clientOutDir = join(outDir, "client");
52
+ await runCommand(
53
+ viteBin ?? "npx",
54
+ viteBin ? ["build", "--outDir", clientOutDir] : ["vite", "build", "--outDir", clientOutDir],
55
+ cwd
56
+ );
57
+ console.log(" \u2713 Client built");
58
+ console.log(` [2/${totalSteps}] Building server...`);
59
+ await buildServer(cwd, entry, outDir, minify, sourcemap);
60
+ console.log(" \u2713 Server built");
61
+ }
62
+ async function buildApiOnly(cwd, entry, outDir, minify, sourcemap) {
63
+ console.log(" [1/1] Building server...");
64
+ await buildServer(cwd, entry, outDir, minify, sourcemap);
65
+ console.log(" \u2713 Server built");
66
+ }
67
+ async function buildServer(cwd, entry, outDir, minify, sourcemap) {
68
+ const tsupBin = findBin(cwd, "tsup");
69
+ const tsupArgs = [
70
+ entry,
71
+ "--format",
72
+ "esm",
73
+ "--out-dir",
74
+ outDir,
75
+ "--clean",
76
+ "--target",
77
+ "node20",
78
+ "--no-splitting"
79
+ ];
80
+ if (minify) tsupArgs.push("--minify");
81
+ if (sourcemap) tsupArgs.push("--sourcemap");
82
+ await runCommand(
83
+ tsupBin ?? "npx",
84
+ tsupBin ? tsupArgs : ["tsup", ...tsupArgs],
85
+ cwd
86
+ );
87
+ }
88
+ function findEntryPoint(cwd) {
89
+ const candidates = [
90
+ "server.ts",
91
+ "server.js",
92
+ "src/index.ts",
93
+ "src/index.js",
94
+ "src/index.mts",
95
+ "src/main.ts",
96
+ "src/main.js"
97
+ ];
98
+ for (const candidate of candidates) {
99
+ if (existsSync(join(cwd, candidate))) {
100
+ return candidate;
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ function findBin(cwd, name) {
106
+ const paths = [
107
+ join(cwd, "node_modules", ".bin", name),
108
+ join(cwd, "..", "node_modules", ".bin", name),
109
+ join(cwd, "..", "..", "node_modules", ".bin", name)
110
+ ];
111
+ for (const p of paths) {
112
+ if (existsSync(p)) return p;
113
+ }
114
+ return null;
115
+ }
116
+ function runCommand(cmd, args, cwd) {
117
+ return new Promise((resolve2, reject) => {
118
+ const child = spawn(cmd, args, {
119
+ cwd,
120
+ stdio: "inherit",
121
+ env: { ...process.env, NODE_ENV: "production" }
122
+ });
123
+ child.on("error", (err) => {
124
+ if (err.code === "ENOENT") {
125
+ console.error(`[voltx] ${cmd} not found. Install it with: npm install -D ${cmd}`);
126
+ }
127
+ reject(err);
128
+ });
129
+ child.on("exit", (code) => {
130
+ if (code === 0) resolve2();
131
+ else reject(new Error(`${cmd} exited with code ${code}`));
132
+ });
133
+ });
134
+ }
135
+
136
+ export {
137
+ runBuild
138
+ };