@rspress/plugin-preview 2.0.0-beta.31 → 2.0.0-beta.32
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/index.js +13 -11
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ import { pluginReact } from "@rsbuild/plugin-react";
|
|
|
6
6
|
import { pluginSolid } from "@rsbuild/plugin-solid";
|
|
7
7
|
import { RSPRESS_TEMP_DIR, normalizePosixPath, removeTrailingSlash } from "@rspress/core";
|
|
8
8
|
import { cloneDeep, isEqual } from "lodash";
|
|
9
|
-
import
|
|
9
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
10
|
+
import node_fs from "node:fs";
|
|
10
11
|
const staticPath = node_path.join(__dirname, '..', 'static');
|
|
11
12
|
const demoBlockComponentPath = node_path.join(staticPath, 'global-components', 'DemoBlock.tsx');
|
|
12
13
|
const virtualDir = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR, 'virtual-demo');
|
|
@@ -30,11 +31,13 @@ const getLangFileExt = (lang)=>{
|
|
|
30
31
|
return lang;
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
function generateEntry(demos, framework, position, customEntry) {
|
|
34
|
+
async function generateEntry(demos, framework, position, customEntry) {
|
|
34
35
|
const sourceEntry = {};
|
|
35
36
|
const entryCssPath = join(staticPath, 'global-styles', 'entry.css');
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
await mkdir(virtualDir, {
|
|
38
|
+
recursive: true
|
|
39
|
+
});
|
|
40
|
+
if ('follow' === position) await Promise.all(Object.values(demos).map((routes)=>routes.map(async (route)=>{
|
|
38
41
|
const { id, path: demoPath } = route;
|
|
39
42
|
const entry = join(virtualDir, `${id}.entry.tsx`);
|
|
40
43
|
const solidEntry = `
|
|
@@ -54,11 +57,10 @@ function generateEntry(demos, framework, position, customEntry) {
|
|
|
54
57
|
entryCssPath,
|
|
55
58
|
demoPath
|
|
56
59
|
}) : 'react' === framework ? reactEntry : solidEntry;
|
|
57
|
-
|
|
60
|
+
await writeFile(entry, entryContent);
|
|
58
61
|
sourceEntry[id] = entry;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
else Object.entries(demos).forEach(([key, routes])=>{
|
|
62
|
+
})).flat());
|
|
63
|
+
else await Promise.all(Object.entries(demos).map(async ([key, routes])=>{
|
|
62
64
|
if (0 === routes.length) return;
|
|
63
65
|
const reactContent = `
|
|
64
66
|
import { createRoot } from 'react-dom/client';
|
|
@@ -92,9 +94,9 @@ function generateEntry(demos, framework, position, customEntry) {
|
|
|
92
94
|
const renderContent = 'solid' === framework ? solidContent : reactContent;
|
|
93
95
|
const id = `_${toValidVarName(key)}`;
|
|
94
96
|
const entry = join(virtualDir, `${id}.entry.tsx`);
|
|
95
|
-
|
|
97
|
+
await writeFile(entry, renderContent);
|
|
96
98
|
sourceEntry[id] = entry;
|
|
97
|
-
});
|
|
99
|
+
}));
|
|
98
100
|
return sourceEntry;
|
|
99
101
|
}
|
|
100
102
|
const convert = function(test) {
|
|
@@ -439,7 +441,7 @@ function pluginPreview(options) {
|
|
|
439
441
|
lastDemos = cloneDeep(remarkPlugin_demos);
|
|
440
442
|
await devServer?.server?.close();
|
|
441
443
|
devServer = void 0;
|
|
442
|
-
const sourceEntry = generateEntry(remarkPlugin_demos, framework, position, customEntry);
|
|
444
|
+
const sourceEntry = await generateEntry(remarkPlugin_demos, framework, position, customEntry);
|
|
443
445
|
const outDir = join(config.outDir ?? 'doc_build', '~demo');
|
|
444
446
|
if (0 === Object.keys(sourceEntry).length) return;
|
|
445
447
|
const { html, source, output, performance } = clientConfig ?? {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-preview",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.32",
|
|
4
4
|
"description": "A plugin for rspress to preview the code block in markdown/mdx file.",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"static"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@rsbuild/core": "~1.5.
|
|
26
|
+
"@rsbuild/core": "~1.5.4",
|
|
27
27
|
"@rsbuild/plugin-babel": "~1.0.6",
|
|
28
28
|
"@rsbuild/plugin-react": "~1.4.0",
|
|
29
29
|
"@rsbuild/plugin-solid": "~1.0.6",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"unist-util-visit": "^5.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@rspress/core": "^2.0.0-beta.
|
|
51
|
+
"@rspress/core": "^2.0.0-beta.32",
|
|
52
52
|
"react": ">=18.0.0",
|
|
53
53
|
"react-router-dom": "^6.8.1"
|
|
54
54
|
},
|