what-framework-cli 0.6.0 → 0.6.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.
- package/package.json +4 -4
- package/src/cli.js +38 -9
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-framework-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "What Framework CLI - Dev server, build, and deployment tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"what": "
|
|
7
|
+
"what": "src/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"main": "src/cli.js",
|
|
10
10
|
"exports": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"author": "ZVN DEV (https://zvndev.com)",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"what-framework": "^0.6.
|
|
25
|
+
"what-framework": "^0.6.2"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/CelsianJs/what-framework"
|
|
29
|
+
"url": "git+https://github.com/CelsianJs/what-framework.git"
|
|
30
30
|
},
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/CelsianJs/what-framework/issues"
|
package/src/cli.js
CHANGED
|
@@ -184,7 +184,7 @@ commands[command]();
|
|
|
184
184
|
async function dev() {
|
|
185
185
|
const port = getFlag('--port', 3000);
|
|
186
186
|
const host = getFlag('--host', 'localhost');
|
|
187
|
-
const config =
|
|
187
|
+
const config = await loadConfigAsync();
|
|
188
188
|
|
|
189
189
|
const server = createServer(async (req, res) => {
|
|
190
190
|
const url = new URL(req.url, `http://${host}:${port}`);
|
|
@@ -347,7 +347,7 @@ async function dev() {
|
|
|
347
347
|
// --- Build ---
|
|
348
348
|
|
|
349
349
|
async function build() {
|
|
350
|
-
const config =
|
|
350
|
+
const config = await loadConfigAsync();
|
|
351
351
|
const outDir = join(cwd, config.outDir || 'dist');
|
|
352
352
|
const useHash = config.hash !== false;
|
|
353
353
|
const hashManifest = {};
|
|
@@ -443,8 +443,8 @@ async function build() {
|
|
|
443
443
|
|
|
444
444
|
// --- Preview ---
|
|
445
445
|
|
|
446
|
-
function preview() {
|
|
447
|
-
const config =
|
|
446
|
+
async function preview() {
|
|
447
|
+
const config = await loadConfigAsync();
|
|
448
448
|
const outDir = join(cwd, config.outDir || 'dist');
|
|
449
449
|
const port = getFlag('--port', 4000);
|
|
450
450
|
|
|
@@ -482,7 +482,7 @@ function preview() {
|
|
|
482
482
|
// --- Static Generation ---
|
|
483
483
|
|
|
484
484
|
async function generate() {
|
|
485
|
-
const config =
|
|
485
|
+
const config = await loadConfigAsync();
|
|
486
486
|
const outDir = join(cwd, config.outDir || 'dist');
|
|
487
487
|
|
|
488
488
|
console.log('\n what generate (SSG)\n');
|
|
@@ -537,7 +537,7 @@ function init() {
|
|
|
537
537
|
generate: 'what generate',
|
|
538
538
|
},
|
|
539
539
|
dependencies: {
|
|
540
|
-
'what-framework': '^0.6.
|
|
540
|
+
'what-framework': '^0.6.2',
|
|
541
541
|
},
|
|
542
542
|
}, null, 2));
|
|
543
543
|
|
|
@@ -556,16 +556,45 @@ function getFlag(name, defaultValue) {
|
|
|
556
556
|
return typeof defaultValue === 'number' ? Number(val) : val;
|
|
557
557
|
}
|
|
558
558
|
|
|
559
|
+
// Async config loader — uses dynamic import() instead of unsafe new Function()
|
|
560
|
+
let _configCache = null;
|
|
561
|
+
async function loadConfigAsync() {
|
|
562
|
+
if (_configCache) return _configCache;
|
|
563
|
+
const configPath = join(cwd, 'what.config.js');
|
|
564
|
+
if (existsSync(configPath)) {
|
|
565
|
+
try {
|
|
566
|
+
// Use file:// URL for cross-platform ESM import compatibility
|
|
567
|
+
const fileUrl = new URL(`file://${configPath}`);
|
|
568
|
+
const mod = await import(fileUrl.href);
|
|
569
|
+
_configCache = mod.default || mod;
|
|
570
|
+
return _configCache;
|
|
571
|
+
} catch (e) { /* use defaults */ }
|
|
572
|
+
}
|
|
573
|
+
_configCache = { mode: 'hybrid', pagesDir: 'src/pages', outDir: 'dist' };
|
|
574
|
+
return _configCache;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Synchronous wrapper for backward compatibility — returns defaults,
|
|
578
|
+
// then callers that need the real config should use loadConfigAsync()
|
|
559
579
|
function loadConfig() {
|
|
580
|
+
// If we already loaded async, return cached
|
|
581
|
+
if (_configCache) return _configCache;
|
|
582
|
+
// Fallback: try JSON.parse for simple object configs (no code execution)
|
|
560
583
|
const configPath = join(cwd, 'what.config.js');
|
|
561
|
-
// Simple sync config load (no dynamic import in this context)
|
|
562
584
|
if (existsSync(configPath)) {
|
|
563
585
|
try {
|
|
564
|
-
// Read and extract basic config
|
|
565
586
|
const src = readFileSync(configPath, 'utf-8');
|
|
566
587
|
const match = src.match(/export default\s*(\{[\s\S]*?\})/);
|
|
567
588
|
if (match) {
|
|
568
|
-
|
|
589
|
+
// Only parse if the content is valid JSON (safe subset)
|
|
590
|
+
// Convert JS object literal to JSON: add quotes to keys
|
|
591
|
+
const jsonLike = match[1]
|
|
592
|
+
.replace(/\/\/[^\n]*/g, '') // strip line comments
|
|
593
|
+
.replace(/\/\*[\s\S]*?\*\//g, '') // strip block comments
|
|
594
|
+
.replace(/,\s*([}\]])/g, '$1') // strip trailing commas
|
|
595
|
+
.replace(/(['"])?(\w+)(['"])?\s*:/g, '"$2":') // quote keys
|
|
596
|
+
.replace(/:\s*'([^']*)'/g, ': "$1"'); // single quotes to double
|
|
597
|
+
return JSON.parse(jsonLike);
|
|
569
598
|
}
|
|
570
599
|
} catch (e) { /* use defaults */ }
|
|
571
600
|
}
|