@voltx/cli 0.3.0 → 0.3.2

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.
@@ -0,0 +1,94 @@
1
+ // src/start.ts
2
+ import { spawn } from "child_process";
3
+ import { resolve, join } from "path";
4
+ import { existsSync, readFileSync } from "fs";
5
+ async function runStart(options = {}) {
6
+ const cwd = process.cwd();
7
+ const { port, outDir = "dist" } = options;
8
+ const distDir = resolve(cwd, outDir);
9
+ if (!existsSync(distDir)) {
10
+ console.error(`[voltx] Build output not found at ${outDir}/`);
11
+ console.error("[voltx] Run `voltx build` first to create a production build.");
12
+ process.exit(1);
13
+ }
14
+ const entry = options.entry ?? findDistEntry(distDir);
15
+ if (!entry) {
16
+ console.error(`[voltx] No entry file found in ${outDir}/`);
17
+ console.error("[voltx] Expected index.js, index.mjs, or main.js");
18
+ process.exit(1);
19
+ }
20
+ const entryPath = resolve(distDir, entry);
21
+ if (!existsSync(entryPath)) {
22
+ console.error(`[voltx] Entry file not found: ${outDir}/${entry}`);
23
+ process.exit(1);
24
+ }
25
+ const env = {
26
+ ...process.env,
27
+ NODE_ENV: "production"
28
+ };
29
+ const envFile = resolve(cwd, ".env");
30
+ if (existsSync(envFile)) {
31
+ const envContent = readFileSync(envFile, "utf-8");
32
+ for (const line of envContent.split("\n")) {
33
+ const trimmed = line.trim();
34
+ if (!trimmed || trimmed.startsWith("#")) continue;
35
+ const eqIdx = trimmed.indexOf("=");
36
+ if (eqIdx === -1) continue;
37
+ const key = trimmed.slice(0, eqIdx).trim();
38
+ const value = trimmed.slice(eqIdx + 1).trim();
39
+ env[key] = value;
40
+ }
41
+ }
42
+ if (port) {
43
+ env.PORT = String(port);
44
+ }
45
+ console.log("");
46
+ console.log(" \u26A1 VoltX Production Server");
47
+ 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");
48
+ console.log(` Entry: ${outDir}/${entry}`);
49
+ if (port) {
50
+ console.log(` Port: ${port}`);
51
+ }
52
+ console.log(` Mode: production`);
53
+ 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");
54
+ console.log("");
55
+ const child = spawn("node", [entryPath], {
56
+ cwd,
57
+ env,
58
+ stdio: "inherit"
59
+ });
60
+ const signals = ["SIGINT", "SIGTERM"];
61
+ for (const signal of signals) {
62
+ process.on(signal, () => {
63
+ child.kill(signal);
64
+ });
65
+ }
66
+ child.on("error", (err) => {
67
+ console.error("[voltx] Failed to start production server:", err.message);
68
+ process.exit(1);
69
+ });
70
+ child.on("exit", (code) => {
71
+ process.exit(code ?? 0);
72
+ });
73
+ }
74
+ function findDistEntry(distDir) {
75
+ const candidates = [
76
+ "index.mjs",
77
+ "index.js",
78
+ "index.cjs",
79
+ "main.mjs",
80
+ "main.js",
81
+ "src/index.mjs",
82
+ "src/index.js"
83
+ ];
84
+ for (const candidate of candidates) {
85
+ if (existsSync(join(distDir, candidate))) {
86
+ return candidate;
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+
92
+ export {
93
+ runStart
94
+ };
@@ -0,0 +1,132 @@
1
+ // src/dev.ts
2
+ import { spawn } from "child_process";
3
+ import { resolve, join } from "path";
4
+ import { existsSync, readFileSync } from "fs";
5
+ async function runDev(options = {}) {
6
+ const cwd = process.cwd();
7
+ const {
8
+ port,
9
+ entry = findEntryPoint(cwd),
10
+ clearScreen = true
11
+ } = options;
12
+ if (!entry) {
13
+ console.error("[voltx] Could not find entry point. Expected src/index.ts or src/index.js");
14
+ process.exit(1);
15
+ }
16
+ const entryPath = resolve(cwd, entry);
17
+ if (!existsSync(entryPath)) {
18
+ console.error(`[voltx] Entry file not found: ${entry}`);
19
+ process.exit(1);
20
+ }
21
+ const envFile = resolve(cwd, ".env");
22
+ const env = {
23
+ ...process.env,
24
+ NODE_ENV: "development"
25
+ };
26
+ if (existsSync(envFile)) {
27
+ const envContent = readFileSync(envFile, "utf-8");
28
+ for (const line of envContent.split("\n")) {
29
+ const trimmed = line.trim();
30
+ if (!trimmed || trimmed.startsWith("#")) continue;
31
+ const eqIdx = trimmed.indexOf("=");
32
+ if (eqIdx === -1) continue;
33
+ const key = trimmed.slice(0, eqIdx).trim();
34
+ const value = trimmed.slice(eqIdx + 1).trim();
35
+ env[key] = value;
36
+ }
37
+ }
38
+ if (port) {
39
+ env.PORT = String(port);
40
+ }
41
+ printDevBanner(entry, port);
42
+ const tsxArgs = ["watch"];
43
+ if (clearScreen) {
44
+ tsxArgs.push("--clear-screen=false");
45
+ }
46
+ const watchDirs = [
47
+ "src/routes",
48
+ "src/agents",
49
+ "src/tools",
50
+ "src/jobs",
51
+ "src/lib",
52
+ "voltx.config.ts",
53
+ ...options.watch ?? []
54
+ ];
55
+ tsxArgs.push("--ignore=node_modules", "--ignore=dist", "--ignore=.turbo");
56
+ tsxArgs.push(entry);
57
+ const tsxBin = findTsxBin(cwd);
58
+ let child;
59
+ if (tsxBin) {
60
+ child = spawn(tsxBin, tsxArgs, {
61
+ cwd,
62
+ env,
63
+ stdio: "inherit"
64
+ });
65
+ } else {
66
+ child = spawn("npx", ["tsx", ...tsxArgs], {
67
+ cwd,
68
+ env,
69
+ stdio: "inherit"
70
+ });
71
+ }
72
+ const signals = ["SIGINT", "SIGTERM"];
73
+ for (const signal of signals) {
74
+ process.on(signal, () => {
75
+ child.kill(signal);
76
+ });
77
+ }
78
+ child.on("error", (err) => {
79
+ if (err.code === "ENOENT") {
80
+ console.error("[voltx] tsx not found. Install it with: npm install -D tsx");
81
+ console.error("[voltx] Or run your app directly: npx tsx watch src/index.ts");
82
+ } else {
83
+ console.error("[voltx] Dev server error:", err.message);
84
+ }
85
+ process.exit(1);
86
+ });
87
+ child.on("exit", (code) => {
88
+ process.exit(code ?? 0);
89
+ });
90
+ }
91
+ function findEntryPoint(cwd) {
92
+ const candidates = [
93
+ "src/index.ts",
94
+ "src/index.js",
95
+ "src/index.mts",
96
+ "src/main.ts",
97
+ "src/main.js",
98
+ "index.ts",
99
+ "index.js"
100
+ ];
101
+ for (const candidate of candidates) {
102
+ if (existsSync(join(cwd, candidate))) {
103
+ return candidate;
104
+ }
105
+ }
106
+ return null;
107
+ }
108
+ function findTsxBin(cwd) {
109
+ const localBin = join(cwd, "node_modules", ".bin", "tsx");
110
+ if (existsSync(localBin)) return localBin;
111
+ const parentBin = join(cwd, "..", "node_modules", ".bin", "tsx");
112
+ if (existsSync(parentBin)) return parentBin;
113
+ const rootBin = join(cwd, "..", "..", "node_modules", ".bin", "tsx");
114
+ if (existsSync(rootBin)) return rootBin;
115
+ return null;
116
+ }
117
+ function printDevBanner(entry, port) {
118
+ console.log("");
119
+ console.log(" \u26A1 VoltX Dev Server");
120
+ 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");
121
+ console.log(` Entry: ${entry}`);
122
+ if (port) {
123
+ console.log(` Port: ${port}`);
124
+ }
125
+ console.log(` Mode: development (hot reload)`);
126
+ 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");
127
+ console.log("");
128
+ }
129
+
130
+ export {
131
+ runDev
132
+ };
package/dist/cli.js CHANGED
@@ -572,6 +572,18 @@ async function runDev(options = {}) {
572
572
  ...process.env,
573
573
  NODE_ENV: "development"
574
574
  };
575
+ if ((0, import_node_fs.existsSync)(envFile)) {
576
+ const envContent = (0, import_node_fs.readFileSync)(envFile, "utf-8");
577
+ for (const line of envContent.split("\n")) {
578
+ const trimmed = line.trim();
579
+ if (!trimmed || trimmed.startsWith("#")) continue;
580
+ const eqIdx = trimmed.indexOf("=");
581
+ if (eqIdx === -1) continue;
582
+ const key = trimmed.slice(0, eqIdx).trim();
583
+ const value = trimmed.slice(eqIdx + 1).trim();
584
+ env[key] = value;
585
+ }
586
+ }
575
587
  if (port) {
576
588
  env.PORT = String(port);
577
589
  }
@@ -830,6 +842,19 @@ async function runStart(options = {}) {
830
842
  ...process.env,
831
843
  NODE_ENV: "production"
832
844
  };
845
+ const envFile = (0, import_node_path3.resolve)(cwd, ".env");
846
+ if ((0, import_node_fs3.existsSync)(envFile)) {
847
+ const envContent = (0, import_node_fs3.readFileSync)(envFile, "utf-8");
848
+ for (const line of envContent.split("\n")) {
849
+ const trimmed = line.trim();
850
+ if (!trimmed || trimmed.startsWith("#")) continue;
851
+ const eqIdx = trimmed.indexOf("=");
852
+ if (eqIdx === -1) continue;
853
+ const key = trimmed.slice(0, eqIdx).trim();
854
+ const value = trimmed.slice(eqIdx + 1).trim();
855
+ env[key] = value;
856
+ }
857
+ }
833
858
  if (port) {
834
859
  env.PORT = String(port);
835
860
  }
@@ -1056,7 +1081,7 @@ var init_index = __esm({
1056
1081
  init_build();
1057
1082
  init_start();
1058
1083
  init_generate();
1059
- CLI_VERSION = "0.2.0";
1084
+ CLI_VERSION = "0.3.2";
1060
1085
  }
1061
1086
  });
1062
1087
 
package/dist/dev.js CHANGED
@@ -47,6 +47,18 @@ async function runDev(options = {}) {
47
47
  ...process.env,
48
48
  NODE_ENV: "development"
49
49
  };
50
+ if ((0, import_node_fs.existsSync)(envFile)) {
51
+ const envContent = (0, import_node_fs.readFileSync)(envFile, "utf-8");
52
+ for (const line of envContent.split("\n")) {
53
+ const trimmed = line.trim();
54
+ if (!trimmed || trimmed.startsWith("#")) continue;
55
+ const eqIdx = trimmed.indexOf("=");
56
+ if (eqIdx === -1) continue;
57
+ const key = trimmed.slice(0, eqIdx).trim();
58
+ const value = trimmed.slice(eqIdx + 1).trim();
59
+ env[key] = value;
60
+ }
61
+ }
50
62
  if (port) {
51
63
  env.PORT = String(port);
52
64
  }
package/dist/dev.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runDev
3
- } from "./chunk-RN7BUALR.mjs";
3
+ } from "./chunk-QND74HUW.mjs";
4
4
  import "./chunk-Y6FXYEAI.mjs";
