Skip to content

Commit f1733b1

Browse files
committedMar 6, 2023
chore: dirctory refactoring.
1 parent e84c3c2 commit f1733b1

30 files changed

+305
-156
lines changed
 

Diff for: ‎.github/workflows/ci.marster.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ jobs:
1515
registry-url: 'https://registry.npmjs.org'
1616

1717
- run: npm install
18+
- run: npm run build:lib
1819
- run: npm run coverage
19-
- run: npm run doc
20+
- run: npm run build:doc
21+
2022
- run: npm run bundle
23+
working-directory: core
2124
- run: npm run bundle:min
25+
working-directory: core
2226

23-
- run: cp -rp coverage build
27+
- run: cp -rp coverage website/build
2428

2529
- name: Create Coverage Badges
2630
uses: jaywcjlove/coverage-badges-cli@main
2731
with:
28-
output: build/badge.svg
32+
output: website/build/badge.svg
2933

3034
- name: Generate Contributors Images
3135
uses: jaywcjlove/github-action-contributors@main
@@ -52,7 +56,7 @@ jobs:
5256
user_email: 'github-actions[bot]@users.noreply.github.com'
5357
commit_message: ${{steps.tag_version.outputs.tag}} ${{ github.event.head_commit.message }}
5458
github_token: ${{ secrets.GITHUB_TOKEN }}
55-
publish_dir: ./build
59+
publish_dir: ./website/build
5660

5761
- name: Generate Changelog
5862
id: changelog
@@ -86,11 +90,13 @@ jobs:
8690
- name: package.json info
8791
uses: jaywcjlove/github-action-package@main
8892
with:
89-
unset: scripts,jest,eslintConfig,engines,browserslist,devDependencies
93+
path: core/package.json
94+
unset: scripts,devDependencies
9095

9196
- run: npm publish
9297
name: 📦 @uiw/react-markdown-preview publish to NPM
9398
continue-on-error: true
99+
working-directory: core
94100
env:
95101
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96102

@@ -109,15 +115,20 @@ jobs:
109115
scope: '@uiwjs'
110116

111117
- run: npm install
118+
112119
- run: npm run bundle
120+
working-directory: core
113121
- run: npm run bundle:min
122+
working-directory: core
114123

115124
- name: Modify @uiw/react-markdown-preview => @uiwjs/react-markdown-preview
116125
uses: jaywcjlove/github-action-package@main
117126
with:
127+
path: core/package.json
118128
rename: '@uiwjs/react-markdown-preview'
119129

120130
- run: npm publish
121131
continue-on-error: true
132+
working-directory: core
122133
env:
123134
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Diff for: ‎.github/workflows/pr.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build & Deploy
1+
name: PR
22
on:
33
pull_request:
44

@@ -10,10 +10,14 @@ jobs:
1010
- uses: actions/setup-node@v3
1111
with:
1212
node-version: 16
13+
registry-url: 'https://registry.npmjs.org'
1314

1415
- run: npm install
15-
- run: npm run build
16+
- run: npm run build:lib
1617
- run: npm run coverage
17-
- run: npm run doc
18+
- run: npm run build:doc
19+
1820
- run: npm run bundle
19-
- run: npm run bundle:min
21+
working-directory: core
22+
- run: npm run bundle:min
23+
working-directory: core

Diff for: ‎.kktrc.ts

-56
This file was deleted.

Diff for: ‎core/.kktrc.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
2+
import lessModules from '@kkt/less-modules';
3+
4+
export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => {
5+
conf = lessModules(conf, env, options);
6+
if (options.bundle) {
7+
conf.output!.library = '@uiw/react-markdown-preview';
8+
conf.externals = {
9+
react: {
10+
root: 'React',
11+
commonjs2: 'react',
12+
commonjs: 'react',
13+
amd: 'react',
14+
},
15+
};
16+
}
17+
return conf;
18+
};

Diff for: ‎README.md renamed to ‎core/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ $ npm install @uiw/react-markdown-preview --save
3131

3232
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-markdown-preview-co1mj?fontsize=14&hidenavigation=1&theme=dark)
3333

34-
```js test:meta
34+
```jsx mdx:preview
35+
import React from 'react';
3536
import MarkdownPreview from '@uiw/react-markdown-preview';
3637

