prev-cli 0.16.4 → 0.17.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/dist/cli.js +97 -0
  2. 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,92 @@ 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 configContent = `# prev-cli configuration
1393
+ # See: https://github.com/lagz0ne/prev-cli
1394
+
1395
+ # Theme: light | dark | system
1396
+ theme: system
1397
+
1398
+ # Content width: constrained | full
1399
+ contentWidth: constrained
1400
+
1401
+ # Port for dev server (optional, can be overridden with -p flag)
1402
+ # port: 3000
1403
+
1404
+ # Hidden pages (glob patterns)
1405
+ hidden: []
1406
+ # - "internal/**"
1407
+ # - "wip-*.md"
1408
+
1409
+ # Custom page ordering per directory
1410
+ order: {}
1411
+ # "/":
1412
+ # - "getting-started.md"
1413
+ # - "guides/"
1414
+ `;
1415
+ writeFileSync4(targetPath, configContent, "utf-8");
1416
+ console.log(`
1417
+ ✨ Created ${targetPath}
1418
+ `);
1419
+ break;
1420
+ }
1421
+ case "path": {
1422
+ if (configPath) {
1423
+ console.log(configPath);
1424
+ } else {
1425
+ console.log(`(no config file found in ${rootDir2})`);
1426
+ process.exit(1);
1427
+ }
1428
+ break;
1429
+ }
1430
+ default:
1431
+ console.error(`Unknown config subcommand: ${subcommand}`);
1432
+ console.log(`
1433
+ Available subcommands: show, init, path`);
1434
+ process.exit(1);
1435
+ }
1436
+ }
1343
1437
  function createPreview(rootDir2, name) {
1344
1438
  const previewDir = path9.join(rootDir2, "previews", name);
1345
1439
  if (existsSync7(previewDir)) {
@@ -1519,6 +1613,9 @@ async function main() {
1519
1613
  case "clearcache":
1520
1614
  await clearViteCache(rootDir);
1521
1615
  break;
1616
+ case "config":
1617
+ handleConfig(rootDir, positionals[1]);
1618
+ break;
1522
1619
  default:
1523
1620
  console.error(`Unknown command: ${command}`);
1524
1621
  printHelp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prev-cli",
3
- "version": "0.16.4",
3
+ "version": "0.17.0",
4
4
  "description": "Transform MDX directories into beautiful documentation websites",
5
5
  "type": "module",
6
6
  "license": "MIT",