@slidev/cli 0.48.0-beta.2 → 0.48.0-beta.20
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/{build-BVDM4ZAC.mjs → build-5AFXNUEB.mjs} +5 -41
- package/dist/chunk-CV7OWJOF.mjs +185 -0
- package/dist/chunk-KNY3KC45.mjs +151 -0
- package/dist/{chunk-FIXL4WBO.mjs → chunk-O56CS6WQ.mjs} +1653 -1461
- package/dist/{chunk-CTBVOVLQ.mjs → chunk-O6TYYGU6.mjs} +4 -16
- package/dist/cli.mjs +73 -74
- package/dist/{export-MLH55TH5.mjs → export-65BQ7S5F.mjs} +20 -13
- package/dist/index.d.mts +21 -25
- package/dist/index.mjs +4 -19
- package/dist/{unocss-6IVIFJMZ.mjs → unocss-M5KPNI4Z.mjs} +3 -4
- package/package.json +18 -18
- package/template.md +133 -26
- package/dist/chunk-BXO7ZPPU.mjs +0 -30
- package/dist/chunk-DWXI5WEO.mjs +0 -72
- package/dist/chunk-PDMXU2K7.mjs +0 -8135
|
@@ -2,19 +2,17 @@ import {
|
|
|
2
2
|
ViteSlidevPlugin,
|
|
3
3
|
getIndexHtml,
|
|
4
4
|
mergeViteConfigs
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-BXO7ZPPU.mjs";
|
|
5
|
+
} from "./chunk-O56CS6WQ.mjs";
|
|
6
|
+
import "./chunk-O6TYYGU6.mjs";
|
|
7
|
+
import "./chunk-CV7OWJOF.mjs";
|
|
9
8
|
|
|
10
9
|
// node/build.ts
|
|
11
|
-
import {
|
|
10
|
+
import { resolve } from "node:path";
|
|
12
11
|
import http from "node:http";
|
|
13
12
|
import fs from "fs-extra";
|
|
14
13
|
import { mergeConfig, build as viteBuild } from "vite";
|
|
15
14
|
import connect from "connect";
|
|
16
15
|
import sirv from "sirv";
|
|
17
|
-
import { blue, yellow } from "kolorist";
|
|
18
16
|
async function build(options, viteConfig = {}, args) {
|
|
19
17
|
const indexPath = resolve(options.userRoot, "index.html");
|
|
20
18
|
let originalIndexHTML;
|
|
@@ -51,40 +49,6 @@ async function build(options, viteConfig = {}, args) {
|
|
|
51
49
|
}
|
|
52
50
|
);
|
|
53
51
|
await viteBuild(inlineConfig);
|
|
54
|
-
if (options.data.features.monaco) {
|
|
55
|
-
if (options.data.config.monaco === "dev") {
|
|
56
|
-
console.log(yellow(" Monaco is disabled in the build, to enabled it, set `monaco: true` in the frontmatter"));
|
|
57
|
-
} else {
|
|
58
|
-
console.log(blue(" building for Monaco...\n"));
|
|
59
|
-
await viteBuild(
|
|
60
|
-
await mergeViteConfigs(
|
|
61
|
-
options,
|
|
62
|
-
inlineConfig,
|
|
63
|
-
{
|
|
64
|
-
root: join(options.clientRoot, "iframes/monaco"),
|
|
65
|
-
base: `${config.base}iframes/monaco/`,
|
|
66
|
-
build: {
|
|
67
|
-
outDir: resolve(config.build.outDir, "iframes/monaco"),
|
|
68
|
-
// fix for monaco workers
|
|
69
|
-
// https://github.com/vitejs/vite/issues/1927#issuecomment-805803918
|
|
70
|
-
rollupOptions: {
|
|
71
|
-
output: {
|
|
72
|
-
manualChunks: {
|
|
73
|
-
jsonWorker: ["monaco-editor/esm/vs/language/json/json.worker"],
|
|
74
|
-
cssWorker: ["monaco-editor/esm/vs/language/css/css.worker"],
|
|
75
|
-
htmlWorker: ["monaco-editor/esm/vs/language/html/html.worker"],
|
|
76
|
-
tsWorker: ["monaco-editor/esm/vs/language/typescript/ts.worker"],
|
|
77
|
-
editorWorker: ["monaco-editor/esm/vs/editor/editor.worker"]
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"build"
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
52
|
} finally {
|
|
89
53
|
if (originalIndexHTML != null)
|
|
90
54
|
await fs.writeFile(indexPath, originalIndexHTML, "utf-8");
|
|
@@ -98,7 +62,7 @@ async function build(options, viteConfig = {}, args) {
|
|
|
98
62
|
await fs.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200
|
|
99
63
|
`, "utf-8");
|
|
100
64
|
if ([true, "true", "auto"].includes(options.data.config.download)) {
|
|
101
|
-
const { exportSlides, getExportOptions } = await import("./export-
|
|
65
|
+
const { exportSlides, getExportOptions } = await import("./export-65BQ7S5F.mjs");
|
|
102
66
|
const port = 12445;
|
|
103
67
|
const app = connect();
|
|
104
68
|
const server = http.createServer(app);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// node/resolver.ts
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { ensurePrefix, slash } from "@antfu/utils";
|
|
7
|
+
import isInstalledGlobally from "is-installed-globally";
|
|
8
|
+
import { resolveGlobal } from "resolve-global";
|
|
9
|
+
import { findClosestPkgJsonPath, findDepPkgJsonPath } from "vitefu";
|
|
10
|
+
import { resolvePath } from "mlly";
|
|
11
|
+
import globalDirs from "global-directory";
|
|
12
|
+
import prompts from "prompts";
|
|
13
|
+
import { parseNi, run } from "@antfu/ni";
|
|
14
|
+
import { underline, yellow } from "kolorist";
|
|
15
|
+
function toAtFS(path) {
|
|
16
|
+
return `/@fs${ensurePrefix("/", slash(path))}`;
|
|
17
|
+
}
|
|
18
|
+
async function resolveImportPath(importName, ensure = false) {
|
|
19
|
+
try {
|
|
20
|
+
return await resolvePath(importName, {
|
|
21
|
+
url: import.meta.url
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
if (isInstalledGlobally) {
|
|
26
|
+
try {
|
|
27
|
+
return resolveGlobal(importName);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (ensure)
|
|
32
|
+
throw new Error(`Failed to resolve package "${importName}"`);
|
|
33
|
+
}
|
|
34
|
+
async function findPkgRoot(dep, parent, ensure = false) {
|
|
35
|
+
const pkgJsonPath = await findDepPkgJsonPath(dep, parent);
|
|
36
|
+
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally ? findGlobalPkgRoot(dep, false) : void 0;
|
|
37
|
+
if (ensure && !path)
|
|
38
|
+
throw new Error(`Failed to resolve package "${dep}"`);
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
async function findGlobalPkgRoot(name, ensure = false) {
|
|
42
|
+
const yarnPath = join(globalDirs.yarn.packages, name);
|
|
43
|
+
if (fs.existsSync(`${yarnPath}/package.json`))
|
|
44
|
+
return yarnPath;
|
|
45
|
+
const npmPath = join(globalDirs.npm.packages, name);
|
|
46
|
+
if (fs.existsSync(`${npmPath}/package.json`))
|
|
47
|
+
return npmPath;
|
|
48
|
+
if (ensure)
|
|
49
|
+
throw new Error(`Failed to resolve global package "${name}"`);
|
|
50
|
+
}
|
|
51
|
+
async function resolveEntry(entryRaw, roots) {
|
|
52
|
+
if (!fs.existsSync(entryRaw) && !entryRaw.endsWith(".md") && !/\/\\/.test(entryRaw))
|
|
53
|
+
entryRaw += ".md";
|
|
54
|
+
const entry = entryRaw.startsWith("@/") ? join(roots.userRoot, entryRaw.slice(2)) : resolve(process.cwd(), entryRaw);
|
|
55
|
+
if (!fs.existsSync(entry)) {
|
|
56
|
+
const { create } = await prompts({
|
|
57
|
+
name: "create",
|
|
58
|
+
type: "confirm",
|
|
59
|
+
initial: "Y",
|
|
60
|
+
message: `Entry file ${yellow(`"${entry}"`)} does not exist, do you want to create it?`
|
|
61
|
+
});
|
|
62
|
+
if (create)
|
|
63
|
+
fs.copyFileSync(resolve(roots.cliRoot, "template.md"), entry);
|
|
64
|
+
else
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
return entry;
|
|
68
|
+
}
|
|
69
|
+
function createResolver(type, officials) {
|
|
70
|
+
async function promptForInstallation(pkgName) {
|
|
71
|
+
const { confirm } = await prompts({
|
|
72
|
+
name: "confirm",
|
|
73
|
+
initial: "Y",
|
|
74
|
+
type: "confirm",
|
|
75
|
+
message: `The ${type} "${pkgName}" was not found ${underline(isInstalledGlobally ? "globally" : "in your project")}, do you want to install it now?`
|
|
76
|
+
});
|
|
77
|
+
if (!confirm)
|
|
78
|
+
process.exit(1);
|
|
79
|
+
if (isInstalledGlobally)
|
|
80
|
+
await run(parseNi, ["-g", pkgName]);
|
|
81
|
+
else
|
|
82
|
+
await run(parseNi, [pkgName]);
|
|
83
|
+
}
|
|
84
|
+
return async function(name, importer) {
|
|
85
|
+
const { userRoot } = await getRoots();
|
|
86
|
+
if (name === "none")
|
|
87
|
+
return ["", null];
|
|
88
|
+
if (name[0] === "/")
|
|
89
|
+
return [name, name];
|
|
90
|
+
if (name.startsWith("@/"))
|
|
91
|
+
return [name, join(userRoot, name.slice(2))];
|
|
92
|
+
if (name[0] === "." || name[0] !== "@" && name.includes("/"))
|
|
93
|
+
return [name, join(dirname(importer), name)];
|
|
94
|
+
if (name.startsWith(`@slidev/${type}-`) || name.startsWith(`slidev-${type}-`)) {
|
|
95
|
+
const pkgRoot = await findPkgRoot(name, importer);
|
|
96
|
+
if (!pkgRoot)
|
|
97
|
+
await promptForInstallation(name);
|
|
98
|
+
return [name, await findPkgRoot(name, importer, true)];
|
|
99
|
+
}
|
|
100
|
+
{
|
|
101
|
+
const possiblePkgNames = [
|
|
102
|
+
`@slidev/${type}-${name}`,
|
|
103
|
+
`slidev-${type}-${name}`,
|
|
104
|
+
name
|
|
105
|
+
];
|
|
106
|
+
for (const pkgName2 of possiblePkgNames) {
|
|
107
|
+
const pkgRoot = await findPkgRoot(pkgName2, importer);
|
|
108
|
+
if (pkgRoot)
|
|
109
|
+
return [pkgName2, pkgRoot];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const pkgName = officials[name] ?? (name[0] === "@" ? name : `slidev-${type}-${name}`);
|
|
113
|
+
await promptForInstallation(pkgName);
|
|
114
|
+
return [pkgName, await findPkgRoot(pkgName, importer, true)];
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function getUserRoot() {
|
|
118
|
+
const pkgJsonPath = await findClosestPkgJsonPath(process.cwd());
|
|
119
|
+
return pkgJsonPath ? dirname(pkgJsonPath) : process.cwd();
|
|
120
|
+
}
|
|
121
|
+
function getUserPkgJson(userRoot) {
|
|
122
|
+
const path = resolve(userRoot, "package.json");
|
|
123
|
+
if (fs.existsSync(path))
|
|
124
|
+
return JSON.parse(fs.readFileSync(path, "utf-8"));
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
function hasWorkspacePackageJSON(root) {
|
|
128
|
+
const path = join(root, "package.json");
|
|
129
|
+
try {
|
|
130
|
+
fs.accessSync(path, fs.constants.R_OK);
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const content = JSON.parse(fs.readFileSync(path, "utf-8")) || {};
|
|
135
|
+
return !!content.workspaces;
|
|
136
|
+
}
|
|
137
|
+
function hasRootFile(root) {
|
|
138
|
+
const ROOT_FILES = [
|
|
139
|
+
// '.git',
|
|
140
|
+
// https://pnpm.js.org/workspaces/
|
|
141
|
+
"pnpm-workspace.yaml"
|
|
142
|
+
// https://rushjs.io/pages/advanced/config_files/
|
|
143
|
+
// 'rush.json',
|
|
144
|
+
// https://nx.dev/latest/react/getting-started/nx-setup
|
|
145
|
+
// 'workspace.json',
|
|
146
|
+
// 'nx.json'
|
|
147
|
+
];
|
|
148
|
+
return ROOT_FILES.some((file) => fs.existsSync(join(root, file)));
|
|
149
|
+
}
|
|
150
|
+
function searchForWorkspaceRoot(current, root = current) {
|
|
151
|
+
if (hasRootFile(current))
|
|
152
|
+
return current;
|
|
153
|
+
if (hasWorkspacePackageJSON(current))
|
|
154
|
+
return current;
|
|
155
|
+
const dir = dirname(current);
|
|
156
|
+
if (!dir || dir === current)
|
|
157
|
+
return root;
|
|
158
|
+
return searchForWorkspaceRoot(dir, root);
|
|
159
|
+
}
|
|
160
|
+
var rootsInfo = null;
|
|
161
|
+
async function getRoots() {
|
|
162
|
+
if (rootsInfo)
|
|
163
|
+
return rootsInfo;
|
|
164
|
+
const cliRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
165
|
+
const clientRoot = await findPkgRoot("@slidev/client", cliRoot, true);
|
|
166
|
+
const userRoot = await getUserRoot();
|
|
167
|
+
const userPkgJson = getUserPkgJson(userRoot);
|
|
168
|
+
const userWorkspaceRoot = searchForWorkspaceRoot(userRoot);
|
|
169
|
+
rootsInfo = {
|
|
170
|
+
cliRoot,
|
|
171
|
+
clientRoot,
|
|
172
|
+
userRoot,
|
|
173
|
+
userPkgJson,
|
|
174
|
+
userWorkspaceRoot
|
|
175
|
+
};
|
|
176
|
+
return rootsInfo;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
toAtFS,
|
|
181
|
+
resolveImportPath,
|
|
182
|
+
resolveEntry,
|
|
183
|
+
createResolver,
|
|
184
|
+
getRoots
|
|
185
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ViteSlidevPlugin,
|
|
3
|
+
checkEngine,
|
|
4
|
+
mergeViteConfigs,
|
|
5
|
+
version
|
|
6
|
+
} from "./chunk-O56CS6WQ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
createResolver,
|
|
9
|
+
getRoots,
|
|
10
|
+
resolveEntry
|
|
11
|
+
} from "./chunk-CV7OWJOF.mjs";
|
|
12
|
+
|
|
13
|
+
// node/server.ts
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import process from "node:process";
|
|
16
|
+
import { createServer as createViteServer, mergeConfig } from "vite";
|
|
17
|
+
async function createServer(options, viteConfig = {}, serverOptions = {}) {
|
|
18
|
+
process.env.EDITOR = process.env.EDITOR || "code";
|
|
19
|
+
const config = await mergeViteConfigs(
|
|
20
|
+
options,
|
|
21
|
+
viteConfig,
|
|
22
|
+
{
|
|
23
|
+
root: options.userRoot,
|
|
24
|
+
optimizeDeps: {
|
|
25
|
+
entries: [
|
|
26
|
+
join(options.clientRoot, "main.ts")
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"serve"
|
|
31
|
+
);
|
|
32
|
+
const server = await createViteServer(
|
|
33
|
+
mergeConfig(
|
|
34
|
+
config,
|
|
35
|
+
{
|
|
36
|
+
plugins: [
|
|
37
|
+
await ViteSlidevPlugin(options, config.slidev || {}, serverOptions)
|
|
38
|
+
],
|
|
39
|
+
define: {
|
|
40
|
+
// Fixes Vue production mode breaking PDF Export #1245
|
|
41
|
+
__VUE_PROD_DEVTOOLS__: JSON.stringify(true)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
return server;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// node/parser.ts
|
|
50
|
+
import * as parser from "@slidev/parser/fs";
|
|
51
|
+
|
|
52
|
+
// node/themes.ts
|
|
53
|
+
import { join as join2 } from "node:path";
|
|
54
|
+
import fs from "fs-extra";
|
|
55
|
+
import { satisfies } from "semver";
|
|
56
|
+
var officialThemes = {
|
|
57
|
+
"none": "",
|
|
58
|
+
"default": "@slidev/theme-default",
|
|
59
|
+
"seriph": "@slidev/theme-seriph",
|
|
60
|
+
"apple-basic": "@slidev/theme-apple-basic",
|
|
61
|
+
"shibainu": "@slidev/theme-shibainu",
|
|
62
|
+
"bricks": "@slidev/theme-bricks"
|
|
63
|
+
};
|
|
64
|
+
var resolveTheme = createResolver("theme", officialThemes);
|
|
65
|
+
async function getThemeMeta(name, root) {
|
|
66
|
+
const path = join2(root, "package.json");
|
|
67
|
+
if (!fs.existsSync(path))
|
|
68
|
+
return {};
|
|
69
|
+
const { slidev = {}, engines = {} } = await fs.readJSON(path);
|
|
70
|
+
if (engines.slidev && !satisfies(version, engines.slidev, { includePrerelease: true }))
|
|
71
|
+
throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
|
|
72
|
+
return slidev;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// node/addons.ts
|
|
76
|
+
import { resolve } from "node:path";
|
|
77
|
+
import fs2 from "fs-extra";
|
|
78
|
+
async function resolveAddons(addonsInConfig) {
|
|
79
|
+
const { userRoot, userPkgJson } = await getRoots();
|
|
80
|
+
const resolved = [];
|
|
81
|
+
const resolveAddonNameAndRoot = createResolver("addon", {});
|
|
82
|
+
async function resolveAddon(name, parent) {
|
|
83
|
+
const [, pkgRoot] = await resolveAddonNameAndRoot(name, parent);
|
|
84
|
+
if (!pkgRoot)
|
|
85
|
+
return;
|
|
86
|
+
resolved.push(pkgRoot);
|
|
87
|
+
const { slidev, engines } = await fs2.readJSON(resolve(pkgRoot, "package.json"));
|
|
88
|
+
checkEngine(name, engines);
|
|
89
|
+
if (Array.isArray(slidev?.addons))
|
|
90
|
+
await Promise.all(slidev.addons.map((addon) => resolveAddon(addon, pkgRoot)));
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(addonsInConfig))
|
|
93
|
+
await Promise.all(addonsInConfig.map((addon) => resolveAddon(addon, userRoot)));
|
|
94
|
+
if (Array.isArray(userPkgJson.slidev?.addons))
|
|
95
|
+
await Promise.all(userPkgJson.slidev.addons.map((addon) => resolveAddon(addon, userRoot)));
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// node/options.ts
|
|
100
|
+
import { uniq } from "@antfu/utils";
|
|
101
|
+
import _debug from "debug";
|
|
102
|
+
var debug = _debug("slidev:options");
|
|
103
|
+
async function resolveOptions(options, mode) {
|
|
104
|
+
const rootsInfo = await getRoots();
|
|
105
|
+
const entry = await resolveEntry(options.entry || "slides.md", rootsInfo);
|
|
106
|
+
const loaded = await parser.load(rootsInfo.userRoot, entry, void 0, mode);
|
|
107
|
+
const themeRaw = options.theme || loaded.headmatter.theme || "default";
|
|
108
|
+
const [theme, themeRoot] = await resolveTheme(themeRaw, entry);
|
|
109
|
+
const themeRoots = themeRoot ? [themeRoot] : [];
|
|
110
|
+
const themeMeta = themeRoot ? await getThemeMeta(theme, themeRoot) : void 0;
|
|
111
|
+
const config = parser.resolveConfig(loaded.headmatter, themeMeta, options.entry);
|
|
112
|
+
const addonRoots = await resolveAddons(config.addons);
|
|
113
|
+
const roots = uniq([...themeRoots, ...addonRoots, rootsInfo.userRoot]);
|
|
114
|
+
debug({
|
|
115
|
+
...rootsInfo,
|
|
116
|
+
...options,
|
|
117
|
+
config,
|
|
118
|
+
mode,
|
|
119
|
+
entry,
|
|
120
|
+
themeRaw,
|
|
121
|
+
theme,
|
|
122
|
+
themeRoots,
|
|
123
|
+
addonRoots,
|
|
124
|
+
roots
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
...rootsInfo,
|
|
128
|
+
...options,
|
|
129
|
+
data: {
|
|
130
|
+
...loaded,
|
|
131
|
+
config,
|
|
132
|
+
themeMeta
|
|
133
|
+
},
|
|
134
|
+
mode,
|
|
135
|
+
entry,
|
|
136
|
+
themeRaw,
|
|
137
|
+
theme,
|
|
138
|
+
themeRoots,
|
|
139
|
+
addonRoots,
|
|
140
|
+
roots
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
createServer,
|
|
146
|
+
parser,
|
|
147
|
+
resolveTheme,
|
|
148
|
+
getThemeMeta,
|
|
149
|
+
resolveAddons,
|
|
150
|
+
resolveOptions
|
|
151
|
+
};
|