3738
const source = `
@@ -40,7 +41,7 @@ const source = `
4041
> todo: React component preview markdown text.
4142
`;
4243

43-
function Demo() {
44+
export default function Demo() {
4445
return (
4546
<MarkdownPreview source={source} />
4647
)
@@ -49,7 +50,8 @@ function Demo() {
4950

5051
## Disable Header links
5152

52-
```js test:meta
53+
```jsx mdx:preview
54+
import React from 'react';
5355
import MarkdownPreview from '@uiw/react-markdown-preview';
5456

5557
const source = `
@@ -60,7 +62,7 @@ const source = `
6062
### Header 3
6163
`;
6264

63-
function Demo() {
65+
export default function Demo() {
6466
return (
6567
<MarkdownPreview
6668
source={source}

Diff for: ‎core/package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@uiw/react-markdown-preview",
3+
"version": "4.1.9",
4+
"description": "React component preview markdown text in web browser. The minimal amount of CSS to replicate the GitHub Markdown style.",
5+
"homepage": "https://uiwjs.github.io/react-markdown-preview",
6+
"main": "lib/index.js",
7+
"module": "esm/index.js",
8+
"scripts": {
9+
"css:build": "compile-less -d src -o esm",
10+
"css:watch": "compile-less -d src -o esm --watch",
11+
"css:build:dist": "compile-less -d src --combine markdown.css --rm-global",
12+
"bundle": "ncc build src/index.tsx --target web --filename markdown",
13+
"bundle:min": "ncc build src/index.tsx --target web --filename markdown --minify",
14+
"watch": "tsbb watch & npm run css:watch",
15+
"build": "tsbb build && npm run css:build && npm run css:build:dist"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/uiwjs/react-markdown-preview.git"
20+
},
21+
"author": "kenny wang <wowohoo@qq.com>",
22+
"license": "MIT",
23+
"files": [
24+
"dist",
25+
"lib",
26+
"esm",
27+
"markdown.css",
28+
"src/**/*.{ts,tsx,less}"
29+
],
30+
"keywords": [
31+
"react",
32+
"markdown",
33+
"prismjs",
34+
"react-markdown"
35+
],
36+
"peerDependencies": {
37+
"react": ">=16.8.0",
38+
"react-dom": ">=16.8.0"
39+
},
40+
"dependencies": {
41+
"@babel/runtime": "^7.17.2",
42+
"@uiw/copy-to-clipboard": "~1.0.12",
43+
"react-markdown": "~8.0.0",
44+
"rehype-attr": "~2.1.0",
45+
"rehype-autolink-headings": "~6.1.1",
46+
"rehype-ignore": "^1.0.1",
47+
"rehype-prism-plus": "~1.5.0",
48+
"rehype-raw": "^6.1.1",
49+
"rehype-rewrite": "~3.0.6",
50+
"rehype-slug": "~5.1.0",
51+
"remark-gfm": "~3.0.1",
52+
"unist-util-visit": "^4.1.0"
53+
}
54+
}

Diff for: ‎src/index.tsx renamed to ‎core/src/index.tsx

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: ‎src/tsconfig.json renamed to ‎core/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"compilerOptions": {
44
"baseUrl": "./",
55
"noEmit": false
6-
}
6+
},
7+
"include": ["src", "./.kktrc.ts"]
78
}

Diff for: ‎lerna.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": "4.1.9",
3+
"packages": ["core", "website"],
4+
"useWorkspaces": true
5+
}

Diff for: ‎package.json

