prev-cli 0.16.4 → 0.17.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/dist/cli.js +98 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1193,6 +1193,7 @@ async function previewSite(rootDir, options = {}) {
|
|
|
1193
1193
|
}
|
|
1194
1194
|
|
|
1195
1195
|
// src/cli.ts
|
|
1196
|
+
import yaml2 from "js-yaml";
|
|
1196
1197
|
function getVersion() {
|
|
1197
1198
|
try {
|
|
1198
1199
|
let dir = path9.dirname(fileURLToPath3(import.meta.url));
|
|
@@ -1231,9 +1232,16 @@ Usage:
|
|
|
1231
1232
|
prev build [options] Build for production
|
|
1232
1233
|
prev preview [options] Preview production build
|
|
1233
1234
|
prev create [name] Create preview in previews/<name>/ (default: "example")
|
|
1235
|
+
prev config [subcommand] Manage configuration
|
|
1234
1236
|
prev clearcache Clear Vite cache (.vite directory)
|
|
1235
1237
|
prev clean [options] Remove old prev-cli caches
|
|
1236
1238
|
|
|
1239
|
+
Config subcommands:
|
|
1240
|
+
prev config Show current configuration
|
|
1241
|
+
prev config show Show current configuration (same as above)
|
|
1242
|
+
prev config init Create .prev.yaml with defaults
|
|
1243
|
+
prev config path Show config file path
|
|
1244
|
+
|
|
1237
1245
|
Options:
|
|
1238
1246
|
-c, --cwd <path> Set working directory
|
|
1239
1247
|
-p, --port <port> Specify port (dev/preview)
|
|
@@ -1340,6 +1348,93 @@ async function clearViteCache(rootDir2) {
|
|
|
1340
1348
|
Cleared ${cleared} cache director${cleared === 1 ? "y" : "ies"}`);
|
|
1341
1349
|
}
|
|
1342
1350
|
}
|
|
1351
|
+
function handleConfig(rootDir2, subcommand) {
|
|
1352
|
+
const configPath = findConfigFile(rootDir2);
|
|
1353
|
+
const config = loadConfig(rootDir2);
|
|
1354
|
+
switch (subcommand) {
|
|
1355
|
+
case undefined:
|
|
1356
|
+
case "show": {
|
|
1357
|
+
console.log(`
|
|
1358
|
+
\uD83D\uDCC4 Configuration
|
|
1359
|
+
`);
|
|
1360
|
+
if (configPath) {
|
|
1361
|
+
console.log(` File: ${configPath}
|
|
1362
|
+
`);
|
|
1363
|
+
} else {
|
|
1364
|
+
console.log(` File: (none - using defaults)
|
|
1365
|
+
`);
|
|
1366
|
+
}
|
|
1367
|
+
const yamlOutput = yaml2.dump(config, {
|
|
1368
|
+
indent: 2,
|
|
1369
|
+
lineWidth: -1,
|
|
1370
|
+
quotingType: '"',
|
|
1371
|
+
forceQuotes: false
|
|
1372
|
+
});
|
|
1373
|
+
const indented = yamlOutput.split(`
|
|
1374
|
+
`).map((line) => ` ${line}`).join(`
|
|
1375
|
+
`);
|
|
1376
|
+
console.log(indented);
|
|
1377
|
+
if (!configPath) {
|
|
1378
|
+
console.log(`
|
|
1379
|
+
Run 'prev config init' to create a config file.
|
|
1380
|
+
`);
|
|
1381
|
+
}
|
|
1382
|
+
break;
|
|
1383
|
+
}
|
|
1384
|
+
case "init": {
|
|
1385
|
+
const targetPath = path9.join(rootDir2, ".prev.yaml");
|
|
1386
|
+
if (configPath) {
|
|
1387
|
+
console.log(`
|
|
1388
|
+
Config already exists: ${configPath}
|
|
1389
|
+
`);
|
|
1390
|
+
process.exit(1);
|
|
1391
|
+
}
|
|
1392
|
+
const randomPort = 3000 + Math.floor(Math.random() * 6000);
|
|
1393
|
+
const configContent = `# prev-cli configuration
|
|
1394
|
+
# See: https://github.com/lagz0ne/prev-cli
|
|
1395
|
+
|
|
1396
|
+
# Theme: light | dark | system
|
|
1397
|
+
theme: system
|
|
1398
|
+
|
|
1399
|
+
# Content width: constrained | full
|
|
1400
|
+
contentWidth: constrained
|
|
1401
|
+
|
|
1402
|
+
# Port for dev server (can be overridden with -p flag)
|
|
1403
|
+
port: ${randomPort}
|
|
1404
|
+
|
|
1405
|
+
# Hidden pages (glob patterns)
|
|
1406
|
+
hidden: []
|
|
1407
|
+
# - "internal/**"
|
|
1408
|
+
# - "wip-*.md"
|
|
1409
|
+
|
|
1410
|
+
# Custom page ordering per directory
|
|
1411
|
+
order: {}
|
|
1412
|
+
# "/":
|
|
1413
|
+
# - "getting-started.md"
|
|
1414
|
+
# - "guides/"
|
|
1415
|
+
`;
|
|
1416
|
+
writeFileSync4(targetPath, configContent, "utf-8");
|
|
1417
|
+
console.log(`
|
|
1418
|
+
✨ Created ${targetPath}
|
|
1419
|
+
`);
|
|
1420
|
+
break;
|
|
1421
|
+
}
|
|
1422
|
+
case "path": {
|
|
1423
|
+
if (configPath) {
|
|
1424
|
+
console.log(configPath);
|
|
1425
|
+
} else {
|
|
1426
|
+
console.log(`(no config file found in ${rootDir2})`);
|
|
1427
|
+
process.exit(1);
|
|
1428
|
+
}
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
default:
|
|
1432
|
+
console.error(`Unknown config subcommand: ${subcommand}`);
|
|
1433
|
+
console.log(`
|
|
1434
|
+
Available subcommands: show, init, path`);
|
|
1435
|
+
process.exit(1);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1343
1438
|
function createPreview(rootDir2, name) {
|
|
1344
1439
|
const previewDir = path9.join(rootDir2, "previews", name);
|
|
1345
1440
|
if (existsSync7(previewDir)) {
|
|
@@ -1519,6 +1614,9 @@ async function main() {
|
|
|
1519
1614
|
case "clearcache":
|
|
1520
1615
|
await clearViteCache(rootDir);
|
|
1521
1616
|
break;
|
|
1617
|
+
case "config":
|
|
1618
|
+
handleConfig(rootDir, positionals[1]);
|
|
1619
|
+
break;
|
|
1522
1620
|
default:
|
|
1523
1621
|
console.error(`Unknown command: ${command}`);
|
|
1524
1622
|
printHelp();
|