@slidev/cli 0.35.5 → 0.36.1

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.mjs CHANGED
@@ -6,16 +6,16 @@ import {
6
6
  resolveOptions,
7
7
  resolveThemeName,
8
8
  version
9
- } from "./chunk-SWNG6UPD.mjs";
9
+ } from "./chunk-S3HDHTBQ.mjs";
10
10
  import {
11
11
  require_fast_deep_equal
12
- } from "./chunk-QPGEWKWZ.mjs";
12
+ } from "./chunk-DRWWOOWC.mjs";
13
13
  import {
14
14
  __dirname,
15
15
  __require,
16
16
  __toESM,
17
17
  init_esm_shims
18
- } from "./chunk-GVA336JI.mjs";
18
+ } from "./chunk-IAMILGBS.mjs";
19
19
 
20
20
  // node/cli.ts
21
21
  init_esm_shims();
@@ -40,261 +40,306 @@ var CONFIG_RESTART_FIELDS = [
40
40
  "css"
41
41
  ];
42
42
  var cli = yargs.scriptName("slidev").usage("$0 [args]").version(version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
43
- cli.command("* [entry]", "Start a local server for Slidev", (args) => commonOptions(args).option("port", {
44
- alias: "p",
45
- type: "number",
46
- describe: "port"
47
- }).option("open", {
48
- alias: "o",
49
- default: false,
50
- type: "boolean",
51
- describe: "open in browser"
52
- }).option("remote", {
53
- type: "string",
54
- describe: "listen public host and enable remote control"
55
- }).option("log", {
56
- default: "warn",
57
- type: "string",
58
- choices: ["error", "warn", "info", "silent"],
59
- describe: "log level"
60
- }).option("force", {
61
- alias: "f",
62
- default: false,
63
- type: "boolean",
64
- describe: "force the optimizer to ignore the cache and re-bundle "
65
- }).strict().help(), async ({ entry, theme, port: userPort, open, log, remote, force }) => {
66
- if (!fs.existsSync(entry) && !entry.endsWith(".md"))
67
- entry = `${entry}.md`;
68
- if (!fs.existsSync(entry)) {
69
- const { create } = await prompts({
70
- name: "create",
71
- type: "confirm",
72
- initial: "Y",
73
- message: `Entry file ${yellow(`"${entry}"`)} does not exist, do you want to create it?`
74
- });
75
- if (create)
76
- await fs.copyFile(path.resolve(__dirname, "../template.md"), entry);
77
- else
78
- process.exit(0);
79
- }
80
- let server;
81
- let port = 3030;
82
- async function initServer() {
83
- if (server)
84
- await server.close();
85
- const options = await resolveOptions({ entry, remote, theme }, "dev");
86
- port = userPort || await findFreePort(3030);
87
- server = await createServer(options, {
88
- server: {
89
- port,
90
- strictPort: true,
91
- open,
92
- host: remote !== void 0 ? "0.0.0.0" : "localhost",
93
- force
94
- },
95
- logLevel: log
96
- }, {
97
- onDataReload(newData, data) {
98
- if (!theme && resolveThemeName(newData.config.theme) !== resolveThemeName(data.config.theme)) {
99
- console.log(yellow("\n restarting on theme change\n"));
100
- initServer();
101
- } else if (CONFIG_RESTART_FIELDS.some((i) => !(0, import_fast_deep_equal.default)(newData.config[i], data.config[i]))) {
102
- console.log(yellow("\n restarting on config change\n"));
43
+ cli.command(
44
+ "* [entry]",
45
+ "Start a local server for Slidev",
46
+ (args) => commonOptions(args).option("port", {
47
+ alias: "p",
48
+ type: "number",
49
+ describe: "port"
50
+ }).option("open", {
51
+ alias: "o",
52
+ default: false,
53
+ type: "boolean",
54
+ describe: "open in browser"
55
+ }).option("remote", {
56
+ type: "string",
57
+ describe: "listen public host and enable remote control"
58
+ }).option("log", {
59
+ default: "warn",
60
+ type: "string",
61
+ choices: ["error", "warn", "info", "silent"],
62
+ describe: "log level"
63
+ }).option("inspect", {
64
+ default: false,
65
+ type: "boolean",
66
+ describe: "enable the inspect plugin for debugging"
67
+ }).option("force", {
68
+ alias: "f",
69
+ default: false,
70
+ type: "boolean",
71
+ describe: "force the optimizer to ignore the cache and re-bundle "
72
+ }).strict().help(),
73
+ async ({ entry, theme, port: userPort, open, log, remote, force, inspect }) => {
74
+ if (!fs.existsSync(entry) && !entry.endsWith(".md"))
75
+ entry = `${entry}.md`;
76
+ if (!fs.existsSync(entry)) {
77
+ const { create } = await prompts({
78
+ name: "create",
79
+ type: "confirm",
80
+ initial: "Y",
81
+ message: `Entry file ${yellow(`"${entry}"`)} does not exist, do you want to create it?`
82
+ });
83
+ if (create)
84
+ await fs.copyFile(path.resolve(__dirname, "../template.md"), entry);
85
+ else
86
+ process.exit(0);
87
+ }
88
+ let server;
89
+ let port = 3030;
90
+ async function initServer() {
91
+ if (server)
92
+ await server.close();
93
+ const options = await resolveOptions({ entry, remote, theme, inspect }, "dev");
94
+ port = userPort || await findFreePort(3030);
95
+ server = await createServer(
96
+ options,
97
+ {
98
+ server: {
99
+ port,
100
+ strictPort: true,
101
+ open,
102
+ host: remote !== void 0 ? "0.0.0.0" : "localhost",
103
+ force
104
+ },
105
+ logLevel: log
106
+ },
107
+ {
108
+ onDataReload(newData, data) {
109
+ if (!theme && resolveThemeName(newData.config.theme) !== resolveThemeName(data.config.theme)) {
110
+ console.log(yellow("\n restarting on theme change\n"));
111
+ initServer();
112
+ } else if (CONFIG_RESTART_FIELDS.some((i) => !(0, import_fast_deep_equal.default)(newData.config[i], data.config[i]))) {
113
+ console.log(yellow("\n restarting on config change\n"));
114
+ initServer();
115
+ }
116
+ }
117
+ }
118
+ );
119
+ await server.listen();
120
+ printInfo(options, port, remote);
121
+ }
122
+ const SHORTCUTS = [
123
+ {
124
+ name: "r",
125
+ fullname: "restart",
126
+ action() {
103
127
  initServer();
104
128
  }
129
+ },
130
+ {
131
+ name: "o",
132
+ fullname: "open",
133
+ action() {
134
+ openBrowser(`http://localhost:${port}`);
135
+ }
136
+ },
137
+ {
138
+ name: "e",
139
+ fullname: "edit",
140
+ action() {
141
+ exec(`code "${entry}"`);
142
+ }
105
143
  }
106
- });
107
- await server.listen();
108
- printInfo(options, port, remote);
109
- }
110
- const SHORTCUTS = [
111
- {
112
- name: "r",
113
- fullname: "restart",
114
- action() {
115
- initServer();
116
- }
117
- },
118
- {
119
- name: "o",
120
- fullname: "open",
121
- action() {
122
- openBrowser(`http://localhost:${port}`);
123
- }
124
- },
125
- {
126
- name: "e",
127
- fullname: "edit",
128
- action() {
129
- exec(`code "${entry}"`);
130
- }
131
- }
132
- ];
133
- function bindShortcut() {
134
- process.stdin.resume();
135
- process.stdin.setEncoding("utf8");
136
- readline.emitKeypressEvents(process.stdin);
137
- if (process.stdin.isTTY)
138
- process.stdin.setRawMode(true);
139
- process.stdin.on("keypress", (str, key) => {
140
- if (key.ctrl && key.name === "c") {
141
- process.exit();
142
- } else {
143
- const [sh] = SHORTCUTS.filter((item) => item.name === str);
144
- if (sh) {
145
- try {
146
- sh.action();
147
- } catch (err) {
148
- console.error(`Failed to execute shortcut ${sh.fullname}`, err);
144
+ ];
145
+ function bindShortcut() {
146
+ process.stdin.resume();
147
+ process.stdin.setEncoding("utf8");
148
+ readline.emitKeypressEvents(process.stdin);
149
+ if (process.stdin.isTTY)
150
+ process.stdin.setRawMode(true);
151
+ process.stdin.on("keypress", (str, key) => {
152
+ if (key.ctrl && key.name === "c") {
153
+ process.exit();
154
+ } else {
155
+ const [sh] = SHORTCUTS.filter((item) => item.name === str);
156
+ if (sh) {
157
+ try {
158
+ sh.action();
159
+ } catch (err) {
160
+ console.error(`Failed to execute shortcut ${sh.fullname}`, err);
161
+ }
149
162
  }
150
163
  }
164
+ });
165
+ }
166
+ initServer();
167
+ bindShortcut();
168
+ }
169
+ );
170
+ cli.command(
171
+ "build [entry]",
172
+ "Build hostable SPA",
173
+ (args) => commonOptions(args).option("watch", {
174
+ alias: "w",
175
+ default: false,
176
+ describe: "build watch"
177
+ }).option("out", {
178
+ alias: "o",
179
+ type: "string",
180
+ default: "dist",
181
+ describe: "output dir"
182
+ }).option("base", {
183
+ type: "string",
184
+ describe: "output base"
185
+ }).option("download", {
186
+ alias: "d",
187
+ type: "boolean",
188
+ describe: "allow download as PDF"
189
+ }).option("inspect", {
190
+ default: false,
191
+ type: "boolean",
192
+ describe: "enable the inspect plugin for debugging"
193
+ }).strict().help(),
194
+ async ({ entry, theme, watch, base, download, out, inspect }) => {
195
+ const { build } = await Promise.resolve().then(() => __toESM(__require("./build-LS63HRWN.mjs")));
196
+ const options = await resolveOptions({ entry, theme, inspect }, "build");
197
+ if (download && !options.data.config.download)
198
+ options.data.config.download = download;
199
+ printInfo(options);
200
+ await build(options, {
201
+ base,
202
+ build: {
203
+ watch: watch ? {} : void 0,
204
+ outDir: out
151
205
  }
152
206
  });
153
207
  }
154
- initServer();
155
- bindShortcut();
156
- });
157
- cli.command("build [entry]", "Build hostable SPA", (args) => commonOptions(args).option("watch", {
158
- alias: "w",
159
- default: false,
160
- describe: "build watch"
161
- }).option("out", {
162
- alias: "o",
163
- type: "string",
164
- default: "dist",
165
- describe: "output dir"
166
- }).option("base", {
167
- type: "string",
168
- describe: "output base"
169
- }).option("download", {
170
- alias: "d",
171
- type: "boolean",
172
- describe: "allow download as PDF"
173
- }).strict().help(), async ({ entry, theme, watch, base, download, out }) => {
174
- const { build } = await Promise.resolve().then(() => __toESM(__require("./build-RBCFVFDG.mjs")));
175
- const options = await resolveOptions({ entry, theme }, "build");
176
- if (download && !options.data.config.download)
177
- options.data.config.download = download;
178
- printInfo(options);
179
- await build(options, {
180
- base,
181
- build: {
182
- watch: watch ? {} : void 0,
183
- outDir: out
184
- }
185
- });
186
- });
187
- cli.command("format [entry]", "Format the markdown file", (args) => commonOptions(args).strict().help(), async ({ entry }) => {
188
- const data = await parser.load(entry);
189
- parser.prettify(data);
190
- await parser.save(data);
191
- });
192
- cli.command("theme [subcommand]", "Theme related operations", (command) => {
193
- return command.command("eject", "Eject current theme into local file system", (args) => commonOptions(args).option("dir", {
194
- type: "string",
195
- default: "theme"
196
- }), async ({ entry, dir, theme: themeInput }) => {
208
+ );
209
+ cli.command(
210
+ "format [entry]",
211
+ "Format the markdown file",
212
+ (args) => commonOptions(args).strict().help(),
213
+ async ({ entry }) => {
197
214
  const data = await parser.load(entry);
198
- const theme = resolveThemeName(themeInput || data.config.theme);
199
- if (theme === "none") {
200
- console.error('Can not eject theme "none"');
201
- process.exit(1);
202
- }
203
- if (isPath(theme)) {
204
- console.error("Theme is already ejected");
205
- process.exit(1);
206
- }
207
- const roots = getThemeRoots(theme, entry);
208
- if (!roots.length) {
209
- console.error(`Does not found theme "${theme}"`);
210
- process.exit(1);
211
- }
212
- const root = roots[0];
213
- await fs.copy(root, path.resolve(dir), {
214
- filter: (i) => !/node_modules|.git/.test(path.relative(root, i))
215
- });
216
- const dirPath = `./${dir}`;
217
- data.slides[0].frontmatter.theme = dirPath;
218
- data.slides[0].raw = null;
215
+ parser.prettify(data);
219
216
  await parser.save(data);
220
- console.log(`Theme "${theme}" ejected successfully to "${dirPath}"`);
221
- });
222
- }, () => {
223
- cli.showHelp();
224
- process.exit(1);
225
- });
226
- cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(args).option("output", {
227
- type: "string",
228
- describe: "path to the output"
229
- }).option("format", {
230
- default: "pdf",
231
- type: "string",
232
- choices: ["pdf", "png", "md"],
233
- describe: "output format"
234
- }).option("timeout", {
235
- default: 3e4,
236
- type: "number",
237
- describe: "timeout for rendering the print page"
238
- }).option("range", {
239
- type: "string",
240
- describe: 'page ranges to export, for example "1,4-5,6"'
241
- }).option("dark", {
242
- default: false,
243
- type: "boolean",
244
- describe: "export as dark theme"
245
- }).option("with-clicks", {
246
- alias: "c",
247
- default: false,
248
- type: "boolean",
249
- describe: "export pages for every clicks"
250
- }).option("executable-path", {
251
- type: "string",
252
- describe: "executable to override playwright bundled browser"
253
- }).strict().help(), async ({
254
- entry,
255
- theme,
256
- output,
257
- format,
258
- timeout,
259
- range,
260
- dark,
261
- "with-clicks": withClicks,
262
- "executable-path": executablePath
263
- }) => {
264
- process.env.NODE_ENV = "production";
265
- const { exportSlides } = await Promise.resolve().then(() => __toESM(__require("./export-U7F6XGP6.mjs")));
266
- const port = await findFreePort(12445);
267
- const options = await resolveOptions({ entry, theme }, "build");
268
- output = output || options.data.config.exportFilename || `${path.basename(entry, ".md")}-export`;
269
- const server = await createServer(options, {
270
- server: { port },
271
- clearScreen: false
272
- });
273
- await server.listen(port);
274
- printInfo(options);
275
- parser.filterDisabled(options.data);
276
- const width = options.data.config.canvasWidth;
277
- const height = Math.round(width / options.data.config.aspectRatio);
278
- output = await exportSlides({
279
- port,
280
- slides: options.data.slides,
281
- total: options.data.slides.length,
282
- range,
283
- format,
217
+ }
218
+ );
219
+ cli.command(
220
+ "theme [subcommand]",
221
+ "Theme related operations",
222
+ (command) => {
223
+ return command.command(
224
+ "eject",
225
+ "Eject current theme into local file system",
226
+ (args) => commonOptions(args).option("dir", {
227
+ type: "string",
228
+ default: "theme"
229
+ }),
230
+ async ({ entry, dir, theme: themeInput }) => {
231
+ const data = await parser.load(entry);
232
+ const theme = resolveThemeName(themeInput || data.config.theme);
233
+ if (theme === "none") {
234
+ console.error('Can not eject theme "none"');
235
+ process.exit(1);
236
+ }
237
+ if (isPath(theme)) {
238
+ console.error("Theme is already ejected");
239
+ process.exit(1);
240
+ }
241
+ const roots = getThemeRoots(theme, entry);
242
+ if (!roots.length) {
243
+ console.error(`Does not found theme "${theme}"`);
244
+ process.exit(1);
245
+ }
246
+ const root = roots[0];
247
+ await fs.copy(root, path.resolve(dir), {
248
+ filter: (i) => !/node_modules|.git/.test(path.relative(root, i))
249
+ });
250
+ const dirPath = `./${dir}`;
251
+ data.slides[0].frontmatter.theme = dirPath;
252
+ data.slides[0].raw = null;
253
+ await parser.save(data);
254
+ console.log(`Theme "${theme}" ejected successfully to "${dirPath}"`);
255
+ }
256
+ );
257
+ },
258
+ () => {
259
+ cli.showHelp();
260
+ process.exit(1);
261
+ }
262
+ );
263
+ cli.command(
264
+ "export [entry]",
265
+ "Export slides to PDF",
266
+ (args) => commonOptions(args).option("output", {
267
+ type: "string",
268
+ describe: "path to the output"
269
+ }).option("format", {
270
+ default: "pdf",
271
+ type: "string",
272
+ choices: ["pdf", "png", "md"],
273
+ describe: "output format"
274
+ }).option("timeout", {
275
+ default: 3e4,
276
+ type: "number",
277
+ describe: "timeout for rendering the print page"
278
+ }).option("range", {
279
+ type: "string",
280
+ describe: 'page ranges to export, for example "1,4-5,6"'
281
+ }).option("dark", {
282
+ default: false,
283
+ type: "boolean",
284
+ describe: "export as dark theme"
285
+ }).option("with-clicks", {
286
+ alias: "c",
287
+ default: false,
288
+ type: "boolean",
289
+ describe: "export pages for every clicks"
290
+ }).option("executable-path", {
291
+ type: "string",
292
+ describe: "executable to override playwright bundled browser"
293
+ }).strict().help(),
294
+ async ({
295
+ entry,
296
+ theme,
284
297
  output,
298
+ format,
285
299
  timeout,
300
+ range,
286
301
  dark,
287
- routerMode: options.data.config.routerMode,
288
- width,
289
- height,
290
- withClicks,
291
- executablePath
292
- });
293
- console.log(`${green(" \u2713 ")}${dim("exported to ")}./${output}
302
+ "with-clicks": withClicks,
303
+ "executable-path": executablePath
304
+ }) => {
305
+ process.env.NODE_ENV = "production";
306
+ const { exportSlides } = await Promise.resolve().then(() => __toESM(__require("./export-26FXNM7P.mjs")));
307
+ const port = await findFreePort(12445);
308
+ const options = await resolveOptions({ entry, theme }, "build");
309
+ output = output || options.data.config.exportFilename || `${path.basename(entry, ".md")}-export`;
310
+ const server = await createServer(
311
+ options,
312
+ {
313
+ server: { port },
314
+ clearScreen: false
315
+ }
316
+ );
317
+ await server.listen(port);
318
+ printInfo(options);
319
+ parser.filterDisabled(options.data);
320
+ const width = options.data.config.canvasWidth;
321
+ const height = Math.round(width / options.data.config.aspectRatio);
322
+ output = await exportSlides({
323
+ port,
324
+ slides: options.data.slides,
325
+ total: options.data.slides.length,
326
+ range,
327
+ format,
328
+ output,
329
+ timeout,
330
+ dark,
331
+ routerMode: options.data.config.routerMode,
332
+ width,
333
+ height,
334
+ withClicks,
335
+ executablePath
336
+ });
337
+ console.log(`${green(" \u2713 ")}${dim("exported to ")}./${output}
294
338
  `);
295
- server.close();
296
- process.exit(0);
297
- });
339
+ server.close();
340
+ process.exit(0);
341
+ }
342
+ );
298
343
  cli.help().parse();
299
344
  function commonOptions(args) {
300
345
  return args.positional("entry", {
@@ -323,10 +368,14 @@ function printInfo(options, port, remote) {
323
368
  if (query)
324
369
  console.log(`${dim(" private slide show ")} > ${cyan(`http://localhost:${bold(port)}/${query}`)}`);
325
370
  console.log(`${dim(" presenter mode ")} > ${blue(`http://localhost:${bold(port)}${presenterPath}`)}`);
371
+ if (options.inspect)
372
+ console.log(`${dim(" inspector")} > ${yellow(`http://localhost:${bold(port)}/__inspect/`)}`);
326
373
  if (remote !== void 0) {
327
- Object.values(os.networkInterfaces()).forEach((v) => (v || []).filter((details) => String(details.family).slice(-1) === "4" && !details.address.includes("127.0.0.1")).forEach(({ address }) => {
328
- console.log(`${dim(" remote control ")} > ${blue(`http://${address}:${port}${presenterPath}`)}`);
329
- }));
374
+ Object.values(os.networkInterfaces()).forEach(
375
+ (v) => (v || []).filter((details) => String(details.family).slice(-1) === "4" && !details.address.includes("127.0.0.1")).forEach(({ address }) => {
376
+ console.log(`${dim(" remote control ")} > ${blue(`http://${address}:${port}${presenterPath}`)}`);
377
+ })
378
+ );
330
379
  } else {
331
380
  console.log(`${dim(" remote control ")} > ${dim("pass --remote to enable")}`);
332
381
  }
@@ -3,7 +3,7 @@ import {
3
3
  __toESM,
4
4
  init_esm_shims,
5
5
  packageExists
6
- } from "./chunk-GVA336JI.mjs";
6
+ } from "./chunk-IAMILGBS.mjs";
7
7
 
8
8
  // node/export.ts
9
9
  init_esm_shims();
@@ -3,10 +3,10 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkSQLX75IOjs = require('./chunk-SQLX75IO.js');
6
+ var _chunk74QPSS6Tjs = require('./chunk-74QPSS6T.js');
7
7
 
8
8
  // node/export.ts
9
- _chunkSQLX75IOjs.init_cjs_shims.call(void 0, );
9
+ _chunk74QPSS6Tjs.init_cjs_shims.call(void 0, );
10
10
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
11
11
  var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
12
12
  var _kolorist = require('kolorist');
@@ -61,10 +61,10 @@ async function exportSlides({
61
61
  withClicks = false,
62
62
  executablePath = void 0
63
63
  }) {
64
- if (!_chunkSQLX75IOjs.packageExists.call(void 0, "playwright-chromium"))
64
+ if (!_chunk74QPSS6Tjs.packageExists.call(void 0, "playwright-chromium"))
65
65
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
66
66
  const pages = _core.parseRangeString.call(void 0, total, range);
67
- const { chromium } = await Promise.resolve().then(() => _chunkSQLX75IOjs.__toESM.call(void 0, _chunkSQLX75IOjs.__require.call(void 0, "playwright-chromium")));
67
+ const { chromium } = await Promise.resolve().then(() => _chunk74QPSS6Tjs.__toESM.call(void 0, _chunk74QPSS6Tjs.__require.call(void 0, "playwright-chromium")));
68
68
  const browser = await chromium.launch({
69
69
  executablePath
70
70
  });
package/dist/index.d.ts CHANGED
@@ -34,6 +34,10 @@ interface SlidevEntryOptions {
34
34
  * @default process.cwd()
35
35
  */
36
36
  userRoot?: string;
37
+ /**
38
+ * Enable inspect plugin
39
+ */
40
+ inspect?: boolean;
37
41
  }
38
42
  interface ResolvedSlidevOptions {
39
43
  data: SlidevMarkdown;
@@ -47,6 +51,7 @@ interface ResolvedSlidevOptions {
47
51
  roots: string[];
48
52
  mode: 'dev' | 'build';
49
53
  remote?: string;
54
+ inspect?: boolean;
50
55
  }
51
56
  interface SlidevPluginOptions extends SlidevEntryOptions {
52
57
  vue?: ArgumentsType<typeof Vue>[0];