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.
Files changed (66) hide show
  1. package/README.md +51 -14
  2. package/package.json +1 -1
  3. package/src/cmpUtils/createCmpByTemplate.js +50 -0
  4. package/src/cmpUtils/createCommonModulesCode.js +15 -15
  5. package/src/cmpUtils/{getCmpModelRegister.js → getCmpModelRegisterCode.js} +2 -2
  6. package/src/cmpUtils/{getCmpPreview.js → getCmpPreviewCode.js} +2 -2
  7. package/src/cmpUtils/{getCmpRegister.js → getCmpRegisterCode.js} +2 -2
  8. package/src/cmpUtils/getCmpTypeByDir.js +41 -0
  9. package/src/cmpUtils/hasCmpTypeByDir.js +11 -0
  10. package/src/{module → cmpUtils}/previewCmp.js +2 -2
  11. package/src/cmpUtils/publishCmp.js +18 -16
  12. package/src/config/default.config.js +1 -1
  13. package/src/module/index.js +144 -21
  14. package/src/module/main.js +15 -11
  15. package/src/module/neoInit.js +3 -0
  16. package/src/module/neoInitByCopy.js +3 -0
  17. package/src/neo/neoRequire.js +7 -7
  18. package/src/neo/neoService.js +32 -31
  19. package/src/oss/publish2oss.js +1 -1
  20. package/src/plugins/AddNeoRequirePlugin.js +5 -3
  21. package/src/projectUtils/createCmpProjectByTemplate.js +49 -0
  22. package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
  23. package/src/template/antd-custom-cmp-template/README.md +2 -2
  24. package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
  25. package/src/template/antd-custom-cmp-template/package.json +2 -2
  26. package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
  27. package/src/template/echarts-custom-cmp-template/README.md +2 -2
  28. package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
  29. package/src/template/echarts-custom-cmp-template/package.json +2 -2
  30. package/src/template/empty-cmp/index.tsx +51 -0
  31. package/src/template/empty-cmp/model.ts +77 -0
  32. package/src/template/empty-cmp/style.scss +72 -0
  33. package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
  34. package/src/template/empty-custom-cmp-template/README.md +45 -0
  35. package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
  36. package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
  37. package/src/template/empty-custom-cmp-template/package.json +57 -0
  38. package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
  39. package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
  40. package/src/template/empty-custom-cmp-template/public/template.html +13 -0
  41. package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
  42. package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
  43. package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
  44. package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
  45. package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
  46. package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
  47. package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
  48. package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
  49. package/src/template/neo-custom-cmp-template/README.md +2 -2
  50. package/src/template/neo-custom-cmp-template/neo.config.js +4 -26
  51. package/src/template/neo-custom-cmp-template/package.json +3 -5
  52. package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +0 -2
  53. package/src/template/react-custom-cmp-template/README.md +2 -2
  54. package/src/template/react-custom-cmp-template/neo.config.js +20 -15
  55. package/src/template/react-custom-cmp-template/package.json +2 -2
  56. package/src/template/react-ts-custom-cmp-template/README.md +2 -2
  57. package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
  58. package/src/template/react-ts-custom-cmp-template/package.json +2 -2
  59. package/src/template/vue2-custom-cmp-template/README.md +2 -2
  60. package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
  61. package/src/template/vue2-custom-cmp-template/package.json +2 -2
  62. package/src/utils/autoEntryRootDir.js +42 -0
  63. package/src/utils/replaceInFilesByMap.js +54 -0
  64. package/test/demo.js +2 -2
  65. /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
  66. /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
@@ -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('cmpType', {
162
- alias: 't',
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.cmpType) {
169
- mainAction.previewCmp(argv.cmpType);
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: 'input',
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('cmpType', {
248
- alias: 't',
333
+ .option('name', {
334
+ alias: 'n',
249
335
  describe: '自定义组件名称'
250
336
  })
251
337
  .alias('h', 'help');
252
338
  },
253
339
  (argv) => {
254
- mainAction.publish2oss(argv.cmpType); // 构建并发布脚本到oss
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
- 'publishCmp [options]',
371
+ 'pushCmp [options]',
259
372
  '发布组件到 NeoCRM 平台',
260
373
  (yargs) => {
261
374
  yargs
262
375
  .reset()
263
- .usage(titleTip('Usage') + ': $0 publishCmp [options]')
264
- .option('cmpType', {
265
- alias: 't',
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.cmpType) {
272
- mainAction.publishCmp(argv.cmpType); // 构建并发布组件到 NeoCRM
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: 'input',
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.publishCmp(ans.cmpType);
409
+ mainAction.pushCmp(ans.cmpType);
287
410
  });
288
411
  }
289
412
  }
@@ -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 publishCmp = require('../cmpUtils/publishCmp');
11
- const getEntries = require('../cmpUtils/getEntries');
12
- const getEntriesWithAutoRegister = require('../cmpUtils/getEntriesWithAutoRegister');
13
- const previewCmp = require('./previewCmp');
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
- publishCmp: (cmpType) => {
276
- // 将 publishCmp 相关配置设置给 build2lib
277
- const publishCmpConfig = curConfig.publishCmp;
278
- curConfig.build2lib = Object.assign(curConfig.build2lib, publishCmpConfig);
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.publishCmp.enableMF) {
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
- // 构建完成后,执行 publishCmp
359
- publishCmp(publishCmpConfig, cmpType);
362
+ // 构建完成后,执行 pushCmp
363
+ pushCmp(pushCmpConfig, cmpType);
360
364
  });
361
365
  },
362
366
  build2esm: (fileName) => akfun.build2esm(fileName, curConfig, consoleTag) // 构建esm输出模块
@@ -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
  };
