@umijs/plugins 4.0.0-beta.9 → 4.0.0-rc.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.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/dist/access.js +73 -1
  3. package/dist/{sass.d.ts → analytics.d.ts} +0 -0
  4. package/dist/analytics.js +67 -0
  5. package/dist/antd.js +89 -145
  6. package/dist/dva.d.ts +3 -0
  7. package/dist/dva.js +168 -4
  8. package/dist/initial-state.js +112 -1
  9. package/dist/layout.js +479 -1
  10. package/dist/locale.d.ts +1 -0
  11. package/dist/locale.js +199 -1
  12. package/dist/model.js +112 -1
  13. package/dist/moment2dayjs.d.ts +3 -0
  14. package/dist/moment2dayjs.js +96 -0
  15. package/dist/qiankun/constants.d.ts +5 -0
  16. package/dist/qiankun/constants.js +8 -0
  17. package/dist/qiankun/master.d.ts +6 -0
  18. package/dist/qiankun/master.js +114 -0
  19. package/dist/qiankun/slave.d.ts +3 -0
  20. package/dist/qiankun/slave.js +141 -0
  21. package/dist/qiankun.js +15 -1
  22. package/dist/request.js +300 -1
  23. package/dist/tailwindcss.d.ts +3 -0
  24. package/dist/tailwindcss.js +38 -0
  25. package/dist/unocss.d.ts +3 -0
  26. package/dist/unocss.js +57 -0
  27. package/dist/utils/astUtils.d.ts +3 -0
  28. package/dist/utils/astUtils.js +34 -0
  29. package/dist/utils/localeUtils.d.ts +33 -0
  30. package/dist/utils/localeUtils.js +135 -0
  31. package/dist/utils/modelUtils.d.ts +35 -0
  32. package/dist/utils/modelUtils.js +145 -0
  33. package/dist/utils/resolveProjectDep.d.ts +5 -0
  34. package/dist/utils/resolveProjectDep.js +15 -0
  35. package/dist/utils/withTmpPath.d.ts +6 -0
  36. package/dist/utils/withTmpPath.js +11 -0
  37. package/libs/dva.ts +10 -0
  38. package/libs/locale/SelectLang.tpl +478 -0
  39. package/libs/locale/locale.tpl +82 -0
  40. package/libs/locale/localeExports.tpl +271 -0
  41. package/libs/locale/runtime.tpl +33 -0
  42. package/libs/model.tsx +140 -0
  43. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  44. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  45. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  46. package/libs/qiankun/master/MicroApp.tsx +262 -0
  47. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  48. package/libs/qiankun/master/common.ts +133 -0
  49. package/libs/qiankun/master/constants.ts +7 -0
  50. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  51. package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
  52. package/libs/qiankun/master/types.ts +44 -0
  53. package/libs/qiankun/slave/connectMaster.tsx +15 -0
  54. package/libs/qiankun/slave/lifecycles.ts +149 -0
  55. package/libs/qiankun/slave/qiankunModel.ts +19 -0
  56. package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
  57. package/package.json +21 -5
  58. package/dist/sass.js +0 -5
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
1
  # @umijs/plugins
2
2
 
3
- See our website [umijs](https://umijs.org) for more information.
3
+ See our website [umijs](https://umijs.org) for more information.
4
+
5
+
6
+
package/dist/access.js CHANGED
@@ -1,5 +1,77 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const path_1 = require("path");
13
+ const withTmpPath_1 = require("./utils/withTmpPath");
3
14
  exports.default = (api) => {
4
- api;
15
+ // TODO: route access
16
+ api.describe({
17
+ config: {
18
+ schema(joi) {
19
+ return joi.object();
20
+ },
21
+ },
22
+ enableBy: api.EnableBy.config,
23
+ });
24
+ api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
25
+ // runtime.tsx
26
+ api.writeTmpFile({
27
+ path: 'runtime.tsx',
28
+ content: `
29
+ import React from 'react';
30
+ import accessFactory from '@/access';
31
+ import { useModel } from '@@/plugin-model';
32
+ import { AccessContext } from './context';
33
+
34
+ function Provider(props) {
35
+ const { initialState } = useModel('@@initialState');
36
+ const access = React.useMemo(() => accessFactory(initialState), [initialState]);
37
+ return (
38
+ <AccessContext.Provider value={access}>
39
+ { props.children }
40
+ </AccessContext.Provider>
41
+ );
42
+ }
43
+
44
+ export function accessProvider(container) {
45
+ return <Provider>{ container }</Provider>;
46
+ }
47
+ `,
48
+ });
49
+ // index.ts
50
+ api.writeTmpFile({
51
+ path: 'index.ts',
52
+ content: `
53
+ import React from 'react';
54
+ import { AccessContext } from './context';
55
+
56
+ export const useAccess = () => {
57
+ return React.useContext(AccessContext);
58
+ };
59
+ `,
60
+ });
61
+ // context.ts
62
+ api.writeTmpFile({
63
+ path: 'context.ts',
64
+ content: `
65
+ import React from 'react';
66
+ export const AccessContext = React.createContext<any>(null);
67
+ `,
68
+ });
69
+ }));
70
+ api.addRuntimePlugin(() => {
71
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
72
+ });
73
+ api.addTmpGenerateWatcherPaths(() => [
74
+ (0, path_1.join)(api.paths.absSrcPath, 'access.ts'),
75
+ (0, path_1.join)(api.paths.absSrcPath, 'access.js'),
76
+ ]);
5
77
  };
File without changes
@@ -0,0 +1,67 @@
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.js CHANGED
@@ -1,169 +1,113 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@umijs/utils");
4
- const fs_1 = require("fs");
5
3
  const path_1 = require("path");
6
- const presets = {
7
- antd: {
8
- plugins: [
9
- 'isSameOrBefore',
10
- 'isSameOrAfter',
11
- 'advancedFormat',
12
- 'customParseFormat',
13
- 'weekday',
14
- 'weekYear',
15
- 'weekOfYear',
16
- 'isMoment',
17
- 'localeData',
18
- 'localizedFormat',
19
- ],
20
- replaceMoment: true,
21
- },
22
- antdv3: {
23
- plugins: [
24
- 'isSameOrBefore',
25
- 'isSameOrAfter',
26
- 'advancedFormat',
27
- 'customParseFormat',
28
- 'weekday',
29
- 'weekYear',
30
- 'weekOfYear',
31
- 'isMoment',
32
- 'localeData',
33
- 'localizedFormat',
34
- 'badMutable',
35
- ],
36
- replaceMoment: true,
37
- },
38
- };
39
- const getConfig = (api) => {
40
- let { preset = 'antd', plugins, replaceMoment, } = api.userConfig.antdDayjs || {};
41
- if (preset && presets[preset]) {
42
- plugins = presets[preset].plugins;
43
- replaceMoment = presets[preset].replaceMoment;
44
- }
45
- if (plugins)
46
- plugins = plugins;
47
- if (replaceMoment !== undefined)
48
- replaceMoment = replaceMoment;
49
- return {
50
- plugins,
51
- replaceMoment,
52
- };
53
- };
54
- const DIR_NAME = 'plugin-antd';
4
+ const plugin_utils_1 = require("umi/plugin-utils");
5
+ const resolveProjectDep_1 = require("./utils/resolveProjectDep");
6
+ const withTmpPath_1 = require("./utils/withTmpPath");
55
7
  exports.default = (api) => {
56
- const opts = api.userConfig.antd;
57
- // dayjs (by default)
58
- const { dayjs = true } = opts;
8
+ const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
9
+ pkg: api.pkg,
10
+ cwd: api.cwd,
11
+ dep: 'antd',
12
+ }) || (0, path_1.dirname)(require.resolve('antd/package.json'));
59
13
  api.describe({
60
14
  config: {
61
15
  schema(Joi) {
62
16
  return Joi.object({
17
+ configProvider: Joi.object(),
18
+ // themes
63
19
  dark: Joi.boolean(),
64
20
  compact: Joi.boolean(),
65
- config: Joi.object(),
66
- dayjs: Joi.alternatives(Joi.boolean(), Joi.object({
67
- preset: Joi.string(),
68
- plugins: Joi.array(),
69
- replaceMoment: Joi.boolean(),
70
- })),
21
+ // babel-plugin-import
22
+ import: Joi.boolean(),
23
+ // less or css, default less
24
+ style: Joi.string().allow('less', 'css'),
71
25
  });
72
26
  },
73
27
  },
28
+ enableBy: api.EnableBy.config,
29
+ });
30
+ api.modifyAppData((memo) => {
31
+ const version = require(`${pkgPath}/package.json`).version;
32
+ memo.antd = {
33
+ pkgPath,
34
+ version,
35
+ };
36
+ return memo;
74
37
  });
