@umijs/plugins 4.0.0-beta.1 → 4.0.0-beta.13
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 +73 -1
- package/dist/{sass.d.ts → analytics.d.ts} +0 -0
- package/dist/analytics.js +67 -0
- package/dist/antd.js +108 -6
- package/dist/dva.d.ts +3 -0
- package/dist/dva.js +169 -4
- package/dist/initial-state.js +112 -1
- package/dist/layout.js +445 -1
- package/dist/model.js +112 -1
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +96 -0
- package/dist/utils/astUtils.d.ts +3 -0
- package/dist/utils/astUtils.js +34 -0
- package/dist/utils/modelUtils.d.ts +34 -0
- package/dist/utils/modelUtils.js +131 -0
- package/dist/utils/resolveProjectDep.d.ts +5 -0
- package/dist/utils/resolveProjectDep.js +15 -0
- package/dist/utils/withTmpPath.d.ts +6 -0
- package/dist/utils/withTmpPath.js +11 -0
- package/libs/dva.ts +10 -0
- package/libs/model.tsx +140 -0
- package/package.json +28 -14
- package/dist/sass.js +0 -5
package/dist/layout.js
CHANGED
|
@@ -1,5 +1,449 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
2
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const allIcons = __importStar(require("@ant-design/icons"));
|
|
26
|
+
const assert_1 = __importDefault(require("assert"));
|
|
27
|
+
const path_1 = require("path");
|
|
28
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
29
|
+
const resolveProjectDep_1 = require("./utils/resolveProjectDep");
|
|
30
|
+
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
3
31
|
exports.default = (api) => {
|
|
4
|
-
api
|
|
32
|
+
api.describe({
|
|
33
|
+
key: 'layout',
|
|
34
|
+
config: {
|
|
35
|
+
schema(joi) {
|
|
36
|
+
return joi.object();
|
|
37
|
+
},
|
|
38
|
+
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
|
39
|
+
},
|
|
40
|
+
enableBy: api.EnableBy.config,
|
|
41
|
+
});
|
|
42
|
+
const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
|
|
43
|
+
pkg: api.pkg,
|
|
44
|
+
cwd: api.cwd,
|
|
45
|
+
dep: '@ant-design/pro-layout',
|
|
46
|
+
}) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
|
|
47
|
+
api.modifyAppData((memo) => {
|
|
48
|
+
const version = require(`${pkgPath}/package.json`).version;
|
|
49
|
+
memo.pluginLayout = {
|
|
50
|
+
pkgPath,
|
|
51
|
+
version,
|
|
52
|
+
};
|
|
53
|
+
return memo;
|
|
54
|
+
});
|
|
55
|
+
api.modifyConfig((memo) => {
|
|
56
|
+
// import from @ant-design/pro-layout
|
|
57
|
+
memo.alias['@ant-design/pro-layout'] = pkgPath;
|
|
58
|
+
return memo;
|
|
59
|
+
});
|
|
60
|
+
api.onGenerateFiles(() => {
|
|
61
|
+
const hasInitialStatePlugin = api.config.initialState;
|
|
62
|
+
// Layout.tsx
|
|
63
|
+
api.writeTmpFile({
|
|
64
|
+
path: 'Layout.tsx',
|
|
65
|
+
content: `
|
|
66
|
+
import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteContext } from 'umi';
|
|
67
|
+
import ProLayout, {
|
|
68
|
+
PageLoading,
|
|
69
|
+
} from '@ant-design/pro-layout';
|
|
70
|
+
import './Layout.less';
|
|
71
|
+
import Logo from './Logo';
|
|
72
|
+
import { getRightRenderContent } from './rightRender';
|
|
73
|
+
${hasInitialStatePlugin
|
|
74
|
+
? `import { useModel } from '@@/plugin-model';`
|
|
75
|
+
: 'const useModel = null;'}
|
|
76
|
+
|
|
77
|
+
export default () => {
|
|
78
|
+
const location = useLocation();
|
|
79
|
+
const navigate = useNavigate();
|
|
80
|
+
const { clientRoutes, pluginManager } = useAppData();
|
|
81
|
+
const initialInfo = (useModel && useModel('@@initialState')) || {
|
|
82
|
+
initialState: undefined,
|
|
83
|
+
loading: false,
|
|
84
|
+
setInitialState: null,
|
|
85
|
+
};
|
|
86
|
+
const { initialState, loading, setInitialState } = initialInfo;
|
|
87
|
+
const userConfig = ${JSON.stringify(api.config.layout, null, 2)};
|
|
88
|
+
const runtimeConfig = pluginManager.applyPlugins({
|
|
89
|
+
key: 'layout',
|
|
90
|
+
type: 'modify',
|
|
91
|
+
initialValue: {},
|
|
92
|
+
});
|
|
93
|
+
return (
|
|
94
|
+
<ProLayout
|
|
95
|
+
route={clientRoutes[0]}
|
|
96
|
+
location={location}
|
|
97
|
+
title={userConfig.name || 'plugin-layout'}
|
|
98
|
+
navTheme="dark"
|
|
99
|
+
siderWidth={256}
|
|
100
|
+
onMenuHeaderClick={(e) => {
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
navigate('/');
|
|
104
|
+
}}
|
|
105
|
+
menu={{ locale: userConfig.locale }}
|
|
106
|
+
logo={Logo}
|
|
107
|
+
menuItemRender={(menuItemProps, defaultDom) => {
|
|
108
|
+
if (menuItemProps.isUrl || menuItemProps.children) {
|
|
109
|
+
return defaultDom;
|
|
110
|
+
}
|
|
111
|
+
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
|
|
112
|
+
return (
|
|
113
|
+
<Link to={menuItemProps.path} target={menuItemProps.target}>
|
|
114
|
+
{defaultDom}
|
|
115
|
+
</Link>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return defaultDom;
|
|
119
|
+
}}
|
|
120
|
+
disableContentMargin
|
|
121
|
+
fixSiderbar
|
|
122
|
+
fixedHeader
|
|
123
|
+
{...runtimeConfig}
|
|
124
|
+
rightContentRender={
|
|
125
|
+
runtimeConfig.rightContentRender !== false &&
|
|
126
|
+
((layoutProps) => {
|
|
127
|
+
const dom = getRightRenderContent({
|
|
128
|
+
runtimeConfig,
|
|
129
|
+
loading,
|
|
130
|
+
initialState,
|
|
131
|
+
setInitialState,
|
|
132
|
+
});
|
|
133
|
+
if (runtimeConfig.rightContentRender) {
|
|
134
|
+
return runtimeConfig.rightContentRender(layoutProps, dom, {
|
|
135
|
+
// BREAK CHANGE userConfig > runtimeConfig
|
|
136
|
+
userConfig,
|
|
137
|
+
runtimeConfig,
|
|
138
|
+
loading,
|
|
139
|
+
initialState,
|
|
140
|
+
setInitialState,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return dom;
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
>
|
|
147
|
+
<Outlet />
|
|
148
|
+
</ProLayout>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
`,
|
|
152
|
+
});
|
|
153
|
+
const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
|
|
154
|
+
const { icon } = api.appData.routes[id];
|
|
155
|
+
if (icon) {
|
|
156
|
+
const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
(0, assert_1.default)(allIcons[upperIcon], `Icon ${upperIcon} is not found`);
|
|
159
|
+
memo[upperIcon] = true;
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
if (allIcons[`${upperIcon}Outlined`]) {
|
|
162
|
+
memo[`${upperIcon}Outlined`] = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return memo;
|
|
166
|
+
}, {});
|
|
167
|
+
const icons = Object.keys(iconsMap);
|
|
168
|
+
const antIconsPath = (0, path_1.dirname)(require.resolve('@ant-design/icons/package'));
|
|
169
|
+
api.writeTmpFile({
|
|
170
|
+
path: 'icons.tsx',
|
|
171
|
+
content: `
|
|
172
|
+
${icons
|
|
173
|
+
.map((icon) => {
|
|
174
|
+
return `import ${icon} from '${antIconsPath}/es/icons/${icon}';`;
|
|
175
|
+
})
|
|
176
|
+
.join('\n')}
|
|
177
|
+
export default { ${icons.join(', ')} };
|
|
178
|
+
`,
|
|
179
|
+
});
|
|
180
|
+
// runtime.tsx
|
|
181
|
+
api.writeTmpFile({
|
|
182
|
+
path: 'runtime.tsx',
|
|
183
|
+
content: `
|
|
184
|
+
import React from 'react';
|
|
185
|
+
import icons from './icons';
|
|
186
|
+
|
|
187
|
+
function formatIcon(name: string) {
|
|
188
|
+
return name
|
|
189
|
+
.replace(name[0], name[0].toUpperCase())
|
|
190
|
+
.replace(/-(\w)/g, function(all, letter) {
|
|
191
|
+
return letter.toUpperCase();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function patchRoutes({ routes }) {
|
|
196
|
+
Object.keys(routes).forEach(key => {
|
|
197
|
+
const { icon } = routes[key];
|
|
198
|
+
if (icon && typeof icon === 'string') {
|
|
199
|
+
const upperIcon = formatIcon(icon);
|
|
200
|
+
routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
`,
|
|
205
|
+
});
|
|
206
|
+
// rightRender.tsx
|
|
207
|
+
api.writeTmpFile({
|
|
208
|
+
path: 'rightRender.tsx',
|
|
209
|
+
content: `
|
|
210
|
+
import React from 'react';
|
|
211
|
+
import { Avatar, Dropdown, Menu, Spin } from 'antd';
|
|
212
|
+
import { LogoutOutlined } from '@ant-design/icons';
|
|
213
|
+
|
|
214
|
+
export function getRightRenderContent (opts: {
|
|
215
|
+
runtimeConfig: any,
|
|
216
|
+
loading: boolean,
|
|
217
|
+
initialState: any,
|
|
218
|
+
setInitialState: any,
|
|
219
|
+
}) {
|
|
220
|
+
if (opts.runtimeConfig.rightRender) {
|
|
221
|
+
return opts.runtimeConfig.rightRender(
|
|
222
|
+
opts.initialState,
|
|
223
|
+
opts.setInitialState,
|
|
224
|
+
opts.runtimeConfig,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const menu = (
|
|
229
|
+
<Menu className="umi-plugin-layout-menu">
|
|
230
|
+
<Menu.Item
|
|
231
|
+
key="logout"
|
|
232
|
+
onClick={() =>
|
|
233
|
+
opts.runtimeConfig.logout && opts.runtimeConfig?.logout(opts.initialState)
|
|
234
|
+
}
|
|
235
|
+
>
|
|
236
|
+
<LogoutOutlined />
|
|
237
|
+
退出登录
|
|
238
|
+
</Menu.Item>
|
|
239
|
+
</Menu>
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const avatar = (
|
|
243
|
+
<span className="umi-plugin-layout-action">
|
|
244
|
+
<Avatar
|
|
245
|
+
size="small"
|
|
246
|
+
className="umi-plugin-layout-avatar"
|
|
247
|
+
src={
|
|
248
|
+
opts.initialState?.avatar ||
|
|
249
|
+
'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
|
|
250
|
+
}
|
|
251
|
+
alt="avatar"
|
|
252
|
+
/>
|
|
253
|
+
<span className="umi-plugin-layout-name">{opts.initialState?.name}</span>
|
|
254
|
+
</span>
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
if (opts.loading) {
|
|
258
|
+
return (
|
|
259
|
+
<div className="umi-plugin-layout-right">
|
|
260
|
+
<Spin size="small" style={{ marginLeft: 8, marginRight: 8 }} />
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div className="umi-plugin-layout-right anticon">
|
|
267
|
+
{opts.runtimeConfig.logout ? (
|
|
268
|
+
<Dropdown overlay={menu} overlayClassName="umi-plugin-layout-container">
|
|
269
|
+
{avatar}
|
|
270
|
+
</Dropdown>
|
|
271
|
+
) : (
|
|
272
|
+
avatar
|
|
273
|
+
)}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
// TODO: <SelectLang />
|
|
277
|
+
}
|
|
278
|
+
`,
|
|
279
|
+
});
|
|
280
|
+
// Layout.less
|
|
281
|
+
api.writeTmpFile({
|
|
282
|
+
path: 'Layout.less',
|
|
283
|
+
content: `
|
|
284
|
+
@import '~antd/es/style/themes/default.less';
|
|
285
|
+
@pro-header-hover-bg: rgba(0, 0, 0, 0.025);
|
|
286
|
+
@media screen and (max-width: @screen-xs) {
|
|
287
|
+
// 在小屏幕的时候可以有更好的体验
|
|
288
|
+
.umi-plugin-layout-container {
|
|
289
|
+
width: 100% !important;
|
|
290
|
+
}
|
|
291
|
+
.umi-plugin-layout-container > * {
|
|
292
|
+
border-radius: 0 !important;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
.umi-plugin-layout-menu {
|
|
296
|
+
.anticon {
|
|
297
|
+
margin-right: 8px;
|
|
298
|
+
}
|
|
299
|
+
.ant-dropdown-menu-item {
|
|
300
|
+
min-width: 160px;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
.umi-plugin-layout-right {
|
|
304
|
+
display: flex;
|
|
305
|
+
float: right;
|
|
306
|
+
height: 100%;
|
|
307
|
+
margin-left: auto;
|
|
308
|
+
overflow: hidden;
|
|
309
|
+
.umi-plugin-layout-action {
|
|
310
|
+
display: flex;
|
|
311
|
+
align-items: center;
|
|
312
|
+
height: 100%;
|
|
313
|
+
padding: 0 12px;
|
|
314
|
+
cursor: pointer;
|
|
315
|
+
transition: all 0.3s;
|
|
316
|
+
> i {
|
|
317
|
+
color: @text-color;
|
|
318
|
+
vertical-align: middle;
|
|
319
|
+
}
|
|
320
|
+
&:hover {
|
|
321
|
+
background: @pro-header-hover-bg;
|
|
322
|
+
}
|
|
323
|
+
&:global(.opened) {
|
|
324
|
+
background: @pro-header-hover-bg;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
.umi-plugin-layout-search {
|
|
328
|
+
padding: 0 12px;
|
|
329
|
+
&:hover {
|
|
330
|
+
background: transparent;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
.umi-plugin-layout-name {
|
|
335
|
+
margin-left: 8px;
|
|
336
|
+
}
|
|
337
|
+
`,
|
|
338
|
+
});
|
|
339
|
+
// Logo.tsx
|
|
340
|
+
api.writeTmpFile({
|
|
341
|
+
path: 'Logo.tsx',
|
|
342
|
+
content: `
|
|
343
|
+
import React from 'react';
|
|
344
|
+
|
|
345
|
+
const LogoIcon: React.FC = () => {
|
|
346
|
+
return (
|
|
347
|
+
<svg
|
|
348
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
349
|
+
width="32"
|
|
350
|
+
height="32"
|
|
351
|
+
viewBox="0 0 200 200"
|
|
352
|
+
>
|
|
353
|
+
<defs>
|
|
354
|
+
<linearGradient
|
|
355
|
+
id="linearGradient-1"
|
|
356
|
+
x1="62.102%"
|
|
357
|
+
x2="108.197%"
|
|
358
|
+
y1="0%"
|
|
359
|
+
y2="37.864%"
|
|
360
|
+
>
|
|
361
|
+
<stop offset="0%" stopColor="#4285EB"></stop>
|
|
362
|
+
<stop offset="100%" stopColor="#2EC7FF"></stop>
|
|
363
|
+
</linearGradient>
|
|
364
|
+
<linearGradient
|
|
365
|
+
id="linearGradient-2"
|
|
366
|
+
x1="69.644%"
|
|
367
|
+
x2="54.043%"
|
|
368
|
+
y1="0%"
|
|
369
|
+
y2="108.457%"
|
|
370
|
+
>
|
|
371
|
+
<stop offset="0%" stopColor="#29CDFF"></stop>
|
|
372
|
+
<stop offset="37.86%" stopColor="#148EFF"></stop>
|
|
373
|
+
<stop offset="100%" stopColor="#0A60FF"></stop>
|
|
374
|
+
</linearGradient>
|
|
375
|
+
<linearGradient
|
|
376
|
+
id="linearGradient-3"
|
|
377
|
+
x1="69.691%"
|
|
378
|
+
x2="16.723%"
|
|
379
|
+
y1="-12.974%"
|
|
380
|
+
y2="117.391%"
|
|
381
|
+
>
|
|
382
|
+
<stop offset="0%" stopColor="#FA816E"></stop>
|
|
383
|
+
<stop offset="41.473%" stopColor="#F74A5C"></stop>
|
|
384
|
+
<stop offset="100%" stopColor="#F51D2C"></stop>
|
|
385
|
+
</linearGradient>
|
|
386
|
+
<linearGradient
|
|
387
|
+
id="linearGradient-4"
|
|
388
|
+
x1="68.128%"
|
|
389
|
+
x2="30.44%"
|
|
390
|
+
y1="-35.691%"
|
|
391
|
+
y2="114.943%"
|
|
392
|
+
>
|
|
393
|
+
<stop offset="0%" stopColor="#FA8E7D"></stop>
|
|
394
|
+
<stop offset="51.264%" stopColor="#F74A5C"></stop>
|
|
395
|
+
<stop offset="100%" stopColor="#F51D2C"></stop>
|
|
396
|
+
</linearGradient>
|
|
397
|
+
</defs>
|
|
398
|
+
<g fill="none" fillRule="evenodd" stroke="none" strokeWidth="1">
|
|
399
|
+
<g transform="translate(-20 -20)">
|
|
400
|
+
<g transform="translate(20 20)">
|
|
401
|
+
<g>
|
|
402
|
+
<g fillRule="nonzero">
|
|
403
|
+
<g>
|
|
404
|
+
<path
|
|
405
|
+
fill="url(#linearGradient-1)"
|
|
406
|
+
d="M91.588 4.177L4.18 91.513a11.981 11.981 0 000 16.974l87.408 87.336a12.005 12.005 0 0016.989 0l36.648-36.618c4.209-4.205 4.209-11.023 0-15.228-4.208-4.205-11.031-4.205-15.24 0l-27.783 27.76c-1.17 1.169-2.945 1.169-4.114 0l-69.802-69.744c-1.17-1.169-1.17-2.942 0-4.11l69.802-69.745c1.17-1.169 2.944-1.169 4.114 0l27.783 27.76c4.209 4.205 11.032 4.205 15.24 0 4.209-4.205 4.209-11.022 0-15.227L108.581 4.056c-4.719-4.594-12.312-4.557-16.993.12z"
|
|
407
|
+
></path>
|
|
408
|
+
<path
|
|
409
|
+
fill="url(#linearGradient-2)"
|
|
410
|
+
d="M91.588 4.177L4.18 91.513a11.981 11.981 0 000 16.974l87.408 87.336a12.005 12.005 0 0016.989 0l36.648-36.618c4.209-4.205 4.209-11.023 0-15.228-4.208-4.205-11.031-4.205-15.24 0l-27.783 27.76c-1.17 1.169-2.945 1.169-4.114 0l-69.802-69.744c-1.17-1.169-1.17-2.942 0-4.11l69.802-69.745c2.912-2.51 7.664-7.596 14.642-8.786 5.186-.883 10.855 1.062 17.009 5.837L108.58 4.056c-4.719-4.594-12.312-4.557-16.993.12z"
|
|
411
|
+
></path>
|
|
412
|
+
</g>
|
|
413
|
+
<path
|
|
414
|
+
fill="url(#linearGradient-3)"
|
|
415
|
+
d="M153.686 135.855c4.208 4.205 11.031 4.205 15.24 0l27.034-27.012c4.7-4.696 4.7-12.28 0-16.974l-27.27-27.15c-4.218-4.2-11.043-4.195-15.254.013-4.209 4.205-4.209 11.022 0 15.227l18.418 18.403c1.17 1.169 1.17 2.943 0 4.111l-18.168 18.154c-4.209 4.205-4.209 11.023 0 15.228z"
|
|
416
|
+
></path>
|
|
417
|
+
</g>
|
|
418
|
+
<ellipse
|
|
419
|
+
cx="100.519"
|
|
420
|
+
cy="100.437"
|
|
421
|
+
fill="url(#linearGradient-4)"
|
|
422
|
+
rx="23.6"
|
|
423
|
+
ry="23.581"
|
|
424
|
+
></ellipse>
|
|
425
|
+
</g>
|
|
426
|
+
</g>
|
|
427
|
+
</g>
|
|
428
|
+
</g>
|
|
429
|
+
</svg>
|
|
430
|
+
);
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export default LogoIcon;
|
|
434
|
+
`,
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
api.addLayouts(() => {
|
|
438
|
+
return [
|
|
439
|
+
{
|
|
440
|
+
id: 'ant-design-pro-layout',
|
|
441
|
+
file: (0, withTmpPath_1.withTmpPath)({ api, path: 'Layout.tsx' }),
|
|
442
|
+
},
|
|
443
|
+
];
|
|
444
|
+
});
|
|
445
|
+
api.addRuntimePluginKey(() => ['layout']);
|
|
446
|
+
api.addRuntimePlugin(() => {
|
|
447
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
448
|
+
});
|
|
5
449
|
};
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
2
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
32
|
+
const fs_1 = require("fs");
|
|
33
|
+
const path_1 = require("path");
|
|
34
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
35
|
+
const modelUtils_1 = require("./utils/modelUtils");
|
|
36
|
+
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
3
37
|
exports.default = (api) => {
|
|
4
|
-
api
|
|
38
|
+
api.describe({
|
|
39
|
+
config: {
|
|
40
|
+
schema(Joi) {
|
|
41
|
+
return Joi.object({
|
|
42
|
+
extraModels: Joi.array().items(Joi.string()),
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
enableBy: api.EnableBy.config,
|
|
47
|
+
});
|
|
48
|
+
api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const models = yield getAllModels(api);
|
|
50
|
+
memo.pluginModel = {
|
|
51
|
+
models,
|
|
52
|
+
};
|
|
53
|
+
return memo;
|
|
54
|
+
}));
|
|
55
|
+
api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const models = args.isFirstTime
|
|
57
|
+
? api.appData.pluginModel.models
|
|
58
|
+
: yield getAllModels(api);
|
|
59
|
+
// model.ts
|
|
60
|
+
api.writeTmpFile({
|
|
61
|
+
path: 'model.ts',
|
|
62
|
+
content: modelUtils_1.ModelUtils.getModelsContent(models),
|
|
63
|
+
});
|
|
64
|
+
// index.tsx
|
|
65
|
+
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')));
|
|
66
|
+
api.writeTmpFile({
|
|
67
|
+
path: 'index.tsx',
|
|
68
|
+
content: indexContent,
|
|
69
|
+
});
|
|
70
|
+
// runtime.tsx
|
|
71
|
+
api.writeTmpFile({
|
|
72
|
+
path: 'runtime.tsx',
|
|
73
|
+
content: `
|
|
74
|
+
import React from 'react';
|
|
75
|
+
import { Provider } from './';
|
|
76
|
+
import { models as rawModels } from './model';
|
|
77
|
+
|
|
78
|
+
function ProviderWrapper(props: any) {
|
|
79
|
+
const models = React.useMemo(() => {
|
|
80
|
+
return Object.keys(rawModels).reduce((memo, key) => {
|
|
81
|
+
memo[rawModels[key].namespace] = rawModels[key].model;
|
|
82
|
+
return memo;
|
|
83
|
+
}, {});
|
|
84
|
+
}, []);
|
|
85
|
+
return <Provider models={models} {...props}>{ props.children }</Provider>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function dataflowProvider(container, opts) {
|
|
89
|
+
return <ProviderWrapper {...opts}>{ container }</ProviderWrapper>;
|
|
90
|
+
}
|
|
91
|
+
`,
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
api.addTmpGenerateWatcherPaths(() => {
|
|
95
|
+
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
96
|
+
});
|
|
97
|
+
api.addRuntimePlugin(() => {
|
|
98
|
+
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
99
|
+
});
|
|
5
100
|
};
|
|
101
|
+
function getAllModels(api) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const extraModels = yield api.applyPlugins({
|
|
104
|
+
key: 'addExtraModels',
|
|
105
|
+
type: api.ApplyPluginsType.add,
|
|
106
|
+
initialValue: [],
|
|
107
|
+
});
|
|
108
|
+
return new modelUtils_1.ModelUtils(api, {
|
|
109
|
+
astTest({ node }) {
|
|
110
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
|
|
111
|
+
},
|
|
112
|
+
}).getAllModels({
|
|
113
|
+
extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@umijs/utils");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/*
|
|
6
|
+
As long as moment2dayjs is registered, moment will be replaced by dayjs.
|
|
7
|
+
The presets that can adapt to antd is registered by default.
|
|
8
|
+
When the user configures preset and plugins at the same time, we will merge them.
|
|
9
|
+
*/
|
|
10
|
+
exports.default = (api) => {
|
|
11
|
+
api.describe({
|
|
12
|
+
key: 'moment2dayjs',
|
|
13
|
+
config: {
|
|
14
|
+
schema(joi) {
|
|
15
|
+
return joi.object({
|
|
16
|
+
preset: joi.string(),
|
|
17
|
+
plugins: joi.array(),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
enableBy: api.EnableBy.config,
|
|
22
|
+
});
|
|
23
|
+
const presets = {
|
|
24
|
+
antd: [
|
|
25
|
+
'isSameOrBefore',
|
|
26
|
+
'isSameOrAfter',
|
|
27
|
+
'advancedFormat',
|
|
28
|
+
'customParseFormat',
|
|
29
|
+
'weekday',
|
|
30
|
+
'weekYear',
|
|
31
|
+
'weekOfYear',
|
|
32
|
+
'isMoment',
|
|
33
|
+
'localeData',
|
|
34
|
+
'localizedFormat',
|
|
35
|
+
],
|
|
36
|
+
antdv3: [
|
|
37
|
+
'isSameOrBefore',
|
|
38
|
+
'isSameOrAfter',
|
|
39
|
+
'advancedFormat',
|
|
40
|
+
'customParseFormat',
|
|
41
|
+
'weekday',
|
|
42
|
+
'weekYear',
|
|
43
|
+
'weekOfYear',
|
|
44
|
+
'isMoment',
|
|
45
|
+
'localeData',
|
|
46
|
+
'localizedFormat',
|
|
47
|
+
'badMutable',
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
const getDayjsPlugins = (api) => {
|
|
51
|
+
let { preset = 'antd', plugins = [] } = api.config.moment2dayjs || {};
|
|
52
|
+
switch (preset) {
|
|
53
|
+
case 'antd':
|
|
54
|
+
return Array.from(new Set(presets['antd'].concat(plugins)));
|
|
55
|
+
case 'antdv3':
|
|
56
|
+
return Array.from(new Set(presets['antdv3'].concat(plugins)));
|
|
57
|
+
case 'none':
|
|
58
|
+
return [].concat(plugins);
|
|
59
|
+
default:
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// replace moment
|
|
64
|
+
api.modifyConfig((memo) => {
|
|
65
|
+
memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
66
|
+
return memo;
|
|
67
|
+
});
|
|
68
|
+
api.onGenerateFiles(() => {
|
|
69
|
+
const plugins = getDayjsPlugins(api);
|
|
70
|
+
const runtimeTpl = `
|
|
71
|
+
import dayjs from '{{{dayjsPath}}}';
|
|
72
|
+
import antdPlugin from '{{{dayjsAntdPluginPath}}}';
|
|
73
|
+
|
|
74
|
+
{{#plugins}}
|
|
75
|
+
import {{.}} from '{{{dayjsPath}}}/plugin/{{.}}';
|
|
76
|
+
{{/plugins}}
|
|
77
|
+
|
|
78
|
+
{{#plugins}}
|
|
79
|
+
dayjs.extend({{.}});
|
|
80
|
+
{{/plugins}}
|
|
81
|
+
|
|
82
|
+
dayjs.extend(antdPlugin);
|
|
83
|
+
`;
|
|
84
|
+
const dayjsAntdPluginPath = require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin');
|
|
85
|
+
const dayjsPath = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
86
|
+
api.writeTmpFile({
|
|
87
|
+
path: 'runtime.tsx',
|
|
88
|
+
content: utils_1.Mustache.render(runtimeTpl, {
|
|
89
|
+
plugins,
|
|
90
|
+
dayjsPath,
|
|
91
|
+
dayjsAntdPluginPath,
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
api.addEntryCodeAhead(() => [`import './plugin-moment2dayjs/runtime.tsx'`]);
|
|
96
|
+
};
|