+14-79
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,17 @@
11
{
2-
"name": "@uiw/react-markdown-preview",
3-
"version": "4.1.9",
4-
"description": "React component preview markdown text in web browser. The minimal amount of CSS to replicate the GitHub Markdown style.",
5-
"homepage": "https://uiwjs.github.io/react-markdown-preview",
6-
"main": "lib/index.js",
7-
"module": "esm/index.js",
2+
"private": true,
83
"scripts": {
4+
"build": "npm run build:lib",
5+
"build:lib": "lerna exec --scope @uiw/* -- npm run build",
6+
"build:doc": "lerna exec --scope website -- npm run build",
7+
"doc": "lerna exec --scope website -- npm run start",
8+
"start": "lerna exec --scope @uiw/* -- npm run watch",
99
"prepare": "npm run build && husky install",
10-
"doc": "kkt build --app-src ./website",
11-
"start": "kkt start --app-src ./website",
12-
"css:build": "compile-less -d src -o esm",
13-
"css:watch": "compile-less -d src -o esm --watch",
14-
"css:build:dist": "compile-less -d src --combine markdown.css --rm-global",
15-
"bundle": "ncc build src/index.tsx --target web --filename markdown",
16-
"bundle:min": "ncc build src/index.tsx --target web --filename markdown --minify",
17-
"watch": "tsbb watch & npm run css:watch",
18-
"build": "tsbb build && npm run css:build && npm run css:build:dist",
1910
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
2011
"pretty-quick": "pretty-quick --staged",
2112
"test": "tsbb test --env=jsdom",
2213
"coverage": "tsbb test --env=jsdom --coverage"
2314
},
24-
"repository": {
25-
"type": "git",
26-
"url": "https://github.com/uiwjs/react-markdown-preview.git"
27-
},
28-
"author": "kenny wang <wowohoo@qq.com>",
29-
"license": "MIT",
30-
"files": [
31-
"dist",
32-
"lib",
33-
"esm",
34-
"markdown.css",
35-
"src/**/*.{ts,tsx,less}"
36-
],
37-
"keywords": [
38-
"react",
39-
"markdown",
40-
"prismjs",
41-
"react-markdown"
42-
],
4315
"jest": {
4416
"coverageReporters": [
4517
"lcov",
@@ -49,64 +21,27 @@
4921
"<rootDir>/node_modules/?!(.*)"
5022
]
5123
},
52-
"peerDependencies": {
53-
"react": ">=16.8.0",
54-
"react-dom": ">=16.8.0"
55-
},
56-
"dependencies": {
57-
"@babel/runtime": "^7.17.2",
58-
"@uiw/copy-to-clipboard": "~1.0.12",
59-
"react-markdown": "~8.0.0",
60-
"rehype-attr": "~2.1.0",
61-
"rehype-autolink-headings": "~6.1.1",
62-
"rehype-ignore": "^1.0.1",
63-
"rehype-prism-plus": "~1.5.0",
64-
"rehype-raw": "^6.1.1",
65-
"rehype-rewrite": "~3.0.6",
66-
"rehype-slug": "~5.1.0",
67-
"remark-gfm": "~3.0.1",
68-
"unist-util-visit": "^4.1.0"
69-
},
7024
"devDependencies": {
71-
"@kkt/less-modules": "~7.2.0",
72-
"@kkt/ncc": "^1.0.13",
73-
"@kkt/raw-modules": "~7.2.0",
74-
"@kkt/scope-plugin-options": "~7.2.0",
25+
"@testing-library/react": "^14.0.0",
7526
"@types/react": "~18.0.9",
7627
"@types/react-dom": "~18.0.3",
7728
"@types/react-test-renderer": "~18.0.0",
78-
"@uiw/react-back-to-top": "^1.2.0",
79-
"@uiw/react-codesandbox": "~1.1.4",
80-
"@uiw/react-github-corners": "~1.5.3",
81-
"@uiw/react-shields": "~1.1.2",
82-
"@uiw/reset.css": "~1.0.5",
83-
"@wcj/dark-mode": "~1.0.9",
29+
"@kkt/ncc": "^1.0.15",
8430
"compile-less-cli": "~1.8.11",
8531
"husky": "~8.0.0",
86-
"kkt": "~7.2.0",
8732
"prettier": "^2.7.1",
8833
"pretty-quick": "~3.1.3",
89-
"react": "~18.2.0",
90-
"react-dom": "~18.2.0",
91-
"react-test-renderer": "~18.2.0",
92-
"tsbb": "~3.7.0"
34+
"lerna": "^6.1.0",
35+
"tsbb": "^3.7.9"
9336
},
9437
"eslintConfig": {
9538
"extends": "react-app"
9639
},
9740
"engines": {
9841
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
9942
},
100-
"browserslist": {
101-
"production": [
102-
">0.2%",
103-
"not dead",
104-
"not op_mini all"
105-
],
106-
"development": [
107-
"last 1 chrome version",
108-
"last 1 firefox version",
109-
"last 1 safari version"
110-
]
111-
}
43+
"workspaces": [
44+
"core",
45+
"website"
46+
]
11247
}

Diff for: ‎test/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useRef } from 'react';
22
import TestRenderer from 'react-test-renderer';
33
import { render } from '@testing-library/react';
4-
import MarkdownPreview, { MarkdownPreviewRef } from '../src';
4+
import MarkdownPreview, { MarkdownPreviewRef } from '../core/src';
55

