prev-cli 0.8.0 → 0.9.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.
- package/dist/cli.js +49 -25
- package/dist/vite/config.d.ts +1 -0
- package/dist/vite/pages.d.ts +4 -1
- package/dist/vite/plugins/pages-plugin.d.ts +4 -1
- package/dist/vite/start.d.ts +5 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -136,14 +136,30 @@ function fileToRoute(file) {
|
|
|
136
136
|
}
|
|
137
137
|
return "/" + withoutExt;
|
|
138
138
|
}
|
|
139
|
-
async function scanPages(rootDir) {
|
|
140
|
-
const
|
|
139
|
+
async function scanPages(rootDir, options = {}) {
|
|
140
|
+
const { include = [] } = options;
|
|
141
|
+
const includeDirs = include.map((dir) => dir.startsWith(".") ? dir : `.${dir}`);
|
|
142
|
+
const patterns = ["**/*.{md,mdx}"];
|
|
143
|
+
for (const dir of includeDirs) {
|
|
144
|
+
patterns.push(`${dir}/**/*.{md,mdx}`);
|
|
145
|
+
}
|
|
146
|
+
const ignore = ["node_modules/**", "dist/**", ".cache/**"];
|
|
147
|
+
const files = await fg.glob(patterns, {
|
|
141
148
|
cwd: rootDir,
|
|
142
|
-
ignore
|
|
143
|
-
dot:
|
|
149
|
+
ignore,
|
|
150
|
+
dot: true
|
|
151
|
+
});
|
|
152
|
+
const filteredFiles = files.filter((file) => {
|
|
153
|
+
const parts = file.split("/");
|
|
154
|
+
for (const part of parts) {
|
|
155
|
+
if (part.startsWith(".") && part !== ".") {
|
|
156
|
+
return includeDirs.some((dir) => file.startsWith(dir.slice(1)) || file.startsWith(dir));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
144
160
|
});
|
|
145
161
|
const routeMap = new Map;
|
|
146
|
-
for (const file of
|
|
162
|
+
for (const file of filteredFiles) {
|
|
147
163
|
const route = fileToRoute(file);
|
|
148
164
|
const basename = path2.basename(file, path2.extname(file)).toLowerCase();
|
|
149
165
|
const priority = basename === "index" ? 1 : basename === "readme" ? 2 : 0;
|
|
@@ -222,7 +238,8 @@ function buildSidebarTree(pages) {
|
|
|
222
238
|
// src/vite/plugins/pages-plugin.ts
|
|
223
239
|
var VIRTUAL_MODULE_ID = "virtual:prev-pages";
|
|
224
240
|
var RESOLVED_VIRTUAL_MODULE_ID = "\x00" + VIRTUAL_MODULE_ID;
|
|
225
|
-
function pagesPlugin(rootDir) {
|
|
241
|
+
function pagesPlugin(rootDir, options = {}) {
|
|
242
|
+
const { include } = options;
|
|
226
243
|
return {
|
|
227
244
|
name: "prev-pages",
|
|
228
245
|
resolveId(id) {
|
|
@@ -232,7 +249,7 @@ function pagesPlugin(rootDir) {
|
|
|
232
249
|
},
|
|
233
250
|
async load(id) {
|
|
234
251
|
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
235
|
-
const pages = await scanPages(rootDir);
|
|
252
|
+
const pages = await scanPages(rootDir, { include });
|
|
236
253
|
const sidebar = buildSidebarTree(pages);
|
|
237
254
|
return `
|
|
238
255
|
export const pages = ${JSON.stringify(pages)};
|
|
@@ -439,7 +456,7 @@ var cliRoot2 = findCliRoot2();
|
|
|
439
456
|
var cliNodeModules = findNodeModules(cliRoot2);
|
|
440
457
|
var srcRoot2 = path4.join(cliRoot2, "src");
|
|
441
458
|
async function createViteConfig(options) {
|
|
442
|
-
const { rootDir, mode, port } = options;
|
|
459
|
+
const { rootDir, mode, port, include } = options;
|
|
443
460
|
const cacheDir = await ensureCacheDir(rootDir);
|
|
444
461
|
return {
|
|
445
462
|
root: rootDir,
|
|
@@ -453,7 +470,7 @@ async function createViteConfig(options) {
|
|
|
453
470
|
rehypePlugins: [rehypeHighlight]
|
|
454
471
|
}),
|
|
455
472
|
react(),
|
|
456
|
-
pagesPlugin(rootDir),
|
|
473
|
+
pagesPlugin(rootDir, { include }),
|
|
457
474
|
entryPlugin(rootDir)
|
|
458
475
|
],
|
|
459
476
|
resolve: {
|
|
@@ -568,7 +585,8 @@ async function startDev(rootDir, options = {}) {
|
|
|
568
585
|
const config = await createViteConfig({
|
|
569
586
|
rootDir,
|
|
570
587
|
mode: "development",
|
|
571
|
-
port
|
|
588
|
+
port,
|
|
589
|
+
include: options.include
|
|
572
590
|
});
|
|
573
591
|
const server = await createServer2(config);
|
|
574
592
|
await server.listen();
|
|
@@ -577,14 +595,15 @@ async function startDev(rootDir, options = {}) {
|
|
|
577
595
|
printReady();
|
|
578
596
|
return server;
|
|
579
597
|
}
|
|
580
|
-
async function buildSite(rootDir) {
|
|
598
|
+
async function buildSite(rootDir, options = {}) {
|
|
581
599
|
console.log();
|
|
582
600
|
console.log(" ✨ prev build");
|
|
583
601
|
console.log();
|
|
584
602
|
console.log(" Building your documentation site...");
|
|
585
603
|
const config = await createViteConfig({
|
|
586
604
|
rootDir,
|
|
587
|
-
mode: "production"
|
|
605
|
+
mode: "production",
|
|
606
|
+
include: options.include
|
|
588
607
|
});
|
|
589
608
|
await build(config);
|
|
590
609
|
console.log();
|
|
@@ -597,7 +616,8 @@ async function previewSite(rootDir, options = {}) {
|
|
|
597
616
|
const config = await createViteConfig({
|
|
598
617
|
rootDir,
|
|
599
618
|
mode: "production",
|
|
600
|
-
port
|
|
619
|
+
port,
|
|
620
|
+
include: options.include
|
|
601
621
|
});
|
|
602
622
|
const server = await preview(config);
|
|
603
623
|
printWelcome("preview");
|
|
@@ -615,6 +635,7 @@ var { values, positionals } = parseArgs({
|
|
|
615
635
|
port: { type: "string", short: "p" },
|
|
616
636
|
days: { type: "string", short: "d" },
|
|
617
637
|
cwd: { type: "string", short: "c" },
|
|
638
|
+
include: { type: "string", short: "i", multiple: true },
|
|
618
639
|
help: { type: "boolean", short: "h" }
|
|
619
640
|
},
|
|
620
641
|
allowPositionals: true
|
|
@@ -635,17 +656,19 @@ Commands:
|
|
|
635
656
|
clean Remove old cache directories
|
|
636
657
|
|
|
637
658
|
Options:
|
|
638
|
-
-c, --cwd <path>
|
|
639
|
-
-p, --port <port>
|
|
640
|
-
-
|
|
641
|
-
-
|
|
659
|
+
-c, --cwd <path> Set working directory
|
|
660
|
+
-p, --port <port> Specify port (dev/preview)
|
|
661
|
+
-i, --include <dir> Include dot-prefixed directory (can use multiple times)
|
|
662
|
+
-d, --days <days> Cache age threshold for clean (default: 30)
|
|
663
|
+
-h, --help Show this help message
|
|
642
664
|
|
|
643
665
|
Examples:
|
|
644
|
-
prev
|
|
645
|
-
prev dev -p 3000
|
|
646
|
-
prev build
|
|
647
|
-
prev
|
|
648
|
-
prev
|
|
666
|
+
prev Start dev server on random port
|
|
667
|
+
prev dev -p 3000 Start dev server on port 3000
|
|
668
|
+
prev build Build static site to ./dist
|
|
669
|
+
prev dev -i .c3 Include .c3 directory in docs
|
|
670
|
+
prev dev -i .c3 -i .notes Include multiple dot directories
|
|
671
|
+
prev clean -d 7 Remove caches older than 7 days
|
|
649
672
|
`);
|
|
650
673
|
}
|
|
651
674
|
async function main() {
|
|
@@ -655,16 +678,17 @@ async function main() {
|
|
|
655
678
|
}
|
|
656
679
|
const port = values.port ? parseInt(values.port, 10) : undefined;
|
|
657
680
|
const days = values.days ? parseInt(values.days, 10) : 30;
|
|
681
|
+
const include = values.include || [];
|
|
658
682
|
try {
|
|
659
683
|
switch (command) {
|
|
660
684
|
case "dev":
|
|
661
|
-
await startDev(rootDir, { port });
|
|
685
|
+
await startDev(rootDir, { port, include });
|
|
662
686
|
break;
|
|
663
687
|
case "build":
|
|
664
|
-
await buildSite(rootDir);
|
|
688
|
+
await buildSite(rootDir, { include });
|
|
665
689
|
break;
|
|
666
690
|
case "preview":
|
|
667
|
-
await previewSite(rootDir, { port });
|
|
691
|
+
await previewSite(rootDir, { port, include });
|
|
668
692
|
break;
|
|
669
693
|
case "clean":
|
|
670
694
|
const removed = await cleanCache({ maxAgeDays: days });
|
package/dist/vite/config.d.ts
CHANGED
package/dist/vite/pages.d.ts
CHANGED
|
@@ -23,5 +23,8 @@ export declare function parseFrontmatter(content: string): {
|
|
|
23
23
|
content: string;
|
|
24
24
|
};
|
|
25
25
|
export declare function fileToRoute(file: string): string;
|
|
26
|
-
export
|
|
26
|
+
export interface ScanOptions {
|
|
27
|
+
include?: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare function scanPages(rootDir: string, options?: ScanOptions): Promise<Page[]>;
|
|
27
30
|
export declare function buildSidebarTree(pages: Page[]): SidebarItem[];
|
package/dist/vite/start.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export interface DevOptions {
|
|
2
2
|
port?: number;
|
|
3
|
+
include?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface BuildOptions {
|
|
6
|
+
include?: string[];
|
|
3
7
|
}
|
|
4
8
|
export declare function startDev(rootDir: string, options?: DevOptions): Promise<import("vite").ViteDevServer>;
|
|
5
|
-
export declare function buildSite(rootDir: string): Promise<void>;
|
|
9
|
+
export declare function buildSite(rootDir: string, options?: BuildOptions): Promise<void>;
|
|
6
10
|
export declare function previewSite(rootDir: string, options?: DevOptions): Promise<import("vite").PreviewServer>;
|