@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,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
+ };