neo-cmp-cli 1.1.8 → 1.1.9

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 (50) hide show
  1. package/package.json +1 -1
  2. package/src/cmpUtils/createCommonModulesCode.js +61 -0
  3. package/src/cmpUtils/getCmpPreview.js +3 -1
  4. package/src/module/index.js +10 -0
  5. package/src/module/main.js +33 -10
  6. package/src/module/neoInitByCopy.js +8 -0
  7. package/src/neo/neoRequire.js +14 -2
  8. package/src/template/antd-custom-cmp-template/neo.config.js +6 -0
  9. package/src/template/antd-custom-cmp-template/src/components/data-dashboard/model.ts +2 -2
  10. package/src/template/antd-custom-cmp-template/src/components/data-dashboard/style.scss +377 -119
  11. package/src/template/echarts-custom-cmp-template/README.md +91 -0
  12. package/src/template/echarts-custom-cmp-template/neo.config.js +117 -0
  13. package/src/template/echarts-custom-cmp-template/package.json +60 -0
  14. package/src/template/echarts-custom-cmp-template/src/components/chart-widget/README.md +186 -0
  15. package/src/template/echarts-custom-cmp-template/src/components/chart-widget/index.tsx +724 -0
  16. package/src/template/echarts-custom-cmp-template/src/components/chart-widget/model.ts +153 -0
  17. package/src/template/echarts-custom-cmp-template/src/components/chart-widget/style.scss +209 -0
  18. package/src/template/neo-custom-cmp-template/.prettierrc.js +12 -0
  19. package/src/template/neo-custom-cmp-template/commitlint.config.js +59 -0
  20. package/src/template/{echart-custom-cmp-template → neo-custom-cmp-template}/package.json +7 -5
  21. package/src/template/neo-custom-cmp-template/public/css/base.css +283 -0
  22. package/src/template/neo-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
  23. package/src/template/neo-custom-cmp-template/public/template.html +13 -0
  24. package/src/template/neo-custom-cmp-template/src/assets/css/common.scss +127 -0
  25. package/src/template/neo-custom-cmp-template/src/assets/css/mixin.scss +47 -0
  26. package/src/template/neo-custom-cmp-template/src/components/info-card/index.tsx +69 -0
  27. package/src/template/neo-custom-cmp-template/src/components/info-card/model.ts +78 -0
  28. package/src/template/neo-custom-cmp-template/src/components/info-card/style.scss +105 -0
  29. package/src/template/neo-custom-cmp-template/src/components/neo-entity-grid/README.md +128 -0
  30. package/src/template/neo-custom-cmp-template/src/components/neo-entity-grid/index.tsx +295 -0
  31. package/src/template/neo-custom-cmp-template/src/components/neo-entity-grid/model.ts +94 -0
  32. package/src/template/neo-custom-cmp-template/src/components/neo-entity-grid/style.scss +127 -0
  33. package/src/template/neo-custom-cmp-template/tsconfig.json +68 -0
  34. package/src/template/echart-custom-cmp-template/src/components/list-widget/README.md +0 -2
  35. package/src/template/echart-custom-cmp-template/src/components/list-widget/index.tsx +0 -208
  36. package/src/template/echart-custom-cmp-template/src/components/list-widget/model.ts +0 -90
  37. package/src/template/echart-custom-cmp-template/src/components/list-widget/style.scss +0 -350
  38. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/.prettierrc.js +0 -0
  39. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/commitlint.config.js +0 -0
  40. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/public/css/base.css +0 -0
  41. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/public/scripts/app/bluebird.js +0 -0
  42. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/public/template.html +0 -0
  43. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/src/assets/css/common.scss +0 -0
  44. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/src/assets/css/mixin.scss +0 -0
  45. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/src/components/info-card/index.tsx +0 -0
  46. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/src/components/info-card/model.ts +0 -0
  47. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/src/components/info-card/style.scss +0 -0
  48. /package/src/template/{echart-custom-cmp-template → echarts-custom-cmp-template}/tsconfig.json +0 -0
  49. /package/src/template/{echart-custom-cmp-template → neo-custom-cmp-template}/README.md +0 -0
  50. /package/src/template/{echart-custom-cmp-template → neo-custom-cmp-template}/neo.config.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -0,0 +1,61 @@
