neo-cmp-cli 1.7.12 → 1.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/module/main.js +24 -94
- package/src/neo/neoRequire.js +10 -0
- package/src/utils/configureNeoBuild.js +108 -0
- package/src/utils/generateEntries.js +5 -15
- package/src/utils/projectUtils/getEntries.js +7 -2
- package/src/utils/projectUtils/getEntriesWithAutoRegister.js +8 -5
- package/test/demo.js +3 -3
- package/test/deprecate-versions.js +1 -1
package/package.json
CHANGED
package/src/module/main.js
CHANGED
|
@@ -10,98 +10,39 @@ const publish2oss = require('../oss/publish2oss');
|
|
|
10
10
|
const pushCmp = require('../utils/cmpUtils/pushCmp');
|
|
11
11
|
const previewCmp = require('../utils/cmpUtils/previewCmp');
|
|
12
12
|
const generateEntries = require('../utils/generateEntries');
|
|
13
|
-
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
14
|
-
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
15
13
|
// const { MFPlugins } = require('../neo/webpack.mf');
|
|
16
|
-
const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
|
|
17
14
|
const createCmpByTemplate = require('../utils/cmpUtils/createCmpByTemplate');
|
|
18
15
|
const createCmpProjectByTemplate = require('../utils/projectUtils/createCmpProjectByTemplate');
|
|
19
16
|
const pullCmp = require('../utils/cmpUtils/pullCmp');
|
|
20
17
|
const deleteCmp = require('../utils/cmpUtils/deleteCmp');
|
|
21
18
|
const openProject = require('../utils/projectUtils/openProject');
|
|
19
|
+
const { configureNeoBuild } = require('../utils/configureNeoBuild');
|
|
22
20
|
const { errorLog, successLog } = require('../utils/common');
|
|
23
21
|
|
|
24
22
|
const getValue = (originValue, defaultValue) => {
|
|
25
23
|
return originValue !== undefined ? originValue : defaultValue;
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
const neoCommonModule = curConfig.neoCommonModule || {};
|
|
29
|
-
// 自定义组件 需要剔除的依赖模块
|
|
30
|
-
const cmpNeoExternals = neoCommonModule.externals || [];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 添加 AddNeoRequirePlugin 到 webpack 配置
|
|
34
|
-
* @param {object} webpackConfig webpack 配置对象
|
|
35
|
-
* @param {object} [options] 选项
|
|
36
|
-
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
37
|
-
*/
|
|
38
|
-
function addNeoRequirePlugin(webpackConfig, options = {}) {
|
|
39
|
-
const { verbose = false } = options;
|
|
40
|
-
const plugin = new AddNeoRequirePlugin({ verbose });
|
|
41
|
-
|
|
42
|
-
if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
|
|
43
|
-
webpackConfig.plugins.push(plugin);
|
|
44
|
-
} else {
|
|
45
|
-
webpackConfig.plugins = [plugin];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 添加 Neo externals 配置
|
|
51
|
-
* @param {object} config 配置对象(dev 或 build2lib)
|
|
52
|
-
* @param {object} externalsConfig 现有的 externals 配置
|
|
53
|
-
*/
|
|
54
|
-
function addNeoExternals(config, externalsConfig) {
|
|
55
|
-
const externals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
56
|
-
if (externalsConfig && _.isPlainObject(externalsConfig)) {
|
|
57
|
-
config.externals = Object.assign(externalsConfig, externals);
|
|
58
|
-
} else {
|
|
59
|
-
config.externals = externals;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 创建并注入 commonModulesCode 到 entry
|
|
65
|
-
* @param {object} config 配置对象(dev 或 build2lib)
|
|
66
|
-
* @param {array} cmpTypes 组件类型列表
|
|
67
|
-
* @param {object} [options] 选项
|
|
68
|
-
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
69
|
-
*/
|
|
70
|
-
function injectCommonModulesCode(config, cmpTypes, options = {}) {
|
|
71
|
-
const { excludeModel = false } = options;
|
|
72
|
-
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
|
|
73
|
-
|
|
74
|
-
if (commonModulesFilePath && config.entry) {
|
|
75
|
-
Object.keys(config.entry).forEach((name) => {
|
|
76
|
-
// 如果 excludeModel 为 true,排除 Model 结尾的文件
|
|
77
|
-
if (!excludeModel || !name.endsWith('Model')) {
|
|
78
|
-
config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
26
|
/**
|
|
85
27
|
* 生成并设置 entry 配置
|
|
86
28
|
* @param {object} config 配置对象(dev 或 build2lib)
|
|
87
29
|
* @param {object} options 生成选项
|
|
88
30
|
* @param {string} options.entryType entry 类型:'widget' | 'linkDebug'
|
|
89
31
|
* @param {string} [options.cmpType] 可选的组件类型
|
|
90
|
-
* @param {boolean} [options.forceGetCmpTypes] 是否强制获取 cmpTypes
|
|
91
32
|
* @returns {array} cmpTypes 组件类型列表
|
|
92
33
|
*/
|
|
93
34
|
function setupEntries(config, options) {
|
|
94
|
-
const { entryType, cmpType
|
|
35
|
+
const { entryType, cmpType } = options;
|
|
95
36
|
|
|
96
37
|
let cmpTypes = [];
|
|
38
|
+
let defaultExports = {};
|
|
97
39
|
try {
|
|
98
|
-
const { entries, cmpTypes: generatedCmpTypes } = generateEntries({
|
|
40
|
+
const { entries, cmpTypes: generatedCmpTypes, defaultExports: generatedDefaultExports } = generateEntries({
|
|
99
41
|
configEntry: config.entry,
|
|
100
42
|
disableAutoRegister: config.disableAutoRegister,
|
|
101
43
|
componentsDir: curConfig.componentsDir,
|
|
102
44
|
entryType,
|
|
103
|
-
cmpType
|
|
104
|
-
forceGetCmpTypes
|
|
45
|
+
cmpType
|
|
105
46
|
});
|
|
106
47
|
|
|
107
48
|
if (entries && Object.keys(entries).length > 0) {
|
|
@@ -109,12 +50,17 @@ function setupEntries(config, options) {
|
|
|
109
50
|
cmpTypes = generatedCmpTypes;
|
|
110
51
|
console.info('已自动生成 entry 入口配置:', entries);
|
|
111
52
|
}
|
|
53
|
+
|
|
54
|
+
defaultExports = generatedDefaultExports;
|
|
112
55
|
} catch (error) {
|
|
113
56
|
errorLog(error.message);
|
|
114
57
|
process.exit(1);
|
|
115
58
|
}
|
|
116
59
|
|
|
117
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
cmpTypes,
|
|
62
|
+
defaultExports
|
|
63
|
+
};
|
|
118
64
|
}
|
|
119
65
|
|
|
120
66
|
/**
|
|
@@ -126,27 +72,6 @@ function prepareBuild2LibConfig(sourceConfig) {
|
|
|
126
72
|
return Object.assign(curConfig.build2lib, sourceConfig);
|
|
127
73
|
}
|
|
128
74
|
|
|
129
|
-
/**
|
|
130
|
-
* 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
|
|
131
|
-
* @param {object} config 配置对象(dev 或 build2lib)
|
|
132
|
-
* @param {array} cmpTypes 组件类型列表
|
|
133
|
-
* @param {object} [options] 选项
|
|
134
|
-
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
135
|
-
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
136
|
-
*/
|
|
137
|
-
function configureNeoBuild(config, cmpTypes, options = {}) {
|
|
138
|
-
const { verbose = false, excludeModel = false } = options;
|
|
139
|
-
|
|
140
|
-
// 添加自定义 webpack 插件
|
|
141
|
-
addNeoRequirePlugin(curConfig.webpack, { verbose });
|
|
142
|
-
|
|
143
|
-
// 添加内置 Neo 的 externals 配置
|
|
144
|
-
addNeoExternals(config, config.externals);
|
|
145
|
-
|
|
146
|
-
// 创建并注入 commonModulesCode
|
|
147
|
-
injectCommonModulesCode(config, cmpTypes, { excludeModel });
|
|
148
|
-
}
|
|
149
|
-
|
|
150
75
|
module.exports = {
|
|
151
76
|
neoInit,
|
|
152
77
|
neoInitByCopy,
|
|
@@ -190,13 +115,14 @@ module.exports = {
|
|
|
190
115
|
curConfig.webpack.ignoreNodeModules = false;
|
|
191
116
|
|
|
192
117
|
// 生成并设置 entry 配置
|
|
193
|
-
const curCmpTypes = setupEntries(curConfig.dev, {
|
|
194
|
-
entryType: 'linkDebug'
|
|
195
|
-
forceGetCmpTypes: true // linkDebug 需要 cmpTypes 来生成 commonModulesCode
|
|
118
|
+
const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.dev, {
|
|
119
|
+
entryType: 'linkDebug'
|
|
196
120
|
});
|
|
197
121
|
|
|
198
122
|
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
199
|
-
configureNeoBuild(curConfig.dev,
|
|
123
|
+
configureNeoBuild(curConfig.dev, {
|
|
124
|
+
cmpTypes: curCmpTypes,
|
|
125
|
+
defaultExports,
|
|
200
126
|
verbose: true,
|
|
201
127
|
excludeModel: false // linkDebug 不排除 Model
|
|
202
128
|
});
|
|
@@ -218,13 +144,15 @@ module.exports = {
|
|
|
218
144
|
curConfig.build2lib = prepareBuild2LibConfig(publish2ossConfig);
|
|
219
145
|
|
|
220
146
|
// 生成并设置 entry 配置
|
|
221
|
-
const curCmpTypes = setupEntries(curConfig.build2lib, {
|
|
147
|
+
const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
|
|
222
148
|
entryType: 'widget',
|
|
223
149
|
cmpType
|
|
224
150
|
});
|
|
225
151
|
|
|
226
152
|
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
227
|
-
configureNeoBuild(curConfig.build2lib,
|
|
153
|
+
configureNeoBuild(curConfig.build2lib, {
|
|
154
|
+
cmpTypes: curCmpTypes,
|
|
155
|
+
defaultExports,
|
|
228
156
|
verbose: true,
|
|
229
157
|
excludeModel: true // publish2oss 排除 Model 结尾的文件
|
|
230
158
|
});
|
|
@@ -246,13 +174,15 @@ module.exports = {
|
|
|
246
174
|
curConfig.build2lib = prepareBuild2LibConfig(pushCmpConfig);
|
|
247
175
|
|
|
248
176
|
// 生成并设置 entry 配置
|
|
249
|
-
const curCmpTypes = setupEntries(curConfig.build2lib, {
|
|
177
|
+
const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
|
|
250
178
|
entryType: 'widget',
|
|
251
179
|
cmpType
|
|
252
180
|
});
|
|
253
181
|
|
|
254
182
|
// 配置 webpack 插件、externals 和 commonModulesCode
|
|
255
|
-
configureNeoBuild(curConfig.build2lib,
|
|
183
|
+
configureNeoBuild(curConfig.build2lib, {
|
|
184
|
+
cmpTypes: curCmpTypes,
|
|
185
|
+
defaultExports,
|
|
256
186
|
verbose: false,
|
|
257
187
|
excludeModel: true // pushCmp 排除 Model 结尾的文件
|
|
258
188
|
});
|
package/src/neo/neoRequire.js
CHANGED
|
@@ -50,7 +50,17 @@ const addNeoCommonModules = (modules) => {
|
|
|
50
50
|
const curModule = modules[moduleId];
|
|
51
51
|
const curCommonModule = window.__NeoCommonModules[moduleId];
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* 如果 Neo 共享出来的依赖模块已经存在,则合并到 window.__NeoCommonModules 中
|
|
55
|
+
* 目的:解决依赖加载顺序问题,确保存在依赖的组件无论其加载顺序如何都能正常运行。
|
|
56
|
+
*
|
|
57
|
+
* 疑问1: 为什么 neoRequire 要返回一个 空的默认模块对象?
|
|
58
|
+
* 答:组件A 依赖 组件B 时,当 组件A 先加载(挂载对应的 asset 资源脚本)会报错,为了避免挂载时报错返回一个默认的空模块对象。
|
|
59
|
+
* 疑问2: 为什么不直接替换已有的模块,而是进行覆盖式合并(保持引用关联)?
|
|
60
|
+
* 答:为了避免依赖模块的引用关系被破坏,保持引用关联。确保动态注册进来的模块可以被提前挂载的组件所使用。
|
|
61
|
+
*/
|
|
53
62
|
if (curCommonModule && Object.keys(curCommonModule).length < 3) {
|
|
63
|
+
// 如果是默认模块对象,则覆盖式合并(保持引用关联)
|
|
54
64
|
window.__NeoCommonModules[moduleId] = Object.assign(window.__NeoCommonModules[moduleId], curModule);
|
|
55
65
|
|
|
56
66
|
// 处理模块中的特殊属性
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
2
|
+
const createCommonModulesCode = require('../utils/cmpUtils/createCommonModulesCode');
|
|
3
|
+
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
4
|
+
const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
|
|
5
|
+
|
|
6
|
+
// neo.config.js 中的添加的 Neo 共享依赖模块配置
|
|
7
|
+
const neoCommonModule = curConfig.neoCommonModule || {};
|
|
8
|
+
// 自定义组件 需要剔除的依赖模块
|
|
9
|
+
const cmpNeoExternals = neoCommonModule.externals || [];
|
|
10
|
+
|
|
11
|
+
// 组件目录
|
|
12
|
+
const componentsDir = curConfig.componentsDir || './src/components';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 添加 AddNeoRequirePlugin 到 webpack 配置
|
|
16
|
+
* @param {object} webpackConfig webpack 配置对象
|
|
17
|
+
* @param {object} [options] 选项
|
|
18
|
+
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
19
|
+
*/
|
|
20
|
+
function addNeoRequirePlugin(webpackConfig, options = {}) {
|
|
21
|
+
const { verbose = false } = options;
|
|
22
|
+
const plugin = new AddNeoRequirePlugin({ verbose });
|
|
23
|
+
|
|
24
|
+
if (webpackConfig && webpackConfig.plugins && Array.isArray(webpackConfig.plugins)) {
|
|
25
|
+
webpackConfig.plugins.push(plugin);
|
|
26
|
+
} else {
|
|
27
|
+
webpackConfig.plugins = [plugin];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 添加 Neo externals 配置
|
|
33
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
34
|
+
* @param {object} externalsConfig 现有的 externals 配置
|
|
35
|
+
*/
|
|
36
|
+
function addNeoExternals(config, externalsConfig) {
|
|
37
|
+
const externals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
38
|
+
if (externalsConfig && _.isPlainObject(externalsConfig)) {
|
|
39
|
+
config.externals = Object.assign(externalsConfig, externals);
|
|
40
|
+
} else {
|
|
41
|
+
config.externals = externals;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 创建并注入 commonModulesCode 到 entry
|
|
47
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
48
|
+
* @param {array} cmpTypes 组件类型列表
|
|
49
|
+
* @param {object} [options] 选项
|
|
50
|
+
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
51
|
+
*/
|
|
52
|
+
function injectCommonModulesCode(config, options = {}) {
|
|
53
|
+
const { cmpTypes, defaultExports, excludeModel = false } = options;
|
|
54
|
+
|
|
55
|
+
// 添加默认导出
|
|
56
|
+
if (defaultExports && _.isPlainObject(defaultExports)) {
|
|
57
|
+
if (neoCommonModule.exports && _.isPlainObject(neoCommonModule.exports)) {
|
|
58
|
+
neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
|
|
59
|
+
} else if (neoCommonModule.exports && _.isArray(neoCommonModule.exports)) {
|
|
60
|
+
// 先将数组格式改成对象格式
|
|
61
|
+
neoCommonModule.exports.forEach((item) => {
|
|
62
|
+
if (_.isString(item)) {
|
|
63
|
+
neoCommonModule.exports[item] = item;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
neoCommonModule.exports = Object.assign(neoCommonModule.exports, defaultExports);
|
|
67
|
+
} else {
|
|
68
|
+
neoCommonModule.exports = defaultExports;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, cmpTypes);
|
|
73
|
+
|
|
74
|
+
if (commonModulesFilePath && config.entry) {
|
|
75
|
+
Object.keys(config.entry).forEach((name) => {
|
|
76
|
+
// 如果 excludeModel 为 true,排除 Model 结尾的文件
|
|
77
|
+
if (!excludeModel || !name.endsWith('Model')) {
|
|
78
|
+
config.entry[name] = [commonModulesFilePath].concat(config.entry[name]);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 配置 webpack 插件、externals 和 commonModulesCode(用于 linkDebug、publish2oss、pushCmp)
|
|
86
|
+
* @param {object} config 配置对象(dev 或 build2lib)
|
|
87
|
+
* @param {object} [options] 选项
|
|
88
|
+
* @param {array} [options.cmpTypes] 组件类型列表
|
|
89
|
+
* @param {object} [options.defaultExports] 默认导出
|
|
90
|
+
* @param {boolean} [options.verbose] 是否启用详细日志,默认为 false
|
|
91
|
+
* @param {boolean} [options.excludeModel] 是否排除 Model 结尾的 entry,默认为 false
|
|
92
|
+
*/
|
|
93
|
+
function configureNeoBuild(config, options = {}) {
|
|
94
|
+
const { cmpTypes, defaultExports, verbose = false, excludeModel = false } = options;
|
|
95
|
+
|
|
96
|
+
// 添加自定义 webpack 插件
|
|
97
|
+
addNeoRequirePlugin(curConfig.webpack, { verbose });
|
|
98
|
+
|
|
99
|
+
// 添加内置 Neo 的 externals 配置
|
|
100
|
+
addNeoExternals(config, config.externals);
|
|
101
|
+
|
|
102
|
+
// 创建并注入 commonModulesCode
|
|
103
|
+
injectCommonModulesCode(config, { cmpTypes, defaultExports, excludeModel });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
configureNeoBuild
|
|
108
|
+
};
|
|
@@ -9,19 +9,16 @@ const getEntriesWithAutoRegister = require('./projectUtils/getEntriesWithAutoReg
|
|
|
9
9
|
* @param {string} options.componentsDir 组件目录路径
|
|
10
10
|
* @param {string} options.entryType entry 类型:'widget' | 'linkDebug',默认为 'widget'
|
|
11
11
|
* @param {string} [options.cmpType] 可选的组件类型,如果指定则只生成该组件的 entry
|
|
12
|
-
* @param {boolean} [options.forceGetCmpTypes] 即使 entry 已存在,也强制获取 cmpTypes,默认为 false
|
|
13
|
-
* @returns {object} { entries: object, cmpTypes: array } 如果 configEntry 已存在且 forceGetCmpTypes 为 false,则返回 { entries: configEntry, cmpTypes: [] }
|
|
14
12
|
*/
|
|
15
13
|
function generateEntries({
|
|
16
14
|
configEntry,
|
|
17
15
|
disableAutoRegister,
|
|
18
16
|
componentsDir,
|
|
19
17
|
entryType = 'widget',
|
|
20
|
-
cmpType
|
|
21
|
-
forceGetCmpTypes = false
|
|
18
|
+
cmpType
|
|
22
19
|
}) {
|
|
23
20
|
// 如果已配置 entry 且不需要强制获取 cmpTypes,直接返回
|
|
24
|
-
if (configEntry && Object.keys(configEntry).length > 0
|
|
21
|
+
if (configEntry && Object.keys(configEntry).length > 0) {
|
|
25
22
|
return {
|
|
26
23
|
entries: configEntry,
|
|
27
24
|
cmpTypes: []
|
|
@@ -48,16 +45,8 @@ function generateEntries({
|
|
|
48
45
|
|
|
49
46
|
const cmpTypes = entriesResult.cmpTypes || [];
|
|
50
47
|
|
|
51
|
-
// 如果 entry 已存在但需要获取 cmpTypes,使用已存在的 entry
|
|
52
|
-
if (configEntry && Object.keys(configEntry).length > 0 && forceGetCmpTypes) {
|
|
53
|
-
entries = configEntry;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
48
|
// 验证 entries 是否有效(仅在需要生成新 entry 时验证)
|
|
57
|
-
if (
|
|
58
|
-
(!configEntry || Object.keys(configEntry).length === 0) &&
|
|
59
|
-
(!entries || Object.keys(entries).length === 0)
|
|
60
|
-
) {
|
|
49
|
+
if (!entries || Object.keys(entries).length === 0) {
|
|
61
50
|
const defaultComponentsDir = componentsDir || './src/components';
|
|
62
51
|
throw new Error(
|
|
63
52
|
`未识别到自定义组件,请检查 ${defaultComponentsDir} 目录下是否存在自定义组件。`
|
|
@@ -66,7 +55,8 @@ function generateEntries({
|
|
|
66
55
|
|
|
67
56
|
return {
|
|
68
57
|
entries: entries || configEntry || {},
|
|
69
|
-
cmpTypes
|
|
58
|
+
cmpTypes,
|
|
59
|
+
defaultExports: entriesResult.defaultExports || {}
|
|
70
60
|
};
|
|
71
61
|
}
|
|
72
62
|
|
|
@@ -14,6 +14,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
14
14
|
index: []
|
|
15
15
|
};
|
|
16
16
|
const cmpTypes = []; // 用于记录组件名称
|
|
17
|
+
const defaultExports = {}; // 用于记录默认导出
|
|
17
18
|
const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
|
|
18
19
|
if (!fs.existsSync(componentsBaseDir)) {
|
|
19
20
|
console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
|
|
@@ -47,7 +48,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
47
48
|
cmpTypes.push(curCmpName);
|
|
48
49
|
|
|
49
50
|
fs.readdirSync(curCmpPath)
|
|
50
|
-
.filter((file) => file.match(/[register|model]\.
|
|
51
|
+
.filter((file) => file.match(/[index|register|model]\.(tsx?|jsx?|vue)$/))
|
|
51
52
|
.map((file) => path.join(defaultComponentsDir, curCmpName, file))
|
|
52
53
|
.forEach((filePath) => {
|
|
53
54
|
const curPath = `./${filePath}`;
|
|
@@ -55,6 +56,9 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
55
56
|
widgetEntries[cmpNameKey] = curPath;
|
|
56
57
|
} else if (filePath.match(/model\.[tj]sx?$/)) {
|
|
57
58
|
widgetEntries[`${cmpNameKey}Model`] = curPath;
|
|
59
|
+
} else if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
|
|
60
|
+
// 组件内容文件
|
|
61
|
+
defaultExports[cmpNameKey] = path.resolve(filePath); // 记录默认导出
|
|
58
62
|
}
|
|
59
63
|
linkDebugEntries.index.push(curPath);
|
|
60
64
|
});
|
|
@@ -70,6 +74,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
70
74
|
return {
|
|
71
75
|
widgetEntries,
|
|
72
76
|
linkDebugEntries,
|
|
73
|
-
cmpTypes
|
|
77
|
+
cmpTypes,
|
|
78
|
+
defaultExports
|
|
74
79
|
};
|
|
75
80
|
};
|
|
@@ -15,6 +15,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
15
15
|
index: []
|
|
16
16
|
};
|
|
17
17
|
const cmpTypes = []; // 用于记录组件名称
|
|
18
|
+
const defaultExports = {}; // 用于记录默认导出
|
|
18
19
|
const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
|
|
19
20
|
if (!fs.existsSync(componentsBaseDir)) {
|
|
20
21
|
console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
|
|
@@ -41,14 +42,12 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
41
42
|
|
|
42
43
|
// 遍历所有目录
|
|
43
44
|
widgetDirs.forEach((dir) => {
|
|
44
|
-
|
|
45
|
+
// 当前自定义组件目录
|
|
46
|
+
const widgetPath = path.join(componentsBaseDir, dir);
|
|
45
47
|
// 获取文件状态
|
|
46
48
|
const stat = fs.statSync(filePath);
|
|
47
49
|
// 如果文件是目录,则递归处理子目录
|
|
48
50
|
if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
|
|
49
|
-
// 当前自定义组件目录
|
|
50
|
-
const widgetPath = path.join(componentsBaseDir, dir);
|
|
51
|
-
|
|
52
51
|
// 当前自定义组件名称
|
|
53
52
|
const curCmpName = dir; // _.camelCase(dir);
|
|
54
53
|
const cmpNameKey = _.camelCase(curCmpName);
|
|
@@ -67,6 +66,9 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
67
66
|
.map((file) => path.join(defaultComponentsDir, curCmpName, file))
|
|
68
67
|
.forEach((filePath) => {
|
|
69
68
|
if (filePath.match(/index\.(tsx?|jsx?|vue)$/)) {
|
|
69
|
+
// 记录默认导出
|
|
70
|
+
defaultExports[cmpNameKey] = path.resolve(filePath);
|
|
71
|
+
|
|
70
72
|
// 自动创建对应的注册文件
|
|
71
73
|
const registerContent = getCmpRegisterCode(componentsBaseDir, curCmpName);
|
|
72
74
|
const registerDir = `${cmpTempDir}/register.js`;
|
|
@@ -100,6 +102,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
100
102
|
return {
|
|
101
103
|
widgetEntries,
|
|
102
104
|
linkDebugEntries,
|
|
103
|
-
cmpTypes
|
|
105
|
+
cmpTypes,
|
|
106
|
+
defaultExports
|
|
104
107
|
};
|
|
105
108
|
};
|
package/test/demo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp
|
|
2
|
-
const getEntries = require('../src/projectUtils/getEntries');
|
|
3
|
-
const getEntriesWithAutoRegister = require('../src/projectUtils/getEntriesWithAutoRegister');
|
|
1
|
+
const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp } = require('../src/module/main');
|
|
2
|
+
const getEntries = require('../src/utils/projectUtils/getEntries');
|
|
3
|
+
const getEntriesWithAutoRegister = require('../src/utils/projectUtils/getEntriesWithAutoRegister');
|
|
4
4
|
// inspect('dev');
|
|
5
5
|
// neoInitByCopy('react-ts', 'test123');
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { execSync } = require('child_process');
|
|
2
2
|
|
|
3
3
|
// 所有需要废弃的版本(1.6.2 之前的所有版本)
|
|
4
|
-
const versionsToDeprecate = ["1.7.
|
|
4
|
+
const versionsToDeprecate = ["1.7.10", "1.7.11"];
|
|
5
5
|
|
|
6
6
|
const packageName = 'neo-cmp-cli';
|
|
7
7
|
const deprecateMessage = '此版本为开发中版本(存在 bug),请升级到最新版本。';
|