@@ -67,16 +67,16 @@ const addNeoCommonModules = (modules) => {
67
67
  }
68
68
  }
69
69
 
70
- // 用于添加自定义组件的远程组件
71
- const addNeoRemotes = (remotes) => {
70
+ // 用于添加自定义组件的远程依赖组件
71
+ const addNeoRemoteDeps = (remoteDeps) => {
72
72
  if (!window.__NeoCommonModules) {
73
73
  window.__NeoCommonModules = {}
74
74
  }
75
- if (!window.__NeoCommonModules.__neoRemotes) {
76
- window.__NeoCommonModules.__neoRemotes = {}
75
+ if (!window.__NeoCommonModules.__neoRemoteDeps) {
76
+ window.__NeoCommonModules.__neoRemoteDeps = {}
77
77
  }
78
- if (_.isPlainObject(remotes)) {
79
- window.__NeoCommonModules.__neoRemotes = Object.assign(window.__NeoCommonModules.__neoRemotes, remotes);
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
- addNeoRemotes,
113
+ addNeoRemoteDeps,
114
114
  getExternalsByNeoCommonModules
115
115
  };
@@ -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('../cmpUtils/updatePublishLog');
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.authorization 授权信息
27
- * @param {string} config.authorization.client_id 客户端 ID
28
- * @param {string} config.authorization.client_secret 客户端密钥
29
- * @param {string} config.authorization.username 用户名
30
- * @param {string} config.authorization.password 密码
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, authorization } = config;
34
- if (!authorization) {
35
- throw new Error('authorization 不能为空');
33
+ const { assetsRoot, neoBaseURL, tokenAPI, authConfig } = config;
34
+ if (!authConfig) {
35
+ throw new Error('authConfig 不能为空');
36
36
  }
37
37
  if (
38
- !authorization.client_id ||
39
- !authorization.client_secret ||
40
- !authorization.username ||
41
- !authorization.password
38
+ !authConfig.client_id ||
39
+ !authConfig.client_secret ||
40
+ !authConfig.username ||
41
+ !authConfig.password
42
42
  ) {
43
43
  throw new Error(
44
- 'authorization 配置不完整,需要包含 client_id、client_secret、username、password'
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.authorization = authorization;
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.authorization.client_id);
110
- formData.append('client_secret', this.authorization.client_secret);
111
- formData.append('username', this.authorization.username);
112
- formData.append('password', this.authorization.password);
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(`文件上传成功: ${fileName} -> ${fileUrl}`);
299
+ console.info(`\n文件上传成功: ${fileName} -> ${fileUrl}`);
300
300
  return fileUrl;
301
301
  } catch (error) {
302
- console.error(`上传文件失败: ${error.message}`);
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 (response.data && response.data.code && response.data.code !== 200) {
424
+ if (code && code !== 200) {
425
425
  throw new Error(`更新组件失败: ${response.data.message || '未知错误'}`);
426
426
  }
427
+
427
428
 
428
- console.info('组件更新成功:', response.data);
429
- return response.data;
429
+ console.info(message ? `组件更新成功: ${message}。` : '组件更新成功。');
430
430
  } catch (error) {
431
- console.error('更新组件失败:', error.message);
432
- if (error.response) {
433
- console.error('响应数据:', error.response.data);
431
+ if (error.message) {
432
+ console.error('更新组件失败:', error.message);
433
+ } else {
434
+ console.error('响应数据:', error);
434
435
  }
435
436
  process.exit(1);
436
437
  }
@@ -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('../cmpUtils/updatePublishLog');
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 = `}); \n${NeoUMDContent}`;
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 getCmpRegister = require('./getCmpRegister');
6
- const getCmpModelRegister = require('./getCmpModelRegister');
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 = getCmpRegister(componentsBaseDir, curCmpName);
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 = getCmpModelRegister(componentsBaseDir, curCmpName);
81
+ const modelRegisterContent = getCmpModelRegisterCode(componentsBaseDir, curCmpName);
82
82
  const modelRegisterDir = `${cmpTempDir}/model.js`;
83
83
 
84
84
  // 写入模型注册文件
@@ -37,10 +37,10 @@ $ npm run preview
37
37
  $ npm run linkDebug
38
38
  ```
39
39
 
40
- 4. **发布到对象存储服务中**
40
+ 4. **发布到 NeoCRM 平台**
41
41
  > 需要确保 package.json 中的 name 值唯一,version 值不重复。
42
42
  ```bash
43
- $ npm run publish2oss
43
+ $ npm run pushCmp
44
44
  ```
45
45
 
46
46
  ### 配置项说明(neo-cmp-cli)