@slidev-react/cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 slidev-react contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # `@slidev-react/cli`
2
+
3
+ `@slidev-react/cli` 提供 `slidev-react` 命令行入口。
4
+
5
+ 当前已经完成两层收口:
6
+
7
+ - 用户入口统一成 `slidev-react`
8
+ - 命令实现收口到 `@slidev-react/node`
9
+
10
+ 当前命令:
11
+
12
+ - `slidev-react dev [file]`
13
+ - `slidev-react build [file]`
14
+ - `slidev-react export [file]`
15
+ - `slidev-react lint [file]`
16
+
17
+ 其中:
18
+
19
+ - `dev` / `build` 走程序化 Vite API
20
+ - `export` 会按需拉起临时 dev server 后再走 Playwright 导出
21
+ - `lint` 直接调用 slides parsing + authoring validation
22
+
23
+ 在当前仓库内做 dogfood 时,可以这样用:
24
+
25
+ ```bash
26
+ pnpm slidev-react -- dev
27
+ pnpm slidev-react -- build slides-ar-3-4.mdx
28
+ pnpm slidev-react -- export slides-ar-3-4.mdx --format png
29
+ pnpm slidev-react -- lint slides.mdx --strict
30
+ ```
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ import { Command, CommanderError } from "@commander-js/extra-typings";
3
+ import { runSlidesBuild, runSlidesDev, runSlidesExport, runSlidesLint } from "@slidev-react/node";
4
+ //#region bin/slidev-react.ts
5
+ const HELP_TEXT = `
6
+ Supported dev options:
7
+ --host, --port, --open, --strictPort, --base, --mode
8
+
9
+ Supported build options:
10
+ --outDir, --base, --mode, --emptyOutDir, --minify, --sourcemap
11
+
12
+ Examples:
13
+ slidev-react dev
14
+ slidev-react dev slides-ar-3-4.mdx --host 0.0.0.0 --port 5174
15
+ slidev-react build slides-ar-3-4.mdx
16
+ slidev-react export slides-ar-3-4.mdx --format png --slides 3-7
17
+ slidev-react lint slides-ar-3-4.mdx --strict
18
+ `;
19
+ function fail(message) {
20
+ console.error(`[slidev-react] ${message}`);
21
+ process.exit(1);
22
+ }
23
+ function parseCommandArgs(argv) {
24
+ const args = [...argv];
25
+ let slidesFile;
26
+ if (args[0] && !args[0].startsWith("-")) slidesFile = args.shift();
27
+ for (let index = 0; index < args.length; index += 1) {
28
+ const entry = args[index];
29
+ if (entry === "--file" && args[index + 1]) {
30
+ slidesFile = args[index + 1];
31
+ args.splice(index, 2);
32
+ index -= 1;
33
+ continue;
34
+ }
35
+ if (entry.startsWith("--file=")) {
36
+ slidesFile = entry.slice(7);
37
+ args.splice(index, 1);
38
+ index -= 1;
39
+ }
40
+ }
41
+ return {
42
+ slidesFile,
43
+ forwardedArgs: args
44
+ };
45
+ }
46
+ function exitWithCommandResult(result) {
47
+ if (result.signal) {
48
+ process.kill(process.pid, result.signal);
49
+ return;
50
+ }
51
+ process.exit(result.code);
52
+ }
53
+ async function runWithViteArgs(argv, runner) {
54
+ const { slidesFile, forwardedArgs } = parseCommandArgs(argv);
55
+ exitWithCommandResult(await runner({
56
+ appRoot: process.cwd(),
57
+ slidesFile,
58
+ viteArgs: forwardedArgs
59
+ }));
60
+ }
61
+ async function runWithCliArgs(argv, runner) {
62
+ const { slidesFile, forwardedArgs } = parseCommandArgs(argv);
63
+ exitWithCommandResult(await runner({
64
+ appRoot: process.cwd(),
65
+ slidesFile,
66
+ cliArgs: forwardedArgs
67
+ }));
68
+ }
69
+ function createPassThroughCommand(program, name, description, runner) {
70
+ program.command(name).description(description).argument("[file]").allowUnknownOption(true).allowExcessArguments(true).action(async (_file, _options, command) => {
71
+ await runner(command.args);
72
+ });
73
+ }
74
+ const program = new Command().name("slidev-react").description("CLI entrypoint for slidev-react authoring and build workflows").usage("<command> [file] [options...]").showHelpAfterError().showSuggestionAfterError().addHelpText("after", HELP_TEXT).exitOverride();
75
+ createPassThroughCommand(program, "dev", "Start the Vite dev server for a slides source file", (argv) => runWithViteArgs(argv, runSlidesDev));
76
+ createPassThroughCommand(program, "build", "Build the current slides app for production", (argv) => runWithViteArgs(argv, runSlidesBuild));
77
+ createPassThroughCommand(program, "export", "Export PDF / PNG artifacts through Playwright", (argv) => runWithCliArgs(argv, runSlidesExport));
78
+ createPassThroughCommand(program, "lint", "Validate slides authoring warnings", (argv) => runWithCliArgs(argv, runSlidesLint));
79
+ try {
80
+ await program.parseAsync(process.argv);
81
+ } catch (error) {
82
+ if (error instanceof CommanderError) {
83
+ if (error.code === "commander.helpDisplayed") process.exit(0);
84
+ process.exit(error.exitCode);
85
+ }
86
+ fail(error instanceof Error ? error.message : String(error));
87
+ }
88
+ //#endregion
89
+ export {};
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@slidev-react/cli",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "CLI entrypoint for slidev-react authoring and build workflows",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "bin": {
12
+ "slidev-react": "./dist/bin/slidev-react.mjs"
13
+ },
14
+ "type": "module",
15
+ "dependencies": {
16
+ "@commander-js/extra-typings": "^14.0.0",
17
+ "commander": "^14.0.3",
18
+ "@slidev-react/node": "0.1.0"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+ssh://git@github.com/hylarucoder/slidev-react.git",
26
+ "directory": "packages/cli"
27
+ },
28
+ "homepage": "https://github.com/hylarucoder/slidev-react/tree/main/packages/cli",
29
+ "bugs": {
30
+ "url": "https://github.com/hylarucoder/slidev-react/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=22"
34
+ },
35
+ "scripts": {
36
+ "build:pkg": "pnpm exec tsdown",
37
+ "dev:pkg": "pnpm exec tsdown --watch"
38
+ }
39
+ }