what-framework-cli 0.8.3 → 0.10.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 +47 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-framework-cli",
3
- "version": "0.8.3",
3
+ "version": "0.10.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.3"
25
+ "what-framework": "^0.10.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';
@@ -151,11 +152,12 @@ class SimpleWebSocket {
151
152
 
152
153
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
153
154
  const cwd = process.cwd();
155
+ const packageVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
154
156
 
155
157
  const args = process.argv.slice(2);
156
158
  const command = args[0];
157
159
 
158
- const commands = { dev, build, preview, generate, init };
160
+ const commands = { dev, build, preview, generate, start, init };
159
161
 
160
162
  if (!command || !commands[command]) {
161
163
  console.log(`
@@ -168,6 +170,7 @@ if (!command || !commands[command]) {
168
170
  build Production build
169
171
  preview Preview production build
170
172
  generate Static site generation
173
+ start Run the full-stack server (Node adapter + ISR)
171
174
  init Create a new project
172
175
 
173
176
  Options:
@@ -504,6 +507,47 @@ async function generate() {
504
507
  console.log('\n Static generation complete.\n');
505
508
  }
506
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
+
507
551
  // --- Init ---
508
552
 
509
553
  function init() {
@@ -537,7 +581,7 @@ function init() {
537
581
  generate: 'what generate',
538
582
  },
539
583
  dependencies: {
540
- 'what-framework': '^0.6.0',
584
+ 'what-framework': `^${packageVersion}`,
541
585
  },
542
586
  }, null, 2));
543
587
 
@@ -557,7 +601,7 @@ function getFlag(name, defaultValue) {
557
601
  }
558
602
 
559
603
  // Async config loader — uses dynamic import() instead of unsafe new Function()
560
- let _configCache = null;
604
+ var _configCache = null;
561
605
  async function loadConfigAsync() {
562
606
  if (_configCache) return _configCache;
563
607
  const configPath = join(cwd, 'what.config.js');