neo-cmp-cli 1.6.0-beta.1 → 1.6.0-beta.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 +1 -1
- package/src/module/index.js +32 -26
- package/src/module/main.js +161 -267
- package/src/module/neoInit.js +1 -0
- package/src/neo/NeoUMDContent.js +5 -5
- package/src/neo/neoService.js +17 -18
- package/src/oss/publish2oss.js +174 -71
- package/src/template/antd-custom-cmp-template/README.md +26 -2
- package/src/template/antd-custom-cmp-template/neo.config.js +2 -2
- package/src/template/echarts-custom-cmp-template/README.md +26 -2
- package/src/template/echarts-custom-cmp-template/neo.config.js +4 -3
- package/src/template/empty-custom-cmp-template/README.md +26 -0
- package/src/template/empty-custom-cmp-template/neo.config.js +2 -2
- package/src/template/neo-custom-cmp-template/README.md +26 -2
- package/src/template/neo-custom-cmp-template/neo.config.js +1 -1
- package/src/template/react-custom-cmp-template/README.md +26 -2
- package/src/template/react-custom-cmp-template/neo.config.js +2 -2
- package/src/template/react-ts-custom-cmp-template/README.md +26 -2
- package/src/template/react-ts-custom-cmp-template/neo.config.js +2 -2
- package/src/template/vue2-custom-cmp-template/README.md +26 -2
- package/src/template/vue2-custom-cmp-template/neo.config.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/createCmpByTemplate.js +7 -5
- package/src/{cmpUtils → utils/cmpUtils}/createCmpByZip.js +5 -2
- package/src/{cmpUtils → utils/cmpUtils}/createCommonModulesCode.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/getCmpModelRegisterCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpPreviewCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpRegisterCode.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/getCmpTypeByDir.js +2 -2
- package/src/{cmpUtils → utils/cmpUtils}/hasCmpTypeByDir.js +1 -1
- package/src/{cmpUtils → utils/cmpUtils}/previewCmp.js +3 -3
- package/src/{cmpUtils → utils/cmpUtils}/pullCmp.js +9 -9
- package/src/{cmpUtils → utils/cmpUtils}/pushCmp.js +7 -5
- package/src/utils/generateEntries.js +73 -0
- package/src/{projectUtils → utils/projectUtils}/createCmpProjectByTemplate.js +10 -6
- package/src/{projectUtils → utils/projectUtils}/createCmpProjectZip.js +1 -3
- package/src/{projectUtils → utils/projectUtils}/getEntries.js +2 -2
- package/src/{projectUtils → utils/projectUtils}/getEntriesWithAutoRegister.js +2 -2
- package/src/{projectUtils → utils/projectUtils}/updatePublishLog.js +1 -1
- package/src/template/neo-custom-cmp-template/pushCmp.js +0 -166
- /package/src/{projectUtils → utils/projectUtils}/hasNeoProject.js +0 -0
package/package.json
CHANGED
package/src/module/index.js
CHANGED
|
@@ -3,15 +3,15 @@ const yargs = require('yargs'); // 命令行工具
|
|
|
3
3
|
const chalk = require('chalk'); // 带样式的log输出
|
|
4
4
|
const inquirer = require('inquirer'); // 问答式交互
|
|
5
5
|
const ora = require('ora');
|
|
6
|
-
|
|
7
6
|
const neoInit = require('./neoInit.js');
|
|
8
7
|
const neoInitByCopy = require('./neoInitByCopy.js');
|
|
9
8
|
const inspect = require('./inspect.js'); // 输出当前项目配置文件
|
|
10
9
|
const neoConfigInit = require('../utils/neoConfigInit.js');
|
|
11
10
|
const { validateProjectName } = require('../utils/projectNameValidator.js');
|
|
12
11
|
const mainAction = require('./main.js'); // 入口文件
|
|
13
|
-
const getCmpTypeByDir = require('../cmpUtils/getCmpTypeByDir.js');
|
|
12
|
+
const getCmpTypeByDir = require('../utils/cmpUtils/getCmpTypeByDir.js');
|
|
14
13
|
const NeoService = require('../neo/neoService.js');
|
|
14
|
+
const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
|
|
15
15
|
|
|
16
16
|
// neo 的 package 文件
|
|
17
17
|
const neoPackage = require('../../package.json');
|
|
@@ -171,11 +171,13 @@ yargs
|
|
|
171
171
|
if (argv.name) {
|
|
172
172
|
mainAction.createCmpProjectByTemplate(argv.name);
|
|
173
173
|
} else {
|
|
174
|
-
const questions = [
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
const questions = [
|
|
175
|
+
{
|
|
176
|
+
name: 'name',
|
|
177
|
+
type: 'input',
|
|
178
|
+
message: '请设置自定义组件项目名称:'
|
|
179
|
+
}
|
|
180
|
+
];
|
|
179
181
|
|
|
180
182
|
inquirer.prompt(questions).then((ans) => {
|
|
181
183
|
// 验证项目名称是否合法
|
|
@@ -184,9 +186,9 @@ yargs
|
|
|
184
186
|
console.error(errors.join('\n'));
|
|
185
187
|
process.exit(1);
|
|
186
188
|
}
|
|
187
|
-
|
|
189
|
+
|
|
188
190
|
if (!ans.name) {
|
|
189
|
-
console.error(
|
|
191
|
+
console.error('自定义组件项目名称不能为空。');
|
|
190
192
|
process.exit(1);
|
|
191
193
|
} else {
|
|
192
194
|
mainAction.createCmpProjectByTemplate(ans.name);
|
|
@@ -212,11 +214,13 @@ yargs
|
|
|
212
214
|
if (argv.name) {
|
|
213
215
|
mainAction.createCmpByTemplate(argv.name);
|
|
214
216
|
} else {
|
|
215
|
-
const questions = [
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
const questions = [
|
|
218
|
+
{
|
|
219
|
+
name: 'name',
|
|
220
|
+
type: 'input',
|
|
221
|
+
message: '请设置自定义组件名称:'
|
|
222
|
+
}
|
|
223
|
+
];
|
|
220
224
|
|
|
221
225
|
inquirer.prompt(questions).then((ans) => {
|
|
222
226
|
if (!ans.name) {
|
|
@@ -247,7 +251,7 @@ yargs
|
|
|
247
251
|
mainAction.pullCmp(argv.name);
|
|
248
252
|
} else {
|
|
249
253
|
// 创建 neoService 实例
|
|
250
|
-
const neoService = new NeoService(
|
|
254
|
+
const neoService = new NeoService(curConfig.neoConfig);
|
|
251
255
|
const spinner = ora('正在获取自定义组件列表...').start();
|
|
252
256
|
const cmpList = await neoService.getCustomCmpList();
|
|
253
257
|
if (cmpList.length === 0) {
|
|
@@ -255,22 +259,24 @@ yargs
|
|
|
255
259
|
process.exit(1);
|
|
256
260
|
}
|
|
257
261
|
spinner.clear();
|
|
258
|
-
const cmpTypeChoices = cmpList.map((
|
|
259
|
-
name:
|
|
260
|
-
value: cmpType
|
|
262
|
+
const cmpTypeChoices = cmpList.map((cmpItem) => ({
|
|
263
|
+
name: cmpItem.label,
|
|
264
|
+
value: cmpItem.cmpType
|
|
261
265
|
}));
|
|
262
|
-
questions
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
const questions = [
|
|
267
|
+
{
|
|
268
|
+
name: 'cmpType',
|
|
269
|
+
type: 'list',
|
|
270
|
+
message: '请选择要拉取的自定义组件:',
|
|
271
|
+
choices: cmpTypeChoices
|
|
272
|
+
}
|
|
273
|
+
];
|
|
268
274
|
inquirer.prompt(questions).then((ans) => {
|
|
269
|
-
if (!ans.
|
|
275
|
+
if (!ans.cmpType) {
|
|
270
276
|
console.error('自定义组件名称不能为空。');
|
|
271
277
|
process.exit(1);
|
|
272
278
|
} else {
|
|
273
|
-
mainAction.pullCmp(ans.
|
|
279
|
+
mainAction.pullCmp(ans.cmpType, neoService);
|
|
274
280
|
}
|
|
275
281
|
});
|
|
276
282
|
}
|
package/src/module/main.js
CHANGED
|
@@ -7,17 +7,16 @@ const neoConfigInit = require('../utils/neoConfigInit.js');
|
|
|
7
7
|
const { consoleTag } = require('../utils/neoParams');
|
|
8
8
|
const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
|
|
9
9
|
const publish2oss = require('../oss/publish2oss');
|
|
10
|
-
const pushCmp = require('../cmpUtils/pushCmp');
|
|
11
|
-
const previewCmp = require('../cmpUtils/previewCmp');
|
|
12
|
-
const
|
|
13
|
-
const getEntriesWithAutoRegister = require('../projectUtils/getEntriesWithAutoRegister');
|
|
10
|
+
const pushCmp = require('../utils/cmpUtils/pushCmp');
|
|
11
|
+
const previewCmp = require('../utils/cmpUtils/previewCmp');
|
|
12
|
+
const generateEntries = require('../utils/generateEntries');
|
|
14
13
|
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
15
14
|
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
16
15
|
// const { MFPlugins } = require('../neo/webpack.mf');
|
|
17
|
-
const createCommonModulesCode = require('../cmpUtils/createCommonModulesCode');
|
|
18
|
-
const createCmpByTemplate = require('../cmpUtils/createCmpByTemplate');
|
|
19
|
-
const createCmpProjectByTemplate = require('../projectUtils/createCmpProjectByTemplate');
|
|
20
|
-
const pullCmp = require('../cmpUtils/pullCmp');
|
|
16
|
+
const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
|
|
17
|
+
const createCmpByTemplate = require('../utils/cmpUtils/createCmpByTemplate');
|
|
18
|
+
const createCmpProjectByTemplate = require('../utils/projectUtils/createCmpProjectByTemplate');
|
|
19
|
+
const pullCmp = require('../utils/cmpUtils/pullCmp');
|
|
21
20
|
|
|
22
21
|
const getValue = (originValue, defaultValue) => {
|
|
23
22
|
return originValue !== undefined ? originValue : defaultValue;
|
|
@@ -27,6 +26,124 @@ const neoCommonModule = curConfig.neoCommonModule || {};
|
|
|
27
26
|
// 自定义组件 需要剔除的依赖模块
|
|
28
27
|
const cmpNeoExternals = neoCommonModule.neoExternals || [];
|
|
29
28
|
|
|
29
|
+
/**
|
|
30
|
+
* 添加 AddNeoRequirePlugin 到 webpack 配置
|
|
31
|
+
* @param {object} webpackConfig webpack 配置对象
|
|
32
|
+
* @param {object} [options] 选项
|
|
33
|
+
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
34
|
+
*/
|
|
35
|
+
function addNeoRequirePlugin(webpackConfig, options = {}) {
|
|
36
|
+
const { verbose = false } = options;
|
|
37
|
+
const plugin = new AddNeoRequirePlugin({ verbose });
|
|
38
|
+
|
|
39
|
+
if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
|
|
40
|
+
webpackConfig.plugins.push(plugin);
|
|
41
|
+
} else {
|
|
42
|
+
webpackConfig.plugins = [plugin];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 添加 Neo externals 配置
|
|
48
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
49
|
+
* @param {object} externalsConfig 现有的 externals 配置
|
|
50
|
+
*/
|
|
51
|
+
function addNeoExternals(config, externalsConfig) {
|
|
52
|
+
const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
53
|
+
if (externalsConfig && _.isPlainObject(externalsConfig)) {
|
|
54
|
+
config.externals = Object.assign(externalsConfig, neoExternals);
|
|
55
|
+
} else {
|
|
56
|
+
config.externals = neoExternals;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 创建并注入 commonModulesCode 到 entry
|
|
62
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
63
|
+
* @param {array} cmpTypes 组件类型列表
|
|
64
|
+
* @param {object} [options] 选项
|
|
65
|
+
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
66
|
+
*/
|
|
67
|
+
function injectCommonModulesCode(config, cmpTypes, options = {}) {
|
|
68
|
+
const { excludeModel = false } = options;
|
|
69
|
+
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
|
|
70
|
+
|
|
71
|
+
if (commonModulesFilePath && config.entry) {
|
|
72
|
+
Object.keys(config.entry).forEach((name) => {
|
|
73
|
+
// 如果 excludeModel 为 true,排除 Model 结尾的文件
|
|
74
|
+
if (!excludeModel || !name.endsWith('Model')) {
|
|
75
|
+
config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 生成并设置 entry 配置
|
|
83
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
84
|
+
* @param {object} options 生成选项
|
|
85
|
+
* @param {string} options.entryType entry 类型:'widget' | 'linkDebug'
|
|
86
|
+
* @param {string} [options.cmpType] 可选的组件类型
|
|
87
|
+
* @param {boolean} [options.forceGetCmpTypes] 是否强制获取 cmpTypes
|
|
88
|
+
* @returns {array} cmpTypes 组件类型列表
|
|
89
|
+
*/
|
|
90
|
+
function setupEntries(config, options) {
|
|
91
|
+
const { entryType, cmpType, forceGetCmpTypes = false } = options;
|
|
92
|
+
|
|
93
|
+
let cmpTypes = [];
|
|
94
|
+
try {
|
|
95
|
+
const { entries, cmpTypes: generatedCmpTypes } = generateEntries({
|
|
96
|
+
configEntry: config.entry,
|
|
97
|
+
disableAutoRegister: config.disableAutoRegister,
|
|
98
|
+
componentsDir: curConfig.componentsDir,
|
|
99
|
+
entryType,
|
|
100
|
+
cmpType,
|
|
101
|
+
forceGetCmpTypes
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (entries && Object.keys(entries).length > 0) {
|
|
105
|
+
config.entry = entries;
|
|
106
|
+
cmpTypes = generatedCmpTypes;
|
|
107
|
+
console.info('已自动生成 entry 入口配置:', entries);
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(error.message);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return cmpTypes;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 准备 build2lib 配置(用于 publish2oss 和 pushCmp)
|
|
119
|
+
* @param {object} sourceConfig 源配置对象
|
|
120
|
+
* @returns {object} 合并后的配置对象
|
|
121
|
+
*/
|
|
122
|
+
function prepareBuild2LibConfig(sourceConfig) {
|
|
123
|
+
return Object.assign(curConfig.build2lib, sourceConfig);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
|
|
128
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
129
|
+
* @param {array} cmpTypes 组件类型列表
|
|
130
|
+
* @param {object} [options] 选项
|
|
131
|
+
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
132
|
+
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
133
|
+
*/
|
|
134
|
+
function configureNeoBuild(config, cmpTypes, options = {}) {
|
|
135
|
+
const { verbose = false, excludeModel = false } = options;
|
|
136
|
+
|
|
137
|
+
// 添加自定义 webpack 插件
|
|
138
|
+
addNeoRequirePlugin(curConfig.webpack, { verbose });
|
|
139
|
+
|
|
140
|
+
// 添加内置 Neo 的 externals 配置
|
|
141
|
+
addNeoExternals(config, config.externals);
|
|
142
|
+
|
|
143
|
+
// 创建并注入 commonModulesCode
|
|
144
|
+
injectCommonModulesCode(config, cmpTypes, { excludeModel });
|
|
145
|
+
}
|
|
146
|
+
|
|
30
147
|
module.exports = {
|
|
31
148
|
neoInit,
|
|
32
149
|
neoInitByCopy,
|
|
@@ -64,208 +181,50 @@ module.exports = {
|
|
|
64
181
|
}
|
|
65
182
|
// 将 linkDebug 设置给 dev
|
|
66
183
|
curConfig.dev = Object.assign(curConfig.dev, curConfig.linkDebug);
|
|
67
|
-
|
|
68
184
|
delete curConfig.linkDebug;
|
|
69
185
|
|
|
70
186
|
delete curConfig.dev.ignoreNodeModules; // 需要注入依赖
|
|
71
187
|
curConfig.webpack.ignoreNodeModules = false;
|
|
72
188
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let entries = {};
|
|
79
|
-
if (curConfig.dev.disableAutoRegister) {
|
|
80
|
-
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
81
|
-
const { linkDebugEntries, cmpTypes } = getEntries(curConfig.componentsDir);
|
|
82
|
-
entries = linkDebugEntries;
|
|
83
|
-
curCmpTypes = cmpTypes;
|
|
84
|
-
} else {
|
|
85
|
-
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
86
|
-
const { linkDebugEntries, cmpTypes } = getEntriesWithAutoRegister(curConfig.componentsDir);
|
|
87
|
-
entries = linkDebugEntries;
|
|
88
|
-
curCmpTypes = cmpTypes;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 注入 webpack/entry
|
|
92
|
-
if (entries && Object.keys(entries).length > 0) {
|
|
93
|
-
curConfig.dev.entry = entries;
|
|
94
|
-
console.info('已自动生成 entry 入口配置:', entries);
|
|
95
|
-
} else {
|
|
96
|
-
console.error(
|
|
97
|
-
`未识别到自定义组件,请检查 ${
|
|
98
|
-
curConfig.componentsDir || './src/components'
|
|
99
|
-
} 目录下是否存在自定义组件。`
|
|
100
|
-
);
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/*
|
|
106
|
-
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
107
|
-
// 添加模块联邦插件
|
|
108
|
-
if (curConfig.dev.enableMF) {
|
|
109
|
-
curConfig.webpack.plugins.push(...MFPlugins);
|
|
110
|
-
}
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
|
-
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
114
|
-
if (
|
|
115
|
-
curConfig.webpack &&
|
|
116
|
-
curConfig.webpack.plugins &&
|
|
117
|
-
Array.isArray(curConfig.webpack.plugins)
|
|
118
|
-
) {
|
|
119
|
-
curConfig.webpack.plugins.push(new AddNeoRequirePlugin({ verbose: true }));
|
|
120
|
-
} else {
|
|
121
|
-
curConfig.webpack.plugins = [new AddNeoRequirePlugin({ verbose: true })];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 添加 内置 Neo 的 externals 配置
|
|
125
|
-
const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
126
|
-
if (curConfig.dev.externals && _.isPlainObject(curConfig.dev.externals)) {
|
|
127
|
-
curConfig.dev.externals = Object.assign(curConfig.dev.externals, neoExternals);
|
|
128
|
-
} else {
|
|
129
|
-
curConfig.dev.externals = neoExternals;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 写入自定义组件的共享模块和远程模块相关信息
|
|
133
|
-
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, curCmpTypes);
|
|
189
|
+
// 生成并设置 entry 配置
|
|
190
|
+
const curCmpTypes = setupEntries(curConfig.dev, {
|
|
191
|
+
entryType: 'linkDebug',
|
|
192
|
+
forceGetCmpTypes: true // linkDebug 需要 cmpTypes 来生成 commonModulesCode
|
|
193
|
+
});
|
|
134
194
|
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
195
|
+
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
196
|
+
configureNeoBuild(curConfig.dev, curCmpTypes, {
|
|
197
|
+
verbose: true,
|
|
198
|
+
excludeModel: false // linkDebug 不排除 Model
|
|
199
|
+
});
|
|
141
200
|
|
|
142
201
|
akfun.dev(curConfig, consoleTag);
|
|
143
202
|
},
|
|
144
203
|
build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
|
|
145
204
|
build2lib: () => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// 如果未配置 entry,则自动生成 entry
|
|
151
|
-
let entries = {};
|
|
152
|
-
if (curConfig.build2lib.disableAutoRegister) {
|
|
153
|
-
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
154
|
-
const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir);
|
|
155
|
-
entries = widgetEntries;
|
|
156
|
-
curCmpTypes = cmpTypes;
|
|
157
|
-
} else {
|
|
158
|
-
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
159
|
-
const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(curConfig.componentsDir);
|
|
160
|
-
entries = widgetEntries;
|
|
161
|
-
curCmpTypes = cmpTypes;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// 注入 webpack/entry
|
|
165
|
-
if (entries && Object.keys(entries).length > 0) {
|
|
166
|
-
curConfig.build2lib.entry = entries;
|
|
167
|
-
console.info('已自动生成 entry 入口配置:', entries);
|
|
168
|
-
} else {
|
|
169
|
-
console.error(
|
|
170
|
-
`未识别到自定义组件,请检查 ${
|
|
171
|
-
curConfig.componentsDir || './src/components'
|
|
172
|
-
} 目录下是否存在自定义组件。`
|
|
173
|
-
);
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/*
|
|
179
|
-
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
180
|
-
if (curConfig.build2lib.enableMF) {
|
|
181
|
-
// 添加模块联邦插件
|
|
182
|
-
curConfig.webpack.plugins.push(...MFPlugins);
|
|
183
|
-
}
|
|
184
|
-
*/
|
|
205
|
+
// 生成并设置 entry 配置
|
|
206
|
+
setupEntries(curConfig.build2lib, {
|
|
207
|
+
entryType: 'widget'
|
|
208
|
+
});
|
|
185
209
|
|
|
186
210
|
akfun.build('lib', curConfig, consoleTag);
|
|
187
211
|
}, // 构建脚本:生产环境
|
|
188
212
|
publish2oss: (cmpType) => {
|
|
189
213
|
// 将 publish2oss 相关配置设置给 build2lib
|
|
190
214
|
const publish2ossConfig = curConfig.publish2oss;
|
|
191
|
-
curConfig.build2lib =
|
|
215
|
+
curConfig.build2lib = prepareBuild2LibConfig(publish2ossConfig);
|
|
192
216
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let entries = {};
|
|
199
|
-
if (curConfig.build2lib.disableAutoRegister) {
|
|
200
|
-
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
201
|
-
const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir, cmpType);
|
|
202
|
-
entries = widgetEntries;
|
|
203
|
-
curCmpTypes = cmpTypes;
|
|
204
|
-
} else {
|
|
205
|
-
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
206
|
-
const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(
|
|
207
|
-
curConfig.componentsDir,
|
|
208
|
-
cmpType
|
|
209
|
-
);
|
|
210
|
-
entries = widgetEntries;
|
|
211
|
-
curCmpTypes = cmpTypes;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// 注入 webpack/entry
|
|
215
|
-
if (entries && Object.keys(entries).length > 0) {
|
|
216
|
-
curConfig.build2lib.entry = entries;
|
|
217
|
-
console.info('已自动生成 entry 入口配置:', entries);
|
|
218
|
-
} else {
|
|
219
|
-
console.error(
|
|
220
|
-
`未识别到自定义组件,请检查 ${
|
|
221
|
-
curConfig.componentsDir || './src/components'
|
|
222
|
-
} 目录下是否存在自定义组件。`
|
|
223
|
-
);
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/*
|
|
229
|
-
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
230
|
-
// 添加模块联邦插件
|
|
231
|
-
if (curConfig.publish2oss.enableMF) {
|
|
232
|
-
curConfig.webpack.plugins.push(...MFPlugins);
|
|
233
|
-
}
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
237
|
-
if (
|
|
238
|
-
curConfig.webpack &&
|
|
239
|
-
curConfig.webpack.plugins &&
|
|
240
|
-
Array.isArray(curConfig.webpack.plugins)
|
|
241
|
-
) {
|
|
242
|
-
curConfig.webpack.plugins.push(new AddNeoRequirePlugin({ verbose: true }));
|
|
243
|
-
} else {
|
|
244
|
-
curConfig.webpack.plugins = [new AddNeoRequirePlugin({ verbose: true })];
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// 添加 内置 Neo 的 externals 配置
|
|
248
|
-
const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
249
|
-
if (curConfig.build2lib.externals && _.isPlainObject(curConfig.build2lib.externals)) {
|
|
250
|
-
curConfig.build2lib.externals = Object.assign(curConfig.build2lib.externals, neoExternals);
|
|
251
|
-
} else {
|
|
252
|
-
curConfig.build2lib.externals = neoExternals;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// 写入自定义组件的共享模块和远程模块相关信息
|
|
256
|
-
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, curCmpTypes);
|
|
217
|
+
// 生成并设置 entry 配置
|
|
218
|
+
const curCmpTypes = setupEntries(curConfig.build2lib, {
|
|
219
|
+
entryType: 'widget',
|
|
220
|
+
cmpType
|
|
221
|
+
});
|
|
257
222
|
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
curConfig.build2lib.entry[name] = [commonModulesFilePath].concat(
|
|
264
|
-
curConfig.build2lib.entry[name]
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
}
|
|
223
|
+
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
224
|
+
configureNeoBuild(curConfig.build2lib, curCmpTypes, {
|
|
225
|
+
verbose: true,
|
|
226
|
+
excludeModel: true // publish2oss 排除 Model 结尾的文件
|
|
227
|
+
});
|
|
269
228
|
|
|
270
229
|
akfun.build('lib', curConfig, consoleTag, () => {
|
|
271
230
|
// 构建完成后,执行 publish2oss
|
|
@@ -281,84 +240,19 @@ module.exports = {
|
|
|
281
240
|
const { neoConfig, pushCmp: _pushCmpConfig } = curConfig;
|
|
282
241
|
const pushCmpConfig = Object.assign({}, _pushCmpConfig, neoConfig);
|
|
283
242
|
// 将 pushCmp 相关配置设置给 build2lib
|
|
284
|
-
curConfig.build2lib =
|
|
243
|
+
curConfig.build2lib = prepareBuild2LibConfig(pushCmpConfig);
|
|
285
244
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
let entries = {};
|
|
292
|
-
if (curConfig.build2lib.disableAutoRegister) {
|
|
293
|
-
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
294
|
-
const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir, cmpType);
|
|
295
|
-
entries = widgetEntries;
|
|
296
|
-
curCmpTypes = cmpTypes;
|
|
297
|
-
} else {
|
|
298
|
-
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
299
|
-
const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(
|
|
300
|
-
curConfig.componentsDir,
|
|
301
|
-
cmpType
|
|
302
|
-
);
|
|
303
|
-
entries = widgetEntries;
|
|
304
|
-
curCmpTypes = cmpTypes;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// 注入 webpack/entry
|
|
308
|
-
if (entries && Object.keys(entries).length > 0) {
|
|
309
|
-
curConfig.build2lib.entry = entries;
|
|
310
|
-
console.info('已自动生成 entry 入口配置:', entries);
|
|
311
|
-
} else {
|
|
312
|
-
console.error(
|
|
313
|
-
`未识别到自定义组件,请检查 ${
|
|
314
|
-
curConfig.componentsDir || './src/components'
|
|
315
|
-
} 目录下是否存在自定义组件。`
|
|
316
|
-
);
|
|
317
|
-
process.exit(1);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/*
|
|
322
|
-
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
323
|
-
// 添加模块联邦插件
|
|
324
|
-
if (curConfig.pushCmp.enableMF) {
|
|
325
|
-
curConfig.webpack.plugins.push(...MFPlugins);
|
|
326
|
-
}
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
330
|
-
if (
|
|
331
|
-
curConfig.webpack &&
|
|
332
|
-
curConfig.webpack.plugins &&
|
|
333
|
-
Array.isArray(curConfig.webpack.plugins)
|
|
334
|
-
) {
|
|
335
|
-
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
336
|
-
} else {
|
|
337
|
-
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// 添加 内置 Neo 的 externals 配置
|
|
341
|
-
const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
342
|
-
if (curConfig.build2lib.externals && _.isPlainObject(curConfig.build2lib.externals)) {
|
|
343
|
-
curConfig.build2lib.externals = Object.assign(curConfig.build2lib.externals, neoExternals);
|
|
344
|
-
} else {
|
|
345
|
-
curConfig.build2lib.externals = neoExternals;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// 写入自定义组件的共享模块和远程模块相关信息
|
|
349
|
-
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, curCmpTypes);
|
|
245
|
+
// 生成并设置 entry 配置
|
|
246
|
+
const curCmpTypes = setupEntries(curConfig.build2lib, {
|
|
247
|
+
entryType: 'widget',
|
|
248
|
+
cmpType
|
|
249
|
+
});
|
|
350
250
|
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
curConfig.build2lib.entry[name] = [commonModulesFilePath].concat(
|
|
357
|
-
curConfig.build2lib.entry[name]
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
}
|
|
251
|
+
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
252
|
+
configureNeoBuild(curConfig.build2lib, curCmpTypes, {
|
|
253
|
+
verbose: false,
|
|
254
|
+
excludeModel: true // pushCmp 排除 Model 结尾的文件
|
|
255
|
+
});
|
|
362
256
|
|
|
363
257
|
akfun.build('lib', curConfig, consoleTag, () => {
|
|
364
258
|
// 构建完成后,执行 pushCmp
|
package/src/module/neoInit.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { gitClone } = require('akfun');
|
|
2
|
+
const path = require('path');
|
|
2
3
|
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
3
4
|
const { replaceInPackage } = require('../utils/replaceInPackage');
|
|
4
5
|
const { resetPackageVersion } = require('../utils/resetPackageVersion');
|
package/src/neo/NeoUMDContent.js
CHANGED
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
else {
|
|
17
17
|
root.NeoCustomCmpModel = factory();
|
|
18
18
|
}
|
|
19
|
-
}(typeof self !== 'undefined' ? self : this, function () {
|
|
19
|
+
})(typeof self !== 'undefined' ? self : this, function () {
|
|
20
20
|
'use strict';
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
const getCustomModels = (cmpType) => {
|
|
23
23
|
// 自定义组件模型列表
|
|
24
24
|
const NEOEditorCustomModels = window.NEOEditorCustomModels || {};
|
|
25
25
|
return NEOEditorCustomModels[cmpType] || {};
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
};
|
|
27
|
+
|
|
28
28
|
// 导出模块
|
|
29
29
|
return getCustomModels;
|
|
30
|
-
})
|
|
30
|
+
});
|