neo-cmp-cli 1.5.0-beta.3 → 1.5.0-beta.6
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 +51 -14
- package/package.json +1 -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/publishCmp.js +18 -16
- package/src/config/default.config.js +1 -1
- package/src/module/index.js +144 -21
- package/src/module/main.js +15 -11
- package/src/module/neoInit.js +3 -0
- package/src/module/neoInitByCopy.js +3 -0
- package/src/neo/neoRequire.js +7 -7
- package/src/neo/neoService.js +32 -31
- package/src/oss/publish2oss.js +1 -1
- package/src/plugins/AddNeoRequirePlugin.js +5 -3
- 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 +2 -2
- package/src/template/neo-custom-cmp-template/neo.config.js +4 -26
- package/src/template/neo-custom-cmp-template/package.json +3 -5
- package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +0 -2
- 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');
|
|
@@ -151,6 +152,81 @@ yargs
|
|
|
151
152
|
neoConfigInit('neo.config.js');
|
|
152
153
|
}
|
|
153
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
|
+
)
|
|
154
230
|
.command(
|
|
155
231
|
'preview [options]',
|
|
156
232
|
'预览指定自定义组件(仅预览组件本身内容)',
|
|
@@ -158,26 +234,36 @@ yargs
|
|
|
158
234
|
yargs
|
|
159
235
|
.reset()
|
|
160
236
|
.usage(titleTip('Usage') + ': $0 preview [options]')
|
|
161
|
-
.option('
|
|
162
|
-
alias: '
|
|
163
|
-
describe: '
|
|
237
|
+
.option('name', {
|
|
238
|
+
alias: 'n',
|
|
239
|
+
describe: '自定义组件名称'
|
|
164
240
|
})
|
|
165
241
|
.alias('h', 'help');
|
|
166
242
|
},
|
|
167
243
|
(argv) => {
|
|
168
|
-
if (argv.
|
|
169
|
-
mainAction.previewCmp(argv.
|
|
244
|
+
if (argv.name) {
|
|
245
|
+
mainAction.previewCmp(argv.name);
|
|
170
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
|
+
}));
|
|
171
256
|
const questions = [
|
|
172
257
|
{
|
|
173
258
|
name: 'cmpType',
|
|
174
|
-
type: '
|
|
175
|
-
message: '
|
|
259
|
+
type: 'list',
|
|
260
|
+
message: '请选择要预览的自定义组件:',
|
|
261
|
+
choices: cmpTypeChoices
|
|
176
262
|
}
|
|
177
263
|
];
|
|
178
264
|
inquirer.prompt(questions).then((ans) => {
|
|
179
265
|
if (!ans.cmpType) {
|
|
180
|
-
console.error('
|
|
266
|
+
console.error('未选择要预览的自定义组件。');
|
|
181
267
|
process.exit(1);
|
|
182
268
|
}
|
|
183
269
|
mainAction.previewCmp(ans.cmpType);
|
|
@@ -244,46 +330,83 @@ yargs
|
|
|
244
330
|
yargs
|
|
245
331
|
.reset()
|
|
246
332
|
.usage(titleTip('Usage') + ': $0 publish2oss [options]')
|
|
247
|
-
.option('
|
|
248
|
-
alias: '
|
|
333
|
+
.option('name', {
|
|
334
|
+
alias: 'n',
|
|
249
335
|
describe: '自定义组件名称'
|
|
250
336
|
})
|
|
251
337
|
.alias('h', 'help');
|
|
252
338
|
},
|
|
253
339
|
(argv) => {
|
|
254
|
-
|
|
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
|
+
}
|
|
255
368
|
}
|
|
256
369
|
)
|
|
257
370
|
.command(
|
|
258
|
-
'
|
|
371
|
+
'pushCmp [options]',
|
|
259
372
|
'发布组件到 NeoCRM 平台',
|
|
260
373
|
(yargs) => {
|
|
261
374
|
yargs
|
|
262
375
|
.reset()
|
|
263
|
-
.usage(titleTip('Usage') + ': $0
|
|
264
|
-
.option('
|
|
265
|
-
alias: '
|
|
376
|
+
.usage(titleTip('Usage') + ': $0 pushCmp [options]')
|
|
377
|
+
.option('name', {
|
|
378
|
+
alias: 'n',
|
|
266
379
|
describe: '自定义组件名称'
|
|
267
380
|
})
|
|
268
381
|
.alias('h', 'help');
|
|
269
382
|
},
|
|
270
383
|
(argv) => {
|
|
271
|
-
if (argv.
|
|
272
|
-
mainAction.
|
|
384
|
+
if (argv.name) {
|
|
385
|
+
mainAction.pushCmp(argv.name); // 构建并发布组件到 NeoCRM
|
|
273
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
|
+
}));
|
|
274
396
|
const questions = [
|
|
275
397
|
{
|
|
276
398
|
name: 'cmpType',
|
|
277
|
-
type: '
|
|
278
|
-
message: '
|
|
399
|
+
type: 'list',
|
|
400
|
+
message: '请选择要发布的自定义组件:',
|
|
401
|
+
choices: cmpTypeChoices
|
|
279
402
|
}
|
|
280
403
|
];
|
|
281
404
|
inquirer.prompt(questions).then((ans) => {
|
|
282
405
|
if (!ans.cmpType) {
|
|
283
|
-
console.error('
|
|
406
|
+
console.error('未选择要发布的自定义组件。');
|
|
284
407
|
process.exit(1);
|
|
285
408
|
}
|
|
286
|
-
mainAction.
|
|
409
|
+
mainAction.pushCmp(ans.cmpType);
|
|
287
410
|
});
|
|
288
411
|
}
|
|
289
412
|
}
|
package/src/module/main.js
CHANGED
|
@@ -7,14 +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
|
|
13
|
-
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');
|
|
14
14
|
const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
|
|
15
15
|
const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
|
|
16
16
|
// const { MFPlugins } = require('../neo/webpack.mf');
|
|
17
17
|
const createCommonModulesCode = require('../cmpUtils/createCommonModulesCode');
|
|
18
|
+
const createCmpProjectByTemplate = require('../projectUtils/createCmpProjectByTemplate');
|
|
19
|
+
const createCmpByTemplate = require('../cmpUtils/createCmpByTemplate');
|
|
18
20
|
|
|
19
21
|
const getValue = (originValue, defaultValue) => {
|
|
20
22
|
return originValue !== undefined ? originValue : defaultValue;
|
|
@@ -29,6 +31,8 @@ module.exports = {
|
|
|
29
31
|
neoInitByCopy,
|
|
30
32
|
inspect,
|
|
31
33
|
neoConfigInit,
|
|
34
|
+
createCmpProjectByTemplate,
|
|
35
|
+
createCmpByTemplate,
|
|
32
36
|
dev: () => {
|
|
33
37
|
if (!curConfig.dev) {
|
|
34
38
|
console.error('未找到 dev 相关配置。');
|
|
@@ -272,10 +276,10 @@ module.exports = {
|
|
|
272
276
|
});
|
|
273
277
|
},
|
|
274
278
|
// 发布组件到 NeoCRM 平台
|
|
275
|
-
|
|
276
|
-
// 将
|
|
277
|
-
const
|
|
278
|
-
curConfig.build2lib = Object.assign(curConfig.build2lib,
|
|
279
|
+
pushCmp: (cmpType) => {
|
|
280
|
+
// 将 pushCmp 相关配置设置给 build2lib
|
|
281
|
+
const pushCmpConfig = curConfig.pushCmp;
|
|
282
|
+
curConfig.build2lib = Object.assign(curConfig.build2lib, pushCmpConfig);
|
|
279
283
|
|
|
280
284
|
const curEntry = curConfig.build2lib.entry;
|
|
281
285
|
let curCmpTypes = [];
|
|
@@ -315,7 +319,7 @@ module.exports = {
|
|
|
315
319
|
/*
|
|
316
320
|
// 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
|
|
317
321
|
// 添加模块联邦插件
|
|
318
|
-
if (curConfig.
|
|
322
|
+
if (curConfig.pushCmp.enableMF) {
|
|
319
323
|
curConfig.webpack.plugins.push(...MFPlugins);
|
|
320
324
|
}
|
|
321
325
|
*/
|
|
@@ -355,8 +359,8 @@ module.exports = {
|
|
|
355
359
|
}
|
|
356
360
|
|
|
357
361
|
akfun.build('lib', curConfig, consoleTag, () => {
|
|
358
|
-
// 构建完成后,执行
|
|
359
|
-
|
|
362
|
+
// 构建完成后,执行 pushCmp
|
|
363
|
+
pushCmp(pushCmpConfig, cmpType);
|
|
360
364
|
});
|
|
361
365
|
},
|
|
362
366
|
build2esm: (fileName) => akfun.build2esm(fileName, curConfig, consoleTag) // 构建esm输出模块
|
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
|
};
|
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
|
};
|
package/src/neo/neoService.js
CHANGED
|
@@ -3,7 +3,7 @@ const FormData = require('form-data');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const _ = require('lodash');
|
|
6
|
-
const updatePublishLog = require('../
|
|
6
|
+
const updatePublishLog = require('../projectUtils/updatePublishLog');
|
|
7
7
|
|
|
8
8
|
// NeoCRM 平台默认 API 配置
|
|
9
9
|
const NeoCrmAPI = {
|
|
@@ -23,32 +23,32 @@ class NeoService {
|
|
|
23
23
|
* @param {object} config 配置信息
|
|
24
24
|
* @param {string} config.neoBaseURL Neo 平台根地址
|
|
25
25
|
* @param {string} config.tokenAPI Token 获取接口地址
|
|
26
|
-
* @param {object} config.
|
|
27
|
-
* @param {string} config.
|
|
28
|
-
* @param {string} config.
|
|
29
|
-
* @param {string} config.
|
|
30
|
-
* @param {string} config.
|
|
26
|
+
* @param {object} config.authConfig 授权信息
|
|
27
|
+
* @param {string} config.authConfig.client_id 客户端 ID
|
|
28
|
+
* @param {string} config.authConfig.client_secret 客户端密钥
|
|
29
|
+
* @param {string} config.authConfig.username 用户名
|
|
30
|
+
* @param {string} config.authConfig.password 密码
|
|
31
31
|
*/
|
|
32
32
|
constructor(config = {}) {
|
|
33
|
-
const { assetsRoot, neoBaseURL, tokenAPI,
|
|
34
|
-
if (!
|
|
35
|
-
throw new Error('
|
|
33
|
+
const { assetsRoot, neoBaseURL, tokenAPI, authConfig } = config;
|
|
34
|
+
if (!authConfig) {
|
|
35
|
+
throw new Error('authConfig 不能为空');
|
|
36
36
|
}
|
|
37
37
|
if (
|
|
38
|
-
!
|
|
39
|
-
!
|
|
40
|
-
!
|
|
41
|
-
!
|
|
38
|
+
!authConfig.client_id ||
|
|
39
|
+
!authConfig.client_secret ||
|
|
40
|
+
!authConfig.username ||
|
|
41
|
+
!authConfig.password
|
|
42
42
|
) {
|
|
43
43
|
throw new Error(
|
|
44
|
-
'
|
|
44
|
+
'authConfig 配置不完整,需要包含 client_id、client_secret、username、password'
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
this.assetsRoot = assetsRoot;
|
|
49
49
|
this.neoBaseURL = neoBaseURL || NeoCrmAPI.neoBaseURL;
|
|
50
50
|
this.tokenAPI = tokenAPI || NeoCrmAPI.tokenAPI;
|
|
51
|
-
this.
|
|
51
|
+
this.authConfig = authConfig;
|
|
52
52
|
|
|
53
53
|
// Token 缓存
|
|
54
54
|
this.tokenCache = {
|
|
@@ -106,10 +106,10 @@ class NeoService {
|
|
|
106
106
|
// 构建表单数据格式的请求参数
|
|
107
107
|
const formData = new URLSearchParams();
|
|
108
108
|
formData.append('grant_type', 'password');
|
|
109
|
-
formData.append('client_id', this.
|
|
110
|
-
formData.append('client_secret', this.
|
|
111
|
-
formData.append('username', this.
|
|
112
|
-
formData.append('password', this.
|
|
109
|
+
formData.append('client_id', this.authConfig.client_id);
|
|
110
|
+
formData.append('client_secret', this.authConfig.client_secret);
|
|
111
|
+
formData.append('username', this.authConfig.username);
|
|
112
|
+
formData.append('password', this.authConfig.password);
|
|
113
113
|
|
|
114
114
|
const tokenUrl = this.buildFullUrl(this.tokenAPI);
|
|
115
115
|
|
|
@@ -123,7 +123,7 @@ class NeoService {
|
|
|
123
123
|
const { access_token, expires_in } = response.data || {};
|
|
124
124
|
|
|
125
125
|
if (!access_token) {
|
|
126
|
-
console.error('获取 token 失败:响应中未包含 access_token', response.data);
|
|
126
|
+
console.error('\n获取 token 失败:响应中未包含 access_token', response.data);
|
|
127
127
|
process.exit(1);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -135,7 +135,7 @@ class NeoService {
|
|
|
135
135
|
};
|
|
136
136
|
return access_token;
|
|
137
137
|
} catch (error) {
|
|
138
|
-
console.error('获取 token 失败:', error.message);
|
|
138
|
+
console.error('\n获取 token 失败:', error.message);
|
|
139
139
|
console.error('\ntoken 授权地址:', tokenUrl);
|
|
140
140
|
console.error('\ntoken 请求参数:', formData);
|
|
141
141
|
if (error.response) {
|
|
@@ -296,11 +296,11 @@ class NeoService {
|
|
|
296
296
|
} else if (resultData && typeof resultData === 'object' && resultData.url) {
|
|
297
297
|
fileUrl = resultData.url;
|
|
298
298
|
}
|
|
299
|
-
console.info(
|
|
299
|
+
console.info(`\n文件上传成功: ${fileName} -> ${fileUrl}`);
|
|
300
300
|
return fileUrl;
|
|
301
301
|
} catch (error) {
|
|
302
|
-
console.error(
|
|
303
|
-
console.error(`文件路径: ${filePath}`);
|
|
302
|
+
console.error(`\n上传文件失败: ${error.message},`);
|
|
303
|
+
console.error(`文件路径: ${filePath}。\n`);
|
|
304
304
|
|
|
305
305
|
// 输出详细的错误信息
|
|
306
306
|
if (error.response) {
|
|
@@ -412,7 +412,6 @@ class NeoService {
|
|
|
412
412
|
|
|
413
413
|
try {
|
|
414
414
|
const fullUpdateAPI = this.saveAPI();
|
|
415
|
-
console.info('更新组件 API 地址:', fullUpdateAPI);
|
|
416
415
|
const response = await axios.post(fullUpdateAPI, componentData, {
|
|
417
416
|
headers: {
|
|
418
417
|
Authorization: `Bearer ${token}`,
|
|
@@ -420,17 +419,19 @@ class NeoService {
|
|
|
420
419
|
'Content-Type': 'application/json'
|
|
421
420
|
}
|
|
422
421
|
});
|
|
422
|
+
const {code, message} = response.data || {};
|
|
423
423
|
|
|
424
|
-
if (
|
|
424
|
+
if (code && code !== 200) {
|
|
425
425
|
throw new Error(`更新组件失败: ${response.data.message || '未知错误'}`);
|
|
426
426
|
}
|
|
427
|
+
|
|
427
428
|
|
|
428
|
-
console.info('
|
|
429
|
-
return response.data;
|
|
429
|
+
console.info(message ? `组件更新成功: ${message}。` : '组件更新成功。');
|
|
430
430
|
} catch (error) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
if (error.message) {
|
|
432
|
+
console.error('更新组件失败:', error.message);
|
|
433
|
+
} else {
|
|
434
|
+
console.error('响应数据:', error);
|
|
434
435
|
}
|
|
435
436
|
process.exit(1);
|
|
436
437
|
}
|
package/src/oss/publish2oss.js
CHANGED
|
@@ -4,7 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const _ = require('lodash');
|
|
5
5
|
const { catchCurPackageJson } = require('../utils/pathUtils');
|
|
6
6
|
const getConfigObj = require('../utils/getConfigObj');
|
|
7
|
-
const updatePublishLog = require('../
|
|
7
|
+
const updatePublishLog = require('../projectUtils/updatePublishLog');
|
|
8
8
|
|
|
9
9
|
// 获取当前项目的package文件
|
|
10
10
|
const currentPackageJsonDir = catchCurPackageJson();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const { ConcatSource } = require('webpack-sources');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
2
4
|
/**
|
|
3
5
|
* 注入 neoRequire 函数
|
|
4
6
|
* 备注:用于实现和 Neo 平台共享依赖
|
|
@@ -162,9 +164,9 @@ class AddNeoRequirePlugin {
|
|
|
162
164
|
})(function(require) {
|
|
163
165
|
`;
|
|
164
166
|
|
|
165
|
-
const NeoUMDContent = fs.readFileSync(path.join(__dirname, '../neo/NeoUMDContent.js'), 'utf8');
|
|
166
|
-
|
|
167
|
-
const Footer = `})
|
|
167
|
+
// const NeoUMDContent = fs.readFileSync(path.join(__dirname, '../neo/NeoUMDContent.js'), 'utf8');
|
|
168
|
+
// const Footer = `}); \n${NeoUMDContent}`;
|
|
169
|
+
const Footer = `});`;
|
|
168
170
|
|
|
169
171
|
// 创建新的资源
|
|
170
172
|
const newSource = new ConcatSource(Header, content, Footer);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { consoleTag } = require('../utils/neoParams'); // 输出标记
|
|
4
|
+
const { replaceInPackage } = require('../utils/replaceInPackage');
|
|
5
|
+
const { resetPackageVersion } = require('../utils/resetPackageVersion');
|
|
6
|
+
const autoEntryRootDir = require('../utils/autoEntryRootDir');
|
|
7
|
+
|
|
8
|
+
const cmpTemplateList = {
|
|
9
|
+
'react-ts': {
|
|
10
|
+
projectName: 'empty-custom-cmp-template',
|
|
11
|
+
dir: path.resolve(__dirname, '../template/empty-custom-cmp-template')
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 通过拷贝模板创建自定义组件
|
|
17
|
+
* @param {*} projectName 自定义组件项目名称
|
|
18
|
+
* @param {*} type 自定义组件类型
|
|
19
|
+
*/
|
|
20
|
+
module.exports = function (projectName, type = 'react-ts') {
|
|
21
|
+
const finalProjectPath = path.resolve(process.cwd(), projectName);
|
|
22
|
+
|
|
23
|
+
if (fs.existsSync(finalProjectPath)) {
|
|
24
|
+
console.error(`${consoleTag}创建自定义组件失败,当前已存在(${projectName})项目,请勿创建重名项目。`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const curCmpTemplate = cmpTemplateList[type];
|
|
29
|
+
if (!curCmpTemplate) {
|
|
30
|
+
console.error(`${consoleTag}创建自定义组件失败,当前不支持${type}类型。`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const currentTemplateDir = curCmpTemplate.dir;
|
|
35
|
+
const finalProjectName = projectName || 'neoCustomCmp';
|
|
36
|
+
|
|
37
|
+
fs.copy(currentTemplateDir, finalProjectPath)
|
|
38
|
+
.then(() => {
|
|
39
|
+
replaceInPackage(finalProjectPath, curCmpTemplate.projectName, finalProjectName);
|
|
40
|
+
replaceInPackage(finalProjectPath, 'wibetter', 'xxx');
|
|
41
|
+
replaceInPackage(finalProjectPath, 'neo自定义组件模板', 'neo自定义组件');
|
|
42
|
+
resetPackageVersion(finalProjectPath);
|
|
43
|
+
|
|
44
|
+
console.log(`${consoleTag}已创建自定义组件(${finalProjectName})!`);
|
|
45
|
+
// 自动切换到项目根目录
|
|
46
|
+
autoEntryRootDir(finalProjectPath);
|
|
47
|
+
})
|
|
48
|
+
.catch((err) => console.error(`${consoleTag}自定义组件模板下载失败:`, err));
|
|
49
|
+
};
|
|
@@ -2,8 +2,8 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const getCmpRegisterCode = require('./getCmpRegisterCode');
|
|
6
|
+
const getCmpModelRegisterCode = require('./getCmpModelRegisterCode');
|
|
7
7
|
/**
|
|
8
8
|
* 从指定目录获取组件入口文件,并自动创建对应的注册文件
|
|
9
9
|
* @param {*} defaultComponentsDir 默认组件目录
|
|
@@ -68,7 +68,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
68
68
|
.forEach((filePath) => {
|
|
69
69
|
if (filePath.match(/index\.[tj]sx?$/)) {
|
|
70
70
|
// 自动创建对应的注册文件
|
|
71
|
-
const registerContent =
|
|
71
|
+
const registerContent = getCmpRegisterCode(componentsBaseDir, curCmpName);
|
|
72
72
|
const registerDir = `${cmpTempDir}/register.js`;
|
|
73
73
|
|
|
74
74
|
// 写入注册文件
|
|
@@ -78,7 +78,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
|
|
|
78
78
|
linkDebugEntries.index.push(registerDir);
|
|
79
79
|
} else if (filePath.match(/model\.[tj]sx?$/)) {
|
|
80
80
|
// 自动创建对应的模型注册文件
|
|
81
|
-
const modelRegisterContent =
|
|
81
|
+
const modelRegisterContent = getCmpModelRegisterCode(componentsBaseDir, curCmpName);
|
|
82
82
|
const modelRegisterDir = `${cmpTempDir}/model.js`;
|
|
83
83
|
|
|
84
84
|
// 写入模型注册文件
|