dumi 2.0.0-beta.2 → 2.0.0-beta.3
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/assetParsers/atom.d.ts +21 -0
- package/dist/assetParsers/atom.js +112 -0
- package/dist/assetParsers/block.d.ts +1 -4
- package/dist/assetParsers/block.js +2 -12
- package/dist/client/theme-api/context.d.ts +2 -0
- package/dist/client/theme-api/context.js +1 -0
- package/dist/client/theme-api/index.d.ts +1 -0
- package/dist/client/theme-api/index.js +1 -0
- package/dist/client/theme-api/useAtomAssets.d.ts +4 -0
- package/dist/client/theme-api/useAtomAssets.js +9 -0
- package/dist/features/compile.js +2 -1
- package/dist/features/configPlugins/schema.js +2 -1
- package/dist/features/meta.d.ts +1 -0
- package/dist/features/meta.js +24 -13
- package/dist/features/parser.d.ts +3 -0
- package/dist/features/parser.js +60 -0
- package/dist/features/routes.js +1 -1
- package/dist/features/theme/index.js +2 -1
- package/dist/loaders/page/index.d.ts +1 -0
- package/dist/loaders/page/index.js +41 -0
- package/dist/preset.js +2 -1
- package/dist/types.d.ts +3 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +18 -2
- package/package.json +3 -2
- package/theme-default/builtins/API/index.d.ts +5 -0
- package/theme-default/builtins/API/index.js +57 -0
- package/theme-default/locales/en-US.json +8 -1
- package/theme-default/locales/zh-CN.json +8 -1
- package/theme-default/slots/Content/index.less +18 -0
- package/dist/client/tsconfig.json +0 -13
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AtomComponentAsset, AtomFunctionAsset } from 'dumi-assets-types';
|
|
2
|
+
declare class AtomAssetsParser {
|
|
3
|
+
private entryDir;
|
|
4
|
+
private resolveDir;
|
|
5
|
+
private unresolvedFiles;
|
|
6
|
+
private parser;
|
|
7
|
+
private resolverDeferrer;
|
|
8
|
+
private watcher;
|
|
9
|
+
private cbs;
|
|
10
|
+
constructor(opts: {
|
|
11
|
+
entryFile: string;
|
|
12
|
+
resolveDir: string;
|
|
13
|
+
watch?: boolean;
|
|
14
|
+
});
|
|
15
|
+
parse(): Promise<{
|
|
16
|
+
components: Record<string, AtomComponentAsset>;
|
|
17
|
+
functions: Record<string, AtomFunctionAsset>;
|
|
18
|
+
}>;
|
|
19
|
+
watch(cb: AtomAssetsParser['cbs'][number]): void;
|
|
20
|
+
}
|
|
21
|
+
export default AtomAssetsParser;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/assetParsers/atom.ts
|
|
23
|
+
var atom_exports = {};
|
|
24
|
+
__export(atom_exports, {
|
|
25
|
+
default: () => atom_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(atom_exports);
|
|
28
|
+
var import_parser = require("dumi-afx-deps/compiled/parser");
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
31
|
+
var MAX_PARSE_SIZE = 1024 * 512;
|
|
32
|
+
var AtomAssetsParser = class {
|
|
33
|
+
constructor(opts) {
|
|
34
|
+
this.unresolvedFiles = [];
|
|
35
|
+
this.watcher = null;
|
|
36
|
+
this.cbs = [];
|
|
37
|
+
this.resolveDir = opts.resolveDir;
|
|
38
|
+
this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(opts.entryFile));
|
|
39
|
+
this.parser = new import_parser.SchemaParser({
|
|
40
|
+
entryPath: opts.entryFile,
|
|
41
|
+
basePath: opts.resolveDir,
|
|
42
|
+
unPkgHost: "https://unpkg.com"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async parse() {
|
|
46
|
+
if (!this.resolverDeferrer || this.unresolvedFiles.length) {
|
|
47
|
+
this.resolverDeferrer = (async () => {
|
|
48
|
+
await this.parser.patch(this.unresolvedFiles);
|
|
49
|
+
return new import_parser.SchemaResolver(await this.parser.parse());
|
|
50
|
+
})();
|
|
51
|
+
}
|
|
52
|
+
return this.resolverDeferrer.then((resolver) => {
|
|
53
|
+
const components = {};
|
|
54
|
+
const functions = {};
|
|
55
|
+
resolver.componentList.forEach((id) => {
|
|
56
|
+
let propsConfig = resolver.getComponent(id).props;
|
|
57
|
+
const size = Buffer.byteLength(JSON.stringify(propsConfig));
|
|
58
|
+
if (size > MAX_PARSE_SIZE) {
|
|
59
|
+
propsConfig = { type: "object", properties: {} };
|
|
60
|
+
import_plugin_utils.logger.warn(`Parsed component ${id} props size ${size} exceeds 512KB, skip it.`);
|
|
61
|
+
}
|
|
62
|
+
components[id] = {
|
|
63
|
+
type: "COMPONENT",
|
|
64
|
+
id,
|
|
65
|
+
title: id,
|
|
66
|
+
propsConfig
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
resolver.functionList.forEach((id) => {
|
|
70
|
+
let signature = resolver.getFunction(id).signature;
|
|
71
|
+
const size = Buffer.byteLength(JSON.stringify(signature));
|
|
72
|
+
if (size > MAX_PARSE_SIZE) {
|
|
73
|
+
signature = { arguments: [] };
|
|
74
|
+
import_plugin_utils.logger.warn(`Parsed function ${id} signature size ${size} exceeds 512KB, skip it.`);
|
|
75
|
+
}
|
|
76
|
+
functions[id] = {
|
|
77
|
+
type: "FUNCTION",
|
|
78
|
+
id,
|
|
79
|
+
title: id,
|
|
80
|
+
signature
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return { components, functions };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
watch(cb) {
|
|
87
|
+
this.cbs.push(cb);
|
|
88
|
+
if (!this.watcher) {
|
|
89
|
+
const lazyParse = import_plugin_utils.lodash.debounce(() => {
|
|
90
|
+
this.parse().then((data) => this.cbs.forEach((cb2) => cb2(data)));
|
|
91
|
+
}, 100);
|
|
92
|
+
this.watcher = import_plugin_utils.chokidar.watch(this.entryDir, {
|
|
93
|
+
cwd: this.resolveDir,
|
|
94
|
+
ignored: [
|
|
95
|
+
"**/.*",
|
|
96
|
+
"**/.*/**",
|
|
97
|
+
"**/_*",
|
|
98
|
+
"**/_*/**",
|
|
99
|
+
"**/*.{md,less,scss,sass,styl,css}"
|
|
100
|
+
]
|
|
101
|
+
}).on("all", (ev, file) => {
|
|
102
|
+
if (["add", "change"].includes(ev) && /\.(j|t)sx?$/.test(file)) {
|
|
103
|
+
this.unresolvedFiles.push(file);
|
|
104
|
+
lazyParse();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var atom_default = AtomAssetsParser;
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {});
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { parseCodeFrontmatter } from "../utils";
|
|
1
2
|
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
2
3
|
export interface IParsedBlockAsset {
|
|
3
4
|
asset: ExampleBlockAsset;
|
|
4
5
|
sources: Record<string, string>;
|
|
5
6
|
frontmatter: ReturnType<typeof parseCodeFrontmatter>['frontmatter'];
|
|
6
7
|
}
|
|
7
|
-
declare function parseCodeFrontmatter(raw: string): {
|
|
8
|
-
code: string;
|
|
9
|
-
frontmatter: Record<string, any> | null;
|
|
10
|
-
};
|
|
11
8
|
declare function parseBlockAsset(opts: {
|
|
12
9
|
fileAbsPath: string;
|
|
13
10
|
id: string;
|
|
@@ -25,21 +25,11 @@ __export(block_exports, {
|
|
|
25
25
|
default: () => block_default
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(block_exports);
|
|
28
|
+
var import_utils = require("../utils");
|
|
28
29
|
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
29
30
|
var import_fs = __toESM(require("fs"));
|
|
30
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
31
31
|
var import_path = __toESM(require("path"));
|
|
32
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
33
|
-
function parseCodeFrontmatter(raw) {
|
|
34
|
-
const [, comment = "", code = ""] = raw.replace(/^\n\s*/, "").match(/^(\/\*\*[^]*?\n\s*\*\/)?(?:\s|\n)*([^]+)?$/);
|
|
35
|
-
const yamlComment = comment.replace(/^\/|\/$/g, "").replace(/(^|\n)\s*\*+/g, "$1");
|
|
36
|
-
let frontmatter = null;
|
|
37
|
-
try {
|
|
38
|
-
frontmatter = import_js_yaml.default.load(yamlComment);
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
41
|
-
return { code: frontmatter ? code : raw, frontmatter };
|
|
42
|
-
}
|
|
43
33
|
async function parseBlockAsset(opts) {
|
|
44
34
|
const asset = {
|
|
45
35
|
type: "BLOCK",
|
|
@@ -101,7 +91,7 @@ async function parseBlockAsset(opts) {
|
|
|
101
91
|
value: opts.entryPointCode ?? import_fs.default.readFileSync(args.path, "utf-8")
|
|
102
92
|
};
|
|
103
93
|
if (isEntryPoint) {
|
|
104
|
-
const { code, frontmatter } = parseCodeFrontmatter(asset.dependencies[filename].value);
|
|
94
|
+
const { code, frontmatter } = (0, import_utils.parseCodeFrontmatter)(asset.dependencies[filename].value);
|
|
105
95
|
if (frontmatter) {
|
|
106
96
|
asset.dependencies[filename].value = code;
|
|
107
97
|
result.frontmatter = frontmatter;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AtomComponentAsset } from 'dumi-assets-types';
|
|
1
2
|
import { type ComponentType } from 'react';
|
|
2
3
|
import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
|
|
3
4
|
interface ISiteContext {
|
|
@@ -5,6 +6,7 @@ interface ISiteContext {
|
|
|
5
6
|
component: ComponentType;
|
|
6
7
|
asset: IPreviewerProps['asset'];
|
|
7
8
|
}>;
|
|
9
|
+
components: Record<string, AtomComponentAsset>;
|
|
8
10
|
locales: NonNullable<ILocalesConfig>;
|
|
9
11
|
themeConfig: IThemeConfig;
|
|
10
12
|
loading: boolean;
|
|
@@ -3,6 +3,7 @@ export { useSiteData } from './context';
|
|
|
3
3
|
export { DumiDemo } from './DumiDemo';
|
|
4
4
|
export { DumiDemoGrid } from './DumiDemoGrid';
|
|
5
5
|
export type { IPreviewerProps } from './types';
|
|
6
|
+
export { useAtomAssets } from './useAtomAssets';
|
|
6
7
|
export { useLocale } from './useLocale';
|
|
7
8
|
export { useNavData } from './useNavData';
|
|
8
9
|
export { useRouteMeta } from './useRouteMeta';
|
|
@@ -2,6 +2,7 @@ export { useIntl } from 'react-intl';
|
|
|
2
2
|
export { useSiteData } from "./context";
|
|
3
3
|
export { DumiDemo } from "./DumiDemo";
|
|
4
4
|
export { DumiDemoGrid } from "./DumiDemoGrid";
|
|
5
|
+
export { useAtomAssets } from "./useAtomAssets";
|
|
5
6
|
export { useLocale } from "./useLocale";
|
|
6
7
|
export { useNavData } from "./useNavData";
|
|
7
8
|
export { useRouteMeta } from "./useRouteMeta";
|
package/dist/features/compile.js
CHANGED
|
@@ -50,13 +50,14 @@ var compile_default = (api) => {
|
|
|
50
50
|
extraRemarkPlugins: api.config.extraRemarkPlugins,
|
|
51
51
|
extraRehypePlugins: api.config.extraRehypePlugins
|
|
52
52
|
};
|
|
53
|
-
memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("md-meta-loader").loader(loaderPath).options({
|
|
53
|
+
memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-meta-loader").loader(loaderPath).options({
|
|
54
54
|
...loaderBaseOpts,
|
|
55
55
|
mode: "meta"
|
|
56
56
|
}).end().end().oneOf("md").use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-loader").loader(loaderPath).options({
|
|
57
57
|
...loaderBaseOpts,
|
|
58
58
|
builtins: api.service.themeData.builtins
|
|
59
59
|
});
|
|
60
|
+
memo.module.rule("dumi-page").type("javascript/auto").test(/\.(j|t)sx?$/).resourceQuery(/meta$/).use("page-meta-loader").loader(require.resolve("../loaders/page"));
|
|
60
61
|
memo.module.rule("dumi-demo").type("javascript/auto").test(/\..+$/).enforce("pre").resourceQuery(/techStack/).use("demo-loader").loader(require.resolve("../loaders/demo")).options({ techStacks, cwd: api.cwd });
|
|
61
62
|
memo.module.rule("dumi-raw").resourceQuery(/raw/).use("raw-loader").loader(require.resolve("raw-loader"));
|
|
62
63
|
if (api.env === "development") {
|
|
@@ -30,7 +30,8 @@ function getSchemas() {
|
|
|
30
30
|
resolve: (Joi) => Joi.object({
|
|
31
31
|
docDirs: Joi.array().items(Joi.string()).optional(),
|
|
32
32
|
entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
|
|
33
|
-
codeBlockMode: Joi.string().valid("active", "passive").optional()
|
|
33
|
+
codeBlockMode: Joi.string().valid("active", "passive").optional(),
|
|
34
|
+
entryFile: Joi.string().optional()
|
|
34
35
|
}).optional(),
|
|
35
36
|
extraRemarkPlugins: getUnifiedPluginSchema,
|
|
36
37
|
extraRehypePlugins: getUnifiedPluginSchema,
|
package/dist/features/meta.d.ts
CHANGED
package/dist/features/meta.js
CHANGED
|
@@ -19,18 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/features/meta.ts
|
|
20
20
|
var meta_exports = {};
|
|
21
21
|
__export(meta_exports, {
|
|
22
|
+
ATOMS_META_PATH: () => ATOMS_META_PATH,
|
|
22
23
|
default: () => meta_default
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(meta_exports);
|
|
25
26
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
27
|
+
var ATOMS_META_PATH = "dumi/meta/atoms.ts";
|
|
26
28
|
var meta_default = (api) => {
|
|
27
|
-
const
|
|
29
|
+
const routeFiles = [];
|
|
28
30
|
api.modifyRoutes((routes) => {
|
|
29
|
-
|
|
31
|
+
routeFiles.length = 0;
|
|
30
32
|
Object.values(routes).forEach((route) => {
|
|
31
|
-
if (route.
|
|
32
|
-
|
|
33
|
-
index:
|
|
33
|
+
if (!route.isLayout && !/\*|:/.test(route.path)) {
|
|
34
|
+
routeFiles.push({
|
|
35
|
+
index: routeFiles.length,
|
|
34
36
|
file: route.file,
|
|
35
37
|
id: route.id
|
|
36
38
|
});
|
|
@@ -39,24 +41,31 @@ var meta_default = (api) => {
|
|
|
39
41
|
return routes;
|
|
40
42
|
});
|
|
41
43
|
api.onGenerateFiles(() => {
|
|
44
|
+
api.writeTmpFile({
|
|
45
|
+
noPluginDir: true,
|
|
46
|
+
path: ATOMS_META_PATH,
|
|
47
|
+
content: "export const components = null;"
|
|
48
|
+
});
|
|
42
49
|
api.writeTmpFile({
|
|
43
50
|
noPluginDir: true,
|
|
44
51
|
path: "dumi/meta/index.ts",
|
|
45
|
-
content: import_plugin_utils.Mustache.render(`{{#
|
|
52
|
+
content: import_plugin_utils.Mustache.render(`{{#routeFiles}}
|
|
46
53
|
import { demos as d{{{index}}}, frontmatter as fm{{{index}}}, toc as toc{{{index}}} } from '{{{file}}}?type=meta';
|
|
47
|
-
{{/
|
|
54
|
+
{{/routeFiles}}
|
|
55
|
+
|
|
56
|
+
export { components } from './atoms';
|
|
48
57
|
|
|
49
58
|
export const demos = {
|
|
50
|
-
{{#
|
|
59
|
+
{{#routeFiles}}
|
|
51
60
|
...d{{{index}}},
|
|
52
|
-
{{/
|
|
61
|
+
{{/routeFiles}}
|
|
53
62
|
};
|
|
54
63
|
|
|
55
64
|
export const routesMeta = {
|
|
56
|
-
{{#
|
|
65
|
+
{{#routeFiles}}
|
|
57
66
|
'{{{id}}}': { frontmatter: fm{{{index}}}, toc: toc{{{index}}} },
|
|
58
|
-
{{/
|
|
59
|
-
}`, {
|
|
67
|
+
{{/routeFiles}}
|
|
68
|
+
}`, { routeFiles })
|
|
60
69
|
});
|
|
61
70
|
api.writeTmpFile({
|
|
62
71
|
noPluginDir: true,
|
|
@@ -75,4 +84,6 @@ export const patchRoutes = ({ routes }) => {
|
|
|
75
84
|
api.addRuntimePlugin(() => "@@/dumi/meta/runtime.ts");
|
|
76
85
|
};
|
|
77
86
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
ATOMS_META_PATH
|
|
89
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/features/parser.ts
|
|
23
|
+
var parser_exports = {};
|
|
24
|
+
__export(parser_exports, {
|
|
25
|
+
default: () => parser_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(parser_exports);
|
|
28
|
+
var import_atom = __toESM(require("../assetParsers/atom"));
|
|
29
|
+
var import_meta = require("./meta");
|
|
30
|
+
var parser_default = (api) => {
|
|
31
|
+
const writeAtomsMetaFile = (data) => {
|
|
32
|
+
api.writeTmpFile({
|
|
33
|
+
noPluginDir: true,
|
|
34
|
+
path: import_meta.ATOMS_META_PATH,
|
|
35
|
+
content: `export const components = ${JSON.stringify(data.components, null, 2)};`
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
api.describe({ key: "apiParser", enableBy: api.EnableBy.config });
|
|
39
|
+
api.modifyDefaultConfig((memo) => {
|
|
40
|
+
var _a;
|
|
41
|
+
if (!((_a = api.userConfig.resolve) == null ? void 0 : _a.entryFile)) {
|
|
42
|
+
api.logger.error("`resolve.entryFile` must be configured when `apiParser` enable");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
return memo;
|
|
46
|
+
});
|
|
47
|
+
api.onStart(() => {
|
|
48
|
+
api.service.atomParser = new import_atom.default({
|
|
49
|
+
entryFile: api.config.resolve.entryFile,
|
|
50
|
+
resolveDir: api.cwd
|
|
51
|
+
});
|
|
52
|
+
if (api.env === "production") {
|
|
53
|
+
api.service.atomParser.parse().then(writeAtomsMetaFile);
|
|
54
|
+
} else {
|
|
55
|
+
api.service.atomParser.watch(writeAtomsMetaFile);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {});
|
package/dist/features/routes.js
CHANGED
|
@@ -162,7 +162,7 @@ var routes_default = (api) => {
|
|
|
162
162
|
const layouts = [
|
|
163
163
|
{
|
|
164
164
|
id: CTX_LAYOUT_ID,
|
|
165
|
-
file:
|
|
165
|
+
file: `${api.paths.absTmpPath}/dumi/theme/ContextWrapper.tsx`
|
|
166
166
|
}
|
|
167
167
|
];
|
|
168
168
|
const { GlobalLayout } = api.service.themeData.layouts;
|
|
@@ -109,7 +109,7 @@ export { default } from '${item.source}';`
|
|
|
109
109
|
content: `import React, { useState, useEffect } from 'react';
|
|
110
110
|
import { useOutlet, history } from 'dumi';
|
|
111
111
|
import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
|
|
112
|
-
import { demos } from '../meta';
|
|
112
|
+
import { demos, components } from '../meta';
|
|
113
113
|
import { locales } from '../locales/config';
|
|
114
114
|
|
|
115
115
|
export default function DumiContextWrapper() {
|
|
@@ -124,6 +124,7 @@ export default function DumiContextWrapper() {
|
|
|
124
124
|
return (
|
|
125
125
|
<SiteContext.Provider value={{
|
|
126
126
|
demos,
|
|
127
|
+
components,
|
|
127
128
|
locales,
|
|
128
129
|
loading,
|
|
129
130
|
setLoading,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function pageMetaLoader(this: any, raw: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/loaders/page/index.ts
|
|
23
|
+
var page_exports = {};
|
|
24
|
+
__export(page_exports, {
|
|
25
|
+
default: () => pageMetaLoader
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(page_exports);
|
|
28
|
+
var import_utils = require("../../utils");
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
31
|
+
function pageMetaLoader(raw) {
|
|
32
|
+
const pathWithoutIndex = this.resourcePath.replace(/(\/index([^/]+)?)?\.(j|t)sx?$/, "");
|
|
33
|
+
let { frontmatter } = (0, import_utils.parseCodeFrontmatter)(raw);
|
|
34
|
+
frontmatter || (frontmatter = {});
|
|
35
|
+
frontmatter.title ?? (frontmatter.title = import_plugin_utils.lodash.startCase(import_path.default.basename(pathWithoutIndex)));
|
|
36
|
+
return `export const frontmatter = ${JSON.stringify(frontmatter)};
|
|
37
|
+
export const toc = [];
|
|
38
|
+
export const demos = {};`;
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {});
|
package/dist/preset.js
CHANGED
|
@@ -37,7 +37,8 @@ var preset_default = (api) => {
|
|
|
37
37
|
require.resolve("./features/routes"),
|
|
38
38
|
require.resolve("./features/meta"),
|
|
39
39
|
require.resolve("./features/theme"),
|
|
40
|
-
require.resolve("./features/locales")
|
|
40
|
+
require.resolve("./features/locales"),
|
|
41
|
+
require.resolve("./features/parser")
|
|
41
42
|
]
|
|
42
43
|
};
|
|
43
44
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type AtomAssetsParser from "./assetParsers/atom";
|
|
1
2
|
import type { IDumiDemoProps } from "./client/theme-api/DumiDemo";
|
|
2
3
|
import type { ILocalesConfig, IThemeConfig } from "./client/theme-api/types";
|
|
3
4
|
import type { IThemeLoadResult } from "./features/theme/loader";
|
|
@@ -14,6 +15,7 @@ export interface IDumiConfig extends IUmiConfig {
|
|
|
14
15
|
dir: string;
|
|
15
16
|
}[];
|
|
16
17
|
codeBlockMode: 'active' | 'passive';
|
|
18
|
+
entryFile?: string;
|
|
17
19
|
};
|
|
18
20
|
locales: ILocalesConfig;
|
|
19
21
|
themeConfig: IThemeConfig;
|
|
@@ -62,6 +64,7 @@ export declare type IApi = IUmiApi & {
|
|
|
62
64
|
userConfig: IDumiUserConfig;
|
|
63
65
|
service: IUmiApi['service'] & {
|
|
64
66
|
themeData: IThemeLoadResult;
|
|
67
|
+
atomParser: AtomAssetsParser;
|
|
65
68
|
};
|
|
66
69
|
/**
|
|
67
70
|
* register a new tech stack
|
package/dist/utils.d.ts
CHANGED
|
@@ -13,3 +13,10 @@ export declare const getFileRangeLines: (content: string, range: string) => stri
|
|
|
13
13
|
* @param filePath source file path
|
|
14
14
|
*/
|
|
15
15
|
export declare const getFileContentByRegExp: (content: string, regexp: string, filePath: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* parse frontmatter from code string
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseCodeFrontmatter(raw: string): {
|
|
20
|
+
code: string;
|
|
21
|
+
frontmatter: Record<string, any> | null;
|
|
22
|
+
};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
21
|
|
|
19
22
|
// src/utils.ts
|
|
@@ -21,9 +24,11 @@ var utils_exports = {};
|
|
|
21
24
|
__export(utils_exports, {
|
|
22
25
|
getFileContentByRegExp: () => getFileContentByRegExp,
|
|
23
26
|
getFileRangeLines: () => getFileRangeLines,
|
|
24
|
-
getRoutePathFromFsPath: () => getRoutePathFromFsPath
|
|
27
|
+
getRoutePathFromFsPath: () => getRoutePathFromFsPath,
|
|
28
|
+
parseCodeFrontmatter: () => parseCodeFrontmatter
|
|
25
29
|
});
|
|
26
30
|
module.exports = __toCommonJS(utils_exports);
|
|
31
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
27
32
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
28
33
|
function getRoutePathFromFsPath(fsPath) {
|
|
29
34
|
return import_plugin_utils.lodash.kebabCase((0, import_plugin_utils.winPath)(fsPath).replace(/((\/|^)index(\.[a-zA-Z-]+)?)?\.\w+$/g, ""));
|
|
@@ -48,9 +53,20 @@ Error: ${err}`);
|
|
|
48
53
|
return content;
|
|
49
54
|
}
|
|
50
55
|
};
|
|
56
|
+
function parseCodeFrontmatter(raw) {
|
|
57
|
+
const [, comment = "", code = ""] = raw.replace(/^\n\s*/, "").match(/^(\/\*\*[^]*?\n\s*\*\/)?(?:\s|\n)*([^]+)?$/);
|
|
58
|
+
const yamlComment = comment.replace(/^\/|\/$/g, "").replace(/(^|\n)\s*\*+/g, "$1");
|
|
59
|
+
let frontmatter = null;
|
|
60
|
+
try {
|
|
61
|
+
frontmatter = import_js_yaml.default.load(yamlComment);
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return { code: frontmatter ? code : raw, frontmatter };
|
|
65
|
+
}
|
|
51
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
67
|
0 && (module.exports = {
|
|
53
68
|
getFileContentByRegExp,
|
|
54
69
|
getFileRangeLines,
|
|
55
|
-
getRoutePathFromFsPath
|
|
70
|
+
getRoutePathFromFsPath,
|
|
71
|
+
parseCodeFrontmatter
|
|
56
72
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "Framework for developing UI components",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"@types/mdast": "^3.0.10",
|
|
60
60
|
"@umijs/bundler-utils": "^4.0.22",
|
|
61
61
|
"@umijs/core": "^4.0.22",
|
|
62
|
+
"dumi-afx-deps": "^1.0.0-alpha.1",
|
|
62
63
|
"dumi-assets-types": "2.0.0-alpha.0",
|
|
63
64
|
"estree-util-to-js": "^1.1.0",
|
|
64
65
|
"estree-util-visit": "^1.2.0",
|
|
@@ -110,7 +111,7 @@
|
|
|
110
111
|
"@umijs/test": "^4.0.22",
|
|
111
112
|
"cross-env": "^7.0.3",
|
|
112
113
|
"eslint": "^8.20.0",
|
|
113
|
-
"father": "^4.0.
|
|
114
|
+
"father": "^4.0.7",
|
|
114
115
|
"husky": "^8.0.1",
|
|
115
116
|
"jest": "^27.0.0",
|
|
116
117
|
"lint-staged": "^13.0.3",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { useAtomAssets, useIntl } from 'dumi';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
|
|
16
|
+
var API = function API(_ref) {
|
|
17
|
+
var _definition$propsConf;
|
|
18
|
+
|
|
19
|
+
var id = _ref.id;
|
|
20
|
+
|
|
21
|
+
var _useAtomAssets = useAtomAssets(),
|
|
22
|
+
components = _useAtomAssets.components;
|
|
23
|
+
|
|
24
|
+
var definition = components === null || components === void 0 ? void 0 : components[id];
|
|
25
|
+
var intl = useIntl();
|
|
26
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
27
|
+
className: "markdown"
|
|
28
|
+
}, /*#__PURE__*/React.createElement("table", null, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
29
|
+
id: 'api.component.name'
|
|
30
|
+
})), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
31
|
+
id: 'api.component.description'
|
|
32
|
+
})), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
33
|
+
id: 'api.component.type'
|
|
34
|
+
})), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
35
|
+
id: 'api.component.default'
|
|
36
|
+
})))), /*#__PURE__*/React.createElement("tbody", null, definition && (_definition$propsConf = definition.propsConfig) !== null && _definition$propsConf !== void 0 && _definition$propsConf.properties ? Object.entries(definition.propsConfig.properties).map(function (_ref2) {
|
|
37
|
+
var _definition$propsConf2;
|
|
38
|
+
|
|
39
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
40
|
+
name = _ref3[0],
|
|
41
|
+
prop = _ref3[1];
|
|
42
|
+
|
|
43
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
44
|
+
key: name
|
|
45
|
+
}, /*#__PURE__*/React.createElement("td", null, name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, prop.type)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf2 = definition.propsConfig.required) !== null && _definition$propsConf2 !== void 0 && _definition$propsConf2.includes(name) ? intl.formatMessage({
|
|
46
|
+
id: 'api.component.required'
|
|
47
|
+
}) : prop.default || '--')));
|
|
48
|
+
}) : /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
|
|
49
|
+
colSpan: 4
|
|
50
|
+
}, intl.formatMessage({
|
|
51
|
+
id: "api.component.".concat(components ? 'not.found' : 'loading')
|
|
52
|
+
}, {
|
|
53
|
+
id: id
|
|
54
|
+
}))))));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default API;
|
|
@@ -7,5 +7,12 @@
|
|
|
7
7
|
"previewer.actions.codepen": "Open in CodePen (Not implemented)",
|
|
8
8
|
"previewer.actions.separate": "Open in separate page",
|
|
9
9
|
"404.title": "PAGE NOT FOUND",
|
|
10
|
-
"404.back": "Back to homepage"
|
|
10
|
+
"404.back": "Back to homepage",
|
|
11
|
+
"api.component.name": "Name",
|
|
12
|
+
"api.component.description": "Description",
|
|
13
|
+
"api.component.type": "Type",
|
|
14
|
+
"api.component.default": "Default",
|
|
15
|
+
"api.component.required": "(required)",
|
|
16
|
+
"api.component.loading": "Properties definition is resolving, wait a moment...",
|
|
17
|
+
"api.component.not.found": "Properties definition not found for {id} component"
|
|
11
18
|
}
|
|
@@ -7,5 +7,12 @@
|
|
|
7
7
|
"previewer.actions.codepen": "在 CodePen 中打开(未实现)",
|
|
8
8
|
"previewer.actions.separate": "在独立页面中打开",
|
|
9
9
|
"404.title": "页面未找到",
|
|
10
|
-
"404.back": "返回首页"
|
|
10
|
+
"404.back": "返回首页",
|
|
11
|
+
"api.component.name": "属性名",
|
|
12
|
+
"api.component.description": "描述",
|
|
13
|
+
"api.component.type": "类型",
|
|
14
|
+
"api.component.default": "默认值",
|
|
15
|
+
"api.component.required": "(必选)",
|
|
16
|
+
"api.component.loading": "属性定义正在解析中,稍等片刻...",
|
|
17
|
+
"api.component.not.found": "未找到 {id} 组件的属性定义"
|
|
11
18
|
}
|
|
@@ -23,6 +23,24 @@
|
|
|
23
23
|
padding-right: 24px;
|
|
24
24
|
background-color: tint(@c-site-bg, 50%);
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
// table
|
|
28
|
+
table {
|
|
29
|
+
width: 100%;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
th {
|
|
33
|
+
background-color: tint(@c-site-bg, 50%);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
th,
|
|
37
|
+
td {
|
|
38
|
+
padding-block-start: 10px;
|
|
39
|
+
padding-block-end: 10px;
|
|
40
|
+
padding-inline-start: 16px;
|
|
41
|
+
padding-inline-end: 16px;
|
|
42
|
+
border-color: @c-border-light;
|
|
43
|
+
}
|
|
26
44
|
}
|
|
27
45
|
|
|
28
46
|
.@{prefix}-content {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"paths": {
|
|
5
|
-
"@/*": ["src/*"],
|
|
6
|
-
"@@/*": ["src/.umi/*"],
|
|
7
|
-
"dumi": ["."],
|
|
8
|
-
"dumi/theme": ["src/client/theme-api"],
|
|
9
|
-
"dumi/theme/*": ["src/client/theme-default/*"]
|
|
10
|
-
},
|
|
11
|
-
"types": ["../../src/.umi/typings"]
|
|
12
|
-
}
|
|
13
|
-
}
|