66
it('Should output a TestRenderer', async () => {
77
const component = TestRenderer.create(<MarkdownPreview source="## Hello World!" />);

Diff for: ‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"noFallthroughCasesInSwitch": true,
1818
"noEmit": true
1919
},
20-
"include": ["website", "test", "src"]
20+
"include": ["test"]
2121
}

Diff for: ‎website/.kktrc.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from 'path';
2+
import webpack from 'webpack';
3+
import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
4+
import lessModules from '@kkt/less-modules';
5+
import scopePluginOptions from '@kkt/scope-plugin-options';
6+
import pkg from '@uiw/react-markdown-preview/package.json';
7+
import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader';
8+
9+
export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => {
10+
conf = lessModules(conf, env, options);
11+
conf = scopePluginOptions(conf, env, {
12+
...options,
13+
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
14+
});
15+
// Get the project version.
16+
conf.plugins!.push(
17+
new webpack.DefinePlugin({
18+
VERSION: JSON.stringify(pkg.version),
19+
}),
20+
);
21+
conf = mdCodeModulesLoader(conf);
22+
// https://github.com/kktjs/kkt/issues/336#issue-1097660932
23+
conf.module!.exprContextCritical = false;
24+
if (env === 'production') {
25+
conf.output = { ...conf.output, publicPath: './' };
26+
conf.optimization = {
27+
...conf.optimization,
28+
splitChunks: {
29+
cacheGroups: {
30+
reactvendor: {
31+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
32+
name: 'react-vendor',
33+
chunks: 'all',
34+
},
35+
prismjs: {
36+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
37+
name: 'refractor-vendor',
38+
chunks: 'all',
39+
},
40+
},
41+
},
42+
};
43+
}
44+
return conf;
45+
};

Diff for: ‎website/README.md

Whitespace-only changes.

