@mauroandre/velojs 0.0.44 → 0.0.45

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/dist/cli.js CHANGED
@@ -1,43 +1,43 @@
1
- import { spawnSync as c } from "node:child_process";
1
+ import { spawnSync as a } from "node:child_process";
2
2
  import { join as n, resolve as u } from "node:path";
3
3
  import p from "node:fs";
4
- const o = process.argv.slice(2), a = o[0], v = (e, s = []) => {
5
- const t = c(e, s, {
4
+ const t = process.argv.slice(2), c = t[0], v = (s, e = []) => {
5
+ const o = a(s, e, {
6
6
  stdio: "inherit",
7
7
  cwd: process.cwd()
8
8
  });
9
- process.exit(t.status ?? 0);
9
+ process.exit(o.status ?? 0);
10
10
  }, m = () => {
11
- v("npx", ["vite", ...o.slice(1)]);
12
- }, j = (e) => {
13
- const s = Date.now().toString(36), t = {
11
+ v("npx", ["vite", ...t.slice(1)]);
12
+ }, f = (s) => {
13
+ const e = Date.now().toString(36), o = {
14
14
  ...process.env,
15
- VELO_BUILD_HASH: s,
16
- ...e ? { VELO_STATIC: "1" } : {}
15
+ VELO_BUILD_HASH: e,
16
+ ...s ? { VELO_STATIC: "1" } : {}
17
17
  };
18
18
  console.log("Building client...");
19
- const r = c("npx", ["vite", "build"], {
19
+ const r = a("npx", ["vite", "build"], {
20
20
  stdio: "inherit",
21
21
  cwd: process.cwd(),
22
- env: t
22
+ env: o
23
23
  });
24
24
  r.status !== 0 && (console.error("Client build failed. Aborting."), process.exit(r.status ?? 1)), console.log("Building server...");
25
- const i = c("npx", ["vite", "build", "--mode", "server"], {
25
+ const i = a("npx", ["vite", "build", "--mode", "server"], {
26
26
  stdio: "inherit",
27
27
  cwd: process.cwd(),
28
- env: t
28
+ env: o
29
29
  });
30
- i.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(i.status ?? 1)), console.log("Build complete!"), e && b();
31
- }, b = async () => {
30
+ i.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(i.status ?? 1)), console.log("Build complete!"), s && j();
31
+ }, j = async () => {
32
32
  process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
33
- const s = await import(u(process.cwd(), "dist/server.js")), t = s.default, r = s.routes;
34
- (!t || !r) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
33
+ const e = await import(u(process.cwd(), "dist/server.js")), o = e.default, r = e.routes;
34
+ (!o || !r) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
35
35
  const { generateStatic: i } = await import("./static.js");
36
- await i(t, r);
37
- }, f = () => {
36
+ await i(o, r);
37
+ }, b = () => {
38
38
  process.env.NODE_ENV = "production";
39
- const e = u(process.cwd(), "dist/server.js");
40
- v("node", [e]);
39
+ const s = u(process.cwd(), "dist/server.js");
40
+ v("node", [s]);
41
41
  }, d = () => {
42
42
  console.log(`
43
43
  VeloJS CLI
@@ -46,7 +46,7 @@ Usage:
46
46
  velojs <command>
47
47
 
48
48
  Commands:
49
- init Create a new VeloJS project
49
+ init Create a new VeloJS project (fails only on file conflicts; --force overwrites)
50
50
  dev Start development server
51
51
  build Build for production (client + server)
52
52
  build --static Build as static site (HTML + JSON)
@@ -65,30 +65,35 @@ Examples:
65
65
  velojs graph --view
66
66
  `);
67
67
  };
68
- switch (a) {
68
+ switch (c) {
69
69
  case "init": {
70
- const { runInit: e } = await import("./init.js");
71
- await e(o[1]);
70
+ const { runInit: s } = await import("./init.js");
71
+ try {
72
+ const e = t[1] && !t[1].startsWith("-") ? t[1] : void 0;
73
+ await s(e, { force: t.includes("--force") });
74
+ } catch (e) {
75
+ console.error(e.message), process.exit(1);
76
+ }
72
77
  break;
73
78
  }
74
79
  case "dev":
75
80
  m();
76
81
  break;
77
82
  case "build": {
78
- const e = o.includes("--static");
79
- j(e);
83
+ const s = t.includes("--static");
84
+ f(s);
80
85
  break;
81
86
  }
82
87
  case "start":
83
- f();
88
+ b();
84
89
  break;
85
90
  case "graph": {
86
- const { buildGraph: e } = await import("./graph.js"), s = process.cwd(), t = o[1] && !o[1].startsWith("-") ? o[1] : null, r = n(s, t ?? "app"), i = e(r), l = n(s, ".velojs");
91
+ const { buildGraph: s } = await import("./graph.js"), e = process.cwd(), o = t[1] && !t[1].startsWith("-") ? t[1] : null, r = n(e, o ?? "app"), i = s(r), l = n(e, ".velojs");
87
92
  p.mkdirSync(l, { recursive: !0 });
88
- const w = n(l, "graph.json");
89
- if (p.writeFileSync(w, JSON.stringify(i)), console.log("Graph written to .velojs/graph.json"), o.includes("--view")) {
90
- const { serveGraphViewer: g } = await import("./graph-viewer.js"), h = await g(s);
91
- console.log(`Graph viewer running at ${h} (Ctrl+C to stop)`);
93
+ const g = n(l, "graph.json");
94
+ if (p.writeFileSync(g, JSON.stringify(i)), console.log("Graph written to .velojs/graph.json"), t.includes("--view")) {
95
+ const { serveGraphViewer: h } = await import("./graph-viewer.js"), w = await h(e);
96
+ console.log(`Graph viewer running at ${w} (Ctrl+C to stop)`);
92
97
  }
93
98
  break;
94
99
  }
@@ -98,5 +103,5 @@ switch (a) {
98
103
  d();
99
104
  break;
100
105
  default:
101
- a && console.error(`Unknown command: ${a}`), d(), process.exit(1);
106
+ c && console.error(`Unknown command: ${c}`), d(), process.exit(1);
102
107
  }
package/dist/init.d.ts CHANGED
@@ -1 +1,3 @@
1
- export declare function runInit(dirName?: string): Promise<void>;
1
+ export declare function runInit(dirName?: string, opts?: {
2
+ force?: boolean;
3
+ }): Promise<void>;
package/dist/init.js CHANGED
@@ -1,12 +1,12 @@
1
- import t from "node:fs";
2
- import s from "node:path";
3
- import { fileURLToPath as d } from "node:url";
4
- const i = "@mauroandre/velojs";
5
- function m() {
6
- const o = s.dirname(d(import.meta.url)), e = s.resolve(o, "../package.json");
7
- return JSON.parse(t.readFileSync(e, "utf-8")).version;
1
+ import e from "node:fs";
2
+ import o from "node:path";
3
+ import { fileURLToPath as x } from "node:url";
4
+ const r = "@mauroandre/velojs";
5
+ function v() {
6
+ const n = o.dirname(x(import.meta.url)), p = o.resolve(n, "../package.json");
7
+ return JSON.parse(e.readFileSync(p, "utf-8")).version;
8
8
  }
9
- const u = {
9
+ const g = {
10
10
  ".gitignore": `# Dependencies
11
11
  node_modules/
12
12
 
@@ -26,7 +26,7 @@ dist/
26
26
  "start": "velojs start"
27
27
  },
28
28
  "dependencies": {
29
- "${i}": "^${m()}"
29
+ "${r}": "^${v()}"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "latest",
@@ -34,7 +34,7 @@ dist/
34
34
  }
35
35
  }
36
36
  `,
37
- "vite.config.ts": `import { veloPlugin } from "${i}/vite";
37
+ "vite.config.ts": `import { veloPlugin } from "${r}/vite";
38
38
 
39
39
  export default { plugins: [veloPlugin()] };
40
40
  `,
@@ -59,7 +59,7 @@ export default { plugins: [veloPlugin()] };
59
59
  "exclude": ["node_modules", "dist"]
60
60
  }
61
61
  `,
62
- "app/routes.tsx": `import type { AppRoutes } from "${i}";
62
+ "app/routes.tsx": `import type { AppRoutes } from "${r}";
63
63
 
64
64
  import * as Root from "./client-root.js";
65
65
  import * as Home from "./pages/Home.js";
@@ -79,11 +79,11 @@ export default [
79
79
  `,
80
80
  "app/server.tsx": `// Server initialization
81
81
  // Use this file to set up server-side logic:
82
- // import { addRoutes, onServer } from "${i}/server";
82
+ // import { addRoutes, onServer } from "${r}/server";
83
83
  `,
84
84
  "app/client.tsx": `import "./styles/global.css";
85
85
  `,
86
- "app/client-root.tsx": `import { Scripts } from "${i}";
86
+ "app/client-root.tsx": `import { Scripts } from "${r}";
87
87
 
88
88
  interface RootProps {
89
89
  children: preact.ComponentChildren;
@@ -147,25 +147,39 @@ a:hover {
147
147
  };
148
148
  `
149
149
  };
150
- async function x(o) {
151
- const e = o ? s.resolve(process.cwd(), o) : process.cwd(), n = s.basename(e);
152
- t.existsSync(e) ? t.readdirSync(e).filter(
153
- (r) => !r.startsWith(".") && r !== "node_modules"
154
- ).length > 0 && (console.error(
155
- `Error: Directory "${n}" is not empty. Use an empty directory.`
156
- ), process.exit(1)) : t.mkdirSync(e, { recursive: !0 });
157
- for (const [a, r] of Object.entries(u)) {
158
- const p = s.join(e, a), l = s.dirname(p);
159
- t.existsSync(l) || t.mkdirSync(l, { recursive: !0 });
160
- const c = a === "package.json" ? r.replace("my-velojs-app", n) : r;
161
- t.writeFileSync(p, c);
150
+ async function b(n, p) {
151
+ const s = n ? o.resolve(process.cwd(), n) : process.cwd(), a = o.basename(s);
152
+ e.existsSync(s) || e.mkdirSync(s, { recursive: !0 });
153
+ const d = Object.keys(g).filter(
154
+ (t) => t !== ".gitignore" && e.existsSync(o.join(s, t))
155
+ );
156
+ if (d.length > 0 && !p?.force)
157
+ throw new Error(
158
+ `Cannot init in "${a}": these files already exist and would be overwritten:
159
+ ` + d.map((t) => ` ${t}`).join(`
160
+ `) + "\nMove them away, or run `velojs init --force` to overwrite."
161
+ );
162
+ for (const [t, l] of Object.entries(g)) {
163
+ const i = o.join(s, t), m = o.dirname(i);
164
+ if (e.existsSync(m) || e.mkdirSync(m, { recursive: !0 }), t === ".gitignore" && e.existsSync(i)) {
165
+ const h = e.readFileSync(i, "utf-8"), u = l.split(`
166
+ `).filter((c) => c && !c.startsWith("#") && !h.includes(c));
167
+ u.length > 0 && e.appendFileSync(i, `
168
+ # VeloJS
169
+ ${u.join(`
170
+ `)}
171
+ `);
172
+ continue;
173
+ }
174
+ const f = t === "package.json" ? l.replace("my-velojs-app", a) : l;
175
+ e.writeFileSync(i, f);
162
176
  }
163
177
  console.log(`
164
- Project created in ${o ? n : "current directory"}!
178
+ Project created in ${n ? a : "current directory"}!
165
179
  `), console.log(`Next steps:
166
- `), o && console.log(` cd ${n}`), console.log(" npm install"), console.log(` npx velojs dev
180
+ `), n && console.log(` cd ${a}`), console.log(" npm install"), console.log(` npx velojs dev
167
181
  `);
168
182
  }
169
183
  export {
170
- x as runInit
184
+ b as runInit
171
185
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [