@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/locale.js CHANGED
@@ -1,199 +1,221 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageNormalize = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const plugin_utils_1 = require("umi/plugin-utils");
7
- const localeUtils_1 = require("./utils/localeUtils");
8
- const withTmpPath_1 = require("./utils/withTmpPath");
9
- const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
10
- exports.packageNormalize = packageNormalize;
11
- // TODO: runtime plugin
12
- exports.default = (api) => {
13
- // TODO: antd 的校验考虑 antd 插件
14
- let hasAntd = false;
15
- try {
16
- hasAntd = !!require.resolve('antd');
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
- catch (e) {
19
- api.logger.warn('antd is not installed. <SelecLang /> unavailable');
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
- const defaultConfig = {
22
- baseNavigator: true,
23
- useLocalStorage: true,
24
- baseSeparator: '-',
25
- antd: hasAntd,
26
- };
27
- api.describe({
28
- key: 'locale',
29
- config: {
30
- schema(joi) {
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
- const reactIntlPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('react-intl/package')));
44
- // polyfill
45
- api.addEntryImportsAhead(() => (0, localeUtils_1.isNeedPolyfill)(api.config.targets || {})
46
- ? [
47
- {
48
- source: require.resolve('intl'),
49
- },
50
- ]
51
- : []);
52
- const addAntdLocales = async (args) => {
53
- var _a;
54
- return await api.applyPlugins({
55
- key: 'addAntdLocales',
56
- type: api.ApplyPluginsType.add,
57
- initialValue: [
58
- `antd/${((_a = api.config) === null || _a === void 0 ? void 0 : _a.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
59
- ],
60
- args,
61
- });
62
- };
63
- const getList = async (resolveKey) => {
64
- var _a;
65
- const { paths } = api;
66
- return (0, localeUtils_1.getLocaleList)({
67
- localeFolder: 'locales',
68
- separator: (_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.baseSeparator,
69
- absSrcPath: paths.absSrcPath,
70
- absPagesPath: paths.absPagesPath,
71
- addAntdLocales,
72
- resolveKey,
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.onGenerateFiles(async () => {
76
- var _a, _b, _c, _d;
77
- const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
78
- // moment2dayjs
79
- const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
80
- const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
81
- const EventEmitterPkg = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('event-emitter/package')));
82
- const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = {
83
- ...defaultConfig,
84
- ...api.config.locale,
85
- };
86
- const defaultLocale = ((_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.default) || `zh${baseSeparator}CN`;
87
- const localeList = await getList(resolveKey);
88
- const momentLocales = localeList
89
- .map(({ momentLocale }) => momentLocale)
90
- .filter((locale) => locale);
91
- const antdLocales = localeList
92
- .map(({ antdLocale }) => antdLocale)
93
- .filter((locale) => locale);
94
- let MomentLocales = momentLocales;
95
- let DefaultMomentLocale = '';
96
- // set moment default accounding to locale.default
97
- if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
98
- const [lang, country = ''] = defaultLocale.split(baseSeparator);
99
- const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
100
- if (momentLocale) {
101
- MomentLocales = [momentLocale];
102
- DefaultMomentLocale = momentLocale;
103
- }
104
- }
105
- let DefaultAntdLocales = [];
106
- // set antd default locale
107
- if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
108
- const [lang, country = ''] = defaultLocale.split(baseSeparator);
109
- DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
110
- lang,
111
- country,
112
- }));
113
- }
114
- const NormalizeAntdLocalesName = function () {
115
- // @ts-ignore
116
- return (0, exports.packageNormalize)(this);
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
- // Runtime Plugin
191
- api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
192
- api.addRuntimePluginKey(() => ['locale']);
193
- // watch locale files
194
- api.addTmpGenerateWatcherPaths(async () => {
195
- const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
196
- const localeList = await getList(resolveKey);
197
- return (0, localeUtils_1.exactLocalePaths)(localeList);
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
- "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;
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
27
- const fs_1 = require("fs");
28
- const path_1 = require("path");
29
- const plugin_utils_1 = require("umi/plugin-utils");
30
- const modelUtils_1 = require("./utils/modelUtils");
31
- const withTmpPath_1 = require("./utils/withTmpPath");
32
- exports.default = (api) => {
33
- api.describe({
34
- config: {
35
- schema(Joi) {
36
- return Joi.object({
37
- extraModels: Joi.array().items(Joi.string()),
38
- });
39
- },
40
- },
41
- enableBy: api.EnableBy.config,
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.onGenerateFiles(async () => {
44
- const models = await getAllModels(api);
45
- // model.ts
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
- const extraModels = await api.applyPlugins({
89
- key: 'addExtraModels',
90
- type: api.ApplyPluginsType.add,
91
- initialValue: [],
92
- });
93
- return new modelUtils_1.ModelUtils(api, {
94
- astTest({ node }) {
95
- return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
96
- },
97
- }).getAllModels({
98
- sort: {},
99
- extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
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 = {});