Diff for: ‎website/package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "website",
3+
"version": "4.1.9",
4+
"private": true,
5+
"scripts": {
6+
"build": "kkt build",
7+
"start": "kkt start"
8+
},
9+
"dependencies": {
10+
"@uiw/react-markdown-preview": "4.1.9",
11+
"@uiw/react-back-to-top": "^1.2.0",
12+
"@uiw/react-codesandbox": "~1.1.4",
13+
"@uiw/react-github-corners": "~1.5.3",
14+
"@uiw/react-shields": "~1.1.2",
15+
"@uiw/reset.css": "~1.0.5",
16+
"@wcj/dark-mode": "~1.0.9",
17+
"react": "~18.2.0",
18+
"react-code-preview-layout": "~2.1.0",
19+
"react-dom": "~18.2.0",
20+
"react-router-dom": "^6.8.1"
21+
},
22+
"devDependencies": {
23+
"@kkt/less-modules": "^7.4.7",
24+
"@kkt/scope-plugin-options": "^7.4.7",
25+
"kkt": "^7.4.7",
26+
"markdown-react-code-preview-loader": "^2.1.4",
27+
"prettier": "^2.8.4",
28+
"pretty-quick": "^3.1.3",
29+
"react-test-renderer": "^18.2.0"
30+
},
31+
"eslintConfig": {
32+
"extends": "react-app"
33+
},
34+
"engines": {
35+
"node": "^14.13.1 || >=16.0.0"
36+
},
37+
"browserslist": {
38+
"production": [
39+
">0.2%",
40+
"not dead",
41+
"not op_mini all"
42+
],
43+
"development": [
44+
"last 1 chrome version",
45+
"last 1 firefox version",
46+
"last 1 safari version"
47+
]
48+
}
49+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: ‎website/App.css renamed to ‎website/src/App.css

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ dark-mode {
5858

5959
.App-markdown {
6060
text-align: left;
61-
font-size: calc(10px + 2vmin);
6261
padding: 16px;
6362
border-radius: 5px;
6463
}

Diff for: ‎website/App.tsx renamed to ‎website/src/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import GitHubCorners from '@uiw/react-github-corners';
33
import Github from '@uiw/react-shields/esm/github';
44
import Npm from '@uiw/react-shields/esm/npm';
55
import BackToUp from '@uiw/react-back-to-top';
6+
import MarkdownPreview from '@uiw/react-markdown-preview';
67
import '@wcj/dark-mode';
78
import logo from './logo.svg';
9+
import { Preview } from './preview';
810
import './App.css';
9-
import MarkdownPreview from '../';
10-
import MDStr from '../README.md';
1111

1212
let val = 1;
1313

@@ -39,7 +39,7 @@ const App = () => {
3939
/>
4040
<MarkdownPreview className="App-editor-preview" source={value} />
4141
</div>
42-
<MarkdownPreview className="App-markdown" source={MDStr.replace(/([\s\S]*)<!--dividing-->/, '')} />
42+
<Preview />
4343
<div className="App-footer">
4444
<Github user="uiwjs" repo="react-markdown-preview">
4545
<Github.Social type="forks" href="https://github.com/uiwjs/react-markdown-preview" />
File renamed without changes.

Diff for: ‎website/logo.svg renamed to ‎website/src/logo.svg

File renamed without changes.

Diff for: ‎website/src/preview/index.tsx

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import MarkdownPreview from '@uiw/react-markdown-preview';
2+
import MDStr from '@uiw/react-markdown-preview/README.md';
3+
import CodeLayout from 'react-code-preview-layout';
4+
import { Root, Element, RootContent } from 'hast';
5+
import { getMetaId, isMeta, getURLParameters } from 'markdown-react-code-preview-loader';
6+
7+
const getBooleanValue = (param: Record<string, string>, field: string, defaultValue: boolean) => {
8+
if (Reflect.has(param, field)) {
9+
const newValue = Reflect.get(param, field);
10+
if (newValue === 'true') {
11+
return true;
12+
}
13+
if (newValue === 'false') {
14+
return false;
15+
}
16+
}
17+
return defaultValue;
18+
};
19+
20+
export const Preview = () => {
21+
return (
22+
<MarkdownPreview
23+
className="App-markdown"
24+
source={MDStr.source}
25+
rehypeRewrite={(node: Root | RootContent, index: number, parent: Root | Element) => {
26+
if (node.type === 'element' && node.tagName === 'pre' && node.children[0].data?.meta) {
27+
const meta = node.children[0].data?.meta as string;
28+
if (isMeta(meta)) {
29+
node.tagName = 'div';
30+
if (!node.properties) {
31+
node.properties = {};
32+
}
33+
node.properties!['data-md'] = meta;
34+
node.properties!['data-meta'] = 'preview';
35+
}
36+
}
37+
}}
38+
components={{
39+
div: ({ node, ...props }) => {
40+
const { 'data-meta': meta, 'data-md': metaData } = props as any;
41+
if (meta === 'preview') {
42+
const line = node.position?.start.line;
43+
const metaId = getMetaId(meta) || String(line);
44+
const Child = MDStr.components[metaId];
45+
if (metaId && typeof Child === 'function') {
46+
const code = MDStr.data[metaId].value || '';
47+
const param = getURLParameters(metaData);
48+
return (
49+
<CodeLayout
50+
disableCheckered={getBooleanValue(param, 'disableCheckered', true)}
51+
disableToolbar={getBooleanValue(param, 'disableToolbar', false)}
52+
disableCode={getBooleanValue(param, 'disableCode', false)}
53+
disablePreview={getBooleanValue(param, 'disablePreview', false)}
54+
bordered={getBooleanValue(param, 'bordered', true)}
55+
copied={getBooleanValue(param, 'copied', true)}
56+
background={param.background}
57+
toolbar={param.title || '示例'}
58+
codeProps={{ style: { padding: 0 } }}
59+
style={{ padding: 0 }}
60+
code={<pre {...(props as React.HTMLAttributes<HTMLPreElement>)} />}
61+
text={code}
62+
>
63+
<Child />
64+
</CodeLayout>
65+
);
66+
}
67+
}
68+
return <div {...props} />;
69+
},
70+
}}
71+
/>
72+
);
73+
};

Diff for: ‎website/react-app-env.d.ts renamed to ‎website/src/react-app-env.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ declare module '*.less' {
99
const src: string;
1010
export default src;
1111
}
12+
1213
declare module '*.md' {
13-
const src: string;
14+
import { CodeBlockData } from 'markdown-react-code-preview-loader';
15+
const src: CodeBlockData;
1416
export default src;
1517
}

Diff for: ‎website/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig",
3+
"compilerOptions": {
4+
"baseUrl": "./"
5+
},
6+
"include": ["src", "./.kktrc.ts"]
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.