neo-cmp-cli 1.5.0-beta.5 → 1.5.0-beta.7

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 (64) hide show
  1. package/README.md +12 -12
  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/hasCmpTypeByDir.js +11 -0
  9. package/src/{module → cmpUtils}/previewCmp.js +2 -2
  10. package/src/cmpUtils/publishCmp.js +4 -4
  11. package/src/config/default.config.js +1 -1
  12. package/src/module/index.js +94 -19
  13. package/src/module/main.js +15 -11
  14. package/src/module/neoInit.js +3 -0
  15. package/src/module/neoInitByCopy.js +3 -0
  16. package/src/neo/neoRequire.js +7 -7
  17. package/src/neo/neoService.js +19 -19
  18. package/src/oss/publish2oss.js +1 -1
  19. package/src/projectUtils/createCmpProjectByTemplate.js +49 -0
  20. package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
  21. package/src/template/antd-custom-cmp-template/README.md +2 -2
  22. package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
  23. package/src/template/antd-custom-cmp-template/package.json +2 -2
  24. package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
  25. package/src/template/echarts-custom-cmp-template/README.md +2 -2
  26. package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
  27. package/src/template/echarts-custom-cmp-template/package.json +2 -2
  28. package/src/template/empty-cmp/index.tsx +51 -0
  29. package/src/template/empty-cmp/model.ts +77 -0
  30. package/src/template/empty-cmp/style.scss +72 -0
  31. package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
  32. package/src/template/empty-custom-cmp-template/README.md +45 -0
  33. package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
  34. package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
  35. package/src/template/empty-custom-cmp-template/package.json +57 -0
  36. package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
  37. package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
  38. package/src/template/empty-custom-cmp-template/public/template.html +13 -0
  39. package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
  40. package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
  41. package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
  42. package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
  43. package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
  44. package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
  45. package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
  46. package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
  47. package/src/template/neo-custom-cmp-template/README.md +2 -2
  48. package/src/template/neo-custom-cmp-template/neo.config.js +4 -25
  49. package/src/template/neo-custom-cmp-template/package.json +3 -5
  50. package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +0 -8
  51. package/src/template/react-custom-cmp-template/README.md +2 -2
  52. package/src/template/react-custom-cmp-template/neo.config.js +20 -15
  53. package/src/template/react-custom-cmp-template/package.json +2 -2
  54. package/src/template/react-ts-custom-cmp-template/README.md +2 -2
  55. package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
  56. package/src/template/react-ts-custom-cmp-template/package.json +2 -2
  57. package/src/template/vue2-custom-cmp-template/README.md +2 -2
  58. package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
  59. package/src/template/vue2-custom-cmp-template/package.json +2 -2
  60. package/src/utils/autoEntryRootDir.js +42 -0
  61. package/src/utils/replaceInFilesByMap.js +54 -0
  62. package/test/demo.js +2 -2
  63. /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
  64. /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
package/README.md CHANGED
@@ -41,7 +41,7 @@ neo preview
41
41
  neo linkDebug
42
42
 
43
43
  # 构建并发布到 NeoCRM(需自行添加授权配置,并确保 package.json 的 name 唯一、version 不重复)
44
- neo publish2neo
44
+ neo pushCmp
45
45
  ```
46
46
 
47
47
  ### 方法二:在现有业务项目中使用自定义组件开发工具
@@ -58,7 +58,7 @@ npm i neo-cmp-cli --save-dev
58
58
  ```bash
59
59
  "preview": "neo preview",
60
60
  "linkDebug": "neo linkDebug",
61
- "publish2neo": "neo publish2neo"
61
+ "pushCmp": "neo pushCmp"
62
62
  ```
63
63
  ##### 3) 初始化配置文件
64
64
  ```bash
@@ -68,7 +68,7 @@ neo config init
68
68
  ```bash
69
69
  npm run preview
70
70
  npm run linkDebug
71
- npm run publish2oss
71
+ npm run pushCmp
72
72
  ```
73
73
 
