@umijs/plugins 4.0.0-canary.20220428.2 → 4.0.0-canary.20220429.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/package.json +3 -3
- package/dist/access.d.ts +0 -3
- package/dist/access.js +0 -148
- package/dist/analytics.d.ts +0 -3
- package/dist/analytics.js +0 -67
- package/dist/antd.d.ts +0 -3
- package/dist/antd.js +0 -131
- package/dist/dva.d.ts +0 -6
- package/dist/dva.js +0 -198
- package/dist/icons.d.ts +0 -3
- package/dist/icons.js +0 -5
- package/dist/initial-state.d.ts +0 -3
- package/dist/initial-state.js +0 -116
- package/dist/layout.d.ts +0 -3
- package/dist/layout.js +0 -538
- package/dist/locale.d.ts +0 -4
- package/dist/locale.js +0 -201
- package/dist/model.d.ts +0 -3
- package/dist/model.js +0 -120
- package/dist/moment2dayjs.d.ts +0 -3
- package/dist/moment2dayjs.js +0 -96
- package/dist/qiankun/constants.d.ts +0 -5
- package/dist/qiankun/constants.js +0 -8
- package/dist/qiankun/master.d.ts +0 -6
- package/dist/qiankun/master.js +0 -120
- package/dist/qiankun/slave.d.ts +0 -3
- package/dist/qiankun/slave.js +0 -145
- package/dist/qiankun.d.ts +0 -3
- package/dist/qiankun.js +0 -19
- package/dist/request.d.ts +0 -3
- package/dist/request.js +0 -309
- package/dist/tailwindcss.d.ts +0 -3
- package/dist/tailwindcss.js +0 -40
- package/dist/unocss.d.ts +0 -3
- package/dist/unocss.js +0 -39
- package/dist/utils/astUtils.d.ts +0 -3
- package/dist/utils/astUtils.js +0 -38
- package/dist/utils/localeUtils.d.ts +0 -33
- package/dist/utils/localeUtils.js +0 -135
- package/dist/utils/modelUtils.d.ts +0 -35
- package/dist/utils/modelUtils.js +0 -149
- package/dist/utils/resolveProjectDep.d.ts +0 -5
- package/dist/utils/resolveProjectDep.js +0 -15
- package/dist/utils/withTmpPath.d.ts +0 -6
- package/dist/utils/withTmpPath.js +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220429.3",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@ahooksjs/use-request": "^2.0.0",
|
|
26
26
|
"@ant-design/icons": "^4.7.0",
|
|
27
27
|
"@ant-design/pro-layout": "^6.35.1",
|
|
28
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
28
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220429.3",
|
|
29
29
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
30
30
|
"axios": "^0.26.1",
|
|
31
31
|
"babel-plugin-import": "^1.13.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"warning": "^4.0.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"umi": "4.0.0-canary.
|
|
47
|
+
"umi": "4.0.0-canary.20220429.3"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
package/dist/access.d.ts
DELETED
package/dist/access.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = require("path");
|
|
17
|
-
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
18
|
-
exports.default = (api) => {
|
|
19
|
-
api.describe({
|
|
20
|
-
config: {
|
|
21
|
-
schema(joi) {
|
|
22
|
-
return joi.object();
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
enableBy: api.EnableBy.config,
|
|
26
|
-
});
|
|
27
|
-
api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
// allow enable access without access file
|
|
29
|
-
const hasAccessFile = ['js', 'jsx', 'ts', 'tsx'].some((ext) => fs_1.default.existsSync((0, path_1.join)(api.paths.absSrcPath, `access.${ext}`)));
|
|
30
|
-
// runtime.tsx
|
|
31
|
-
api.writeTmpFile({
|
|
32
|
-
path: 'runtime.tsx',
|
|
33
|
-
content: `
|
|
34
|
-
import React from 'react';${hasAccessFile
|
|
35
|
-
? `
|
|
36
|
-
import accessFactory from '@/access'
|
|
37
|
-
import { useModel } from '@@/plugin-model';
|
|
38
|
-
`
|
|
39
|
-
: ''}
|
|
40
|
-
import { AccessContext } from './context';
|
|
41
|
-
|
|
42
|
-
function Provider(props) {${hasAccessFile
|
|
43
|
-
? `
|
|
44
|
-
const { initialState } = useModel('@@initialState');
|
|
45
|
-
const access = React.useMemo(() => accessFactory(initialState), [initialState]);
|
|
46
|
-
`
|
|
47
|
-
: `
|
|
48
|
-
const access = {};
|
|
49
|
-
`}
|
|
50
|
-
return (
|
|
51
|
-
<AccessContext.Provider value={access}>
|
|
52
|
-
{ props.children }
|
|
53
|
-
</AccessContext.Provider>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function accessProvider(container) {
|
|
58
|
-
return <Provider>{ container }</Provider>;
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
});
|
|
62
|
-
// index.tsx
|
|
63
|
-
api.writeTmpFile({
|
|
64
|
-
path: 'index.tsx',
|
|
65
|
-
content: `
|
|
66
|
-
import React from 'react';
|
|
67
|
-
import { AccessContext } from './context';
|
|
68
|
-
import type { IRoute } from 'umi';
|
|
69
|
-
|
|
70
|
-
export const useAccess = () => {
|
|
71
|
-
return React.useContext(AccessContext);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export interface AccessProps {
|
|
75
|
-
accessible: boolean;
|
|
76
|
-
fallback?: React.ReactNode;
|
|
77
|
-
}
|
|
78
|
-
export const Access: React.FC<AccessProps> = (props) => {
|
|
79
|
-
if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
|
|
80
|
-
throw new Error('[access] the \`accessible\` property on <Access /> should be a boolean');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return <>{ props.accessible ? props.children : props.fallback }</>;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const useAccessMarkedRoutes = (routes: IRoute[]) => {
|
|
87
|
-
const access = useAccess();
|
|
88
|
-
const markdedRoutes: IRoute[] = React.useMemo(() => {
|
|
89
|
-
const process = (route, parentAccessCode) => {
|
|
90
|
-
const accessCode = route.access || parentAccessCode;
|
|
91
|
-
|
|
92
|
-
// set default status
|
|
93
|
-
route.unaccessible = ${api.config.access.strictMode ? 'true' : 'false'};
|
|
94
|
-
|
|
95
|
-
// check access code
|
|
96
|
-
if (typeof accessCode === 'string') {
|
|
97
|
-
const detector = access[route.access];
|
|
98
|
-
|
|
99
|
-
if (typeof detector === 'function') {
|
|
100
|
-
route.unaccessible = !detector(route);
|
|
101
|
-
} else if (typeof detector === 'boolean') {
|
|
102
|
-
route.unaccessible = !detector;
|
|
103
|
-
} else if (typeof detector === 'undefined') {
|
|
104
|
-
route.unaccessible = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// check children access code
|
|
109
|
-
if (route.routes) {
|
|
110
|
-
const isNoAccessibleChild = !route.routes.reduce((hasAccessibleChild, child) => {
|
|
111
|
-
process(child, accessCode);
|
|
112
|
-
|
|
113
|
-
return hasAccessibleChild || !child.unaccessible;
|
|
114
|
-
}, false);
|
|
115
|
-
|
|
116
|
-
// make sure parent route is unaccessible if all children are unaccessible
|
|
117
|
-
if (isNoAccessibleChild) {
|
|
118
|
-
route.unaccessible = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return route;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return routes.map(route => process(route));
|
|
126
|
-
}, [routes.length]);
|
|
127
|
-
|
|
128
|
-
return markdedRoutes;
|
|
129
|
-
}
|
|
130
|
-
`,
|
|
131
|
-
});
|
|
132
|
-
// context.ts
|
|
133
|
-
api.writeTmpFile({
|
|
134
|
-
path: 'context.ts',
|
|
135
|
-
content: `
|
|
136
|
-
import React from 'react';
|
|
137
|
-
export const AccessContext = React.createContext<any>(null);
|
|
138
|
-
`,
|
|
139
|
-
});
|
|
140
|
-
}));
|
|
141
|
-
api.addRuntimePlugin(() => {
|
|
142
|
-
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
143
|
-
});
|
|
144
|
-
api.addTmpGenerateWatcherPaths(() => [
|
|
145
|
-
(0, path_1.join)(api.paths.absSrcPath, 'access.ts'),
|
|
146
|
-
(0, path_1.join)(api.paths.absSrcPath, 'access.js'),
|
|
147
|
-
]);
|
|
148
|
-
};
|
package/dist/analytics.d.ts
DELETED
package/dist/analytics.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (api) => {
|
|
4
|
-
const GA_KEY = process.env.GA_KEY;
|
|
5
|
-
const enableBy = (opts) => {
|
|
6
|
-
return opts.config.analytics || GA_KEY;
|
|
7
|
-
};
|
|
8
|
-
api.describe({
|
|
9
|
-
key: 'analytics',
|
|
10
|
-
config: {
|
|
11
|
-
schema(joi) {
|
|
12
|
-
return joi.object();
|
|
13
|
-
},
|
|
14
|
-
onChange: api.ConfigChangeType.reload,
|
|
15
|
-
},
|
|
16
|
-
enableBy,
|
|
17
|
-
});
|
|
18
|
-
// https://tongji.baidu.com/web/help/article?id=174&type=0
|
|
19
|
-
const baiduTpl = (code) => {
|
|
20
|
-
return `
|
|
21
|
-
(function() {
|
|
22
|
-
var hm = document.createElement('script');
|
|
23
|
-
hm.src = 'https://hm.baidu.com/hm.js?${code}';
|
|
24
|
-
var s = document.getElementsByTagName('script')[0];
|
|
25
|
-
s.parentNode.insertBefore(hm, s);
|
|
26
|
-
})();
|
|
27
|
-
`;
|
|
28
|
-
};
|
|
29
|
-
const gaTpl = (code) => {
|
|
30
|
-
return `
|
|
31
|
-
(function(){
|
|
32
|
-
if (!location.port) {
|
|
33
|
-
(function (i, s, o, g, r, a, m) {
|
|
34
|
-
i['GoogleAnalyticsObject'] = r;
|
|
35
|
-
i[r] = i[r] || function () {
|
|
36
|
-
(i[r].q = i[r].q || []).push(arguments)
|
|
37
|
-
}, i[r].l = 1 * new Date();
|
|
38
|
-
a = s.createElement(o),
|
|
39
|
-
m = s.getElementsByTagName(o)[0];
|
|
40
|
-
a.async = 1;
|
|
41
|
-
a.src = g;
|
|
42
|
-
m.parentNode.insertBefore(a, m)
|
|
43
|
-
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
|
44
|
-
ga('create', '${code}', 'auto');
|
|
45
|
-
ga('send', 'pageview');
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
48
|
-
`;
|
|
49
|
-
};
|
|
50
|
-
api.addHTMLHeadScripts(() => {
|
|
51
|
-
const { analytics = {} } = api.config;
|
|
52
|
-
const { ga = GA_KEY, baidu } = analytics;
|
|
53
|
-
return [
|
|
54
|
-
baidu && {
|
|
55
|
-
content: 'var _hmt = _hmt || [];',
|
|
56
|
-
},
|
|
57
|
-
api.env !== 'development' &&
|
|
58
|
-
baidu && {
|
|
59
|
-
content: baiduTpl(baidu),
|
|
60
|
-
},
|
|
61
|
-
api.env !== 'development' &&
|
|
62
|
-
ga && {
|
|
63
|
-
content: gaTpl(ga),
|
|
64
|
-
},
|
|
65
|
-
].filter(Boolean);
|
|
66
|
-
});
|
|
67
|
-
};
|
package/dist/antd.d.ts
DELETED
package/dist/antd.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const plugin_utils_1 = require("umi/plugin-utils");
|
|
5
|
-
const resolveProjectDep_1 = require("./utils/resolveProjectDep");
|
|
6
|
-
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
7
|
-
exports.default = (api) => {
|
|
8
|
-
let pkgPath;
|
|
9
|
-
try {
|
|
10
|
-
pkgPath =
|
|
11
|
-
(0, resolveProjectDep_1.resolveProjectDep)({
|
|
12
|
-
pkg: api.pkg,
|
|
13
|
-
cwd: api.cwd,
|
|
14
|
-
dep: 'antd',
|
|
15
|
-
}) || (0, path_1.dirname)(require.resolve('antd/package.json'));
|
|
16
|
-
}
|
|
17
|
-
catch (e) { }
|
|
18
|
-
api.describe({
|
|
19
|
-
config: {
|
|
20
|
-
schema(Joi) {
|
|
21
|
-
return Joi.object({
|
|
22
|
-
configProvider: Joi.object(),
|
|
23
|
-
// themes
|
|
24
|
-
dark: Joi.boolean(),
|
|
25
|
-
compact: Joi.boolean(),
|
|
26
|
-
// babel-plugin-import
|
|
27
|
-
import: Joi.boolean(),
|
|
28
|
-
// less or css, default less
|
|
29
|
-
style: Joi.string().allow('less', 'css'),
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
enableBy: api.EnableBy.config,
|
|
34
|
-
});
|
|
35
|
-
function checkPkgPath() {
|
|
36
|
-
if (!pkgPath) {
|
|
37
|
-
throw new Error(`Can't find antd package. Please install antd first.`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
api.modifyAppData((memo) => {
|
|
41
|
-
checkPkgPath();
|
|
42
|
-
const version = require(`${pkgPath}/package.json`).version;
|
|
43
|
-
memo.antd = {
|
|
44
|
-
pkgPath,
|
|
45
|
-
version,
|
|
46
|
-
};
|
|
47
|
-
return memo;
|
|
48
|
-
});
|
|
49
|
-
api.modifyConfig((memo) => {
|
|
50
|
-
checkPkgPath();
|
|
51
|
-
// antd import
|
|
52
|
-
memo.alias.antd = pkgPath;
|
|
53
|
-
// moment > dayjs
|
|
54
|
-
if (memo.antd.dayjs) {
|
|
55
|
-
memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
56
|
-
}
|
|
57
|
-
// dark mode & compact mode
|
|
58
|
-
if (memo.antd.dark || memo.antd.compact) {
|
|
59
|
-
const { getThemeVariables } = require('antd/dist/theme');
|
|
60
|
-
memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
|
|
61
|
-
}
|
|
62
|
-
return memo;
|
|
63
|
-
});
|
|
64
|
-
api.modifyConfig((memo) => {
|
|
65
|
-
memo.theme = Object.assign({ 'root-entry-name': 'default' }, memo.theme);
|
|
66
|
-
return memo;
|
|
67
|
-
});
|
|
68
|
-
// babel-plugin-import
|
|
69
|
-
api.addExtraBabelPlugins(() => {
|
|
70
|
-
const style = api.config.antd.style || 'less';
|
|
71
|
-
return api.config.antd.import && !api.appData.vite
|
|
72
|
-
? [
|
|
73
|
-
[
|
|
74
|
-
require.resolve('babel-plugin-import'),
|
|
75
|
-
{
|
|
76
|
-
libraryName: 'antd',
|
|
77
|
-
libraryDirectory: 'es',
|
|
78
|
-
style: style === 'less' ? true : 'css',
|
|
79
|
-
},
|
|
80
|
-
'antd',
|
|
81
|
-
],
|
|
82
|
-
]
|
|
83
|
-
: [];
|
|
84
|
-
});
|
|
85
|
-
// antd config provider
|
|
86
|
-
api.onGenerateFiles(() => {
|
|
87
|
-
if (!api.config.antd.configProvider)
|
|
88
|
-
return;
|
|
89
|
-
api.writeTmpFile({
|
|
90
|
-
path: `runtime.tsx`,
|
|
91
|
-
content: plugin_utils_1.Mustache.render(`
|
|
92
|
-
import React from 'react';
|
|
93
|
-
import { ConfigProvider, Modal, message, notification } from 'antd';
|
|
94
|
-
|
|
95
|
-
export function rootContainer(container) {
|
|
96
|
-
const finalConfig = {...{{{ config }}}}
|
|
97
|
-
if (finalConfig.prefixCls) {
|
|
98
|
-
Modal.config({
|
|
99
|
-
rootPrefixCls: finalConfig.prefixCls
|
|
100
|
-
});
|
|
101
|
-
message.config({
|
|
102
|
-
prefixCls: \`\${finalConfig.prefixCls}-message\`
|
|
103
|
-
});
|
|
104
|
-
notification.config({
|
|
105
|
-
prefixCls: \`\${finalConfig.prefixCls}-notification\`
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return <ConfigProvider {...finalConfig}>{container}</ConfigProvider>;
|
|
109
|
-
}
|
|
110
|
-
`.trim(), {
|
|
111
|
-
config: JSON.stringify(api.config.antd.configProvider),
|
|
112
|
-
}),
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
api.addRuntimePlugin(() => {
|
|
116
|
-
return api.config.antd.configProvider
|
|
117
|
-
? [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]
|
|
118
|
-
: [];
|
|
119
|
-
});
|
|
120
|
-
// import antd style if antd.import is not configured
|
|
121
|
-
api.addEntryImportsAhead(() => {
|
|
122
|
-
const style = api.config.antd.style || 'less';
|
|
123
|
-
return api.config.antd.import && !api.appData.vite
|
|
124
|
-
? []
|
|
125
|
-
: [
|
|
126
|
-
{
|
|
127
|
-
source: style === 'less' ? 'antd/dist/antd.less' : 'antd/dist/antd.css',
|
|
128
|
-
},
|
|
129
|
-
];
|
|
130
|
-
});
|
|
131
|
-
};
|
package/dist/dva.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { IApi } from 'umi';
|
|
2
|
-
import { Model, ModelUtils } from './utils/modelUtils';
|
|
3
|
-
declare const _default: (api: IApi) => void;
|
|
4
|
-
export default _default;
|
|
5
|
-
export declare function getModelUtil(api: IApi | null): ModelUtils;
|
|
6
|
-
export declare function getAllModels(api: IApi): Model[];
|
package/dist/dva.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
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;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getAllModels = exports.getModelUtil = void 0;
|
|
27
|
-
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
28
|
-
const utils_1 = require("@umijs/utils");
|
|
29
|
-
const path_1 = require("path");
|
|
30
|
-
const plugin_utils_1 = require("umi/plugin-utils");
|
|
31
|
-
const modelUtils_1 = require("./utils/modelUtils");
|
|
32
|
-
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
33
|
-
exports.default = (api) => {
|
|
34
|
-
const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
|
|
35
|
-
api.describe({
|
|
36
|
-
config: {
|
|
37
|
-
schema(Joi) {
|
|
38
|
-
return Joi.object({
|
|
39
|
-
extraModels: Joi.array().items(Joi.string()),
|
|
40
|
-
immer: Joi.object(),
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
enableBy: api.EnableBy.config,
|
|
45
|
-
});
|
|
46
|
-
api.modifyAppData((memo) => {
|
|
47
|
-
const models = getAllModels(api);
|
|
48
|
-
memo.pluginDva = {
|
|
49
|
-
pkgPath,
|
|
50
|
-
models,
|
|
51
|
-
};
|
|
52
|
-
return memo;
|
|
53
|
-
});
|
|
54
|
-
api.modifyConfig((memo) => {
|
|
55
|
-
// import from dva
|
|
56
|
-
memo.alias['dva$'] = pkgPath;
|
|
57
|
-
return memo;
|
|
58
|
-
});
|
|
59
|
-
api.onGenerateFiles((args) => {
|
|
60
|
-
var _a, _b, _c, _d, _e, _f;
|
|
61
|
-
const models = args.isFirstTime
|
|
62
|
-
? api.appData.pluginDva.models
|
|
63
|
-
: getAllModels(api);
|
|
64
|
-
// models.ts
|
|
65
|
-
api.writeTmpFile({
|
|
66
|
-
path: 'models.ts',
|
|
67
|
-
content: modelUtils_1.ModelUtils.getModelsContent(models),
|
|
68
|
-
});
|
|
69
|
-
// dva.tsx
|
|
70
|
-
api.writeTmpFile({
|
|
71
|
-
path: 'dva.tsx',
|
|
72
|
-
tpl: `
|
|
73
|
-
// It's faked dva
|
|
74
|
-
// aliased to @umijs/plugins/templates/dva
|
|
75
|
-
import { create, Provider } from 'dva';
|
|
76
|
-
import createLoading from '${(0, utils_1.winPath)(require.resolve('dva-loading'))}';
|
|
77
|
-
${((_a = api.config.dva) === null || _a === void 0 ? void 0 : _a.immer)
|
|
78
|
-
? `
|
|
79
|
-
import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(require.resolve('dva-immer'))}';
|
|
80
|
-
`
|
|
81
|
-
: ''}
|
|
82
|
-
import React, { useRef } from 'react';
|
|
83
|
-
import { history, ApplyPluginsType, useAppData } from 'umi';
|
|
84
|
-
import { models } from './models';
|
|
85
|
-
|
|
86
|
-
export function RootContainer(props: any) {
|
|
87
|
-
const { pluginManager } = useAppData();
|
|
88
|
-
const app = useRef<any>();
|
|
89
|
-
const runtimeDva = pluginManager.applyPlugins({
|
|
90
|
-
key: 'dva',
|
|
91
|
-
type: ApplyPluginsType.modify,
|
|
92
|
-
initialValue: {},
|
|
93
|
-
});
|
|
94
|
-
if (!app.current) {
|
|
95
|
-
app.current = create(
|
|
96
|
-
{
|
|
97
|
-
history,
|
|
98
|
-
...(runtimeDva.config || {}),
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
initialReducer: {},
|
|
102
|
-
setupMiddlewares(middlewares: Function[]) {
|
|
103
|
-
return [...middlewares];
|
|
104
|
-
},
|
|
105
|
-
setupApp(app: IDvaApp) {
|
|
106
|
-
app._history = history;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
app.current.use(createLoading());
|
|
111
|
-
${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
|
|
112
|
-
${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
|
|
113
|
-
${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
|
|
114
|
-
for (const id of Object.keys(models)) {
|
|
115
|
-
app.current.model(models[id].model);
|
|
116
|
-
}
|
|
117
|
-
app.current.start();
|
|
118
|
-
}
|
|
119
|
-
return <Provider store={app.current!._store}>{props.children}</Provider>;
|
|
120
|
-
}
|
|
121
|
-
`,
|
|
122
|
-
context: {},
|
|
123
|
-
});
|
|
124
|
-
// runtime.tsx
|
|
125
|
-
api.writeTmpFile({
|
|
126
|
-
path: 'runtime.tsx',
|
|
127
|
-
content: `
|
|
128
|
-
import React from 'react';
|
|
129
|
-
import { RootContainer } from './dva';
|
|
130
|
-
|
|
131
|
-
export function dataflowProvider(container, opts) {
|
|
132
|
-
return React.createElement(RootContainer, opts, container);
|
|
133
|
-
}
|
|
134
|
-
`,
|
|
135
|
-
});
|
|
136
|
-
// index.ts for export
|
|
137
|
-
api.writeTmpFile({
|
|
138
|
-
path: 'index.ts',
|
|
139
|
-
content: `
|
|
140
|
-
export { connect, useDispatch, useStore, useSelector } from 'dva';`,
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
api.addTmpGenerateWatcherPaths(() => {
|
|
144
|
-
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
145
|
-
});
|
|
146
|
-
api.addRuntimePlugin(() => {
|
|
147
|
-
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
148
|
-
});
|
|
149
|
-
api.addRuntimePluginKey(() => ['dva']);
|
|
150
|
-
// dva list model
|
|
151
|
-
api.registerCommand({
|
|
152
|
-
name: 'dva',
|
|
153
|
-
fn() {
|
|
154
|
-
api.logger.info(plugin_utils_1.chalk.green.bold('dva models'));
|
|
155
|
-
api.appData.pluginDva.models.forEach((model) => {
|
|
156
|
-
api.logger.info(` - ${(0, path_1.relative)(api.cwd, model.file)}`);
|
|
157
|
-
});
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
function getModelUtil(api) {
|
|
162
|
-
return new modelUtils_1.ModelUtils(api, {
|
|
163
|
-
contentTest(content) {
|
|
164
|
-
return content.startsWith('// @dva-model');
|
|
165
|
-
},
|
|
166
|
-
astTest({ node, content }) {
|
|
167
|
-
if (isModelObject(node)) {
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
else if (content.includes('dva-model-extend') &&
|
|
171
|
-
t.isCallExpression(node) &&
|
|
172
|
-
node.arguments.length === 2 &&
|
|
173
|
-
isModelObject(node.arguments[1])) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
return false;
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
exports.getModelUtil = getModelUtil;
|
|
181
|
-
function getAllModels(api) {
|
|
182
|
-
return getModelUtil(api).getAllModels({
|
|
183
|
-
extraModels: [...(api.config.dva.extraModels || [])],
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
exports.getAllModels = getAllModels;
|
|
187
|
-
function isModelObject(node) {
|
|
188
|
-
return (t.isObjectExpression(node) &&
|
|
189
|
-
node.properties.some((property) => {
|
|
190
|
-
return [
|
|
191
|
-
'state',
|
|
192
|
-
'reducers',
|
|
193
|
-
'subscriptions',
|
|
194
|
-
'effects',
|
|
195
|
-
'namespace',
|
|
196
|
-
].includes(property.key.name);
|
|
197
|
-
}));
|
|
198
|
-
}
|
package/dist/icons.d.ts
DELETED
package/dist/icons.js
DELETED
package/dist/initial-state.d.ts
DELETED