what-framework-cli 0.10.0 → 0.11.1
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/package.json +2 -2
- package/src/cli.js +43 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-framework-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
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.
|
|
25
|
+
"what-framework": "^0.11.1"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
package/src/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync, statSy
|
|
|
7
7
|
import { join, resolve, relative, extname, basename, normalize } from 'path';
|
|
8
8
|
import { createServer } from 'http';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
|
+
import { createRequire } from 'module';
|
|
10
11
|
import { fileURLToPath } from 'url';
|
|
11
12
|
import { createHash } from 'crypto';
|
|
12
13
|
import { gzipSync } from 'zlib';
|
|
@@ -171,7 +172,7 @@ if (!command || !commands[command]) {
|
|
|
171
172
|
preview Preview production build
|
|
172
173
|
generate Static site generation
|
|
173
174
|
start Run the full-stack server (Node adapter + ISR)
|
|
174
|
-
init Create a new project
|
|
175
|
+
init Create a new project (same scaffold as npm create what@latest)
|
|
175
176
|
|
|
176
177
|
Options:
|
|
177
178
|
--port Dev server port (default: 3000)
|
|
@@ -550,45 +551,51 @@ async function start() {
|
|
|
550
551
|
|
|
551
552
|
// --- Init ---
|
|
552
553
|
|
|
554
|
+
// Delegates to create-what (the canonical scaffolder) so `what init my-app`
|
|
555
|
+
// produces exactly the same app as `npm create what@latest` — real app files,
|
|
556
|
+
// working package.json scripts, both templates. Every flag is forwarded
|
|
557
|
+
// (--fullstack, --template=<name>, --yes), and create-what prints next steps
|
|
558
|
+
// that work end-to-end (cd / npm install / npm run dev).
|
|
553
559
|
function init() {
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
process.exit(1);
|
|
560
|
+
const initArgs = args.slice(1);
|
|
561
|
+
// Non-interactive contexts (CI, piped stdin): scaffold with defaults rather
|
|
562
|
+
// than streaming prompt text into logs.
|
|
563
|
+
if (!process.stdin.isTTY && !initArgs.includes('--yes') && !initArgs.includes('-y')) {
|
|
564
|
+
initArgs.push('--yes');
|
|
560
565
|
}
|
|
561
566
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
567
|
+
const entry = resolveCreateWhat();
|
|
568
|
+
const child = entry
|
|
569
|
+
? spawn(process.execPath, [entry, ...initArgs], { cwd, stdio: 'inherit' })
|
|
570
|
+
: // Not installed anywhere local — fetch the matching release via npm.
|
|
571
|
+
spawn(
|
|
572
|
+
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
573
|
+
['exec', '--yes', `create-what@^${packageVersion}`, '--', ...initArgs],
|
|
574
|
+
{ cwd, stdio: 'inherit' }
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
child.on('error', (err) => {
|
|
578
|
+
console.error(`\n what init could not launch the scaffolder: ${err.message}`);
|
|
579
|
+
console.error(' Run it directly instead: npm create what@latest\n');
|
|
580
|
+
process.exit(1);
|
|
581
|
+
});
|
|
582
|
+
child.on('exit', (code) => process.exit(code == null ? 1 : code));
|
|
583
|
+
}
|
|
572
584
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
console.log(` Done! Next steps:\n`);
|
|
589
|
-
console.log(` cd ${name}`);
|
|
590
|
-
console.log(` npm install`);
|
|
591
|
-
console.log(` npm run dev\n`);
|
|
585
|
+
// Locate the create-what scaffolder without a network hit:
|
|
586
|
+
// 1) monorepo sibling (this repo's dev checkout)
|
|
587
|
+
// 2) an installed create-what package (next to the CLI, or in the project)
|
|
588
|
+
// Returns null when neither exists — init falls back to `npm exec create-what`.
|
|
589
|
+
function resolveCreateWhat() {
|
|
590
|
+
const sibling = resolve(__dirname, '../../create-what/index.js');
|
|
591
|
+
if (existsSync(sibling)) return sibling;
|
|
592
|
+
try {
|
|
593
|
+
return createRequire(import.meta.url).resolve('create-what');
|
|
594
|
+
} catch { /* not installed next to the CLI */ }
|
|
595
|
+
try {
|
|
596
|
+
return createRequire(join(cwd, 'package.json')).resolve('create-what');
|
|
597
|
+
} catch { /* not installed in the project */ }
|
|
598
|
+
return null;
|
|
592
599
|
}
|
|
593
600
|
|
|
594
601
|
// --- Helpers ---
|