@umijs/plugins 4.0.6 → 4.0.9
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/access.js +69 -53
- package/dist/analytics.js +62 -41
- package/dist/antd.js +139 -123
- package/dist/dva.js +133 -142
- package/dist/icons.js +28 -4
- package/dist/initial-state.js +71 -54
- package/dist/layout.js +201 -209
- package/dist/locale.js +214 -192
- package/dist/model.js +79 -78
- package/dist/moment2dayjs.js +102 -81
- package/dist/qiankun/constants.js +41 -8
- package/dist/qiankun/master.js +147 -121
- package/dist/qiankun/slave.js +160 -150
- package/dist/qiankun.js +46 -19
- package/dist/request.js +87 -56
- package/dist/tailwindcss.js +70 -49
- package/dist/unocss.js +57 -37
- package/dist/utils/astUtils.js +38 -34
- package/dist/utils/localeUtils.js +125 -120
- package/dist/utils/modelUtils.js +216 -237
- package/dist/utils/resolveProjectDep.js +36 -13
- package/dist/utils/withTmpPath.js +31 -9
- package/libs/locale/SelectLang.tpl +1 -1
- package/libs/locale/localeExports.tpl +4 -3
- package/libs/qiankun/master/MicroApp.tsx +17 -12
- package/libs/qiankun/slave/lifecycles.ts +20 -6
- package/package.json +6 -6
package/dist/locale.js
CHANGED
|
@@ -1,199 +1,221 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
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));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// locale.ts
|
|
40
|
+
var locale_exports = {};
|
|
41
|
+
__export(locale_exports, {
|
|
42
|
+
default: () => locale_default,
|
|
43
|
+
packageNormalize: () => packageNormalize
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(locale_exports);
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
49
|
+
var import_localeUtils = require("./utils/localeUtils");
|
|
50
|
+
var import_withTmpPath = require("./utils/withTmpPath");
|
|
51
|
+
var packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, "_");
|
|
52
|
+
var locale_default = (api) => {
|
|
53
|
+
let hasAntd = false;
|
|
54
|
+
try {
|
|
55
|
+
hasAntd = !!require.resolve("antd");
|
|
56
|
+
} catch (e) {
|
|
57
|
+
api.logger.warn("antd is not installed. <SelecLang /> unavailable");
|
|
58
|
+
}
|
|
59
|
+
const defaultConfig = {
|
|
60
|
+
baseNavigator: true,
|
|
61
|
+
useLocalStorage: true,
|
|
62
|
+
baseSeparator: "-",
|
|
63
|
+
antd: hasAntd
|
|
64
|
+
};
|
|
65
|
+
api.describe({
|
|
66
|
+
key: "locale",
|
|
67
|
+
config: {
|
|
68
|
+
schema(Joi) {
|
|
69
|
+
return Joi.alternatives().try(Joi.object({
|
|
70
|
+
default: Joi.string(),
|
|
71
|
+
useLocalStorage: Joi.boolean(),
|
|
72
|
+
baseNavigator: Joi.boolean(),
|
|
73
|
+
title: Joi.boolean(),
|
|
74
|
+
antd: Joi.boolean(),
|
|
75
|
+
baseSeparator: Joi.string()
|
|
76
|
+
}), Joi.boolean().invalid(true));
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
enableBy: api.EnableBy.config
|
|
80
|
+
});
|
|
81
|
+
const reactIntlPkgPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("react-intl/package")));
|
|
82
|
+
api.addEntryImportsAhead(() => (0, import_localeUtils.isNeedPolyfill)(api.config.targets || {}) ? [
|
|
83
|
+
{
|
|
84
|
+
source: require.resolve("intl")
|
|
20
85
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return joi.object({
|
|
32
|
-
default: joi.string(),
|
|
33
|
-
useLocalStorage: joi.boolean(),
|
|
34
|
-
baseNavigator: joi.boolean(),
|
|
35
|
-
title: joi.boolean(),
|
|
36
|
-
antd: joi.boolean(),
|
|
37
|
-
baseSeparator: joi.string(),
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
enableBy: api.EnableBy.config,
|
|
86
|
+
] : []);
|
|
87
|
+
const addAntdLocales = async (args) => {
|
|
88
|
+
var _a;
|
|
89
|
+
return await api.applyPlugins({
|
|
90
|
+
key: "addAntdLocales",
|
|
91
|
+
type: api.ApplyPluginsType.add,
|
|
92
|
+
initialValue: [
|
|
93
|
+
`antd/${((_a = api.config) == null ? void 0 : _a.ssr) ? "lib" : "es"}/locale/${(0, import_localeUtils.getAntdLocale)(args.lang, args.country)}`
|
|
94
|
+
],
|
|
95
|
+
args
|
|
42
96
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
};
|
|
98
|
+
const getList = async (resolveKey) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const { paths } = api;
|
|
101
|
+
return (0, import_localeUtils.getLocaleList)({
|
|
102
|
+
localeFolder: "locales",
|
|
103
|
+
separator: (_a = api.config.locale) == null ? void 0 : _a.baseSeparator,
|
|
104
|
+
absSrcPath: paths.absSrcPath,
|
|
105
|
+
absPagesPath: paths.absPagesPath,
|
|
106
|
+
addAntdLocales,
|
|
107
|
+
resolveKey
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
api.onGenerateFiles(async () => {
|
|
111
|
+
var _a, _b, _c, _d;
|
|
112
|
+
const localeTpl = (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../libs/locale/locale.tpl"), "utf-8");
|
|
113
|
+
const resolveKey = api.config.moment2dayjs ? "dayjs" : "moment";
|
|
114
|
+
const momentPkgPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve(`${resolveKey}/package.json`)));
|
|
115
|
+
const EventEmitterPkg = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("event-emitter/package")));
|
|
116
|
+
const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = __spreadValues(__spreadValues({}, defaultConfig), api.config.locale);
|
|
117
|
+
const defaultLocale = ((_a = api.config.locale) == null ? void 0 : _a.default) || `zh${baseSeparator}CN`;
|
|
118
|
+
const localeList = await getList(resolveKey);
|
|
119
|
+
const momentLocales = localeList.map(({ momentLocale }) => momentLocale).filter((locale) => locale);
|
|
120
|
+
const antdLocales = localeList.map(({ antdLocale }) => antdLocale).filter((locale) => locale);
|
|
121
|
+
let MomentLocales = momentLocales;
|
|
122
|
+
let DefaultMomentLocale = "";
|
|
123
|
+
if (!MomentLocales.length && ((_b = api.config.locale) == null ? void 0 : _b.default)) {
|
|
124
|
+
const [lang, country = ""] = defaultLocale.split(baseSeparator);
|
|
125
|
+
const { momentLocale } = (0, import_localeUtils.getMomentLocale)(lang, country, resolveKey);
|
|
126
|
+
if (momentLocale) {
|
|
127
|
+
MomentLocales = [momentLocale];
|
|
128
|
+
DefaultMomentLocale = momentLocale;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let DefaultAntdLocales = [];
|
|
132
|
+
if (!antdLocales.length && ((_c = api.config.locale) == null ? void 0 : _c.antd)) {
|
|
133
|
+
const [lang, country = ""] = defaultLocale.split(baseSeparator);
|
|
134
|
+
DefaultAntdLocales = import_plugin_utils.lodash.uniq(await addAntdLocales({
|
|
135
|
+
lang,
|
|
136
|
+
country
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
const NormalizeAntdLocalesName = function() {
|
|
140
|
+
return packageNormalize(this);
|
|
74
141
|
};
|
|
75
|
-
api.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
api.writeTmpFile({
|
|
119
|
-
content: plugin_utils_1.Mustache.render(localeTpl, {
|
|
120
|
-
MomentLocales,
|
|
121
|
-
DefaultMomentLocale,
|
|
122
|
-
NormalizeAntdLocalesName,
|
|
123
|
-
DefaultAntdLocales,
|
|
124
|
-
Antd: !!antd,
|
|
125
|
-
Title: title && api.config.title,
|
|
126
|
-
BaseSeparator: baseSeparator,
|
|
127
|
-
DefaultLocale: defaultLocale,
|
|
128
|
-
DefaultLang: defaultLocale,
|
|
129
|
-
momentPkgPath,
|
|
130
|
-
}),
|
|
131
|
-
path: 'locale.tsx',
|
|
132
|
-
});
|
|
133
|
-
const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
|
|
134
|
-
const localeDirName = 'locales';
|
|
135
|
-
const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
|
|
136
|
-
api.writeTmpFile({
|
|
137
|
-
path: 'localeExports.ts',
|
|
138
|
-
content: plugin_utils_1.Mustache.render(localeExportsTpl, {
|
|
139
|
-
EventEmitterPkg,
|
|
140
|
-
BaseSeparator: baseSeparator,
|
|
141
|
-
BaseNavigator: baseNavigator,
|
|
142
|
-
UseLocalStorage: !!useLocalStorage,
|
|
143
|
-
LocaleDir: localeDirName,
|
|
144
|
-
ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
|
|
145
|
-
LocaleList: localeList.map((locale) => ({
|
|
146
|
-
...locale,
|
|
147
|
-
antdLocale: locale.antdLocale.map((antdLocale, index) => ({
|
|
148
|
-
locale: antdLocale,
|
|
149
|
-
index: index,
|
|
150
|
-
})),
|
|
151
|
-
paths: locale.paths.map((path, index) => ({
|
|
152
|
-
path,
|
|
153
|
-
index,
|
|
154
|
-
})),
|
|
155
|
-
})),
|
|
156
|
-
Antd: !!antd,
|
|
157
|
-
DefaultLocale: JSON.stringify(defaultLocale),
|
|
158
|
-
warningPkgPath: (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('warning/package'))),
|
|
159
|
-
reactIntlPkgPath,
|
|
160
|
-
}),
|
|
161
|
-
});
|
|
162
|
-
// runtime.tsx
|
|
163
|
-
const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/runtime.tpl'), 'utf-8');
|
|
164
|
-
api.writeTmpFile({
|
|
165
|
-
path: 'runtime.tsx',
|
|
166
|
-
content: plugin_utils_1.Mustache.render(runtimeTpl, {
|
|
167
|
-
Title: !!title,
|
|
168
|
-
}),
|
|
169
|
-
});
|
|
170
|
-
// SelectLang.tsx
|
|
171
|
-
const selectLang = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/SelectLang.tpl'), 'utf-8');
|
|
172
|
-
api.writeTmpFile({
|
|
173
|
-
path: 'SelectLang.tsx',
|
|
174
|
-
content: plugin_utils_1.Mustache.render(selectLang, {
|
|
175
|
-
Antd: !!antd,
|
|
176
|
-
LocaleList: localeList,
|
|
177
|
-
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
178
|
-
antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
|
|
179
|
-
}),
|
|
180
|
-
});
|
|
181
|
-
// index.ts
|
|
182
|
-
api.writeTmpFile({
|
|
183
|
-
path: 'index.ts',
|
|
184
|
-
content: `
|
|
185
|
-
export { setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage, getAllLocales } from './localeExports.ts';
|
|
186
|
-
export { SelectLang } from './SelectLang.tsx';
|
|
187
|
-
`,
|
|
188
|
-
});
|
|
142
|
+
api.writeTmpFile({
|
|
143
|
+
content: import_plugin_utils.Mustache.render(localeTpl, {
|
|
144
|
+
MomentLocales,
|
|
145
|
+
DefaultMomentLocale,
|
|
146
|
+
NormalizeAntdLocalesName,
|
|
147
|
+
DefaultAntdLocales,
|
|
148
|
+
Antd: !!antd,
|
|
149
|
+
Title: title && api.config.title,
|
|
150
|
+
BaseSeparator: baseSeparator,
|
|
151
|
+
DefaultLocale: defaultLocale,
|
|
152
|
+
DefaultLang: defaultLocale,
|
|
153
|
+
momentPkgPath
|
|
154
|
+
}),
|
|
155
|
+
path: "locale.tsx"
|
|
156
|
+
});
|
|
157
|
+
const localeExportsTpl = (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../libs/locale/localeExports.tpl"), "utf-8");
|
|
158
|
+
const localeDirName = "locales";
|
|
159
|
+
const localeDirPath = (0, import_path.join)(api.paths.absSrcPath, localeDirName);
|
|
160
|
+
api.writeTmpFile({
|
|
161
|
+
path: "localeExports.ts",
|
|
162
|
+
content: import_plugin_utils.Mustache.render(localeExportsTpl, {
|
|
163
|
+
EventEmitterPkg,
|
|
164
|
+
BaseSeparator: baseSeparator,
|
|
165
|
+
BaseNavigator: baseNavigator,
|
|
166
|
+
UseLocalStorage: !!useLocalStorage,
|
|
167
|
+
LocaleDir: localeDirName,
|
|
168
|
+
ExistLocaleDir: (0, import_fs.existsSync)(localeDirPath),
|
|
169
|
+
LocaleList: localeList.map((locale) => __spreadProps(__spreadValues({}, locale), {
|
|
170
|
+
antdLocale: locale.antdLocale.map((antdLocale, index) => ({
|
|
171
|
+
locale: antdLocale,
|
|
172
|
+
index
|
|
173
|
+
})),
|
|
174
|
+
paths: locale.paths.map((path, index) => ({
|
|
175
|
+
path,
|
|
176
|
+
index
|
|
177
|
+
}))
|
|
178
|
+
})),
|
|
179
|
+
Antd: !!antd,
|
|
180
|
+
DefaultLocale: JSON.stringify(defaultLocale),
|
|
181
|
+
warningPkgPath: (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("warning/package"))),
|
|
182
|
+
reactIntlPkgPath
|
|
183
|
+
})
|
|
189
184
|
});
|
|
190
|
-
|
|
191
|
-
api.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
const runtimeTpl = (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../libs/locale/runtime.tpl"), "utf-8");
|
|
186
|
+
api.writeTmpFile({
|
|
187
|
+
path: "runtime.tsx",
|
|
188
|
+
content: import_plugin_utils.Mustache.render(runtimeTpl, {
|
|
189
|
+
Title: !!title
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
const selectLang = (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../libs/locale/SelectLang.tpl"), "utf-8");
|
|
193
|
+
api.writeTmpFile({
|
|
194
|
+
path: "SelectLang.tsx",
|
|
195
|
+
content: import_plugin_utils.Mustache.render(selectLang, {
|
|
196
|
+
Antd: !!antd,
|
|
197
|
+
LocaleList: localeList,
|
|
198
|
+
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
199
|
+
antdFiles: ((_d = api.config) == null ? void 0 : _d.ssr) ? "lib" : "es"
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
api.writeTmpFile({
|
|
203
|
+
path: "index.ts",
|
|
204
|
+
content: `
|
|
205
|
+
export { addLocale, setLocale, getLocale, getIntl, useIntl, injectIntl, formatMessage, FormattedMessage, getAllLocales } from './localeExports.ts';
|
|
206
|
+
export { SelectLang } from './SelectLang.tsx';
|
|
207
|
+
`
|
|
198
208
|
});
|
|
209
|
+
});
|
|
210
|
+
api.addRuntimePlugin(() => [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })]);
|
|
211
|
+
api.addRuntimePluginKey(() => ["locale"]);
|
|
212
|
+
api.addTmpGenerateWatcherPaths(async () => {
|
|
213
|
+
const resolveKey = api.config.moment2dayjs ? "dayjs" : "moment";
|
|
214
|
+
const localeList = await getList(resolveKey);
|
|
215
|
+
return (0, import_localeUtils.exactLocalePaths)(localeList);
|
|
216
|
+
});
|
|
199
217
|
};
|
|
218
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
219
|
+
0 && (module.exports = {
|
|
220
|
+
packageNormalize
|
|
221
|
+
});
|
package/dist/model.js
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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;
|
|
24
18
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
// model.ts
|
|
23
|
+
var model_exports = {};
|
|
24
|
+
__export(model_exports, {
|
|
25
|
+
default: () => model_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(model_exports);
|
|
28
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
29
|
+
var import_fs = require("fs");
|
|
30
|
+
var import_path = require("path");
|
|
31
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
32
|
+
var import_modelUtils = require("./utils/modelUtils");
|
|
33
|
+
var import_withTmpPath = require("./utils/withTmpPath");
|
|
34
|
+
var model_default = (api) => {
|
|
35
|
+
api.describe({
|
|
36
|
+
config: {
|
|
37
|
+
schema(Joi) {
|
|
38
|
+
return Joi.alternatives().try(Joi.object({
|
|
39
|
+
extraModels: Joi.array().items(Joi.string())
|
|
40
|
+
}), Joi.boolean().invalid(true));
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
enableBy: api.EnableBy.config
|
|
44
|
+
});
|
|
45
|
+
api.onGenerateFiles(async () => {
|
|
46
|
+
const models = await getAllModels(api);
|
|
47
|
+
api.writeTmpFile({
|
|
48
|
+
path: "model.ts",
|
|
49
|
+
content: import_modelUtils.ModelUtils.getModelsContent(models)
|
|
50
|
+
});
|
|
51
|
+
const indexContent = (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../libs/model.tsx"), "utf-8").replace("fast-deep-equal", (0, import_plugin_utils.winPath)(require.resolve("fast-deep-equal")));
|
|
52
|
+
api.writeTmpFile({
|
|
53
|
+
path: "index.tsx",
|
|
54
|
+
content: indexContent
|
|
42
55
|
});
|
|
43
|
-
api.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
api.writeTmpFile({
|
|
47
|
-
path: 'model.ts',
|
|
48
|
-
content: modelUtils_1.ModelUtils.getModelsContent(models),
|
|
49
|
-
});
|
|
50
|
-
// index.tsx
|
|
51
|
-
const indexContent = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/model.tsx'), 'utf-8').replace('fast-deep-equal', (0, plugin_utils_1.winPath)(require.resolve('fast-deep-equal')));
|
|
52
|
-
api.writeTmpFile({
|
|
53
|
-
path: 'index.tsx',
|
|
54
|
-
content: indexContent,
|
|
55
|
-
});
|
|
56
|
-
// runtime.tsx
|
|
57
|
-
api.writeTmpFile({
|
|
58
|
-
path: 'runtime.tsx',
|
|
59
|
-
content: `
|
|
56
|
+
api.writeTmpFile({
|
|
57
|
+
path: "runtime.tsx",
|
|
58
|
+
content: `
|
|
60
59
|
import React from 'react';
|
|
61
60
|
import { Provider } from './';
|
|
62
61
|
import { models as rawModels } from './model';
|
|
@@ -74,28 +73,30 @@ function ProviderWrapper(props: any) {
|
|
|
74
73
|
export function dataflowProvider(container, opts) {
|
|
75
74
|
return <ProviderWrapper {...opts}>{ container }</ProviderWrapper>;
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
api.addTmpGenerateWatcherPaths(() => {
|
|
81
|
-
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
82
|
-
});
|
|
83
|
-
api.addRuntimePlugin(() => {
|
|
84
|
-
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
76
|
+
`
|
|
85
77
|
});
|
|
78
|
+
});
|
|
79
|
+
api.addTmpGenerateWatcherPaths(() => {
|
|
80
|
+
return [(0, import_path.join)(api.paths.absSrcPath, "models")];
|
|
81
|
+
});
|
|
82
|
+
api.addRuntimePlugin(() => {
|
|
83
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
|
|
84
|
+
});
|
|
86
85
|
};
|
|
87
86
|
async function getAllModels(api) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
const extraModels = await api.applyPlugins({
|
|
88
|
+
key: "addExtraModels",
|
|
89
|
+
type: api.ApplyPluginsType.add,
|
|
90
|
+
initialValue: []
|
|
91
|
+
});
|
|
92
|
+
return new import_modelUtils.ModelUtils(api, {
|
|
93
|
+
astTest({ node }) {
|
|
94
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
|
|
95
|
+
}
|
|
96
|
+
}).getAllModels({
|
|
97
|
+
sort: {},
|
|
98
|
+
extraModels: [...extraModels, ...api.config.model.extraModels || []]
|
|
99
|
+
});
|
|
101
100
|
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {});
|