neo-cmp-cli 1.3.10 → 1.5.0-beta.10
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/README.md +52 -15
- package/package.json +4 -1
- package/src/cmpUtils/createCmpByTemplate.js +50 -0
- package/src/cmpUtils/createCommonModulesCode.js +15 -15
- package/src/cmpUtils/{getCmpModelRegister.js → getCmpModelRegisterCode.js} +2 -2
- package/src/cmpUtils/{getCmpPreview.js → getCmpPreviewCode.js} +2 -2
- package/src/cmpUtils/{getCmpRegister.js → getCmpRegisterCode.js} +2 -2
- package/src/cmpUtils/getCmpTypeByDir.js +41 -0
- package/src/cmpUtils/hasCmpTypeByDir.js +11 -0
- package/src/{module → cmpUtils}/previewCmp.js +2 -2
- package/src/cmpUtils/pushCmp.js +232 -0
- package/src/config/default.config.js +14 -2
- package/src/module/index.js +174 -11
- package/src/module/main.js +96 -3
- package/src/module/neoInit.js +3 -0
- package/src/module/neoInitByCopy.js +3 -0
- package/src/neo/NeoUMDContent.js +29 -0
- package/src/neo/neoRequire.js +7 -7
- package/src/neo/neoService.js +525 -0
- package/src/neo/wrapperContent.js +2 -1
- package/src/oss/publish2oss.js +96 -96
- package/src/plugins/AddNeoRequirePlugin.js +5 -2
- package/src/projectUtils/createCmpProjectByTemplate.js +49 -0
- package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
- package/src/template/antd-custom-cmp-template/README.md +2 -2
- package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
- package/src/template/antd-custom-cmp-template/package.json +2 -2
- package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
- package/src/template/echarts-custom-cmp-template/README.md +2 -2
- package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
- package/src/template/echarts-custom-cmp-template/package.json +2 -2
- package/src/template/empty-cmp/index.tsx +51 -0
- package/src/template/empty-cmp/model.ts +77 -0
- package/src/template/empty-cmp/style.scss +72 -0
- package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
- package/src/template/empty-custom-cmp-template/README.md +45 -0
- package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
- package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
- package/src/template/empty-custom-cmp-template/package.json +57 -0
- package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
- package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
- package/src/template/empty-custom-cmp-template/public/template.html +13 -0
- package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
- package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
- package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
- package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
- package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
- package/src/template/neo-custom-cmp-template/README.md +5 -5
- package/src/template/neo-custom-cmp-template/neo.config.js +18 -29
- package/src/template/neo-custom-cmp-template/package.json +3 -4
- package/src/template/react-custom-cmp-template/.prettierrc.js +1 -1
- package/src/template/react-custom-cmp-template/README.md +2 -2
- package/src/template/react-custom-cmp-template/neo.config.js +20 -15
- package/src/template/react-custom-cmp-template/package.json +2 -2
- package/src/template/react-ts-custom-cmp-template/README.md +2 -2
- package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
- package/src/template/react-ts-custom-cmp-template/package.json +2 -2
- package/src/template/vue2-custom-cmp-template/README.md +2 -2
- package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
- package/src/template/vue2-custom-cmp-template/package.json +2 -2
- package/src/utils/autoEntryRootDir.js +42 -0
- package/src/utils/replaceInFilesByMap.js +54 -0
- package/test/demo.js +2 -2
- /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
- /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
package/src/module/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const inspect = require('./inspect.js'); // 输出当前项目配置文件
|
|
|
9
9
|
const neoConfigInit = require('../utils/neoConfigInit.js');
|
|
10
10
|
const { validateProjectName } = require('../utils/projectNameValidator.js');
|
|
11
11
|
const mainAction = require('./main.js'); // 入口文件
|
|
12
|
+
const getCmpTypeByDir = require('../cmpUtils/getCmpTypeByDir.js');
|
|
12
13
|
|
|
13
14
|
// neo 的 package 文件
|
|
14
15
|
const neoPackage = require('../../package.json');
|
|
@@ -81,11 +82,14 @@ yargs
|
|
|
81
82
|
value: 'neo',
|
|
82
83
|
short: 'neo'
|
|
83
84
|
},
|
|
85
|
+
/*
|
|
86
|
+
// 暂不提供 react js 模板(react js 模板已废弃)
|
|
84
87
|
{
|
|
85
88
|
name: 'react 自定义组件',
|
|
86
89
|
value: 'react',
|
|
87
90
|
short: 'react'
|
|
88
91
|
},
|
|
92
|
+
*/
|
|
89
93
|
{
|
|
90
94
|
name: 'vue2 自定义组件',
|
|
91
95
|
value: 'vue2',
|
|
@@ -148,6 +152,81 @@ yargs
|
|
|
148
152
|
neoConfigInit('neo.config.js');
|
|
149
153
|
}
|
|
150
154
|
)
|
|
155
|
+
.command(
|
|
156
|
+
'createProject [options]',
|
|
157
|
+
'创建自定义组件项目(含工程代码)',
|
|
158
|
+
(yargs) => {
|
|
159
|
+
yargs
|
|
160
|
+
.reset()
|
|
161
|
+
.usage(titleTip('Usage') + ': $0 preview [options]')
|
|
162
|
+
.option('name', {
|
|
163
|
+
alias: 'n',
|
|
164
|
+
describe: '自定义组件项目名称'
|
|
165
|
+
})
|
|
166
|
+
.alias('h', 'help');
|
|
167
|
+
},
|
|
168
|
+
(argv) => {
|
|
169
|
+
if (argv.name) {
|
|
170
|
+
mainAction.createCmpProjectByTemplate(argv.name);
|
|
171
|
+
} else {
|
|
172
|
+
questions.push({
|
|
173
|
+
name: 'name',
|
|
174
|
+
type: 'input',
|
|
175
|
+
message: '请设置自定义组件项目名称:',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
inquirer.prompt(questions).then((ans) => {
|
|
179
|
+
// 验证项目名称是否合法
|
|
180
|
+
const { isValid, errors } = validateProjectName(ans.name);
|
|
181
|
+
if (!isValid) {
|
|
182
|
+
console.error(errors.join('\n'));
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!ans.name) {
|
|
187
|
+
console.error(errors.join('\n'));
|
|
188
|
+
process.exit(1);
|
|
189
|
+
} else {
|
|
190
|
+
mainAction.createCmpProjectByTemplate(argv.name);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
.command(
|
|
197
|
+
'createCmp [options]',
|
|
198
|
+
'创建自定义组件',
|
|
199
|
+
(yargs) => {
|
|
200
|
+
yargs
|
|
201
|
+
.reset()
|
|
202
|
+
.usage(titleTip('Usage') + ': $0 preview [options]')
|
|
203
|
+
.option('name', {
|
|
204
|
+
alias: 'n',
|
|
205
|
+
describe: '自定义组件名称'
|
|
206
|
+
})
|
|
207
|
+
.alias('h', 'help');
|
|
208
|
+
},
|
|
209
|
+
(argv) => {
|
|
210
|
+
if (argv.name) {
|
|
211
|
+
mainAction.createCmpByTemplate(argv.name);
|
|
212
|
+
} else {
|
|
213
|
+
questions.push({
|
|
214
|
+
name: 'name',
|
|
215
|
+
type: 'input',
|
|
216
|
+
message: '请设置自定义组件名称:',
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
inquirer.prompt(questions).then((ans) => {
|
|
220
|
+
if (!ans.name) {
|
|
221
|
+
console.error('自定义组件名称不能为空。');
|
|
222
|
+
process.exit(1);
|
|
223
|
+
} else {
|
|
224
|
+
mainAction.createCmpByTemplate(argv.name);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
)
|
|
151
230
|
.command(
|
|
152
231
|
'preview [options]',
|
|
153
232
|
'预览指定自定义组件(仅预览组件本身内容)',
|
|
@@ -155,25 +234,38 @@ yargs
|
|
|
155
234
|
yargs
|
|
156
235
|
.reset()
|
|
157
236
|
.usage(titleTip('Usage') + ': $0 preview [options]')
|
|
158
|
-
.option('
|
|
159
|
-
alias: '
|
|
160
|
-
describe: '
|
|
237
|
+
.option('name', {
|
|
238
|
+
alias: 'n',
|
|
239
|
+
describe: '自定义组件名称'
|
|
161
240
|
})
|
|
162
241
|
.alias('h', 'help');
|
|
163
242
|
},
|
|
164
243
|
(argv) => {
|
|
165
|
-
if (argv.
|
|
166
|
-
mainAction.previewCmp(argv.
|
|
244
|
+
if (argv.name) {
|
|
245
|
+
mainAction.previewCmp(argv.name);
|
|
167
246
|
} else {
|
|
247
|
+
const cmpTypes = getCmpTypeByDir();
|
|
248
|
+
if (cmpTypes.length === 0) {
|
|
249
|
+
console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
253
|
+
name: cmpType,
|
|
254
|
+
value: cmpType
|
|
255
|
+
}));
|
|
168
256
|
const questions = [
|
|
169
257
|
{
|
|
170
258
|
name: 'cmpType',
|
|
171
|
-
type: '
|
|
172
|
-
message: '
|
|
173
|
-
|
|
259
|
+
type: 'list',
|
|
260
|
+
message: '请选择要预览的自定义组件:',
|
|
261
|
+
choices: cmpTypeChoices
|
|
174
262
|
}
|
|
175
263
|
];
|
|
176
264
|
inquirer.prompt(questions).then((ans) => {
|
|
265
|
+
if (!ans.cmpType) {
|
|
266
|
+
console.error('未选择要预览的自定义组件。');
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
177
269
|
mainAction.previewCmp(ans.cmpType);
|
|
178
270
|
});
|
|
179
271
|
}
|
|
@@ -238,14 +330,85 @@ yargs
|
|
|
238
330
|
yargs
|
|
239
331
|
.reset()
|
|
240
332
|
.usage(titleTip('Usage') + ': $0 publish2oss [options]')
|
|
241
|
-
.option('
|
|
242
|
-
alias: '
|
|
333
|
+
.option('name', {
|
|
334
|
+
alias: 'n',
|
|
243
335
|
describe: '自定义组件名称'
|
|
244
336
|
})
|
|
245
337
|
.alias('h', 'help');
|
|
246
338
|
},
|
|
247
339
|
(argv) => {
|
|
248
|
-
|
|
340
|
+
if (argv.name) {
|
|
341
|
+
mainAction.publish2oss(argv.name); // 构建并发布脚本到oss
|
|
342
|
+
} else {
|
|
343
|
+
const cmpTypes = getCmpTypeByDir();
|
|
344
|
+
if (cmpTypes.length === 0) {
|
|
345
|
+
console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
349
|
+
name: cmpType,
|
|
350
|
+
value: cmpType
|
|
351
|
+
}));
|
|
352
|
+
const questions = [
|
|
353
|
+
{
|
|
354
|
+
name: 'cmpType',
|
|
355
|
+
type: 'list',
|
|
356
|
+
message: '请选择要发布的自定义组件:',
|
|
357
|
+
choices: cmpTypeChoices
|
|
358
|
+
}
|
|
359
|
+
];
|
|
360
|
+
inquirer.prompt(questions).then((ans) => {
|
|
361
|
+
if (!ans.cmpType) {
|
|
362
|
+
console.error('未选择要发布的自定义组件。');
|
|
363
|
+
process.exit(1);
|
|
364
|
+
}
|
|
365
|
+
mainAction.publish2oss(ans.cmpType);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
.command(
|
|
371
|
+
'pushCmp [options]',
|
|
372
|
+
'发布组件到 NeoCRM 平台',
|
|
373
|
+
(yargs) => {
|
|
374
|
+
yargs
|
|
375
|
+
.reset()
|
|
376
|
+
.usage(titleTip('Usage') + ': $0 pushCmp [options]')
|
|
377
|
+
.option('name', {
|
|
378
|
+
alias: 'n',
|
|
379
|
+
describe: '自定义组件名称'
|
|
380
|
+
})
|
|
381
|
+
.alias('h', 'help');
|
|
382
|
+
},
|
|
383
|
+
(argv) => {
|
|
384
|
+
if (argv.name) {
|
|
385
|
+
mainAction.pushCmp(argv.name); // 构建并发布组件到 NeoCRM
|
|
386
|
+
} else {
|
|
387
|
+
const cmpTypes = getCmpTypeByDir();
|
|
388
|
+
if (cmpTypes.length === 0) {
|
|
389
|
+
console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
390
|
+
process.exit(1);
|
|
391
|
+
}
|
|
392
|
+
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
393
|
+
name: cmpType,
|
|
394
|
+
value: cmpType
|
|
395
|
+
}));
|
|
396
|
+
const questions = [
|
|
397
|
+
{
|
|
398
|
+
name: 'cmpType',
|
|
399
|
+
type: 'list',
|
|
400
|
+
message: '请选择要发布的自定义组件:',
|
|
401
|
+
choices: cmpTypeChoices
|
|
402
|
+
}
|
|
403
|
+
];
|
|
404
|
+
inquirer.prompt(questions).then((ans) => {
|
|
405
|
+
if (!ans.cmpType) {
|
|
406
|
+
console.error('未选择要发布的自定义组件。');
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
409
|
+
mainAction.pushCmp(ans.cmpType);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
249
412
|
}
|
|
250
413
|
)
|
|
251
414
|
.command(
|
package/src/module/main.js
CHANGED
|
@@ -7,13 +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
|
|
11
|
-
const
|
|
12
|
-
const
|
|
10
|
+
const pushCmp = require('../cmpUtils/pushCmp');
|
|
11
|
+
const previewCmp = require('../cmpUtils/previewCmp');
|
|
12
|
+
const getEntries = require('../projectUtils/getEntries');
|
|
13
|
+
const getEntriesWithAutoRegister = require('../projectUtils/getEntriesWithAutoRegister');
|
|
13
14
|
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
14
15
|
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
15
16
|
// const { MFPlugins } = require('../neo/webpack.mf');
|
|
16
17
|
const createCommonModulesCode = require('../cmpUtils/createCommonModulesCode');
|
|
18
|
+
const createCmpByTemplate = require('../cmpUtils/createCmpByTemplate');
|
|
19
|
+
const createCmpProjectByTemplate = require('../projectUtils/createCmpProjectByTemplate');
|
|
17
20
|
|
|
18
21
|
const getValue = (originValue, defaultValue) => {
|
|
19
22
|
return originValue !== undefined ? originValue : defaultValue;
|
|
@@ -28,6 +31,8 @@ module.exports = {
|
|
|
28
31
|
neoInitByCopy,
|
|
29
32
|
inspect,
|
|
30
33
|
neoConfigInit,
|
|
34
|
+
createCmpProjectByTemplate,
|
|
35
|
+
createCmpByTemplate,
|
|
31
36
|
dev: () => {
|
|
32
37
|
if (!curConfig.dev) {
|
|
33
38
|
console.error('未找到 dev 相关配置。');
|
|
@@ -270,5 +275,93 @@ module.exports = {
|
|
|
270
275
|
);
|
|
271
276
|
});
|
|
272
277
|
},
|
|
278
|
+
// 发布组件到 NeoCRM 平台
|
|
279
|
+
pushCmp: (cmpType) => {
|
|
280
|
+
// 将 pushCmp 相关配置设置给 build2lib
|
|
281
|
+
const pushCmpConfig = curConfig.pushCmp;
|
|
282
|
+
curConfig.build2lib = Object.assign(curConfig.build2lib, pushCmpConfig);
|
|
283
|
+
|
|
284
|
+
const curEntry = curConfig.build2lib.entry;
|
|
285
|
+
let curCmpTypes = [];
|
|
286
|
+
|
|
287
|
+
if (!curEntry || Object.keys(curEntry).length === 0) {
|
|
288
|
+
// 如果未配置 entry,则自动生成 entry
|
|
289
|
+
let entries = {};
|
|
290
|
+
if (curConfig.build2lib.disableAutoRegister) {
|
|
291
|
+
// disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
|
|
292
|
+
const { widgetEntries, cmpTypes } = getEntries(curConfig.componentsDir, cmpType);
|
|
293
|
+
entries = widgetEntries;
|
|
294
|
+
curCmpTypes = cmpTypes;
|
|
295
|
+
} else {
|
|
296
|
+
// 自动生成入口文件(并自动创建对应的注册文件)
|
|
297
|
+
const { widgetEntries, cmpTypes } = getEntriesWithAutoRegister(
|
|
298
|
+
curConfig.componentsDir,
|
|
299
|
+
cmpType
|
|
300
|
+
);
|
|
301
|
+
entries = widgetEntries;
|
|
302
|
+
curCmpTypes = cmpTypes;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// 注入 webpack/entry
|
|
306
|
+
if (entries && Object.keys(entries).length > 0) {
|
|
307
|
+
curConfig.build2lib.entry = entries;
|
|
308
|
+
console.info('已自动生成 entry 入口配置:', entries);
|
|
309
|
+
} else {
|
|
310
|
+
console.error(
|
|
311
|
+
`未识别到自定义组件,请检查 ${
|
|
312
|
+
curConfig.componentsDir || './src/components'
|
|
313
|
+
} 目录下是否存在自定义组件。`
|
|
314
|
+
);
|
|
315
|
+
process.exit(1);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/*
|
|
320
|
+
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
321
|
+
// 添加模块联邦插件
|
|
322
|
+
if (curConfig.pushCmp.enableMF) {
|
|
323
|
+
curConfig.webpack.plugins.push(...MFPlugins);
|
|
324
|
+
}
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
// 添加自定义 webpack 插件: 用于实现和 Neo 平台共享依赖
|
|
328
|
+
if (
|
|
329
|
+
curConfig.webpack &&
|
|
330
|
+
curConfig.webpack.plugins &&
|
|
331
|
+
Array.isArray(curConfig.webpack.plugins)
|
|
332
|
+
) {
|
|
333
|
+
curConfig.webpack.plugins.push(new AddNeoRequirePlugin());
|
|
334
|
+
} else {
|
|
335
|
+
curConfig.webpack.plugins = [new AddNeoRequirePlugin()];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 添加 内置 Neo 的 externals 配置
|
|
339
|
+
const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
|
|
340
|
+
if (curConfig.build2lib.externals && _.isPlainObject(curConfig.build2lib.externals)) {
|
|
341
|
+
curConfig.build2lib.externals = Object.assign(curConfig.build2lib.externals, neoExternals);
|
|
342
|
+
} else {
|
|
343
|
+
curConfig.build2lib.externals = neoExternals;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 写入自定义组件的共享模块和远程模块相关信息
|
|
347
|
+
const commonModulesFilePath = createCommonModulesCode(neoCommonModule, curCmpTypes);
|
|
348
|
+
|
|
349
|
+
// 所有入口文件添加 commonModulesFile
|
|
350
|
+
if (commonModulesFilePath && curConfig.build2lib.entry) {
|
|
351
|
+
Object.keys(curConfig.build2lib.entry).forEach((name) => {
|
|
352
|
+
// 判断不是以Model结尾的文件
|
|
353
|
+
if (!name.endsWith('Model')) {
|
|
354
|
+
curConfig.build2lib.entry[name] = [commonModulesFilePath].concat(
|
|
355
|
+
curConfig.build2lib.entry[name]
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
akfun.build('lib', curConfig, consoleTag, () => {
|
|
362
|
+
// 构建完成后,执行 pushCmp
|
|
363
|
+
pushCmp(pushCmpConfig, cmpType);
|
|
364
|
+
});
|
|
365
|
+
},
|
|
273
366
|
build2esm: (fileName) => akfun.build2esm(fileName, curConfig, consoleTag) // 构建esm输出模块
|
|
274
367
|
};
|
package/src/module/neoInit.js
CHANGED
|
@@ -2,6 +2,7 @@ const { gitClone } = require('akfun');
|
|
|
2
2
|
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
3
3
|
const { replaceInPackage } = require('../utils/replaceInPackage');
|
|
4
4
|
const { resetPackageVersion } = require('../utils/resetPackageVersion');
|
|
5
|
+
const autoEntryRootDir = require('../utils/autoEntryRootDir');
|
|
5
6
|
|
|
6
7
|
const templateList = {
|
|
7
8
|
react: {
|
|
@@ -43,6 +44,8 @@ const neoInit = function (type, projectName) {
|
|
|
43
44
|
replaceInPackage(finalProjectPath, 'wibetter', 'xxx');
|
|
44
45
|
replaceInPackage(finalProjectPath, 'neo自定义组件模板', 'neo自定义组件');
|
|
45
46
|
resetPackageVersion(finalProjectPath);
|
|
47
|
+
// 自动切换到项目根目录
|
|
48
|
+
autoEntryRootDir(finalProjectPath);
|
|
46
49
|
},
|
|
47
50
|
consoleTag
|
|
48
51
|
);
|
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
|
3
3
|
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
4
4
|
const { replaceInPackage } = require('../utils/replaceInPackage');
|
|
5
5
|
const { resetPackageVersion } = require('../utils/resetPackageVersion');
|
|
6
|
+
const autoEntryRootDir = require('../utils/autoEntryRootDir');
|
|
6
7
|
|
|
7
8
|
const templateList = {
|
|
8
9
|
react: {
|
|
@@ -50,6 +51,8 @@ const neoInitByCopy = function (type, projectName) {
|
|
|
50
51
|
resetPackageVersion(finalProjectPath);
|
|
51
52
|
|
|
52
53
|
console.log(`${consoleTag}已创建自定义组件(${finalProjectName})!`);
|
|
54
|
+
// 自动切换到项目根目录
|
|
55
|
+
autoEntryRootDir(finalProjectPath);
|
|
53
56
|
})
|
|
54
57
|
.catch((err) => console.error(`${consoleTag}自定义组件模板下载失败:`, err));
|
|
55
58
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置 UMD 模块,用于在 Node cli 端加载自定义组件模型
|
|
3
|
+
* 特别说明:这个文件内容会通过 AddNeoRequirePlugin 插入的构建代码中。
|
|
4
|
+
*/
|
|
5
|
+
(function (root, factory) {
|
|
6
|
+
// AMD 环境检测
|
|
7
|
+
if (typeof define === 'function' && define.amd) {
|
|
8
|
+
define([], factory);
|
|
9
|
+
}
|
|
10
|
+
// CommonJS 环境检测
|
|
11
|
+
else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
|
|
12
|
+
module.exports = factory();
|
|
13
|
+
}
|
|
14
|
+
// 浏览器全局变量
|
|
15
|
+
else {
|
|
16
|
+
root.NeoCustomCmpModel = factory();
|
|
17
|
+
}
|
|
18
|
+
}(typeof self !== 'undefined' ? self : this, function () {
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const getCustomModels = (cmpType) => {
|
|
22
|
+
// 自定义组件模型列表
|
|
23
|
+
const NEOEditorCustomModels = window.NEOEditorCustomModels || {};
|
|
24
|
+
return NEOEditorCustomModels[cmpType] || {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 导出模块
|
|
28
|
+
return getCustomModels;
|
|
29
|
+
}));
|
package/src/neo/neoRequire.js
CHANGED
|
@@ -67,16 +67,16 @@ const addNeoCommonModules = (modules) => {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
//
|
|
71
|
-
const
|
|
70
|
+
// 用于添加自定义组件的远程依赖组件
|
|
71
|
+
const addNeoRemoteDeps = (remoteDeps) => {
|
|
72
72
|
if (!window.__NeoCommonModules) {
|
|
73
73
|
window.__NeoCommonModules = {}
|
|
74
74
|
}
|
|
75
|
-
if (!window.__NeoCommonModules.
|
|
76
|
-
window.__NeoCommonModules.
|
|
75
|
+
if (!window.__NeoCommonModules.__neoRemoteDeps) {
|
|
76
|
+
window.__NeoCommonModules.__neoRemoteDeps = {}
|
|
77
77
|
}
|
|
78
|
-
if (_.isPlainObject(
|
|
79
|
-
window.__NeoCommonModules.
|
|
78
|
+
if (_.isPlainObject(remoteDeps)) {
|
|
79
|
+
window.__NeoCommonModules.__neoRemoteDeps = Object.assign(window.__NeoCommonModules.__neoRemoteDeps, remoteDeps);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -110,6 +110,6 @@ const neoRequire = (moduleName) => {
|
|
|
110
110
|
module.exports = {
|
|
111
111
|
initNeoRequire,
|
|
112
112
|
addNeoCommonModules,
|
|
113
|
-
|
|
113
|
+
addNeoRemoteDeps,
|
|
114
114
|
getExternalsByNeoCommonModules
|
|
115
115
|
};
|