1
+ const fs = require('fs');
2
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
3
+ const { isPlainObject } = require('lodash');
4
+
5
+ /**
6
+ * 获取组件预览代码
7
+ * @param {*} cmpsDir 自定义组件目录
8
+ * @param {*} cmpName 自定义组件名称
9
+ * @returns 组件预览代码
10
+ */
11
+ const createCommonModulesCode = (neoExports) => {
12
+ if (!neoExports) {
13
+ return '';
14
+ }
15
+ const CustomCmpCommonModules = {};
16
+
17
+ // 根据 neoExports 获取共享的依赖模块
18
+ if (Array.isArray(neoExports) && neoExports.length > 0) {
19
+ neoExports.forEach(module => {
20
+ CustomCmpCommonModules[module] = require(module);
21
+ });
22
+ } else if (isPlainObject(neoExports)) {
23
+ CustomCmpCommonModules = Object.assign(CustomCmpCommonModules, neoExports);
24
+ } else {
25
+ console.error('neoExports 格式不正确,请检查 neo.config.js 文件中的 neoCommonModule / neoExports 配置');
26
+ process.exit(1);
27
+ return '';
28
+ }
29
+
30
+ const commonModulesCode = `
31
+ /**
32
+ * 自定义组件 共享出来的依赖模块
33
+ * 备注:可在其他模块中通过 neoRequire 中使用
34
+ */
35
+ const CustomCmpCommonModules = ${JSON.stringify(CustomCmpCommonModules)};
36
+
37
+ // 用于添加共享的依赖模块
38
+ const addNeoCommonModules = (modules) => {
39
+ if (!window.__NeoCommonModules) {
40
+ window.__NeoCommonModules = {};
41
+ }
42
+ window.__NeoCommonModules = Object.assign(window.__NeoCommonModules, modules);
43
+ };
44
+
45
+ addNeoCommonModules(CustomCmpCommonModules);
46
+ `;
47
+
48
+ // 创建存放 cli 的临时目录
49
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
50
+ if (!fs.existsSync(cliTempDir)) {
51
+ fs.mkdirSync(cliTempDir);
52
+ }
53
+
54
+ // 将 commonModulesCode 写入到临时目录中
55
+ const commonModulesFilePath = `${cliTempDir}/commonModules.js`;
56
+ fs.writeFileSync(commonModulesFilePath, commonModulesCode);
57
+
58
+ return commonModulesFilePath;
59
+ };
60
+
61
+ module.exports = createCommonModulesCode;
@@ -35,13 +35,15 @@ import CustomCmpModel from '${cpmModelDir}';
35
35
 
36
36
  // 获取组件模型中的默认属性
37
37
  const curDefaultComProps = new CustomCmpModel().defaultComProps;
38
+ const previewComProps = new CustomCmpModel().previewComProps;
39
+ const curPreviewComProps = Object.assign(curDefaultComProps, previewComProps);
38
40
 
39
41
  /* 引入公共的静态资源 */
40
42
  import '$public/css/base.css';
41
43
 
42
44
  // 预览 自定义组件
43
45
  ReactDOM.render(
44
- <CustomCmp {...curDefaultComProps} />,
46
+ <CustomCmp {...curPreviewComProps} />,
45
47
  document.getElementById('root'),
46
48
  );
