@slidev-react/node 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 +21 -0
- package/README.md +21 -0
- package/dist/build.d.mts +10 -0
- package/dist/build.mjs +28 -0
- package/dist/cli/buildArgs.mjs +78 -0
- package/dist/cli/devArgs.mjs +74 -0
- package/dist/cli/exportArgs.mjs +87 -0
- package/dist/cli/lintArgs.mjs +32 -0
- package/dist/cli/readOptionValue.mjs +16 -0
- package/dist/context.d.mts +11 -0
- package/dist/context.mjs +37 -0
- package/dist/dev.d.mts +13 -0
- package/dist/dev.mjs +61 -0
- package/dist/export.d.mts +11 -0
- package/dist/export.mjs +67 -0
- package/dist/exportBrowser.d.mts +8 -0
- package/dist/exportBrowser.mjs +123 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/lint.d.mts +15 -0
- package/dist/lint.mjs +36 -0
- package/dist/slides/build/createSlidesViteConfig.d.mts +9 -0
- package/dist/slides/build/createSlidesViteConfig.mjs +25 -0
- package/dist/slides/build/generateCompiledSlides.mjs +264 -0
- package/dist/slides/build/slidesSourceFile.mjs +9 -0
- package/dist/slides/compiling/mdx-options.mjs +18 -0
- package/dist/slides/compiling/rehypeShikiVitesse.mjs +93 -0
- package/dist/slides/mdx/remarkDiagramComponents.mjs +38 -0
- package/dist/slides/parsing/frontmatter.mjs +29 -0
- package/dist/slides/parsing/parseSlides.mjs +159 -0
- package/dist/slides/validation/validateSlidesAuthoring.mjs +93 -0
- package/package.json +57 -0
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,21 @@
|
|
|
1
|
+
# `@slidev-react/node`
|
|
2
|
+
|
|
3
|
+
`@slidev-react/node` 提供 `slidev-react` 的 Node 侧命令 API。
|
|
4
|
+
|
|
5
|
+
当前导出分两层:
|
|
6
|
+
|
|
7
|
+
高层命令 API:
|
|
8
|
+
|
|
9
|
+
- `runSlidesDev`
|
|
10
|
+
- `runSlidesBuild`
|
|
11
|
+
- `runSlidesExport`
|
|
12
|
+
- `runSlidesLint`
|
|
13
|
+
|
|
14
|
+
更底层的 programmatic API:
|
|
15
|
+
|
|
16
|
+
- `startSlidesDevServer`
|
|
17
|
+
- `buildSlidesApp`
|
|
18
|
+
- `exportSlidesArtifacts`
|
|
19
|
+
- `lintSlides`
|
|
20
|
+
|
|
21
|
+
这一层的目标是把 CLI 和根仓库脚本解耦,同时把 slides authoring/build 生命周期沉到可复用的 Node 侧能力。
|
package/dist/build.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommandResult, SlidesCommandOptions } from "./context.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/build.d.ts
|
|
4
|
+
interface BuildSlidesOptions extends SlidesCommandOptions {
|
|
5
|
+
viteArgs?: string[];
|
|
6
|
+
}
|
|
7
|
+
declare function buildSlidesApp(options?: BuildSlidesOptions): Promise<void>;
|
|
8
|
+
declare function runSlidesBuild(options?: BuildSlidesOptions): Promise<CommandResult>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { buildSlidesApp, runSlidesBuild };
|
package/dist/build.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createSuccessResult, resolveSlidesCommandContext } from "./context.mjs";
|
|
2
|
+
import { parseBuildArgs } from "./cli/buildArgs.mjs";
|
|
3
|
+
import { createSlidesViteConfig } from "./slides/build/createSlidesViteConfig.mjs";
|
|
4
|
+
import { build, mergeConfig } from "vite";
|
|
5
|
+
//#region src/build.ts
|
|
6
|
+
async function buildSlidesApp(options = {}) {
|
|
7
|
+
const parsedArgs = parseBuildArgs(options.viteArgs ?? []);
|
|
8
|
+
await build(mergeConfig(createSlidesViteConfig(resolveSlidesCommandContext({
|
|
9
|
+
...options,
|
|
10
|
+
slidesFile: options.slidesFile ?? parsedArgs.slidesFile
|
|
11
|
+
})), {
|
|
12
|
+
configFile: false,
|
|
13
|
+
mode: parsedArgs.mode,
|
|
14
|
+
base: parsedArgs.base,
|
|
15
|
+
build: {
|
|
16
|
+
outDir: parsedArgs.outDir,
|
|
17
|
+
emptyOutDir: parsedArgs.emptyOutDir,
|
|
18
|
+
sourcemap: parsedArgs.sourcemap,
|
|
19
|
+
minify: parsedArgs.minify
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
async function runSlidesBuild(options = {}) {
|
|
24
|
+
await buildSlidesApp(options);
|
|
25
|
+
return createSuccessResult();
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { buildSlidesApp, runSlidesBuild };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { parseBooleanFlag } from "../context.mjs";
|
|
2
|
+
import { readOptionValue } from "./readOptionValue.mjs";
|
|
3
|
+
//#region src/cli/buildArgs.ts
|
|
4
|
+
function parseBuildArgs(argv) {
|
|
5
|
+
let slidesFile;
|
|
6
|
+
let outDir;
|
|
7
|
+
let base;
|
|
8
|
+
let mode;
|
|
9
|
+
let emptyOutDir;
|
|
10
|
+
let sourcemap;
|
|
11
|
+
let minify;
|
|
12
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
13
|
+
const entry = argv[index];
|
|
14
|
+
if (!entry.startsWith("--")) {
|
|
15
|
+
if (!slidesFile) {
|
|
16
|
+
slidesFile = entry;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Unknown build argument "${entry}".`);
|
|
20
|
+
}
|
|
21
|
+
if (entry === "--emptyOutDir") {
|
|
22
|
+
emptyOutDir = true;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (entry === "--sourcemap") {
|
|
26
|
+
sourcemap = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (entry === "--minify") {
|
|
30
|
+
minify = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (entry === "--outDir" || entry.startsWith("--outDir=")) {
|
|
34
|
+
const result = readOptionValue(argv, index, "--outDir");
|
|
35
|
+
outDir = result.value;
|
|
36
|
+
index = result.nextIndex;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (entry === "--base" || entry.startsWith("--base=")) {
|
|
40
|
+
const result = readOptionValue(argv, index, "--base");
|
|
41
|
+
base = result.value;
|
|
42
|
+
index = result.nextIndex;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (entry === "--mode" || entry.startsWith("--mode=")) {
|
|
46
|
+
const result = readOptionValue(argv, index, "--mode");
|
|
47
|
+
mode = result.value;
|
|
48
|
+
index = result.nextIndex;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (entry.startsWith("--emptyOutDir=")) {
|
|
52
|
+
emptyOutDir = parseBooleanFlag(entry.slice(14));
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (entry.startsWith("--sourcemap=")) {
|
|
56
|
+
const value = entry.slice(12);
|
|
57
|
+
sourcemap = value === "inline" || value === "hidden" ? value : parseBooleanFlag(value);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (entry.startsWith("--minify=")) {
|
|
61
|
+
const value = entry.slice(9);
|
|
62
|
+
minify = value === "esbuild" || value === "terser" ? value : parseBooleanFlag(value);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Unknown build option "${entry}".`);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
slidesFile,
|
|
69
|
+
outDir,
|
|
70
|
+
base,
|
|
71
|
+
mode,
|
|
72
|
+
emptyOutDir,
|
|
73
|
+
sourcemap,
|
|
74
|
+
minify
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { parseBuildArgs };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { parseBooleanFlag, parsePositiveIntegerOption } from "../context.mjs";
|
|
2
|
+
import { readOptionValue } from "./readOptionValue.mjs";
|
|
3
|
+
//#region src/cli/devArgs.ts
|
|
4
|
+
function parseDevArgs(argv) {
|
|
5
|
+
let slidesFile;
|
|
6
|
+
let host;
|
|
7
|
+
let port;
|
|
8
|
+
let open;
|
|
9
|
+
let strictPort;
|
|
10
|
+
let base;
|
|
11
|
+
let mode;
|
|
12
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
13
|
+
const entry = argv[index];
|
|
14
|
+
if (!entry.startsWith("--")) {
|
|
15
|
+
if (!slidesFile) {
|
|
16
|
+
slidesFile = entry;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Unknown dev argument "${entry}".`);
|
|
20
|
+
}
|
|
21
|
+
if (entry === "--open") {
|
|
22
|
+
open = true;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (entry === "--strictPort") {
|
|
26
|
+
strictPort = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (entry === "--host" || entry.startsWith("--host=")) {
|
|
30
|
+
const result = readOptionValue(argv, index, "--host");
|
|
31
|
+
host = result.value;
|
|
32
|
+
index = result.nextIndex;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (entry === "--port" || entry.startsWith("--port=")) {
|
|
36
|
+
const result = readOptionValue(argv, index, "--port");
|
|
37
|
+
port = parsePositiveIntegerOption("--port", result.value);
|
|
38
|
+
index = result.nextIndex;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (entry === "--base" || entry.startsWith("--base=")) {
|
|
42
|
+
const result = readOptionValue(argv, index, "--base");
|
|
43
|
+
base = result.value;
|
|
44
|
+
index = result.nextIndex;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (entry === "--mode" || entry.startsWith("--mode=")) {
|
|
48
|
+
const result = readOptionValue(argv, index, "--mode");
|
|
49
|
+
mode = result.value;
|
|
50
|
+
index = result.nextIndex;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (entry === "--open=false" || entry === "--open=true") {
|
|
54
|
+
open = parseBooleanFlag(entry.slice(7));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (entry === "--strictPort=false" || entry === "--strictPort=true") {
|
|
58
|
+
strictPort = parseBooleanFlag(entry.slice(13));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Unknown dev option "${entry}".`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
slidesFile,
|
|
65
|
+
host,
|
|
66
|
+
port,
|
|
67
|
+
open,
|
|
68
|
+
strictPort,
|
|
69
|
+
base,
|
|
70
|
+
mode
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { parseDevArgs };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { parsePositiveIntegerOption } from "../context.mjs";
|
|
2
|
+
import { readOptionValue } from "./readOptionValue.mjs";
|
|
3
|
+
import { parseSlideSelection } from "@slidev-react/core/presentation/export/selection";
|
|
4
|
+
//#region src/cli/exportArgs.ts
|
|
5
|
+
const DEFAULT_HOST = "127.0.0.1";
|
|
6
|
+
const DEFAULT_PORT = 4173;
|
|
7
|
+
const DEFAULT_OUTPUT_DIR = "output/export";
|
|
8
|
+
function parseExportArgs(argv) {
|
|
9
|
+
let slidesFile;
|
|
10
|
+
let format = "all";
|
|
11
|
+
let host = DEFAULT_HOST;
|
|
12
|
+
let port = DEFAULT_PORT;
|
|
13
|
+
let baseUrl;
|
|
14
|
+
let withClicks = false;
|
|
15
|
+
let outputDir = DEFAULT_OUTPUT_DIR;
|
|
16
|
+
let slideSelection = parseSlideSelection(void 0);
|
|
17
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
18
|
+
const entry = argv[index];
|
|
19
|
+
if (!entry.startsWith("--")) {
|
|
20
|
+
if (!slidesFile) {
|
|
21
|
+
slidesFile = entry;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`Unknown export argument "${entry}".`);
|
|
25
|
+
}
|
|
26
|
+
if (entry === "--with-clicks") {
|
|
27
|
+
withClicks = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (entry === "--file" || entry.startsWith("--file=")) {
|
|
31
|
+
const result = readOptionValue(argv, index, "--file");
|
|
32
|
+
slidesFile = result.value;
|
|
33
|
+
index = result.nextIndex;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (entry === "--format" || entry.startsWith("--format=")) {
|
|
37
|
+
const result = readOptionValue(argv, index, "--format");
|
|
38
|
+
if (result.value === "pdf" || result.value === "png" || result.value === "all") format = result.value;
|
|
39
|
+
else throw new Error(`Unknown export format "${result.value}".`);
|
|
40
|
+
index = result.nextIndex;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (entry === "--host" || entry.startsWith("--host=")) {
|
|
44
|
+
const result = readOptionValue(argv, index, "--host");
|
|
45
|
+
host = result.value;
|
|
46
|
+
index = result.nextIndex;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (entry === "--port" || entry.startsWith("--port=")) {
|
|
50
|
+
const result = readOptionValue(argv, index, "--port");
|
|
51
|
+
port = parsePositiveIntegerOption("--port", result.value);
|
|
52
|
+
index = result.nextIndex;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (entry === "--base-url" || entry.startsWith("--base-url=")) {
|
|
56
|
+
const result = readOptionValue(argv, index, "--base-url");
|
|
57
|
+
baseUrl = result.value;
|
|
58
|
+
index = result.nextIndex;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (entry === "--output" || entry.startsWith("--output=")) {
|
|
62
|
+
const result = readOptionValue(argv, index, "--output");
|
|
63
|
+
outputDir = result.value;
|
|
64
|
+
index = result.nextIndex;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (entry === "--slides" || entry.startsWith("--slides=")) {
|
|
68
|
+
const result = readOptionValue(argv, index, "--slides");
|
|
69
|
+
slideSelection = parseSlideSelection(result.value);
|
|
70
|
+
index = result.nextIndex;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
throw new Error(`Unknown export option "${entry}".`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
slidesFile,
|
|
77
|
+
format,
|
|
78
|
+
host,
|
|
79
|
+
port,
|
|
80
|
+
baseUrl: baseUrl || `http://${host}:${port}`,
|
|
81
|
+
withClicks,
|
|
82
|
+
outputDir,
|
|
83
|
+
slideSelection
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { parseExportArgs };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/cli/lintArgs.ts
|
|
2
|
+
function parseLintArgs(argv) {
|
|
3
|
+
let slidesFile;
|
|
4
|
+
let strict = false;
|
|
5
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
6
|
+
const entry = argv[index];
|
|
7
|
+
if (entry === "--strict") {
|
|
8
|
+
strict = true;
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (entry === "--file" && argv[index + 1]) {
|
|
12
|
+
slidesFile = argv[index + 1];
|
|
13
|
+
index += 1;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (entry.startsWith("--file=")) {
|
|
17
|
+
slidesFile = entry.slice(7);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!entry.startsWith("--")) {
|
|
21
|
+
slidesFile = entry;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`Unknown lint option "${entry}".`);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
slidesFile,
|
|
28
|
+
strict
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { parseLintArgs };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/cli/readOptionValue.ts
|
|
2
|
+
function readOptionValue(argv, index, optionName) {
|
|
3
|
+
const current = argv[index];
|
|
4
|
+
if (current.startsWith(`${optionName}=`)) return {
|
|
5
|
+
value: current.slice(optionName.length + 1),
|
|
6
|
+
nextIndex: index
|
|
7
|
+
};
|
|
8
|
+
const nextValue = argv[index + 1];
|
|
9
|
+
if (!nextValue || nextValue.startsWith("--")) throw new Error(`Missing value for ${optionName}.`);
|
|
10
|
+
return {
|
|
11
|
+
value: nextValue,
|
|
12
|
+
nextIndex: index + 1
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readOptionValue };
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { resolveSlidesSourceFile } from "./slides/build/slidesSourceFile.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/context.ts
|
|
4
|
+
function createSuccessResult() {
|
|
5
|
+
return {
|
|
6
|
+
code: 0,
|
|
7
|
+
signal: null
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function createFailureResult(code = 1) {
|
|
11
|
+
return {
|
|
12
|
+
code,
|
|
13
|
+
signal: null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function resolveSlidesCommandContext(options = {}) {
|
|
17
|
+
const appRoot = path.resolve(options.appRoot ?? process.cwd());
|
|
18
|
+
const slidesFile = options.slidesFile?.trim() || void 0;
|
|
19
|
+
return {
|
|
20
|
+
appRoot,
|
|
21
|
+
slidesFile,
|
|
22
|
+
slidesSourceFile: resolveSlidesSourceFile(appRoot, slidesFile)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseBooleanFlag(value, defaultValue = true) {
|
|
26
|
+
if (value == null || value === "") return defaultValue;
|
|
27
|
+
if (value === "true") return true;
|
|
28
|
+
if (value === "false") return false;
|
|
29
|
+
throw new Error(`Expected a boolean value, received "${value}".`);
|
|
30
|
+
}
|
|
31
|
+
function parsePositiveIntegerOption(name, value) {
|
|
32
|
+
const parsed = Number.parseInt(value, 10);
|
|
33
|
+
if (!Number.isFinite(parsed) || parsed <= 0) throw new Error(`Expected ${name} to be a positive integer, received "${value}".`);
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createFailureResult, createSuccessResult, parseBooleanFlag, parsePositiveIntegerOption, resolveSlidesCommandContext };
|
package/dist/dev.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CommandResult, SlidesCommandOptions } from "./context.mjs";
|
|
2
|
+
import { ViteDevServer } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/dev.d.ts
|
|
5
|
+
interface DevSlidesOptions extends SlidesCommandOptions {
|
|
6
|
+
viteArgs?: string[];
|
|
7
|
+
printUrls?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function startSlidesDevServer(options?: DevSlidesOptions): Promise<ViteDevServer>;
|
|
10
|
+
declare function runSlidesDev(options?: DevSlidesOptions): Promise<CommandResult>;
|
|
11
|
+
declare function stopSlidesDevServer(server: ViteDevServer): Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { runSlidesDev, startSlidesDevServer, stopSlidesDevServer };
|
package/dist/dev.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolveSlidesCommandContext } from "./context.mjs";
|
|
2
|
+
import { createSlidesViteConfig } from "./slides/build/createSlidesViteConfig.mjs";
|
|
3
|
+
import { parseDevArgs } from "./cli/devArgs.mjs";
|
|
4
|
+
import { createServer, mergeConfig } from "vite";
|
|
5
|
+
//#region src/dev.ts
|
|
6
|
+
async function startSlidesDevServer(options = {}) {
|
|
7
|
+
const parsedArgs = parseDevArgs(options.viteArgs ?? []);
|
|
8
|
+
const server = await createServer(mergeConfig(createSlidesViteConfig(resolveSlidesCommandContext({
|
|
9
|
+
...options,
|
|
10
|
+
slidesFile: options.slidesFile ?? parsedArgs.slidesFile
|
|
11
|
+
})), {
|
|
12
|
+
configFile: false,
|
|
13
|
+
clearScreen: false,
|
|
14
|
+
mode: parsedArgs.mode,
|
|
15
|
+
base: parsedArgs.base,
|
|
16
|
+
server: {
|
|
17
|
+
host: parsedArgs.host,
|
|
18
|
+
port: parsedArgs.port,
|
|
19
|
+
open: parsedArgs.open,
|
|
20
|
+
strictPort: parsedArgs.strictPort
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
await server.listen();
|
|
24
|
+
if (options.printUrls !== false) server.printUrls();
|
|
25
|
+
return server;
|
|
26
|
+
}
|
|
27
|
+
function waitForServerShutdown(server) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let settled = false;
|
|
30
|
+
const signalHandlers = /* @__PURE__ */ new Map();
|
|
31
|
+
const cleanup = async (signal) => {
|
|
32
|
+
if (settled) return;
|
|
33
|
+
settled = true;
|
|
34
|
+
for (const [eventName, handler] of signalHandlers) process.off(eventName, handler);
|
|
35
|
+
try {
|
|
36
|
+
await server.close();
|
|
37
|
+
resolve({
|
|
38
|
+
code: 0,
|
|
39
|
+
signal
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
reject(error);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
46
|
+
const handler = () => {
|
|
47
|
+
cleanup(signal);
|
|
48
|
+
};
|
|
49
|
+
signalHandlers.set(signal, handler);
|
|
50
|
+
process.on(signal, handler);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function runSlidesDev(options = {}) {
|
|
55
|
+
return waitForServerShutdown(await startSlidesDevServer(options));
|
|
56
|
+
}
|
|
57
|
+
async function stopSlidesDevServer(server) {
|
|
58
|
+
await server.close();
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { runSlidesDev, startSlidesDevServer, stopSlidesDevServer };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommandResult, SlidesCommandOptions } from "./context.mjs";
|
|
2
|
+
import { ExportSlidesArtifactsResult } from "./exportBrowser.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/export.d.ts
|
|
5
|
+
interface ExportSlidesOptions extends SlidesCommandOptions {
|
|
6
|
+
cliArgs?: string[];
|
|
7
|
+
}
|
|
8
|
+
declare function exportSlidesArtifacts(options?: ExportSlidesOptions): Promise<ExportSlidesArtifactsResult>;
|
|
9
|
+
declare function runSlidesExport(options?: ExportSlidesOptions): Promise<CommandResult>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { exportSlidesArtifacts, runSlidesExport };
|
package/dist/export.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createSuccessResult } from "./context.mjs";
|
|
2
|
+
import { parseExportArgs } from "./cli/exportArgs.mjs";
|
|
3
|
+
import { startSlidesDevServer, stopSlidesDevServer } from "./dev.mjs";
|
|
4
|
+
import { exportSlidesInBrowser } from "./exportBrowser.mjs";
|
|
5
|
+
import { setTimeout } from "node:timers/promises";
|
|
6
|
+
import { buildPrintExportUrl } from "@slidev-react/core/presentation/export/urls";
|
|
7
|
+
//#region src/export.ts
|
|
8
|
+
const DEV_SERVER_TIMEOUT_MS = 12e4;
|
|
9
|
+
async function isServerReachable(baseUrl) {
|
|
10
|
+
try {
|
|
11
|
+
return (await fetch(baseUrl, { signal: AbortSignal.timeout(2e3) })).ok;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function waitForServer(baseUrl, timeoutMs) {
|
|
17
|
+
const startedAt = Date.now();
|
|
18
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
19
|
+
if (await isServerReachable(baseUrl)) return;
|
|
20
|
+
await setTimeout(500);
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Timed out waiting for ${baseUrl}`);
|
|
23
|
+
}
|
|
24
|
+
async function exportSlidesArtifacts(options = {}) {
|
|
25
|
+
const parsedArgs = parseExportArgs(options.cliArgs ?? []);
|
|
26
|
+
const exportOptions = {
|
|
27
|
+
...parsedArgs,
|
|
28
|
+
slidesFile: options.slidesFile ?? parsedArgs.slidesFile
|
|
29
|
+
};
|
|
30
|
+
const printUrl = buildPrintExportUrl(exportOptions.baseUrl, { withClicks: exportOptions.withClicks });
|
|
31
|
+
const devServer = await isServerReachable(exportOptions.baseUrl) ? null : await startSlidesDevServer({
|
|
32
|
+
appRoot: options.appRoot,
|
|
33
|
+
slidesFile: exportOptions.slidesFile,
|
|
34
|
+
printUrls: false,
|
|
35
|
+
viteArgs: [
|
|
36
|
+
"--host",
|
|
37
|
+
exportOptions.host,
|
|
38
|
+
"--port",
|
|
39
|
+
String(exportOptions.port)
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
if (devServer) await waitForServer(exportOptions.baseUrl, DEV_SERVER_TIMEOUT_MS);
|
|
43
|
+
try {
|
|
44
|
+
return await exportSlidesInBrowser({
|
|
45
|
+
printUrl,
|
|
46
|
+
format: exportOptions.format,
|
|
47
|
+
outputDir: exportOptions.outputDir,
|
|
48
|
+
withClicks: exportOptions.withClicks,
|
|
49
|
+
slideSelection: exportOptions.slideSelection
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
if (/Executable doesn't exist|browserType\.launch/i.test(message)) throw new Error(`${message}\nRun \`pnpm run test:e2e:install\` first so Playwright can install Chromium.`);
|
|
54
|
+
throw error;
|
|
55
|
+
} finally {
|
|
56
|
+
if (devServer) await stopSlidesDevServer(devServer);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function runSlidesExport(options = {}) {
|
|
60
|
+
const result = await exportSlidesArtifacts(options);
|
|
61
|
+
console.log("[slide-react] export complete");
|
|
62
|
+
console.log(` slides: ${result.selectedSlides.join(", ")}${result.variantLabel ? ` (${result.variantLabel})` : ""}`);
|
|
63
|
+
for (const file of result.createdFiles) console.log(` - ${file}`);
|
|
64
|
+
return createSuccessResult();
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { exportSlidesArtifacts, runSlidesExport };
|