5
5
  export {
6
6
  runDev
package/dist/index.d.mts CHANGED
@@ -4,6 +4,6 @@ export { BuildOptions, runBuild } from './build.mjs';
4
4
  export { StartOptions, runStart } from './start.mjs';
5
5
  export { GenerateOptions, GeneratorType, runGenerate } from './generate.mjs';
6
6
 
7
- declare const CLI_VERSION = "0.2.0";
7
+ declare const CLI_VERSION = "0.3.2";
8
8
 
9
9
  export { CLI_VERSION };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ export { BuildOptions, runBuild } from './build.js';
4
4
  export { StartOptions, runStart } from './start.js';
5
5
  export { GenerateOptions, GeneratorType, runGenerate } from './generate.js';
6
6
 
7
- declare const CLI_VERSION = "0.2.0";
7
+ declare const CLI_VERSION = "0.3.2";
8
8
 
9
9
  export { CLI_VERSION };
package/dist/index.js CHANGED
@@ -565,6 +565,18 @@ async function runDev(options = {}) {
565
565
  ...process.env,
566
566
  NODE_ENV: "development"
567
567
  };
568
+ if ((0, import_node_fs.existsSync)(envFile)) {
569
+ const envContent = (0, import_node_fs.readFileSync)(envFile, "utf-8");
570
+ for (const line of envContent.split("\n")) {
571
+ const trimmed = line.trim();
572
+ if (!trimmed || trimmed.startsWith("#")) continue;
573
+ const eqIdx = trimmed.indexOf("=");
574
+ if (eqIdx === -1) continue;
575
+ const key = trimmed.slice(0, eqIdx).trim();
576
+ const value = trimmed.slice(eqIdx + 1).trim();
577
+ env[key] = value;
578
+ }
579
+ }
568
580
  if (port) {
569
581
  env.PORT = String(port);
570
582
  }
@@ -803,6 +815,19 @@ async function runStart(options = {}) {
803
815
  ...process.env,
804
816
  NODE_ENV: "production"
805
817
  };
818
+ const envFile = (0, import_node_path3.resolve)(cwd, ".env");
819
+ if ((0, import_node_fs3.existsSync)(envFile)) {
820
+ const envContent = (0, import_node_fs3.readFileSync)(envFile, "utf-8");
821
+ for (const line of envContent.split("\n")) {
822
+ const trimmed = line.trim();
823
+ if (!trimmed || trimmed.startsWith("#")) continue;
824
+ const eqIdx = trimmed.indexOf("=");
825
+ if (eqIdx === -1) continue;
826
+ const key = trimmed.slice(0, eqIdx).trim();
827
+ const value = trimmed.slice(eqIdx + 1).trim();
828
+ env[key] = value;
829
+ }
830
+ }
806
831
  if (port) {
807
832
  env.PORT = String(port);
808
833
  }
@@ -992,7 +1017,7 @@ function toCamelCase(str) {
992
1017
  }
993
1018
 
994
1019
  // src/index.ts
995
- var CLI_VERSION = "0.2.0";
1020
+ var CLI_VERSION = "0.3.2";
996
1021
  // Annotate the CommonJS export names for ESM import in node:
997
1022
  0 && (module.exports = {
998
1023
  CLI_VERSION,
package/dist/index.mjs CHANGED
@@ -6,18 +6,18 @@ import {
6
6
  } from "./chunk-KFHPTRKZ.mjs";
7
7
  import {
8
8
  runDev
9
- } from "./chunk-RN7BUALR.mjs";
9
+ } from "./chunk-QND74HUW.mjs";
10
10
  import {
11
11
  runGenerate
12
12
  } from "./chunk-AONHLE42.mjs";
13
13
  import {
14
14
  runStart
15
- } from "./chunk-L3247M3A.mjs";
15
+ } from "./chunk-BXHQORLN.mjs";
16
16
  import "./chunk-IV352HZA.mjs";
17
17
  import "./chunk-Y6FXYEAI.mjs";
18
18
 
19
19
  // src/index.ts
20
- var CLI_VERSION = "0.2.0";
20
+ var CLI_VERSION = "0.3.2";
21
21
  export {
22
22
  CLI_VERSION,
23
23
  createProject,
package/dist/start.js CHANGED
@@ -50,6 +50,19 @@ async function runStart(options = {}) {
50
50
  ...process.env,
51
51
  NODE_ENV: "production"
52
52
  };
53
+ const envFile = (0, import_node_path.resolve)(cwd, ".env");
54
+ if ((0, import_node_fs.existsSync)(envFile)) {
55
+ const envContent = (0, import_node_fs.readFileSync)(envFile, "utf-8");
56
+ for (const line of envContent.split("\n")) {
57
+ const trimmed = line.trim();
58
+ if (!trimmed || trimmed.startsWith("#")) continue;
59
+ const eqIdx = trimmed.indexOf("=");
60
+ if (eqIdx === -1) continue;
61
+ const key = trimmed.slice(0, eqIdx).trim();
62
+ const value = trimmed.slice(eqIdx + 1).trim();
63
+ env[key] = value;
64
+ }
65
+ }
53
66
  if (port) {
54
67
  env.PORT = String(port);
55
68
  }
package/dist/start.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runStart
3
- } from "./chunk-L3247M3A.mjs";
3
+ } from "./chunk-BXHQORLN.mjs";
4
4
  import "./chunk-Y6FXYEAI.mjs";
5
5
  export {
6
6
  runStart
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltx/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "VoltX CLI — dev server, build, start, generate, and scaffolding",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {
24
- "@voltx/core": "workspace:*"
24
+ "@voltx/core": "^0.3.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "tsx": ">=4.0.0",