47
49
  `;
@@ -71,6 +71,16 @@ yargs
71
71
  value: 'antd',
72
72
  short: 'antd'
73
73
  },
74
+ {
75
+ name: 'echarts 自定义组件',
76
+ value: 'echarts',
77
+ short: 'echarts'
78
+ },
79
+ {
80
+ name: 'Neo 自定义组件',
81
+ value: 'neo',
82
+ short: 'neo'
83
+ },
74
84
  {
75
85
  name: 'react 自定义组件',
76
86
  value: 'react',
@@ -14,11 +14,18 @@ const previewCmp = require('./previewCmp');
14
14
  const AddNeoRequirePlugin = require('../plugins/AddNeoRequirePlugin');
15
15
  const { getExternalsByNeoCommonModules } = require('../neo/neoRequire');
16
16
  // const { MFPlugins } = require('../utils/webpack.mf');
17
+ const createCommonModulesCode = require('../cmpUtils/createCommonModulesCode');
17
18
 
18
19
  const getValue = (originValue, defaultValue) => {
19
20
  return originValue !== undefined ? originValue : defaultValue;
20
21
  };
21
22
 
23
+ const neoCommonModule = curConfig.neoCommonModule || {};
24
+ // 自定义组件 共享出来的依赖模块
25
+ const cmpNeoExports = neoCommonModule.neoExports || [];
26
+ // 自定义组件 需要剔除的依赖模块
27
+ const cmpNeoExternals = neoCommonModule.neoExternals || [];
28
+
22
29
  module.exports = {
23
30
  neoInit,
24
31
  neoInitByCopy,
@@ -111,16 +118,24 @@ module.exports = {
111
118
  }
112
119
 
113
120
  // 添加 内置 Neo 的 externals 配置
114
- const neoExternals = getExternalsByNeoCommonModules();
115
- if (
116
- curConfig.dev.externals &&
117
- _.isPlainObject(curConfig.dev.externals)
118
- ) {
121
+ const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
122
+ if (curConfig.dev.externals && _.isPlainObject(curConfig.dev.externals)) {
119
123
  curConfig.dev.externals = Object.assign(curConfig.dev.externals, neoExternals);
120
124
  } else {
121
125
  curConfig.dev.externals = neoExternals;
122
126
  }
123
127
 
128
+ if (cmpNeoExports && Array.isArray(cmpNeoExports) && cmpNeoExports.length > 0) {
129
+ const commonModulesFilePath = createCommonModulesCode(cmpNeoExports);
130
+
131
+ // 所有入口文件添加 commonModulesFile
132
+ if (curConfig.dev.entry) {
133
+ Object.keys(curConfig.dev.entry).forEach((name) => {
134
+ webpackDevConfig.entry[name] = [commonModulesFilePath].concat(webpackDevConfig.entry[name]);
135
+ });
136
+ }
137
+ }
138
+
124
139
  akfun.dev(curConfig, consoleTag);
125
140
  },
126
141
  build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
@@ -214,16 +229,24 @@ module.exports = {
214
229
  }
215
230
 
216
231
  // 添加 内置 Neo 的 externals 配置
217
- const neoExternals = getExternalsByNeoCommonModules();
218
- if (
219
- curConfig.build2lib.externals &&
220
- _.isPlainObject(curConfig.dev.externals)
221
- ) {
232
+ const neoExternals = getExternalsByNeoCommonModules(cmpNeoExternals);
233
+ if (curConfig.build2lib.externals && _.isPlainObject(curConfig.dev.externals)) {
222
234
  curConfig.build2lib.externals = Object.assign(curConfig.build2lib.externals, neoExternals);
223
235
  } else {
224
236
  curConfig.build2lib.externals = neoExternals;
225
237
  }
226
238
 
239
+ if (cmpNeoExports && Array.isArray(cmpNeoExports) && cmpNeoExports.length > 0) {
240
+ const commonModulesFilePath = createCommonModulesCode(cmpNeoExports);
241
+
242
+ // 所有入口文件添加 commonModulesFile
243
+ if (curConfig.dev.entry) {
244
+ Object.keys(curConfig.dev.entry).forEach((name) => {
245
+ webpackDevConfig.entry[name] = [commonModulesFilePath].concat(webpackDevConfig.entry[name]);
246
+ });
247
+ }
248
+ }
249
+
227
250
  akfun.build('lib', curConfig, consoleTag, () => {
228
251
  // 构建完成后,执行 publish2oss
229
252
  publish2oss(
@@ -16,6 +16,14 @@ const templateList = {
16
16
  projectName: 'antd-custom-cmp-template',
17
17
  dir: path.resolve(__dirname, '../template/antd-custom-cmp-template')
18
18
  },
19
+ echarts: {
20
+ projectName: 'echarts-custom-cmp-template',
21
+ dir: path.resolve(__dirname, '../template/echarts-custom-cmp-template')
22
+ },
23
+ 'neo': {
24
+ projectName: 'neo-custom-cmp-template',
25
+ dir: path.resolve(__dirname, '../template/neo-custom-cmp-template')
26
+ },
19
27
  vue2: {
20
28
  projectName: 'vue2-custom-cmp-template',
21
29
  dir: path.resolve(__dirname, '../template/vue2-custom-cmp-template')
@@ -1,3 +1,5 @@
1
+ const _ = require('lodash');
2
+
1
3
  // Neo 共享出来的依赖模块
2
4
  const NeoCommonModules = {
3
5
  react: '^16.13.1',
@@ -13,15 +15,25 @@ const NeoCommonModules = {
13
15
  axios: '^0.27.2',
14
16
  classnames: '^2.3.2',
15
17
  qs: '^6.11.0',
16
- lodash: '^4.17.21'
18
+ lodash: '^4.17.21',
19
+ 'neo-ui-component-web': '^1.0.0',
20
+ 'neo-ui-common': '^1.0.0'
17
21
  };
18
22
 
19
23
  // 根据 Neo 共享出来的依赖模块,获取 externals 配置
20
- const getExternalsByNeoCommonModules = () => {
24
+ const getExternalsByNeoCommonModules = (cmpNeoExternals) => {
21
25
  const neoExternals = {};
22
26
  Object.keys(NeoCommonModules).forEach(moduleName => {
23
27
  neoExternals[moduleName] = `commonjs ${moduleName}`;
24
28
  });
29
+
30
+ // 如果自定义组件有共享的依赖模块,则合并到 neoExternals 中
31
+ if (cmpNeoExternals && _.isPlainObject(cmpNeoExternals) && Object.keys(cmpNeoExternals).length > 0) {
32
+ Object.keys(cmpNeoExternals).forEach(moduleName => {
33
+ neoExternals[moduleName] = `commonjs ${moduleName}`;
34
+ });
35
+ }
36
+
25
37
  return neoExternals;
26
38
  };
27
39
 
@@ -38,6 +38,12 @@ module.exports = {
38
38
  // plugins: [],
39
39
  // babelPlugins: [],
40
40
  },
41
+ // Neo 共享依赖模块
42
+ neoCommonModule: {
43
+ // neoExports: ['echarts'], // 自定义组件 共享出来的模块,支持数组和对象
44
+ // neoExports: {},
45
+ neoExternals: ['neo-register'], // 自定义组件 需要剔除的模块,仅支持数组写法
46
+ },
41
47
  preview: {
42
48
  // 用于开启本地预览模式的相关配置信息
43
49
  /*
@@ -54,8 +54,8 @@ export class DataDashboardModel {
54
54
  options: [
55
55
  { label: '渐变主题', value: 'gradient' },
56
56
  { label: '深色主题', value: 'dark' },
57
- { label: '浅色主题', value: 'light' }
58
- ]
57
+ { label: '浅色主题', value: 'light' },
58
+ ],
59
59
  },
60
60
  {
61
61
  type: 'switch',