vite-plugin-react-deck 1.0.7 → 1.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/config.d.ts +13 -0
- package/helpers.d.ts +5 -1
- package/index.cjs +138 -20
- package/index.d.ts +2 -1
- package/index.mjs +147 -21
- package/package.json +11 -6
- package/slides.d.ts +2 -2
- package/themes/green.d.ts +7 -0
- package/themes/index.d.ts +2 -0
- package/themes/purple.d.ts +7 -0
- package/types.d.ts +13 -2
package/config.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PestacleConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Allow to type the config object (similar to Vite's defineConfig)
|
|
4
|
+
*/
|
|
5
|
+
export declare function defineConfig(config: PestacleConfig): PestacleConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Create a default config object
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDefaultConfig(): PestacleConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Load the config file from the project root
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadConfigFile(): Promise<PestacleConfig>;
|
package/helpers.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export declare function createIndexFile({ entrypoint }: {
|
|
2
2
|
entrypoint: string;
|
|
3
3
|
}): string;
|
|
4
|
-
export declare function createAppDeckFile({ slidePath }: {
|
|
4
|
+
export declare function createAppDeckFile({ slidePath, theme, config, }: {
|
|
5
5
|
slidePath: string;
|
|
6
|
+
theme: string;
|
|
7
|
+
config: {
|
|
8
|
+
layoutsFile: string;
|
|
9
|
+
};
|
|
6
10
|
}): string;
|
package/index.cjs
CHANGED
|
@@ -4,6 +4,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
7
11
|
var __copyProps = (to, from, except, desc) => {
|
|
8
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
13
|
for (let key of __getOwnPropNames(from))
|
|
@@ -26,17 +30,16 @@ var fs2 = __toESM(require("fs/promises"), 1);
|
|
|
26
30
|
|
|
27
31
|
// src/slides.ts
|
|
28
32
|
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
33
|
+
var import_remark_directive = __toESM(require("remark-directive"), 1);
|
|
29
34
|
var import_fs = __toESM(require("fs"), 1);
|
|
30
35
|
var import_mdx = require("@mdx-js/mdx");
|
|
31
36
|
|
|
32
37
|
// src/codegen.ts
|
|
33
38
|
var Patterns = {
|
|
34
|
-
FragmentProd:
|
|
35
|
-
FragmentDev:
|
|
39
|
+
FragmentProd: /^\s*_jsxs\(_Fragment, {\s*children:|\s*\}\);/g,
|
|
40
|
+
FragmentDev: /^\s*<>\s*|\s*<\/>;\s*$/g
|
|
36
41
|
};
|
|
37
|
-
function extractMainCodeAsChildren(source, {
|
|
38
|
-
isJsx
|
|
39
|
-
}) {
|
|
42
|
+
function extractMainCodeAsChildren(source, { isJsx }) {
|
|
40
43
|
const start = source.indexOf("const _components = {");
|
|
41
44
|
const end = source.indexOf("\n}", start);
|
|
42
45
|
const components = source.slice(start, end);
|
|
@@ -48,13 +51,13 @@ function extractMainCodeAsChildren(source, {
|
|
|
48
51
|
const header = lines.slice(0, returnPos).join("\n");
|
|
49
52
|
const footer = lines.slice(returnPos).join("\n").replace("return", "");
|
|
50
53
|
if (isJsx) {
|
|
51
|
-
const finalFooter2 = footer.replace(Patterns.FragmentDev, "");
|
|
54
|
+
const finalFooter2 = footer.replace(Patterns.FragmentDev, " ").replace(/;$/, "");
|
|
52
55
|
return `${header}
|
|
53
56
|
const {wrapper: MDXLayout} = _components;
|
|
54
57
|
return <MDXLayout {...props}>${finalFooter2}</MDXLayout>;
|
|
55
58
|
`.trim();
|
|
56
59
|
}
|
|
57
|
-
const finalFooter = footer.match(/^\s*_jsxs?\(_Fragment,/gm) ? footer.replace(Patterns.FragmentProd, "") : footer;
|
|
60
|
+
const finalFooter = footer.match(/^\s*_jsxs?\(_Fragment,/gm) ? footer.replace(Patterns.FragmentProd, " ") : footer;
|
|
58
61
|
return `
|
|
59
62
|
${header}
|
|
60
63
|
const _content = ${finalFooter};
|
|
@@ -68,6 +71,20 @@ ${header}
|
|
|
68
71
|
|
|
69
72
|
// src/slides.ts
|
|
70
73
|
var import_remark_gfm = __toESM(require("remark-gfm"), 1);
|
|
74
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
75
|
+
function myRemarkPlugin() {
|
|
76
|
+
return (tree) => {
|
|
77
|
+
(0, import_unist_util_visit.visit)(tree, (node) => {
|
|
78
|
+
if (node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective") {
|
|
79
|
+
const data = node.data || (node.data = {});
|
|
80
|
+
data.hName = "directive";
|
|
81
|
+
data.hProperties = node.attributes;
|
|
82
|
+
data.hProperties._name = node.name;
|
|
83
|
+
data.hProperties._kind = node.type;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
71
88
|
async function transformSlidesMdxToReact(sourceContent, {
|
|
72
89
|
production: isProd,
|
|
73
90
|
...options
|
|
@@ -101,8 +118,13 @@ ${slide}
|
|
|
101
118
|
outputFormat: "program",
|
|
102
119
|
jsx: !isProd,
|
|
103
120
|
providerImportSource: "@mdx-js/react",
|
|
104
|
-
|
|
105
|
-
|
|
121
|
+
...options,
|
|
122
|
+
remarkPlugins: [
|
|
123
|
+
import_remark_gfm.default,
|
|
124
|
+
import_remark_directive.default,
|
|
125
|
+
myRemarkPlugin,
|
|
126
|
+
...options.remarkPlugins
|
|
127
|
+
]
|
|
106
128
|
});
|
|
107
129
|
const mainCode = extractMainCodeAsChildren(result.value.toString(), {
|
|
108
130
|
isJsx: !isProd
|
|
@@ -169,6 +191,42 @@ function normalizeNewline(input) {
|
|
|
169
191
|
return input.replace(new RegExp(CRLF, "g"), "\n");
|
|
170
192
|
}
|
|
171
193
|
|
|
194
|
+
// src/themes/index.ts
|
|
195
|
+
var themes_exports = {};
|
|
196
|
+
__export(themes_exports, {
|
|
197
|
+
green: () => green_exports,
|
|
198
|
+
purple: () => purple_exports
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// src/themes/green.ts
|
|
202
|
+
var green_exports = {};
|
|
203
|
+
__export(green_exports, {
|
|
204
|
+
themeTokens: () => themeTokens
|
|
205
|
+
});
|
|
206
|
+
var colors = {
|
|
207
|
+
primary: "#FFFFFF",
|
|
208
|
+
secondary: "#F49676",
|
|
209
|
+
tertiary: "#042F3B"
|
|
210
|
+
};
|
|
211
|
+
var themeTokens = {
|
|
212
|
+
colors
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// src/themes/purple.ts
|
|
216
|
+
var purple_exports = {};
|
|
217
|
+
__export(purple_exports, {
|
|
218
|
+
themeTokens: () => themeTokens2
|
|
219
|
+
});
|
|
220
|
+
var colors2 = {
|
|
221
|
+
//primary: "#56D4F8",
|
|
222
|
+
primary: "#ffffff",
|
|
223
|
+
secondary: "#F530EC",
|
|
224
|
+
tertiary: "#2B135A"
|
|
225
|
+
};
|
|
226
|
+
var themeTokens2 = {
|
|
227
|
+
colors: colors2
|
|
228
|
+
};
|
|
229
|
+
|
|
172
230
|
// src/helpers.ts
|
|
173
231
|
function createIndexFile({ entrypoint }) {
|
|
174
232
|
return `<!DOCTYPE html>
|
|
@@ -193,10 +251,19 @@ function createIndexFile({ entrypoint }) {
|
|
|
193
251
|
</html>
|
|
194
252
|
`;
|
|
195
253
|
}
|
|
196
|
-
function createAppDeckFile({
|
|
254
|
+
function createAppDeckFile({
|
|
255
|
+
slidePath,
|
|
256
|
+
theme,
|
|
257
|
+
config
|
|
258
|
+
}) {
|
|
259
|
+
if (!themes_exports[theme]) {
|
|
260
|
+
throw new Error(`Theme ${theme} not found`);
|
|
261
|
+
}
|
|
262
|
+
const themeObject = themes_exports[theme];
|
|
197
263
|
return `import React, { StrictMode } from "react";
|
|
198
264
|
import * as ReactDOM from "react-dom/client";
|
|
199
265
|
import { Deck } from '@gpichot/spectacle-deck';
|
|
266
|
+
import layouts from "${config.layoutsFile}";
|
|
200
267
|
|
|
201
268
|
import deck from "${slidePath}";
|
|
202
269
|
|
|
@@ -205,7 +272,7 @@ const root = ReactDOM.createRoot(
|
|
|
205
272
|
);
|
|
206
273
|
root.render(
|
|
207
274
|
<StrictMode>
|
|
208
|
-
<Deck deck={deck} />
|
|
275
|
+
<Deck deck={deck} theme={${JSON.stringify(themeObject)}} layouts={layouts} />
|
|
209
276
|
</StrictMode>
|
|
210
277
|
)`;
|
|
211
278
|
}
|
|
@@ -213,6 +280,17 @@ root.render(
|
|
|
213
280
|
// src/index.ts
|
|
214
281
|
var glob = __toESM(require("glob"), 1);
|
|
215
282
|
var import_node_path = __toESM(require("path"), 1);
|
|
283
|
+
|
|
284
|
+
// src/config.ts
|
|
285
|
+
var import_lodash = __toESM(require("lodash"), 1);
|
|
286
|
+
|
|
287
|
+
// src/types.ts
|
|
288
|
+
var import_zod = require("zod");
|
|
289
|
+
var PestacleConfigSchema = import_zod.z.object({
|
|
290
|
+
theme: import_zod.z.enum(["green", "purple"]).default("green")
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// src/index.ts
|
|
216
294
|
async function checkIfDirectoryExists(path2) {
|
|
217
295
|
try {
|
|
218
296
|
await fs2.access(path2);
|
|
@@ -221,17 +299,44 @@ async function checkIfDirectoryExists(path2) {
|
|
|
221
299
|
return false;
|
|
222
300
|
}
|
|
223
301
|
}
|
|
224
|
-
|
|
302
|
+
async function findDecks({ port }) {
|
|
303
|
+
const decks = await glob.glob("./src/**/deck.mdx");
|
|
304
|
+
return decks.map((deck) => ({
|
|
305
|
+
deckFile: deck,
|
|
306
|
+
deckUrl: `http://localhost:${port}/${deck.replace("src/", "").replace("deck.mdx", "")}`
|
|
307
|
+
}));
|
|
308
|
+
}
|
|
309
|
+
async function fileExists(name, path2) {
|
|
310
|
+
const candidateExts = [".ts", ".tsx", ".js", ".jsx"];
|
|
311
|
+
for await (const ext of candidateExts) {
|
|
312
|
+
const fullPath = `${path2}${ext}`;
|
|
313
|
+
try {
|
|
314
|
+
await fs2.access(fullPath);
|
|
315
|
+
return fullPath.replace(/^\./, "");
|
|
316
|
+
} catch {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async function loadCustomConfig() {
|
|
322
|
+
const layoutsFile = await fileExists("layouts", "./pestacle/layouts");
|
|
323
|
+
return {
|
|
324
|
+
layoutsFile
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
var src_default = async (options) => {
|
|
328
|
+
const config = await loadCustomConfig();
|
|
329
|
+
console.log(config);
|
|
225
330
|
let isProd = false;
|
|
226
331
|
const deckConfig = {
|
|
227
332
|
decks: []
|
|
228
333
|
};
|
|
229
334
|
return {
|
|
230
335
|
name: "react-deck",
|
|
231
|
-
async config(
|
|
336
|
+
async config(config2) {
|
|
232
337
|
var _a, _b, _c;
|
|
233
338
|
const decks = await glob.glob("./src/**/deck.mdx");
|
|
234
|
-
const inputs = ((_b = (_a =
|
|
339
|
+
const inputs = ((_b = (_a = config2.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input) || {};
|
|
235
340
|
deckConfig.decks = decks.map((deck) => ({
|
|
236
341
|
originalFile: deck,
|
|
237
342
|
index: deck.replace("/deck.mdx", "/index.html").replace("src/", "")
|
|
@@ -242,18 +347,18 @@ var src_default = (options) => {
|
|
|
242
347
|
}, []);
|
|
243
348
|
const finalInputs = typeof inputs === "string" ? [inputs, ...decks] : Array.isArray(inputs) ? [...inputs, ...decks] : { ...inputs, ...newInputs };
|
|
244
349
|
return {
|
|
245
|
-
...
|
|
350
|
+
...config2,
|
|
246
351
|
build: {
|
|
247
|
-
...
|
|
352
|
+
...config2.build,
|
|
248
353
|
rollupOptions: {
|
|
249
|
-
...(_c =
|
|
354
|
+
...(_c = config2.build) == null ? void 0 : _c.rollupOptions,
|
|
250
355
|
input: finalInputs
|
|
251
356
|
}
|
|
252
357
|
}
|
|
253
358
|
};
|
|
254
359
|
},
|
|
255
|
-
configResolved(
|
|
256
|
-
isProd =
|
|
360
|
+
configResolved(config2) {
|
|
361
|
+
isProd = config2.isProduction;
|
|
257
362
|
},
|
|
258
363
|
resolveId(id) {
|
|
259
364
|
if (deckConfig.decks.some((deck) => deck.index === id)) {
|
|
@@ -282,8 +387,11 @@ var src_default = (options) => {
|
|
|
282
387
|
return;
|
|
283
388
|
}
|
|
284
389
|
const contentIndex = createAppDeckFile({
|
|
285
|
-
slidePath: `${directory}/deck.mdx
|
|
390
|
+
slidePath: `${directory}/deck.mdx`,
|
|
391
|
+
theme: options.theme,
|
|
392
|
+
config
|
|
286
393
|
});
|
|
394
|
+
console.log({ contentIndex });
|
|
287
395
|
return contentIndex;
|
|
288
396
|
}
|
|
289
397
|
if (!id.endsWith("deck.mdx")) {
|
|
@@ -312,6 +420,16 @@ var src_default = (options) => {
|
|
|
312
420
|
const deckPath = dir.startsWith(".") ? dir : `.${dir}`;
|
|
313
421
|
return html.replace("__SCRIPT__", `${deckPath}/__deck.tsx`);
|
|
314
422
|
}
|
|
423
|
+
},
|
|
424
|
+
configureServer(server) {
|
|
425
|
+
var _a;
|
|
426
|
+
(_a = server.httpServer) == null ? void 0 : _a.once("listening", async () => {
|
|
427
|
+
const port = server.config.server.port || 5173;
|
|
428
|
+
const decks = await findDecks({ port });
|
|
429
|
+
for (const deck of decks) {
|
|
430
|
+
console.log(`Deck available at ${deck.deckUrl}`);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
315
433
|
}
|
|
316
434
|
};
|
|
317
435
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PluginOption } from "vite";
|
|
2
2
|
import { ReactDeckOptions } from "./types";
|
|
3
|
-
|
|
3
|
+
export { defineConfig } from "./config";
|
|
4
|
+
declare const _default: (options: ReactDeckOptions) => Promise<PluginOption>;
|
|
4
5
|
export default _default;
|
package/index.mjs
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
1
7
|
// src/index.ts
|
|
2
8
|
import * as fs2 from "fs/promises";
|
|
3
9
|
|
|
4
10
|
// src/slides.ts
|
|
5
11
|
import matter from "gray-matter";
|
|
12
|
+
import remarkDirective from "remark-directive";
|
|
6
13
|
import fs from "fs";
|
|
7
14
|
import { compile } from "@mdx-js/mdx";
|
|
8
15
|
|
|
9
16
|
// src/codegen.ts
|
|
10
17
|
var Patterns = {
|
|
11
|
-
FragmentProd:
|
|
12
|
-
FragmentDev:
|
|
18
|
+
FragmentProd: /^\s*_jsxs\(_Fragment, {\s*children:|\s*\}\);/g,
|
|
19
|
+
FragmentDev: /^\s*<>\s*|\s*<\/>;\s*$/g
|
|
13
20
|
};
|
|
14
|
-
function extractMainCodeAsChildren(source, {
|
|
15
|
-
isJsx
|
|
16
|
-
}) {
|
|
21
|
+
function extractMainCodeAsChildren(source, { isJsx }) {
|
|
17
22
|
const start = source.indexOf("const _components = {");
|
|
18
23
|
const end = source.indexOf("\n}", start);
|
|
19
24
|
const components = source.slice(start, end);
|
|
@@ -25,13 +30,13 @@ function extractMainCodeAsChildren(source, {
|
|
|
25
30
|
const header = lines.slice(0, returnPos).join("\n");
|
|
26
31
|
const footer = lines.slice(returnPos).join("\n").replace("return", "");
|
|
27
32
|
if (isJsx) {
|
|
28
|
-
const finalFooter2 = footer.replace(Patterns.FragmentDev, "");
|
|
33
|
+
const finalFooter2 = footer.replace(Patterns.FragmentDev, " ").replace(/;$/, "");
|
|
29
34
|
return `${header}
|
|
30
35
|
const {wrapper: MDXLayout} = _components;
|
|
31
36
|
return <MDXLayout {...props}>${finalFooter2}</MDXLayout>;
|
|
32
37
|
`.trim();
|
|
33
38
|
}
|
|
34
|
-
const finalFooter = footer.match(/^\s*_jsxs?\(_Fragment,/gm) ? footer.replace(Patterns.FragmentProd, "") : footer;
|
|
39
|
+
const finalFooter = footer.match(/^\s*_jsxs?\(_Fragment,/gm) ? footer.replace(Patterns.FragmentProd, " ") : footer;
|
|
35
40
|
return `
|
|
36
41
|
${header}
|
|
37
42
|
const _content = ${finalFooter};
|
|
@@ -45,6 +50,20 @@ ${header}
|
|
|
45
50
|
|
|
46
51
|
// src/slides.ts
|
|
47
52
|
import remarkGfm from "remark-gfm";
|
|
53
|
+
import { visit } from "unist-util-visit";
|
|
54
|
+
function myRemarkPlugin() {
|
|
55
|
+
return (tree) => {
|
|
56
|
+
visit(tree, (node) => {
|
|
57
|
+
if (node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective") {
|
|
58
|
+
const data = node.data || (node.data = {});
|
|
59
|
+
data.hName = "directive";
|
|
60
|
+
data.hProperties = node.attributes;
|
|
61
|
+
data.hProperties._name = node.name;
|
|
62
|
+
data.hProperties._kind = node.type;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
}
|
|
48
67
|
async function transformSlidesMdxToReact(sourceContent, {
|
|
49
68
|
production: isProd,
|
|
50
69
|
...options
|
|
@@ -78,8 +97,13 @@ ${slide}
|
|
|
78
97
|
outputFormat: "program",
|
|
79
98
|
jsx: !isProd,
|
|
80
99
|
providerImportSource: "@mdx-js/react",
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
...options,
|
|
101
|
+
remarkPlugins: [
|
|
102
|
+
remarkGfm,
|
|
103
|
+
remarkDirective,
|
|
104
|
+
myRemarkPlugin,
|
|
105
|
+
...options.remarkPlugins
|
|
106
|
+
]
|
|
83
107
|
});
|
|
84
108
|
const mainCode = extractMainCodeAsChildren(result.value.toString(), {
|
|
85
109
|
isJsx: !isProd
|
|
@@ -146,6 +170,42 @@ function normalizeNewline(input) {
|
|
|
146
170
|
return input.replace(new RegExp(CRLF, "g"), "\n");
|
|
147
171
|
}
|
|
148
172
|
|
|
173
|
+
// src/themes/index.ts
|
|
174
|
+
var themes_exports = {};
|
|
175
|
+
__export(themes_exports, {
|
|
176
|
+
green: () => green_exports,
|
|
177
|
+
purple: () => purple_exports
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// src/themes/green.ts
|
|
181
|
+
var green_exports = {};
|
|
182
|
+
__export(green_exports, {
|
|
183
|
+
themeTokens: () => themeTokens
|
|
184
|
+
});
|
|
185
|
+
var colors = {
|
|
186
|
+
primary: "#FFFFFF",
|
|
187
|
+
secondary: "#F49676",
|
|
188
|
+
tertiary: "#042F3B"
|
|
189
|
+
};
|
|
190
|
+
var themeTokens = {
|
|
191
|
+
colors
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// src/themes/purple.ts
|
|
195
|
+
var purple_exports = {};
|
|
196
|
+
__export(purple_exports, {
|
|
197
|
+
themeTokens: () => themeTokens2
|
|
198
|
+
});
|
|
199
|
+
var colors2 = {
|
|
200
|
+
//primary: "#56D4F8",
|
|
201
|
+
primary: "#ffffff",
|
|
202
|
+
secondary: "#F530EC",
|
|
203
|
+
tertiary: "#2B135A"
|
|
204
|
+
};
|
|
205
|
+
var themeTokens2 = {
|
|
206
|
+
colors: colors2
|
|
207
|
+
};
|
|
208
|
+
|
|
149
209
|
// src/helpers.ts
|
|
150
210
|
function createIndexFile({ entrypoint }) {
|
|
151
211
|
return `<!DOCTYPE html>
|
|
@@ -170,10 +230,19 @@ function createIndexFile({ entrypoint }) {
|
|
|
170
230
|
</html>
|
|
171
231
|
`;
|
|
172
232
|
}
|
|
173
|
-
function createAppDeckFile({
|
|
233
|
+
function createAppDeckFile({
|
|
234
|
+
slidePath,
|
|
235
|
+
theme,
|
|
236
|
+
config
|
|
237
|
+
}) {
|
|
238
|
+
if (!themes_exports[theme]) {
|
|
239
|
+
throw new Error(`Theme ${theme} not found`);
|
|
240
|
+
}
|
|
241
|
+
const themeObject = themes_exports[theme];
|
|
174
242
|
return `import React, { StrictMode } from "react";
|
|
175
243
|
import * as ReactDOM from "react-dom/client";
|
|
176
244
|
import { Deck } from '@gpichot/spectacle-deck';
|
|
245
|
+
import layouts from "${config.layoutsFile}";
|
|
177
246
|
|
|
178
247
|
import deck from "${slidePath}";
|
|
179
248
|
|
|
@@ -182,7 +251,7 @@ const root = ReactDOM.createRoot(
|
|
|
182
251
|
);
|
|
183
252
|
root.render(
|
|
184
253
|
<StrictMode>
|
|
185
|
-
<Deck deck={deck} />
|
|
254
|
+
<Deck deck={deck} theme={${JSON.stringify(themeObject)}} layouts={layouts} />
|
|
186
255
|
</StrictMode>
|
|
187
256
|
)`;
|
|
188
257
|
}
|
|
@@ -190,6 +259,22 @@ root.render(
|
|
|
190
259
|
// src/index.ts
|
|
191
260
|
import * as glob from "glob";
|
|
192
261
|
import path from "path";
|
|
262
|
+
|
|
263
|
+
// src/config.ts
|
|
264
|
+
import _ from "lodash";
|
|
265
|
+
|
|
266
|
+
// src/types.ts
|
|
267
|
+
import { z } from "zod";
|
|
268
|
+
var PestacleConfigSchema = z.object({
|
|
269
|
+
theme: z.enum(["green", "purple"]).default("green")
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// src/config.ts
|
|
273
|
+
function defineConfig(config) {
|
|
274
|
+
return config;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/index.ts
|
|
193
278
|
async function checkIfDirectoryExists(path2) {
|
|
194
279
|
try {
|
|
195
280
|
await fs2.access(path2);
|
|
@@ -198,17 +283,44 @@ async function checkIfDirectoryExists(path2) {
|
|
|
198
283
|
return false;
|
|
199
284
|
}
|
|
200
285
|
}
|
|
201
|
-
|
|
286
|
+
async function findDecks({ port }) {
|
|
287
|
+
const decks = await glob.glob("./src/**/deck.mdx");
|
|
288
|
+
return decks.map((deck) => ({
|
|
289
|
+
deckFile: deck,
|
|
290
|
+
deckUrl: `http://localhost:${port}/${deck.replace("src/", "").replace("deck.mdx", "")}`
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
async function fileExists(name, path2) {
|
|
294
|
+
const candidateExts = [".ts", ".tsx", ".js", ".jsx"];
|
|
295
|
+
for await (const ext of candidateExts) {
|
|
296
|
+
const fullPath = `${path2}${ext}`;
|
|
297
|
+
try {
|
|
298
|
+
await fs2.access(fullPath);
|
|
299
|
+
return fullPath.replace(/^\./, "");
|
|
300
|
+
} catch {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async function loadCustomConfig() {
|
|
306
|
+
const layoutsFile = await fileExists("layouts", "./pestacle/layouts");
|
|
307
|
+
return {
|
|
308
|
+
layoutsFile
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
var src_default = async (options) => {
|
|
312
|
+
const config = await loadCustomConfig();
|
|
313
|
+
console.log(config);
|
|
202
314
|
let isProd = false;
|
|
203
315
|
const deckConfig = {
|
|
204
316
|
decks: []
|
|
205
317
|
};
|
|
206
318
|
return {
|
|
207
319
|
name: "react-deck",
|
|
208
|
-
async config(
|
|
320
|
+
async config(config2) {
|
|
209
321
|
var _a, _b, _c;
|
|
210
322
|
const decks = await glob.glob("./src/**/deck.mdx");
|
|
211
|
-
const inputs = ((_b = (_a =
|
|
323
|
+
const inputs = ((_b = (_a = config2.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input) || {};
|
|
212
324
|
deckConfig.decks = decks.map((deck) => ({
|
|
213
325
|
originalFile: deck,
|
|
214
326
|
index: deck.replace("/deck.mdx", "/index.html").replace("src/", "")
|
|
@@ -219,18 +331,18 @@ var src_default = (options) => {
|
|
|
219
331
|
}, []);
|
|
220
332
|
const finalInputs = typeof inputs === "string" ? [inputs, ...decks] : Array.isArray(inputs) ? [...inputs, ...decks] : { ...inputs, ...newInputs };
|
|
221
333
|
return {
|
|
222
|
-
...
|
|
334
|
+
...config2,
|
|
223
335
|
build: {
|
|
224
|
-
...
|
|
336
|
+
...config2.build,
|
|
225
337
|
rollupOptions: {
|
|
226
|
-
...(_c =
|
|
338
|
+
...(_c = config2.build) == null ? void 0 : _c.rollupOptions,
|
|
227
339
|
input: finalInputs
|
|
228
340
|
}
|
|
229
341
|
}
|
|
230
342
|
};
|
|
231
343
|
},
|
|
232
|
-
configResolved(
|
|
233
|
-
isProd =
|
|
344
|
+
configResolved(config2) {
|
|
345
|
+
isProd = config2.isProduction;
|
|
234
346
|
},
|
|
235
347
|
resolveId(id) {
|
|
236
348
|
if (deckConfig.decks.some((deck) => deck.index === id)) {
|
|
@@ -259,8 +371,11 @@ var src_default = (options) => {
|
|
|
259
371
|
return;
|
|
260
372
|
}
|
|
261
373
|
const contentIndex = createAppDeckFile({
|
|
262
|
-
slidePath: `${directory}/deck.mdx
|
|
374
|
+
slidePath: `${directory}/deck.mdx`,
|
|
375
|
+
theme: options.theme,
|
|
376
|
+
config
|
|
263
377
|
});
|
|
378
|
+
console.log({ contentIndex });
|
|
264
379
|
return contentIndex;
|
|
265
380
|
}
|
|
266
381
|
if (!id.endsWith("deck.mdx")) {
|
|
@@ -289,9 +404,20 @@ var src_default = (options) => {
|
|
|
289
404
|
const deckPath = dir.startsWith(".") ? dir : `.${dir}`;
|
|
290
405
|
return html.replace("__SCRIPT__", `${deckPath}/__deck.tsx`);
|
|
291
406
|
}
|
|
407
|
+
},
|
|
408
|
+
configureServer(server) {
|
|
409
|
+
var _a;
|
|
410
|
+
(_a = server.httpServer) == null ? void 0 : _a.once("listening", async () => {
|
|
411
|
+
const port = server.config.server.port || 5173;
|
|
412
|
+
const decks = await findDecks({ port });
|
|
413
|
+
for (const deck of decks) {
|
|
414
|
+
console.log(`Deck available at ${deck.deckUrl}`);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
292
417
|
}
|
|
293
418
|
};
|
|
294
419
|
};
|
|
295
420
|
export {
|
|
296
|
-
src_default as default
|
|
421
|
+
src_default as default,
|
|
422
|
+
defineConfig
|
|
297
423
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-deck",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.cjs",
|
|
@@ -22,11 +22,16 @@
|
|
|
22
22
|
"fast refresh"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@mdx-js/mdx": "^3.0.
|
|
26
|
-
"@mdx-js/react": "^3.0.
|
|
27
|
-
"@swc/core": "^1.
|
|
28
|
-
"glob": "^10.3.
|
|
25
|
+
"@mdx-js/mdx": "^3.0.1",
|
|
26
|
+
"@mdx-js/react": "^3.0.1",
|
|
27
|
+
"@swc/core": "^1.5.7",
|
|
28
|
+
"glob": "^10.3.15",
|
|
29
29
|
"gray-matter": "^4.0.3",
|
|
30
|
-
"
|
|
30
|
+
"hastscript": "^9.0.0",
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"remark-directive": "^3.0.0",
|
|
33
|
+
"remark-gfm": "^4.0.0",
|
|
34
|
+
"unist-util-visit": "^5.0.0",
|
|
35
|
+
"zod": "^3.23.8"
|
|
31
36
|
}
|
|
32
37
|
}
|
package/slides.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactDeckOptions } from "./types";
|
|
2
|
-
type CompileOptions = Pick<ReactDeckOptions, "rehypePlugins">;
|
|
2
|
+
type CompileOptions = Pick<ReactDeckOptions, "rehypePlugins" | "remarkPlugins">;
|
|
3
3
|
/**
|
|
4
4
|
* Slides are separated by "---" in the markdown file.
|
|
5
5
|
*
|
|
@@ -15,7 +15,7 @@ type CompileOptions = Pick<ReactDeckOptions, "rehypePlugins">;
|
|
|
15
15
|
* # Slide 1
|
|
16
16
|
*
|
|
17
17
|
* ---
|
|
18
|
-
|
|
18
|
+
t
|
|
19
19
|
* layout: slide2
|
|
20
20
|
*
|
|
21
21
|
* ---
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface ReactDeckOptions {
|
|
2
3
|
rehypePlugins: any[];
|
|
3
|
-
|
|
4
|
+
remarkPlugins: any[];
|
|
5
|
+
theme: "green" | "purple";
|
|
6
|
+
}
|
|
7
|
+
export declare const PestacleConfigSchema: z.ZodObject<{
|
|
8
|
+
theme: z.ZodDefault<z.ZodEnum<["green", "purple"]>>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
theme?: "green" | "purple";
|
|
11
|
+
}, {
|
|
12
|
+
theme?: "green" | "purple";
|
|
13
|
+
}>;
|
|
14
|
+
export type PestacleConfig = z.infer<typeof PestacleConfigSchema>;
|