75
- // antd import
76
- // TODO: use api.modifyConfig for support with vite
77
- api.chainWebpack((memo) => {
78
- function getUserLibDir({ library }) {
79
- if (
80
- // @ts-ignore
81
- (api.pkg.dependencies && api.pkg.dependencies[library]) ||
82
- // @ts-ignore
83
- (api.pkg.devDependencies && api.pkg.devDependencies[library]) ||
84
- // egg project using `clientDependencies` in ali tnpm
85
- // @ts-ignore
86
- (api.pkg.clientDependencies && api.pkg.clientDependencies[library])) {
87
- return (0, utils_1.winPath)((0, path_1.dirname)(
88
- // 通过 resolve 往上找,可支持 lerna 仓库
89
- // lerna 仓库如果用 yarn workspace 的依赖不一定在 node_modules,可能被提到根目录,并且没有 link
90
- utils_1.resolve.sync(`${library}/package.json`, {
91
- basedir: api.paths.cwd,
92
- })));
93
- }
94
- return null;
38
+ api.modifyConfig((memo) => {
39
+ // antd import
40
+ memo.alias.antd = pkgPath;
41
+ // moment > dayjs
42
+ if (memo.antd.dayjs) {
43
+ memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
95
44
  }
96
- memo.resolve.alias.set('antd', getUserLibDir({ library: 'antd' }) ||
97
- (0, path_1.dirname)(require.resolve('antd/package.json')));
98
- if (dayjs !== false) {
99
- const { replaceMoment } = getConfig(api);
100
- if (replaceMoment) {
101
- memo.resolve.alias.set('moment', getUserLibDir({ library: 'dayjs' }) ||
102
- (0, path_1.dirname)(require.resolve('dayjs/package.json')));
103
- }
45
+ // dark mode & compact mode
46
+ if (memo.antd.dark || memo.antd.compact) {
47
+ const { getThemeVariables } = require('antd/dist/theme');
48
+ memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
104
49
  }
105
50
  return memo;
106
51
  });
107
- // dark mode
108
- // compat mode
109
- if ((opts === null || opts === void 0 ? void 0 : opts.dark) || (opts === null || opts === void 0 ? void 0 : opts.compact)) {
110
- // support dark mode, user use antd 4 by default
111
- const { getThemeVariables } = require('antd/dist/theme');
112
- api.modifyDefaultConfig((config) => {
113
- config.theme = Object.assign(Object.assign({}, getThemeVariables(opts)), config.theme);
114
- return config;
115
- });
116
- }
117
- if (dayjs !== false) {
118
- api.onGenerateFiles({
119
- fn: () => {
120
- const { plugins } = getConfig(api);
121
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/dayjs.tpl'), 'utf-8');
122
- api.writeTmpFile({
123
- path: 'plugin-antd/dayjs.tsx',
124
- content: utils_1.Mustache.render(runtimeTpl, {
125
- plugins,
126
- dayjsPath: (0, path_1.dirname)(require.resolve('dayjs/package.json')),
127
- dayjsPluginPath: (0, path_1.dirname)(require.resolve('antd-dayjs-webpack-plugin/package.json')),
128
- }),
129
- });
130
- },
131
- });
132
- api.addEntryCodeAhead(() => {
133
- return [`import './${DIR_NAME}/dayjs.tsx'`];
134
- });
135
- }
136
52
  // babel-plugin-import
137
53
  api.addExtraBabelPlugins(() => {
138
- return [
139
- [
140
- require.resolve('babel-plugin-import'),
141
- {
142
- libraryName: 'antd',
143
- libraryDirectory: 'es',
144
- style: true,
145
- },
146
- ],
147
- ];
54
+ const style = api.config.antd.style || 'less';
55
+ return api.config.antd.import && !api.appData.vite
56
+ ? [
57
+ [
58
+ require.resolve('babel-plugin-import'),
59
+ {
60
+ libraryName: 'antd',
61
+ libraryDirectory: 'es',
62
+ style: style === 'less' ? true : 'css',
63
+ },
64
+ ],
65
+ ]
66
+ : [];
148
67
  });
149
68
  // antd config provider
150
- // TODO: use umi provider
151
- if (opts === null || opts === void 0 ? void 0 : opts.config) {
152
- api.onGenerateFiles({
153
- fn() {
154
- // runtime.tsx
155
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/runtime.tpl'), 'utf-8');
156
- api.writeTmpFile({
157
- path: `${DIR_NAME}/runtime.tsx`,
158
- content: utils_1.Mustache.render(runtimeTpl, {
159
- config: JSON.stringify(opts === null || opts === void 0 ? void 0 : opts.config),
160
- }),
161
- });
162
- },
69
+ api.onGenerateFiles(() => {
70
+ if (!api.config.antd.config)
71
+ return;
72
+ api.writeTmpFile({
73
+ path: `runtime.tsx`,
74
+ content: plugin_utils_1.Mustache.render(`
75
+ import { ConfigProvider, Modal, message, notification } from 'antd';
76
+
77
+ export function rootContainer(container) {
78
+ const finalConfig = {...{{{ config }}}}
79
+ if (finalConfig.prefixCls) {
80
+ Modal.config({
81
+ rootPrefixCls: finalConfig.prefixCls
82
+ });
83
+ message.config({
84
+ prefixCls: \`\${finalConfig.prefixCls}-message\`
85
+ });
86
+ notification.config({
87
+ prefixCls: \`\${finalConfig.prefixCls}-notification\`
88
+ });
89
+ }
90
+ return <ConfigProvider {...finalConfig}>{container}</ConfigProvider>;
91
+ }
92
+ `.trim(), {
93
+ config: JSON.stringify(api.config.antd.config),
94
+ }),
163
95
  });
164
- //TODO:Runtime Plugin
165
- api.addRuntimePlugin(() => [
166
- (0, path_1.join)(api.paths.absTmpPath, DIR_NAME, 'runtime.tsx'),
167
- ]);
168
- }
96
+ });
97
+ api.addRuntimePlugin(() => {
98
+ return api.config.antd.config
99
+ ? [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]
100
+ : [];
101
+ });
102
+ // import antd style if antd.import is not configured
103
+ api.addEntryImportsAhead(() => {
104
+ const style = api.config.antd.style || 'less';
105
+ return api.config.antd.import && !api.appData.vite
106
+ ? []
107
+ : [
108
+ {
109
+ source: style === 'less' ? 'antd/dist/antd.less' : 'antd/dist/antd.css',
110
+ },
111
+ ];
112
+ });
169
113
  };
package/dist/dva.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import { IApi } from 'umi';
2
+ import { Model, ModelUtils } from './utils/modelUtils';
2
3
  declare const _default: (api: IApi) => void;
3
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 CHANGED
@@ -1,9 +1,173 @@
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getAllModels = exports.getModelUtil = void 0;
23
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
24
+ const path_1 = require("path");
25
+ const plugin_utils_1 = require("umi/plugin-utils");
26
+ const modelUtils_1 = require("./utils/modelUtils");
27
+ const withTmpPath_1 = require("./utils/withTmpPath");
3
28
  exports.default = (api) => {
4
- api;
5
- // import from dva
6
- // model register
7
- // container
29
+ const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
30
+ api.describe({
31
+ config: {
32
+ schema(Joi) {
33
+ return Joi.object({
34
+ extraModels: Joi.array().items(Joi.string()),
35
+ });
36
+ },
37
+ },
38
+ enableBy: api.EnableBy.config,
39
+ });
40
+ api.modifyAppData((memo) => {
41
+ const models = getAllModels(api);
42
+ memo.pluginDva = {
43
+ pkgPath,
44
+ models,
45
+ };
46
+ return memo;
47
+ });
48
+ api.modifyConfig((memo) => {
49
+ // import from dva
50
+ memo.alias['dva$'] = pkgPath;
51
+ return memo;
52
+ });
53
+ api.onGenerateFiles((args) => {
54
+ const models = args.isFirstTime
55
+ ? api.appData.pluginDva.models
56
+ : getAllModels(api);
57
+ // models.ts
58
+ api.writeTmpFile({
59
+ path: 'models.ts',
60
+ content: modelUtils_1.ModelUtils.getModelsContent(models),
61
+ });
62
+ // dva.tsx
63
+ api.writeTmpFile({
64
+ path: 'dva.tsx',
65
+ tpl: `
66
+ // It's faked dva
67
+ // aliased to @umijs/plugins/templates/dva
68
+ import { create, Provider } from 'dva';
69
+ import React, { useRef } from 'react';
70
+ import { history } from 'umi';
71
+ import { models } from './models';
72
+
73
+ export function RootContainer(props: any) {
74
+ const app = useRef<any>();
75
+ if (!app.current) {
76
+ app.current = create(
77
+ {
78
+ history,
79
+ },
80
+ {
81
+ initialReducer: {},
82
+ setupMiddlewares(middlewares: Function[]) {
83
+ return [...middlewares];
84
+ },
85
+ setupApp(app: IDvaApp) {
86
+ app._history = history;
87
+ },
88
+ },
89
+ );
90
+ for (const id of Object.keys(models)) {
91
+ app.current.model(models[id].model);
92
+ }
93
+ app.current.start();
94
+ }
95
+ return <Provider store={app.current!._store}>{props.children}</Provider>;
96
+ }
97
+ `,
98
+ context: {},
99
+ });
100
+ // runtime.tsx
101
+ api.writeTmpFile({
102
+ path: 'runtime.tsx',
103
+ content: `
104
+ import React from 'react';
105
+ import { RootContainer } from './dva';
106
+
107
+ export function dataflowProvider(container, opts) {
108
+ return React.createElement(RootContainer, opts, container);
109
+ }
110
+ `,
111
+ });
112
+ // index.ts for export
113
+ api.writeTmpFile({
114
+ path: 'index.ts',
115
+ content: `
116
+ export { connect, useDispatch, useStore, useSelector } from 'dva';`,
117
+ });
118
+ });
119
+ api.addTmpGenerateWatcherPaths(() => {
120
+ return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
121
+ });
122
+ api.addRuntimePlugin(() => {
123
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
124
+ });
8
125
  // dva list model
126
+ api.registerCommand({
127
+ name: 'dva',
128
+ fn() {
129
+ api.logger.info(plugin_utils_1.chalk.green.bold('dva models'));
130
+ api.appData.pluginDva.models.forEach((model) => {
131
+ api.logger.info(` - ${(0, path_1.relative)(api.cwd, model.file)}`);
132
+ });
133
+ },
134
+ });
9
135
  };
136
+ function getModelUtil(api) {
137
+ return new modelUtils_1.ModelUtils(api, {
138
+ contentTest(content) {
139
+ return content.startsWith('// @dva-model');
140
+ },
141
+ astTest({ node, content }) {
142
+ if (isModelObject(node)) {
143
+ return true;
144
+ }
145
+ else if (content.includes('dva-model-extend') &&
146
+ t.isCallExpression(node) &&
147
+ node.arguments.length === 2 &&
148
+ isModelObject(node.arguments[1])) {
149
+ return true;
150
+ }
151
+ return false;
152
+ },
153
+ });
154
+ }
155
+ exports.getModelUtil = getModelUtil;
156
+ function getAllModels(api) {
157
+ return getModelUtil(api).getAllModels({
158
+ extraModels: [...(api.config.dva.extraModels || [])],
159
+ });
160
+ }
161
+ exports.getAllModels = getAllModels;
162
+ function isModelObject(node) {
163
+ return (t.isObjectExpression(node) &&
164
+ node.properties.some((property) => {
165
+ return [
166
+ 'state',
167
+ 'reducers',
168
+ 'subscriptions',
169
+ 'effects',
170
+ 'namespace',
171
+ ].includes(property.key.name);
172
+ }));
173
+ }