what-framework-cli 0.8.4 → 0.11.0

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/cli.js +44 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-framework-cli",
3
- "version": "0.8.4",
3
+ "version": "0.11.0",
4
4
  "description": "What Framework CLI - Dev server, build, and deployment tools",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  "author": "ZVN DEV (https://zvndev.com)",
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "what-framework": "^0.8.4"
25
+ "what-framework": "^0.11.0"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
package/src/cli.js CHANGED
@@ -6,6 +6,7 @@
6
6
  import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync, statSync, copyFileSync, realpathSync } from 'fs';
7
7
  import { join, resolve, relative, extname, basename, normalize } from 'path';
8
8
  import { createServer } from 'http';
9
+ import { spawn } from 'child_process';
9
10
  import { fileURLToPath } from 'url';
10
11
  import { createHash } from 'crypto';
11
12
  import { gzipSync } from 'zlib';
@@ -156,7 +157,7 @@ const packageVersion = JSON.parse(readFileSync(new URL('../package.json', import
156
157
  const args = process.argv.slice(2);
157
158
  const command = args[0];
158
159
 
159
- const commands = { dev, build, preview, generate, init };
160
+ const commands = { dev, build, preview, generate, start, init };
160
161
 
161
162
  if (!command || !commands[command]) {
162
163
  console.log(`
@@ -169,6 +170,7 @@ if (!command || !commands[command]) {
169
170
  build Production build
170
171
  preview Preview production build
171
172
  generate Static site generation
173
+ start Run the full-stack server (Node adapter + ISR)
172
174
  init Create a new project
173
175
 
174
176
  Options:
@@ -505,6 +507,47 @@ async function generate() {
505
507
  console.log('\n Static generation complete.\n');
506
508
  }
507
509
 
510
+ // --- Start (full-stack server) ---
511
+
512
+ // Runs the project's full-stack server (Node adapter + origin-first ISR). The
513
+ // scaffold's `server.js` wires createServer({routes, cache, scheduler, …}) and
514
+ // self-starts when run as the main module, so we delegate to it — keeping the
515
+ // server's wiring in the app (where it's editable) rather than hidden in the CLI.
516
+ async function start() {
517
+ const config = await loadConfigAsync();
518
+ const adapter = config.adapter || 'node';
519
+ const serverEntry = join(cwd, 'server.js');
520
+
521
+ if (!existsSync(serverEntry)) {
522
+ console.error(`
523
+ what start — no server.js found in ${cwd}
524
+
525
+ Full-stack apps run from a server.js (Node adapter + ISR engine). Scaffold one
526
+ with \`npm create what@latest -- --fullstack\`, or create server.js wiring
527
+ createServer({ routes, cache }) from 'what-framework/server'.
528
+ `);
529
+ process.exit(1);
530
+ return;
531
+ }
532
+
533
+ if (adapter !== 'node') {
534
+ console.log(` Note: what.config.js adapter is "${adapter}"; \`what start\` runs the Node server. Use \`what build\` for ${adapter} output.`);
535
+ }
536
+
537
+ console.log(`\n what start → running server.js (${adapter} adapter)\n`);
538
+
539
+ const child = spawn(process.execPath, [serverEntry], { cwd, stdio: 'inherit', env: process.env });
540
+ // Forward termination signals so Ctrl-C / SIGTERM reach the server (scheduler
541
+ // cleanup runs in its SIGTERM handler).
542
+ const forward = (sig) => { try { child.kill(sig); } catch { /* already gone */ } };
543
+ process.on('SIGINT', () => forward('SIGINT'));
544
+ process.on('SIGTERM', () => forward('SIGTERM'));
545
+ child.on('exit', (code, signal) => {
546
+ if (signal) { process.kill(process.pid, signal); return; }
547
+ process.exit(code == null ? 0 : code);
548
+ });
549
+ }
550
+
508
551
  // --- Init ---
509
552
 
510
553
  function init() {