74
74
  ## 常用命令说明
@@ -76,11 +76,11 @@ npm run publish2oss
76
76
  - **neo preview**: 本地预览自定义组件内容,默认支持热更新与接口代理。
77
77
  - **neo linkDebug**: 外链调试模式,在平台端页面设计器中调试自定义组件。
78
78
  - **neo publish2oss**: 构建并上传到对象存储(可自定义配置对象存储)。
79
- - **neo publish2neo**: 构建并发布到NeoCRM平台(需自行添加授权配置)。
79
+ - **neo pushCmp**: 构建并发布到NeoCRM平台(需自行添加授权配置)。
80
80
 
81
81
  ## 开发须知
82
82
  #### 1)默认自动识别自定义组件
83
- - **自动生成入口配置**: 当 `entry` 未配置时,自动从 `src/components` 目录下扫描并识别自定义组件,`src/components` 下的子目录名称作为自定义组件的 cmpType,并以其目录下的 `index.ts/.tsx/.js/.jsx` 文件作为组件内容文件,model.[tj]s 作为模型内容文件;
83
+ - **自动生成入口配置**: 当 `entry` 未配置时,自动从 `src/components` 目录下扫描并识别自定义组件,`src/components` 下的子目录名称作为自定义组件的名称,并以其目录下的 `index.ts/.tsx/.js/.jsx` 文件作为组件内容文件,model.[tj]s 作为模型内容文件;
84
84
  - **自动注册自定义组件**: 当 `entry` 未配置时,自动生成自定义组件注册文件和模型注册文件,并注入到构建脚本中,无需用户手动编写注册文件([neo-register](https://www.npmjs.com/package/neo-register))。
85
85
 
86
86
  #### 2)设置自定义组件属性配置项
@@ -130,7 +130,7 @@ neo linkDebug
130
130
  将第 1 步生成的「外链脚本地址」添加进来,即可在此页面设计器 / 组件物料面板中看到对应自定义组件。
131
131
 
132
132
  #### 6)发布自定义组件至 NeoCRM
133
- 执行 `neo publish2neo` 即可构建并发布自定义组件至 NeoCRM 平台,其构建后资源也会上传到 NeoCRM 平台端提供的 CDN 中。
133
+ 执行 `neo pushCmp` 即可构建并发布自定义组件至 NeoCRM 平台,其构建后资源也会上传到 NeoCRM 平台端提供的 CDN 中。
134
134
 
135
135
  ##### 发布前请确保
136
136
  - **package.json 的 name 唯一**
@@ -139,11 +139,11 @@ neo linkDebug
139
139
  ##### 需自行添加授权配置
140
140
  ```javascript
141
141
  module.exports = {
142
- publishCmp: {
142
+ pushCmp: {
143
143
  neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
144
144
  tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
145
145
  // NeoCRM 授权配置
146
- authorization: {
146
+ authConfig: {
147
147
  /**
148
148
  * 客户端 ID 和 客户端秘钥 需通过 创建连接器 获取,
149
149
  * 详细见:https://doc.xiaoshouyi.com / 创建连接器。
@@ -163,7 +163,7 @@ module.exports = {
163
163
  ```
164
164
 
165
165
  ##### 支持发布指定自定义组件
166
- 执行 `neo publish2oss --cmpType=xxCmp`
166
+ 执行 `neo pushCmp --name=xxCmp`
167
167
 
168
168
  #### 7)发布自定义组件至CDN
169
169
  执行 `neo publish2oss` 即可构建对应自定义组件,并自动将构建后资源上传到对象存储(OSS)中。
@@ -194,7 +194,7 @@ module.exports = {
194
194
  ```
195
195
 
196
196
  ##### 支持发布指定自定义组件
197
- 执行 `neo publish2oss --cmpType=xxCmp`
197
+ 执行 `neo publish2oss --name=xxCmp`
198
198
 
199
199
  ## 项目工程配置说明(neo.config.js)
200
200
  neo-cmp-cli 默认提供完整配置;
@@ -364,8 +364,8 @@ module.exports = {
364
364
  ```javascript
365
365
  module.exports = {
366
366
  neoCommonModule: {
367
- remotes: ['neo-custom-cmpA'], // 远程自定义组件,表示当前自定义组件 B 会用到的自定义组件
368
- neoExternals: ['xxModule_A'], // 自定义组件中需要剔除的模块(远程自定义组件中分享出来的模块),仅支持数组写法,需要和 remotes 配合使用
367
+ remoteDeps: ['neo-custom-cmpA'], // 远程自定义组件,表示当前自定义组件 B 会用到的自定义组件
368
+ neoExternals: ['xxModule_A'], // 自定义组件中需要剔除的模块(远程自定义组件中分享出来的模块),仅支持数组写法,需要和 remoteDeps 配合使用
369
369
  },
370
370
  }
371
371
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.5.0-beta.5",
3
+ "version": "1.5.0-beta.7",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -0,0 +1,50 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const _ = require('lodash');
4
+ const { consoleTag } = require('../utils/neoParams'); // 输出标记
5
+ const replaceInFilesByMap = require('../utils/replaceInFilesByMap');
6
+ const hasCmpTypeByDir = require('./hasCmpTypeByDir');
7
+
8
+ // 自定义组件内容模板信息
9
+ const curCmpTemplate = {
10
+ // 需要替换掉的字段信息(模板中的字段)
11
+ widgetInfo: {
12
+ cmpName: 'CustomCmp',
13
+ modelName: 'CustomCmpModel',
14
+ cmpClassName: 'custom-cmp-container',
15
+ cmpType: 'xx-custom-cmp',
16
+ cmpLabel: 'xx组件',
17
+ },
18
+ dir: path.resolve(__dirname, '../template/empty-cmp')
19
+ };
20
+
21
+ /**
22
+ * 创建自定义组件
23
+ * @param {*} cmpName 自定义组件名称
24
+ */
25
+ module.exports = function (cmpName) {
26
+ const currentTemplateDir = curCmpTemplate.dir;
27
+ const finalCmpName = cmpName || 'neoCustomCmp';
28
+ const finalCmpPath = path.resolve(process.cwd(), finalCmpName);
29
+
30
+ if (hasCmpTypeByDir(cmpType)) {
31
+ console.error(`${consoleTag}创建自定义组件失败,当前已经存在${cmpType}自定义组件。`);
32
+ process.exit(1);
33
+ }
34
+
35
+ fs.copy(currentTemplateDir, finalCmpPath)
36
+ .then(() => {
37
+ const curCmpName = _.camelCase(cmpName);
38
+ const cmpType = _.kebabCase(cmpName);
39
+ replaceInFilesByMap(finalCmpPath, {
40
+ [curCmpTemplate.widgetInfo.cmpName]: curCmpName,
41
+ [curCmpTemplate.widgetInfo.modelName]: `${curCmpName}Model`,
42
+ [curCmpTemplate.widgetInfo.cmpClassName]: `${cmpType}-container`,
43
+ [curCmpTemplate.widgetInfo.cmpType]: cmpType,
44
+ [curCmpTemplate.widgetInfo.cmpLabel]: `${cmpType}组件`,
45
+ });
46
+
47
+ console.log(`${consoleTag}已创建自定义组件(${finalCmpName})!`);
48
+ })
49
+ .catch((err) => console.error(`${consoleTag}自定义组件创建失败(${finalCmpName}):`, err));
50
+ };;
@@ -9,15 +9,15 @@ const { isPlainObject } = require('lodash');
9
9
  * @returns 组件预览代码
10
10
  */
11
11
  const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
12
- const {neoExports, remotes} = neoCommonModule;
12
+ const {neoExports, remoteDeps} = neoCommonModule;
13
13
 
14
- if (!neoExports && !remotes) {
14
+ if (!neoExports && !remoteDeps) {
15
15
  return '';
16
16
  }
17
17
  // 记录当前自定义组件共享出去的模块
18
18
  const CustomCmpCommonModules = {};
19
- // 记录当前自定义组件需要的远程组件
20
- const CustomCmpRemotes = {};
19
+ // 记录当前自定义组件需要的远程依赖组件
20
+ const CustomCmpRemoteDeps = {};
21
21
 
22
22
  // 根据 neoExports 获取共享的依赖模块
23
23
  if (Array.isArray(neoExports) && neoExports.length > 0) {
@@ -35,10 +35,10 @@ const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
35
35
  process.exit(1);
36
36
  }
37
37
 
38
- // 根据 cmpTypes 和 remotes 设置远程组件信息
39
- if (Array.isArray(remotes) && remotes.length > 0) {
38
+ // 根据 cmpTypes 和 remoteDeps 设置远程依赖组件信息
39
+ if (Array.isArray(remoteDeps) && remoteDeps.length > 0) {
40
40
  cmpTypes.forEach((cmpType) => {
41
- CustomCmpRemotes[cmpType] = remotes;
41
+ CustomCmpRemoteDeps[cmpType] = remoteDeps;
42
42
  });
43
43
  }
44
44
 
@@ -58,7 +58,7 @@ const createCommonModulesCode = (neoCommonModule, cmpTypes) => {
58
58
  */
59
59
  import { isPlainObject } from 'lodash';
60
60
  const CustomCmpCommonModules = ${customCmpCommonModulesCode};
61
- const CustomCmpRemotes = ${JSON.stringify(CustomCmpRemotes)};
61
+ const CustomCmpRemoteDeps = ${JSON.stringify(CustomCmpRemoteDeps)};
62
62
 
63
63
  // 用于添加共享的依赖模块
64
64
  const addNeoCommonModules = (modules) => {
@@ -88,21 +88,21 @@ const addNeoCommonModules = (modules) => {
88
88
  }
89
89
  }
90
90
 
91
- // 用于添加自定义组件的远程组件(关联使用)
92
- const addNeoRemotes = (remotes) => {
91
+ // 用于添加自定义组件的远程依赖组件(关联使用)
92
+ const addNeoRemoteDeps = (remoteDeps) => {
93
93
  if (!window.__NeoCommonModules) {
94
94
  window.__NeoCommonModules = {}
95
95
  }
96
- if (!window.__NeoCommonModules.__neoRemotes) {
97
- window.__NeoCommonModules.__neoRemotes = {}
96
+ if (!window.__NeoCommonModules.__neoRemoteDeps) {
97
+ window.__NeoCommonModules.__neoRemoteDeps = {}
98
98
  }
99
- if (isPlainObject(remotes)) {
100
- window.__NeoCommonModules.__neoRemotes = Object.assign(window.__NeoCommonModules.__neoRemotes, remotes)
99
+ if (isPlainObject(remoteDeps)) {
100
+ window.__NeoCommonModules.__neoRemoteDeps = Object.assign(window.__NeoCommonModules.__neoRemoteDeps, remoteDeps)
101
101
  }
102
102
  }
103
103
 
104
104
  addNeoCommonModules(CustomCmpCommonModules);
105
- addNeoRemotes(CustomCmpRemotes);
105
+ addNeoRemoteDeps(CustomCmpRemoteDeps);
106
106
  `;
107
107
 
108
108
  // 创建存放 cli 的临时目录
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
7
7
  * @param {*} cmpName 自定义组件名称
8
8
  * @returns 组件注册文件内容
9
9
  */
10
- const getCmpModelRegister = (cmpsDir, cmpName) => {
10
+ const getCmpModelRegisterCode = (cmpsDir, cmpName) => {
11
11
  const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
12
12
 
13
13
  /*
@@ -28,4 +28,4 @@ registerNeoEditorModel(CustomCmpModel, '${cmpName}');
28
28
  `;
29
29
  };
30
30
 
31
- module.exports = getCmpModelRegister;
31
+ module.exports = getCmpModelRegisterCode;
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
7
7
  * @param {*} cmpName 自定义组件名称
8
8
  * @returns 组件预览代码
9
9
  */
10
- const getCmpPreview = (cmpsDir, cmpName) => {
10
+ const getCmpPreviewCode = (cmpsDir, cmpName) => {
11
11
  const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
12
12
  const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
13
13
 
@@ -37,4 +37,4 @@ ReactDOM.render(
37
37
  `;
38
38
  };
39
39
 
40
- module.exports = getCmpPreview;
40
+ module.exports = getCmpPreviewCode;
@@ -7,7 +7,7 @@ const { resolveToCurrentRoot } = require('../utils/pathUtils');
7
7
  * @param {*} cmpName 自定义组件名称
8
8
  * @returns 组件注册文件内容
9
9
  */
10
- const getCmpRegister = (cmpsDir, cmpName) => {
10
+ const getCmpRegisterCode = (cmpsDir, cmpName) => {
11
11
  const cpmIndexDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/index`);
12
12
 
13
13
  /*
@@ -28,4 +28,4 @@ registerNeoCmp(CustomCmp, '${cmpName}');
28
28
  `;
29
29
  };
30
30
 
31
- module.exports = getCmpRegister;
31
+ module.exports = getCmpRegisterCode;
@@ -0,0 +1,11 @@
1
+ const getCmpTypeByDir = require('./getCmpTypeByDir');
2
+ /**
3
+ * 判断当前组件目录是否已经存在该组件类型
4
+ * @param {*} componentsBaseDir 自定义组件目录
5
+ * @param {*} cmpType 组件类型
6
+ * @returns Boolean
7
+ */
8
+ module.exports = (cmpType) => {
9
+ const cmpTypes = getCmpTypeByDir();
10
+ return cmpTypes.includes(cmpType);
11
+ };;
@@ -2,7 +2,7 @@ const fs = require('fs');
2
2
  const akfun = require('akfun');
3
3
  const { consoleTag } = require('../utils/neoParams'); // 输出标记
4
4
  const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
- const getCmpPreview = require('../cmpUtils/getCmpPreview');
5
+ const getCmpPreviewCode = require('../cmpUtils/getCmpPreviewCode'); // 获取自定义组件预览代码
6
6
 
7
7
  /**
8
8
  * 用于预览指定自定义组件的脚本
@@ -35,7 +35,7 @@ module.exports = (config, cmpName, defaultComponentsDir = './src/components') =>
35
35
  fs.mkdirSync(cmpTempDir);
36
36
  }
37
37
 
38
- const cmpPreviewContent = getCmpPreview(cmpsDir, cmpName);
38
+ const cmpPreviewContent = getCmpPreviewCode(cmpsDir, cmpName);
39
39
  fs.writeFileSync(`${cmpTempDir}/preview.jsx`, cmpPreviewContent);
40
40
 
41
41
  // 将临时预览文件添加到预览配置中
@@ -184,13 +184,13 @@ const buildComponentData = async (assetsRoot, cmpInfo) => {
184
184
  * @param {object} config 配置信息
185
185
  * @param {string} assetsRoot 构建产物的目录
186
186
  */
187
- const publishCmp = async (config, cmpType) => {
187
+ const pushCmp = async (config, cmpType) => {
188
188
  const {
189
- authorization: credentials
189
+ authConfig: credentials
190
190
  } = config;
191
191
 
192
192
  if (!credentials) {
193
- console.error('未找到 NeoCRM 平台授权配置(neo.config.js / publishCmpConfig / credentials)。');
193
+ console.error('未找到 NeoCRM 平台授权配置(neo.config.js / pushCmp / authConfig)。');
194
194
  return;
195
195
  }
196
196
 
@@ -229,4 +229,4 @@ const publishCmp = async (config, cmpType) => {
229
229
  }
230
230
  };
231
231
 
232
- module.exports = publishCmp;
232
+ module.exports = pushCmp;
@@ -133,7 +133,7 @@ const defaultNEOConfig = {
133
133
  },
134
134
  assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
135
135
  },
136
- publishCmp: {
136
+ pushCmp: {
137
137
  output: {
138
138
  filename: '[name].js',
139
139
  library: {
@@ -152,6 +152,81 @@ yargs
152
152
  neoConfigInit('neo.config.js');
153
153
  }
154
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
+ )
155
230
  .command(
156
231
  'preview [options]',
157
232
  '预览指定自定义组件(仅预览组件本身内容)',
@@ -159,18 +234,18 @@ yargs
159
234
  yargs
160
235
  .reset()
161
236
  .usage(titleTip('Usage') + ': $0 preview [options]')
162
- .option('cmpType', {
163
- alias: 't',
164
- describe: '自定义组件项目名称'
237
+ .option('name', {
238
+ alias: 'n',
239
+ describe: '自定义组件名称'
165
240
  })
166
241
  .alias('h', 'help');
167
242
  },
168
243
  (argv) => {
169
- if (argv.cmpType) {
170
- mainAction.previewCmp(argv.cmpType);
244
+ if (argv.name) {
245
+ mainAction.previewCmp(argv.name);
171
246
  } else {
172
247
  const cmpTypes = getCmpTypeByDir();
173
- if (!cmpTypes.lenth || cmpTypes.length === 0) {
248
+ if (cmpTypes.length === 0) {
174
249
  console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
175
250
  process.exit(1);
176
251
  }
@@ -255,18 +330,18 @@ yargs
255
330
  yargs
256
331
  .reset()
257
332
  .usage(titleTip('Usage') + ': $0 publish2oss [options]')
258
- .option('cmpType', {
259
- alias: 't',
333
+ .option('name', {
334
+ alias: 'n',
260
335
  describe: '自定义组件名称'
261
336
  })
262
337
  .alias('h', 'help');
263
338
  },
264
339
  (argv) => {
265
- if (argv.cmpType) {
266
- mainAction.publish2oss(argv.cmpType); // 构建并发布脚本到oss
340
+ if (argv.name) {
341
+ mainAction.publish2oss(argv.name); // 构建并发布脚本到oss
267
342
  } else {
268
343
  const cmpTypes = getCmpTypeByDir();
269
- if (!cmpTypes.lenth || cmpTypes.length === 0) {
344
+ if (cmpTypes.length === 0) {
270
345
  console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
271
346
  process.exit(1);
272
347
  }
@@ -293,24 +368,24 @@ yargs
293
368
  }
294
369
  )
295
370
  .command(
296
- 'publishCmp [options]',
371
+ 'pushCmp [options]',
297
372
  '发布组件到 NeoCRM 平台',
298
373
  (yargs) => {
299
374
  yargs
300
375
  .reset()
301
- .usage(titleTip('Usage') + ': $0 publishCmp [options]')
302
- .option('cmpType', {
303
- alias: 't',
376
+ .usage(titleTip('Usage') + ': $0 pushCmp [options]')
377
+ .option('name', {
378
+ alias: 'n',
304
379
  describe: '自定义组件名称'
305
380
  })
306
381
  .alias('h', 'help');
307
382
  },
308
383
  (argv) => {
309
- if (argv.cmpType) {
310
- mainAction.publishCmp(argv.cmpType); // 构建并发布组件到 NeoCRM
384
+ if (argv.name) {
385
+ mainAction.pushCmp(argv.name); // 构建并发布组件到 NeoCRM
311
386
  } else {
312
387
  const cmpTypes = getCmpTypeByDir();
313
- if (!cmpTypes.lenth || cmpTypes.length === 0) {
388
+ if (cmpTypes.length === 0) {
314
389
  console.error('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
315
390
  process.exit(1);
316
391
  }
@@ -331,7 +406,7 @@ yargs
331
406
  console.error('未选择要发布的自定义组件。');
332
407
  process.exit(1);
333
408
  }
334
- mainAction.publishCmp(ans.cmpType);
409
+ mainAction.pushCmp(ans.cmpType);
335
410
  });
336
411
  }
337
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('../projectUtils/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
  };