neo-cmp-cli 1.0.18 → 1.1.0

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 (33) hide show
  1. package/package.json +1 -1
  2. package/src/cmpUtils/getCmpModelRegister.js +31 -0
  3. package/src/cmpUtils/getCmpPreview.js +48 -0
  4. package/src/cmpUtils/getCmpRegister.js +31 -0
  5. package/src/{utils → cmpUtils}/getEntries.js +25 -13
  6. package/src/cmpUtils/getEntriesWithAutoRegister.js +95 -0
  7. package/src/initData/neo.config.js +14 -14
  8. package/src/module/index.js +8 -6
  9. package/src/module/main.js +48 -8
  10. package/src/module/neoInit.js +5 -0
  11. package/src/module/neoInitByCopy.js +5 -0
  12. package/src/module/previewCmp.js +16 -21
  13. package/src/oss/publish2oss.js +5 -1
  14. package/src/template/react-custom-cmp-template/README.md +4 -4
  15. package/src/template/react-custom-cmp-template/package.json +3 -3
  16. package/src/template/react-custom-cmp-template/src/components/info-card/model.js +5 -7
  17. package/src/template/react-ts-custom-cmp-template/README.md +5 -5
  18. package/src/template/react-ts-custom-cmp-template/neo.config.js +7 -3
  19. package/src/template/react-ts-custom-cmp-template/package.json +3 -3
  20. package/src/template/react-ts-custom-cmp-template/src/components/info-card/model.ts +5 -7
  21. package/src/template/react-ts-custom-cmp-template/src/components/list-widget/model.ts +5 -7
  22. package/src/template/vue2-custom-cmp-template/README.md +4 -4
  23. package/src/template/vue2-custom-cmp-template/neo.config.js +4 -4
  24. package/src/template/vue2-custom-cmp-template/package.json +4 -5
  25. package/src/template/vue2-custom-cmp-template/src/{widgets/info-card → components/vue-info-card}/model.js +5 -7
  26. package/src/utils/webpack.mf.js +1 -1
  27. package/test/demo.js +7 -2
  28. package/src/template/react-custom-cmp-template/src/components/info-card/register.js +0 -4
  29. package/src/template/react-ts-custom-cmp-template/src/components/info-card/register.ts +0 -5
  30. package/src/template/react-ts-custom-cmp-template/src/components/list-widget/register.ts +0 -5
  31. package/src/template/vue2-custom-cmp-template/src/widgets/info-card/register.js +0 -8
  32. package/src/utils/getCmpPreview.js +0 -26
  33. /package/src/template/vue2-custom-cmp-template/src/{widgets/info-card → components/vue-info-card}/index.vue +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.0.18",
3
+ "version": "1.1.0",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
3
+
4
+ /**
5
+ * 获取组件注册文件内容
6
+ * @param {*} cmpsDir 自定义组件目录
7
+ * @param {*} cmpName 自定义组件名称
8
+ * @returns 组件注册文件内容
9
+ */
10
+ const getCmpModelRegister = (cmpsDir, cmpName) => {
11
+ const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
12
+
13
+ /*
14
+ if (!fs.existsSync(cpmModelDir)) {
15
+ console.error(`未找到 ${cmpName} 组件模型文件,请检查 ${cpmModelDir} 是否存在。`);
16
+
17
+ // 退出进程
18
+ process.exit(1);
19
+ }
20
+ */
21
+
22
+ return `
23
+ // @ts-ignore
24
+ import { registerNeoEditorModel } from 'neo-register';
25
+ import CustomCmpModel from '${cpmModelDir}';
26
+
27
+ registerNeoEditorModel(CustomCmpModel, '${cmpName}');
28
+ `;
29
+ };
30
+
31
+ module.exports = getCmpModelRegister;
@@ -0,0 +1,48 @@
1
+ const fs = require('fs');
2
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
3
+
4
+ /**
5
+ * 获取组件预览代码
6
+ * @param {*} cmpsDir 自定义组件目录
7
+ * @param {*} cmpName 自定义组件名称
8
+ * @returns 组件预览代码
9
+ */
10
+ const getCmpPreview = (cmpsDir, cmpName) => {
11
+ const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
12
+ const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
13
+
14
+ if (!fs.existsSync(cpmDir)) {
15
+ console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmDir} 是否存在。`);
16
+
17
+ // 退出进程
18
+ process.exit(1);
19
+ }
20
+
21
+ if (!fs.existsSync(cpmModelDir)) {
22
+ console.error(`未找到 ${cmpName} 组件模型文件,请检查 ${cpmModelDir} 是否存在。`);
23
+
24
+ // 退出进程
25
+ process.exit(1);
26
+ }
27
+
28
+ return `
29
+ import * as React from 'react';
30
+ import ReactDOM from 'react-dom';
31
+ import CustomCmp from '${cpmDir}';
32
+ import CustomCmpModel from '${cpmModelDir}';
33
+
34
+ // 获取组件模型中的默认属性
35
+ const curDefaultComProps = new CustomCmpModel().defaultComProps;
36
+
37
+ /* 引入公共的静态资源 */
38
+ import '$public/css/base.css';
39
+
40
+ // 预览 自定义组件
41
+ ReactDOM.render(
42
+ <CustomCmp {...curDefaultComProps} />,
43
+ document.getElementById('root'),
44
+ );
45
+ `;
46
+ };
47
+
48
+ module.exports = getCmpPreview;
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
3
+
4
+ /**
5
+ * 获取组件注册文件内容
6
+ * @param {*} cmpsDir 自定义组件目录
7
+ * @param {*} cmpName 自定义组件名称
8
+ * @returns 组件注册文件内容
9
+ */
10
+ const getCmpRegister = (cmpsDir, cmpName) => {
11
+ const cpmIndexDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/index`);
12
+
13
+ /*
14
+ if (!fs.existsSync(cpmIndexDir)) {
15
+ console.error(`未找到 ${cmpName} 组件入口文件,请检查 ${cpmIndexDir} 是否存在。`);
16
+
17
+ // 退出进程
18
+ process.exit(1);
19
+ }
20
+ */
21
+
22
+ return `
23
+ // @ts-ignore
24
+ import { registerNeoCmp } from 'neo-register';
25
+ import CustomCmp from '${cpmIndexDir}';
26
+
27
+ registerNeoCmp(CustomCmp, '${cmpName}');
28
+ `;
29
+ };
30
+
31
+ module.exports = getCmpRegister;
@@ -1,42 +1,51 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const _ = require('lodash');
4
- const { resolveToCurrentRoot } = require('./pathUtils');
4
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
5
 
6
+ /**
7
+ * 从指定目录获取组件入口文件
8
+ * @param {*} buildType 构建类型
9
+ * @param {*} defaultComponentsDir 默认组件目录
10
+ * @returns 组件入口文件
11
+ */
6
12
  module.exports = (buildType = 'build2lib', defaultComponentsDir = './src/components') => {
7
13
  const widgetEntries = {};
8
14
  const linkDebugEntries = {
9
15
  index: []
10
16
  };
11
- const componentsDir = resolveToCurrentRoot(defaultComponentsDir);
12
- if (!fs.existsSync(componentsDir)) {
17
+ const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
18
+ if (!fs.existsSync(componentsBaseDir)) {
13
19
  console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
14
- return widgetEntries;
20
+
21
+ // 退出进程
22
+ process.exit(1);
15
23
  }
16
24
 
17
25
  try {
18
26
  // 读取指定目录下的所有文件
19
- const widgetDirs = fs.readdirSync(componentsDir);
27
+ const widgetDirs = fs.readdirSync(componentsBaseDir);
20
28
 
21
29
  // 遍历所有目录
22
30
  widgetDirs.forEach((dir) => {
23
- const filePath = path.join(componentsDir, dir);
31
+ const filePath = path.join(componentsBaseDir, dir);
24
32
  // 获取文件状态
25
33
  const stat = fs.statSync(filePath);
26
34
  // 如果文件是目录,则递归处理子目录
27
35
  if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
28
- const widgetPath = path.join(defaultComponentsDir, dir);
29
- const curWidgetName = _.camelCase(dir);
36
+ const curCmpPath = path.join(componentsBaseDir, dir);
37
+ const curCmpName = dir; // _.camelCase(dir);
30
38
 
31
- fs.readdirSync(widgetPath)
39
+ fs.readdirSync(curCmpPath)
32
40
  .filter((file) => file.match(/[register|model]\.[tj]sx?$/))
33
- .map((file) => path.join(widgetPath, file))
41
+ .map((file) => path.join(defaultComponentsDir, curCmpName, file))
34
42
  .forEach((filePath) => {
43
+ console.log(filePath);
35
44
  const curPath = `./${filePath}`;
36
45
  if (filePath.match(/register\.[tj]sx?$/)) {
37
- widgetEntries[curWidgetName] = curPath;
46
+ widgetEntries[curCmpName] = curPath;
38
47
  } else if (filePath.match(/model\.[tj]sx?$/)) {
39
- widgetEntries[`${curWidgetName}Model`] = curPath;
48
+ widgetEntries[`${curCmpName}Model`] = curPath;
40
49
  }
41
50
  linkDebugEntries.index.push(curPath);
42
51
  });
@@ -47,7 +56,10 @@ module.exports = (buildType = 'build2lib', defaultComponentsDir = './src/compone
47
56
  return linkDebugEntries;
48
57
  }
49
58
  } catch (error) {
50
- console.error('replaceInFiles 运行失败:', error);
59
+ console.error('获取自定义组件入口文件失败(getEntries):', error);
60
+
61
+ // 退出进程
62
+ process.exit(1);
51
63
  }
52
64
 
53
65
  return widgetEntries;
@@ -0,0 +1,95 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const _ = require('lodash');
4
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
+ const getCmpRegister = require('./getCmpRegister');
6
+ const getCmpModelRegister = require('./getCmpModelRegister');
7
+ /**
8
+ * 从指定目录获取组件入口文件,并自动创建对应的注册文件
9
+ * @param {*} buildType 构建类型
10
+ * @param {*} defaultComponentsDir 默认组件目录
11
+ * @returns 组件入口文件
12
+ */
13
+ module.exports = (buildType = 'build2lib', defaultComponentsDir = './src/components') => {
14
+ const widgetEntries = {};
15
+ const linkDebugEntries = {
16
+ index: []
17
+ };
18
+ const componentsBaseDir = resolveToCurrentRoot(defaultComponentsDir);
19
+ if (!fs.existsSync(componentsBaseDir)) {
20
+ console.error(`未找到组件目录,请检查 ${defaultComponentsDir} 目录是否存在`);
21
+
22
+ // 退出进程
23
+ process.exit(1);
24
+ }
25
+
26
+ // 创建存放 cli 的临时目录
27
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
28
+ if (!fs.existsSync(cliTempDir)) {
29
+ fs.mkdirSync(cliTempDir);
30
+ }
31
+
32
+ try {
33
+ // 读取指定目录下的所有文件
34
+ const widgetDirs = fs.readdirSync(componentsBaseDir);
35
+
36
+ // 遍历所有目录
37
+ widgetDirs.forEach((dir) => {
38
+ const filePath = path.join(componentsBaseDir, dir);
39
+ // 获取文件状态
40
+ const stat = fs.statSync(filePath);
41
+ // 如果文件是目录,则递归处理子目录
42
+ if (stat.isDirectory() && !dir.startsWith('.') && dir !== 'node_modules') {
43
+ // 当前自定义组件目录
44
+ const widgetPath = path.join(componentsBaseDir, dir);
45
+
46
+ // 当前自定义组件名称
47
+ const curCmpName = dir; // _.camelCase(dir);
48
+
49
+ // 当前自定义组件临时目录
50
+ const cmpTempDir = `${cliTempDir}/${curCmpName}`;
51
+ if (!fs.existsSync(cmpTempDir)) {
52
+ fs.mkdirSync(cmpTempDir);
53
+ }
54
+
55
+ fs.readdirSync(widgetPath)
56
+ .filter((file) => file.match(/[index|model]\.[tj]sx?$/))
57
+ .map((file) => path.join(defaultComponentsDir, curCmpName, file))
58
+ .forEach((filePath) => {
59
+ if (filePath.match(/index\.[tj]sx?$/)) {
60
+ // 自动创建对应的注册文件
61
+ const registerContent = getCmpRegister(componentsBaseDir, curCmpName);
62
+ const registerDir = `${cmpTempDir}/register.js`;
63
+
64
+ // 写入注册文件
65
+ fs.writeFileSync(registerDir, registerContent);
66
+
67
+ widgetEntries[curCmpName] = registerDir;
68
+ linkDebugEntries.index.push(registerDir);
69
+ } else if (filePath.match(/model\.[tj]sx?$/)) {
70
+ // 自动创建对应的模型注册文件
71
+ const modelRegisterContent = getCmpModelRegister(componentsBaseDir, curCmpName);
72
+ const modelRegisterDir = `${cmpTempDir}/model.js`;
73
+
74
+ // 写入模型注册文件
75
+ fs.writeFileSync(modelRegisterDir, modelRegisterContent);
76
+
77
+ widgetEntries[`${curCmpName}Model`] = modelRegisterDir;
78
+ linkDebugEntries.index.push(modelRegisterDir);
79
+ }
80
+ });
81
+ }
82
+ });
83
+
84
+ if (buildType === 'linkDebug') {
85
+ return linkDebugEntries;
86
+ }
87
+ } catch (error) {
88
+ console.error('获取自定义组件入口文件失败(getEntriesWithAutoRegister):', error);
89
+
90
+ // 退出进程
91
+ process.exit(1);
92
+ }
93
+
94
+ return widgetEntries;
95
+ };
@@ -12,7 +12,7 @@ module.exports = {
12
12
  enableESLint: true, // 调试模式是否开启ESLint,默认开启ESLint检测代码格式
13
13
  enableESLintFix: true, // 是否自动修正代码格式,默认不自动修正
14
14
  enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
15
- enableStyleLintFix: false, // 是否需要StyleLint自动修正代码格式
15
+ enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
16
16
  },
17
17
  webpack: {
18
18
  target: ['web', 'es5'], // 指定目标环境为 web 和 es5,确保兼容性
@@ -22,30 +22,30 @@ module.exports = {
22
22
  alias: {
23
23
  '@': resolve('src'),
24
24
  $assets: resolve('src/assets'),
25
- $public: resolve('public'),
26
- },
25
+ $public: resolve('public')
26
+ }
27
27
  },
28
28
  // sassResources中的sass文件会自动注入每一个sass文件中
29
29
  sassResources: [
30
30
  resolve('./src/assets/css/common.scss'),
31
- resolve('./src/assets/css/mixin.scss'),
31
+ resolve('./src/assets/css/mixin.scss')
32
32
  ],
33
33
  // createDeclaration: true, // 打包时是否创建ts声明文件
34
34
  ignoreNodeModules: false, // 打包时是否忽略 node_modules
35
35
  allowList: [], // ignoreNodeModules为true时生效
36
- projectDir: ['src'],
36
+ projectDir: ['src']
37
37
  // template: resolve('./public/template.html'), // 自定义html模板
38
- plugins: [],
39
- babelPlugins: [],
38
+ // plugins: [],
39
+ // babelPlugins: [],
40
40
  },
41
41
  preview: {
42
42
  // 用于开启本地预览模式的相关配置信息
43
- entry: {
44
- // 本地预览自定义组件内容
45
- index: './src/preview.tsx',
46
- },
47
43
  /*
48
44
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
45
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
46
+ // 本地预览自定义组件内容
47
+ index: './src/preview.jsx',
48
+ },
49
49
  NODE_ENV: 'development',
50
50
  port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
51
51
  assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
@@ -64,7 +64,7 @@ module.exports = {
64
64
  // 用于开启本地调试模式的相关配置信息
65
65
  /*
66
66
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
67
- entry: { // entry 会根据 src/components 目录下的文件自动生成
67
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
68
68
  // 外链调试(在线上页面设计器端预览自定义组件)
69
69
  index: [
70
70
  './src/components/info-card/register.ts',
@@ -90,7 +90,7 @@ module.exports = {
90
90
  /*
91
91
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
92
92
  NODE_ENV: 'production',
93
- entry: { // entry 未配置时,cli 会根据 src/components 目录下的文件自动生成对应的 entry
93
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
94
94
  InfoCardModel: './src/components/info-card/model.ts',
95
95
  infoCard: './src/components/info-card/register.ts'
96
96
  },
@@ -104,5 +104,5 @@ module.exports = {
104
104
  },
105
105
  assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
106
106
  */
107
- },
107
+ }
108
108
  };
@@ -150,12 +150,14 @@ yargs
150
150
  if (argv.cmpType) {
151
151
  mainAction.previewCmp(argv.cmpType);
152
152
  } else {
153
- const questions = [{
154
- name: 'cmpType',
155
- type: 'input',
156
- message: '请输入要预览的自定义组件名称(默认 info-card):',
157
- default: 'info-card'
158
- }];
153
+ const questions = [
154
+ {
155
+ name: 'cmpType',
156
+ type: 'input',
157
+ message: '请输入要预览的自定义组件名称(默认 info-card):',
158
+ default: 'info-card'
159
+ }
160
+ ];
159
161
  inquirer.prompt(questions).then((ans) => {
160
162
  mainAction.previewCmp(ans.cmpType);
161
163
  });
@@ -7,7 +7,8 @@ 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 getEntries = require('../utils/getEntries');
10
+ const getEntries = require('../cmpUtils/getEntries');
11
+ const getEntriesWithAutoRegister = require('../cmpUtils/getEntriesWithAutoRegister');
11
12
  const previewCmp = require('./previewCmp');
12
13
  // const { MFPlugins } = require('../utils/webpack.mf');
13
14
 
@@ -64,12 +65,25 @@ module.exports = {
64
65
 
65
66
  if (!curEntry || Object.keys(curEntry).length === 0) {
66
67
  // 如果未配置 entry,则自动生成 entry
67
- const entries = getEntries('linkDebug', curConfig.componentsDir);
68
+ let entries = {};
69
+ if (curConfig.linkDebug.disableAutoRegister) {
70
+ // disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
71
+ entries = getEntries('linkDebug', curConfig.componentsDir);
72
+ } else {
73
+ // 自动生成入口文件(并自动创建对应的注册文件)
74
+ entries = getEntriesWithAutoRegister('linkDebug', curConfig.componentsDir);
75
+ }
76
+
77
+ // 注入 webpack/entry
68
78
  if (entries && Object.keys(entries).length > 0) {
69
79
  curConfig.dev.entry = entries;
70
80
  console.info('已自动生成 entry 入口配置:', entries);
71
81
  } else {
72
- console.error('未找到自定义组件,请检查 neo.config.js 中的 linkDebug / entry 配置。');
82
+ console.error(
83
+ `未识别到自定义组件,请检查 ${
84
+ curConfig.componentsDir || './src/components'
85
+ } 目录下是否存在自定义组件。`
86
+ );
73
87
  process.exit(1);
74
88
  }
75
89
  }
@@ -78,7 +92,7 @@ module.exports = {
78
92
  // 说明:自定义组件和平台模块联邦使用异常,所以暂时注释掉
79
93
  // 添加模块联邦插件
80
94
  if (curConfig.dev.enableMF) {
81
- curConfig.webpack.plugins.push(...MFPlugins);
95
+ curConfig.webpack.plugins.push(...MFPlugins);
82
96
  }
83
97
  */
84
98
 
@@ -90,12 +104,25 @@ module.exports = {
90
104
 
91
105
  if (!curEntry || Object.keys(curEntry).length === 0) {
92
106
  // 如果未配置 entry,则自动生成 entry
93
- const entries = getEntries('build2lib', curConfig.componentsDir);
107
+ let entries = {};
108
+ if (curConfig.build2lib.disableAutoRegister) {
109
+ // disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
110
+ entries = getEntries('build2lib', curConfig.componentsDir);
111
+ } else {
112
+ // 自动生成入口文件(并自动创建对应的注册文件)
113
+ entries = getEntriesWithAutoRegister('build2lib', curConfig.componentsDir);
114
+ }
115
+
116
+ // 注入 webpack/entry
94
117
  if (entries && Object.keys(entries).length > 0) {
95
118
  curConfig.build2lib.entry = entries;
96
119
  console.info('已自动生成 entry 入口配置:', entries);
97
120
  } else {
98
- console.error('未找到自定义组件,请检查 neo.config.js 中的 build2lib / entry 配置。');
121
+ console.error(
122
+ `未识别到自定义组件,请检查 ${
123
+ curConfig.componentsDir || './src/components'
124
+ } 目录下是否存在自定义组件。`
125
+ );
99
126
  process.exit(1);
100
127
  }
101
128
  }
@@ -119,12 +146,25 @@ module.exports = {
119
146
 
120
147
  if (!curEntry || Object.keys(curEntry).length === 0) {
121
148
  // 如果未配置 entry,则自动生成 entry
122
- const entries = getEntries('build2lib', curConfig.componentsDir);
149
+ let entries = {};
150
+ if (curConfig.build2lib.disableAutoRegister) {
151
+ // disableAutoRegister 为 true 时,仅自动生成入口文件(不自动注册)
152
+ entries = getEntries('build2lib', curConfig.componentsDir);
153
+ } else {
154
+ // 自动生成入口文件(并自动创建对应的注册文件)
155
+ entries = getEntriesWithAutoRegister('build2lib', curConfig.componentsDir);
156
+ }
157
+
158
+ // 注入 webpack/entry
123
159
  if (entries && Object.keys(entries).length > 0) {
124
160
  curConfig.build2lib.entry = entries;
125
161
  console.info('已自动生成 entry 入口配置:', entries);
126
162
  } else {
127
- console.error('未找到自定义组件,请检查 neo.config.js 中的 publish2oss / entry 配置。');
163
+ console.error(
164
+ `未识别到自定义组件,请检查 ${
165
+ curConfig.componentsDir || './src/components'
166
+ } 目录下是否存在自定义组件。`
167
+ );
128
168
  process.exit(1);
129
169
  }
130
170
  }
@@ -23,6 +23,11 @@ const templateList = {
23
23
  */
24
24
  };
25
25
 
26
+ /**
27
+ * 通过 git clone 从 github 拉取并创建自定义组件
28
+ * @param {*} type 自定义组件类型
29
+ * @param {*} projectName 自定义组件项目名称
30
+ */
26
31
  const neoInit = function (type, projectName) {
27
32
  const currentTemplate = templateList[type || 'react'];
28
33
  const currentTemplateUrl = currentTemplate.url;
@@ -18,6 +18,11 @@ const templateList = {
18
18
  }
19
19
  };
20
20
 
21
+ /**
22
+ * 通过拷贝模板创建自定义组件
23
+ * @param {*} type 自定义组件类型
24
+ * @param {*} projectName 自定义组件项目名称
25
+ */
21
26
  const neoInitByCopy = function (type, projectName) {
22
27
  const currentTemplate = templateList[type || 'react'];
23
28
  const currentTemplateDir = currentTemplate.dir;
@@ -1,17 +1,11 @@
1
- const path = require('path');
2
1
  const fs = require('fs');
3
2
  const akfun = require('akfun');
4
3
  const { consoleTag } = require('../utils/neoParams'); // 输出标记
5
- const { resolveToCurrentRoot, catchCurPackageJson } = require('../utils/pathUtils');
6
- const getConfigObj = require('../utils/getConfigObj');
7
- const getCmpPreview = require('../utils/getCmpPreview');
8
-
9
- // 获取当前项目的package文件
10
- const currentPackageJsonDir = catchCurPackageJson();
11
- const currentPackageJson = getConfigObj(currentPackageJsonDir);
4
+ const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
+ const getCmpPreview = require('../cmpUtils/getCmpPreview');
12
6
 
13
7
  /**
14
- * 用于预览指定自定义组件
8
+ * 用于预览指定自定义组件的脚本
15
9
  */
16
10
  module.exports = (config, cmpName, defaultComponentsDir = './src/components') => {
17
11
  const cmpsDir = config.componentsDir || defaultComponentsDir;
@@ -29,31 +23,32 @@ module.exports = (config, cmpName, defaultComponentsDir = './src/components') =>
29
23
  process.exit(1);
30
24
  }
31
25
 
32
- // 创建存放预览文件的临时目录
33
- const tempDir = resolveToCurrentRoot('./.neo-cli');
34
-
35
- if (!fs.existsSync(tempDir)) {
36
- fs.mkdirSync(tempDir);
26
+ // 创建 cli 的临时目录
27
+ const cliTempDir = resolveToCurrentRoot('./.neo-cli');
28
+ if (!fs.existsSync(cliTempDir)) {
29
+ fs.mkdirSync(cliTempDir);
37
30
  }
38
- const tempCmpDir = `${tempDir}/${currentPackageJson.name}`;
39
- if (!fs.existsSync(tempCmpDir)) {
40
- fs.mkdirSync(tempCmpDir);
31
+
32
+ // 当前自定义组件临时目录
33
+ const cmpTempDir = `${cliTempDir}/${cmpName}`;
34
+ if (!fs.existsSync(cmpTempDir)) {
35
+ fs.mkdirSync(cmpTempDir);
41
36
  }
42
37
 
43
38
  const cmpPreviewContent = getCmpPreview(cmpsDir, cmpName);
44
- fs.writeFileSync(`${tempCmpDir}/preview.jsx`, cmpPreviewContent);
39
+ fs.writeFileSync(`${cmpTempDir}/preview.jsx`, cmpPreviewContent);
45
40
 
46
41
  // 将临时预览文件添加到预览配置中
47
42
  if (!config.dev.entry) {
48
43
  config.dev.entry = {};
49
44
  }
50
45
  // 添加预览入口文件
51
- config.dev.entry.index = `${tempCmpDir}/preview.jsx`;
46
+ config.dev.entry.index = `${cmpTempDir}/preview.jsx`;
52
47
 
53
48
  if (config.webpack.projectDir) {
54
- config.webpack.projectDir.push(tempCmpDir);
49
+ config.webpack.projectDir.push(cmpTempDir);
55
50
  } else {
56
- config.webpack.projectDir = [tempCmpDir];
51
+ config.webpack.projectDir = [cmpTempDir];
57
52
  }
58
53
 
59
54
  akfun.dev(config, consoleTag);
@@ -196,7 +196,11 @@ const getResultFilesByWidgetName = (files) => {
196
196
  };
197
197
 
198
198
  // 文件名中添加当前项目版本号
199
- function addVersionToFilename(filename, version = currentPackageJson.version, projectName = currentPackageJson.name) {
199
+ function addVersionToFilename(
200
+ filename,
201
+ version = currentPackageJson.version,
202
+ projectName = currentPackageJson.name
203
+ ) {
200
204
  // 找到最后一个点的位置,用于分离文件名和扩展名
201
205
  let lastDotIndex = filename.lastIndexOf('.umd');
202
206
  if (lastDotIndex === -1) {
@@ -2,13 +2,12 @@
2
2
  - src: 自定义组件源码;
3
3
  - src/assets: 存放组件静态资源,比如 css、img等;
4
4
  - src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
5
- - src/components/info-card/index.jsx: 信息卡片自定义组件代码;
6
- - src/components/info-card/register.js: 用于注册一个 neo 自定义组件,注册成功后编辑器画布区中才会正常展示自定义组件内容;
7
- - src/components/info-card/model.js: 用于注册一个 neo-editor 自定义组件模型,注册成功后编辑器左侧组件面板中会展示;
5
+ - src/components/info-card/index.jsx: 自定义组件的内容文件;
6
+ - src/components/info-card/model.js: 自定义组件的模型文件,用于对接页面设计器;
8
7
  - neo.config.js: neo-cmp-cli 配置文件。
9
8
 
10
9
  ### 组件开发规范
11
- - 存放在 src/components 目录下的自定义组件,默认 index 为自定义组件源码入口文件,register.[tj]s 为注册 Neo 组件的脚本文件,model.[tj]s 为自定义组件的描述文件(和页面设计器对接需要);
10
+ - 存放在 src/components 目录下的自定义组件,默认 index 为自定义组件源码入口文件,register.[tj]s 为注册 自定义组件的脚本文件,model.[tj]s 为自定义组件的模型文件(对接页面设计器需要);
12
11
  - 当 neo.config.js 中的 entry 为空或者不存在时,cli 将根据 src/components 目录下的自定义组件结构生成对应的 entry 配置(可在命令控制台查看生成的 entry 配置);
13
12
  - 自定义组件中可用的配置项类型 请见 [当前可用表单项](https://github.com/wibetter/neo-register/blob/master/docs/FormItemType.md);
14
13
  - 自定义组件最外层请设置一个唯一的 ClassName(比如 xx-cmpType-container),所有内容样式请放在该 ClassName 中,避免自定义组件样式相互干扰;
@@ -17,6 +16,7 @@
17
16
 
18
17
  ### 自定义组件注册器使用说明
19
18
  - [neo-register 使用说明](https://www.npmjs.com/package/neo-register?activeTab=readme)
19
+ 备注:预览、调试(linkDebug)和构建发布时 cli 会自动创建对应的注册文件(含 neo-register 的使用),用户无需关注 neo-register。
20
20
 
21
21
  ### 开发说明
22
22
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-custom-cmp-template",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "neo自定义组件模板(react技术栈)",
5
5
  "keywords": [
6
6
  "自定义组件模板",
@@ -10,7 +10,7 @@
10
10
  "author": "wibetter",
11
11
  "license": "MIT",
12
12
  "scripts": {
13
- "preview": "neo preview",
13
+ "preview": "neo preview --cmpType=info-card",
14
14
  "linkDebug": "neo linkDebug",
15
15
  "publish2oss": "neo publish2oss",
16
16
  "format": "prettier --write \"src/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@commitlint/cli": "^8.3.5",
46
46
  "@commitlint/config-conventional": "^9.1.1",
47
- "neo-cmp-cli": "^1.0.15",
47
+ "neo-cmp-cli": "^1.1.0",
48
48
  "husky": "^4.2.5",
49
49
  "lint-staged": "^10.2.9",
50
50
  "prettier": "^2.0.5"
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @file 自定义组件对接编辑器的描述文件
3
3
  */
4
- // @ts-ignore
5
- import { registerNeoEditorModel } from 'neo-register';
6
-
7
4
  export class InfoCardModel {
8
- // 自定义组件名称,用于标识组件的唯一性
9
- cmpType = 'info-card';
5
+ /**
6
+ * cmpType 为自定义组件名称,用于标识组件的唯一性
7
+ * 在构建时根据当前组件目录名称自动生成
8
+ */
9
+ // cmpType: string = 'info-card';
10
10
 
11
11
  // 组件名称,用于设置在编辑器左侧组件面板中展示的名称
12
12
  label = '信息卡片';
@@ -76,6 +76,4 @@ export class InfoCardModel {
76
76
  */
77
77
  }
78
78
 
79
- registerNeoEditorModel(InfoCardModel);
80
-
81
79
  export default InfoCardModel;
@@ -1,14 +1,13 @@
1
1
  ### 目录说明
2
2
  - src: 自定义组件源码;
3
3
  - src/assets: 存放组件静态资源,比如 css、img等;
4
- - src/components: 存放自定义组件代码,每个自定义组件以自身名称作为目录进行存放;
5
- - src/components/info-card/index.tsx: 信息卡片自定义组件代码;
6
- - src/components/info-card/register.ts: 用于注册一个 neo 自定义组件,注册成功后编辑器画布区中才会正常展示自定义组件内容;
7
- - src/components/info-card/model.ts: 用于注册一个 neo-editor 自定义组件模型,注册成功后编辑器左侧组件面板中会展示;
4
+ - src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
5
+ - src/components/info-card/index.tsx: 自定义组件的内容文件;
6
+ - src/components/info-card/model.ts: 自定义组件的模型文件,用于对接页面设计器;
8
7
  - neo.config.js: neo-cmp-cli 配置文件。
9
8
 
10
9
  ### 组件开发规范
11
- - 存放在 src/components 目录下的自定义组件,默认 index 为自定义组件源码入口文件,register.[tj]s 为注册 Neo 组件的脚本文件,model.[tj]s 为自定义组件的描述文件(和页面设计器对接需要);
10
+ - 存放在 src/components 目录下的自定义组件,默认 index 为自定义组件源码入口文件,register.[tj]s 为注册 自定义组件的脚本文件,model.[tj]s 为自定义组件的模型文件(对接页面设计器需要);
12
11
  - 当 neo.config.js 中的 entry 为空或者不存在时,cli 将根据 src/components 目录下的自定义组件结构生成对应的 entry 配置(可在命令控制台查看生成的 entry 配置);
13
12
  - 自定义组件中可用的配置项类型 请见 [当前可用表单项](https://github.com/wibetter/neo-register/blob/master/docs/FormItemType.md);
14
13
  - 自定义组件最外层请设置一个唯一的 ClassName(比如 xx-cmpType-container),所有内容样式请放在该 ClassName 中,避免自定义组件样式相互干扰;
@@ -17,6 +16,7 @@
17
16
 
18
17
  ### 自定义组件注册器使用说明
19
18
  - [neo-register 使用说明](https://www.npmjs.com/package/neo-register?activeTab=readme)
19
+ 备注:预览、调试(linkDebug)和构建发布时 cli 会自动创建对应的注册文件(含 neo-register 的使用),用户无需关注 neo-register。
20
20
 
21
21
  ### 开发说明
22
22
 
@@ -36,12 +36,16 @@ module.exports = {
36
36
  projectDir: ['src'],
37
37
  // template: resolve('./public/template.html'), // 自定义html模板
38
38
  // plugins: [],
39
- babelPlugins: [],
39
+ // babelPlugins: [],
40
40
  },
41
41
  preview: {
42
42
  // 用于开启本地预览模式的相关配置信息
43
43
  /*
44
44
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
45
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
46
+ // 本地预览自定义组件内容
47
+ index: './src/preview.jsx',
48
+ },
45
49
  NODE_ENV: 'development',
46
50
  port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
47
51
  assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
@@ -60,7 +64,7 @@ module.exports = {
60
64
  // 用于开启本地调试模式的相关配置信息
61
65
  /*
62
66
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
63
- entry: { // entry 会根据 src/components 目录下的文件自动生成
67
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
64
68
  // 外链调试(在线上页面设计器端预览自定义组件)
65
69
  index: [
66
70
  './src/components/info-card/register.ts',
@@ -86,7 +90,7 @@ module.exports = {
86
90
  /*
87
91
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
88
92
  NODE_ENV: 'production',
89
- entry: { // entry 未配置时,cli 会根据 src/components 目录下的文件自动生成对应的 entry
93
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
90
94
  InfoCardModel: './src/components/info-card/model.ts',
91
95
  infoCard: './src/components/info-card/register.ts'
92
96
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ts-custom-cmp-template",
3
- "version": "1.0.24",
3
+ "version": "1.1.0",
4
4
  "description": "neo自定义组件模板(react&ts技术栈)",
5
5
  "keywords": [
6
6
  "自定义组件模板",
@@ -10,7 +10,7 @@
10
10
  "author": "wibetter",
11
11
  "license": "MIT",
12
12
  "scripts": {
13
- "preview": "neo preview",
13
+ "preview": "neo preview --cmpType=info-card",
14
14
  "linkDebug": "neo linkDebug",
15
15
  "publish2oss": "neo publish2oss",
16
16
  "format": "prettier --write \"src/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
@@ -47,7 +47,7 @@
47
47
  "@commitlint/config-conventional": "^9.1.1",
48
48
  "@types/react": "^16.9.11",
49
49
  "@types/react-dom": "^16.9.15",
50
- "neo-cmp-cli": "^1.0.15",
50
+ "neo-cmp-cli": "^1.1.0",
51
51
  "husky": "^4.2.5",
52
52
  "lint-staged": "^10.2.9",
53
53
  "prettier": "^2.0.5"
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @file 自定义组件对接编辑器的描述文件
3
3
  */
4
- // @ts-ignore
5
- import { registerNeoEditorModel } from 'neo-register';
6
-
7
4
  export class InfoCardModel {
8
- // 自定义组件名称,用于标识组件的唯一性
9
- cmpType: string = 'info-card';
5
+ /**
6
+ * cmpType 为自定义组件名称,用于标识组件的唯一性
7
+ * 在构建时根据当前组件目录名称自动生成
8
+ */
9
+ // cmpType: string = 'info-card';
10
10
 
11
11
  // 组件名称,用于设置在编辑器左侧组件面板中展示的名称
12
12
  label: string = '信息卡片';
@@ -75,6 +75,4 @@ export class InfoCardModel {
75
75
  */
76
76
  }
77
77
 
78
- registerNeoEditorModel(InfoCardModel);
79
-
80
78
  export default InfoCardModel;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @file 列表组件对接编辑器的描述文件
3
3
  */
4
- // @ts-ignore
5
- import { registerNeoEditorModel } from 'neo-register';
6
-
7
4
  export class ListWidgetModel {
8
- // 自定义组件名称,用于标识组件的唯一性
9
- cmpType: string = 'list-widget';
5
+ /**
6
+ * cmpType 为自定义组件名称,用于标识组件的唯一性
7
+ * 在构建时根据当前组件目录名称自动生成
8
+ */
9
+ // cmpType: string = 'list-widget';
10
10
 
11
11
  // 组件名称,用于设置在编辑器左侧组件面板中展示的名称
12
12
  label: string = '列表组件';
@@ -87,6 +87,4 @@ export class ListWidgetModel {
87
87
  */
88
88
  }
89
89
 
90
- registerNeoEditorModel(ListWidgetModel);
91
-
92
90
  export default ListWidgetModel;
@@ -1,10 +1,9 @@
1
1
  ### 目录说明
2
2
  - src: 自定义组件源码;
3
3
  - src/assets: 存放组件静态资源,比如 css、img等;
4
- - src/components: 存放自定义组件代码,每个自定义组件以自身名称作为目录进行存放;
5
- - src/components/info-card/index.vue: 信息卡片自定义组件代码;
6
- - src/components/info-card/register.js: 用于注册一个 neo 自定义组件,注册成功后编辑器画布区中才会正常展示自定义组件内容;
7
- - src/components/info-card/model.js: 用于注册一个 neo-editor 自定义组件模型,注册成功后编辑器左侧组件面板中会展示;
4
+ - src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
5
+ - src/components/info-card/index.vue: 自定义组件的内容文件;
6
+ - src/components/info-card/model.js: 自定义组件的模型文件,用于对接页面设计器;
8
7
  - neo.config.js: neo-cmp-cli 配置文件。
9
8
 
10
9
  ### 组件开发规范
@@ -17,6 +16,7 @@
17
16
 
18
17
  ### 自定义组件注册器使用说明
19
18
  - [neo-register 使用说明](https://www.npmjs.com/package/neo-register?activeTab=readme)
19
+ 备注:预览、调试(linkDebug)和构建发布时 cli 会自动创建对应的注册文件(含 neo-register 的使用),用户无需关注 neo-register。
20
20
 
21
21
  ### 开发说明
22
22
 
@@ -73,8 +73,8 @@ module.exports = {
73
73
  entry: { // entry 未配置时,cli 会根据 src/components 目录下的文件自动生成对应的 entry
74
74
  // 外链调试(在线上页面设计器端预览自定义组件)
75
75
  index: [
76
- './src/components/info-card/register.js',
77
- './src/components/info-card/model.js',
76
+ './src/components/vue-info-card/register.js',
77
+ './src/components/vue-info-card/model.js',
78
78
  ],
79
79
  },
80
80
  NODE_ENV: 'development',
@@ -100,8 +100,8 @@ module.exports = {
100
100
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
101
101
  NODE_ENV: 'production',
102
102
  entry: { // entry 会根据 src/components 目录下的文件自动生成
103
- InfoCardModel: './src/components/info-card/model.ts',
104
- infoCard: './src/components/info-card/register.ts'
103
+ InfoCardModel: './src/components/vue-info-card/model.ts',
104
+ infoCard: './src/components/vue-info-card/register.ts'
105
105
  },
106
106
  cssExtract: false, // 不额外提取css文件
107
107
  ossType: 'ali', // oss类型:ali、baidu
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-custom-cmp-template",
3
- "version": "1.1.2",
3
+ "version": "1.0.1",
4
4
  "description": "neo自定义组件模板(vue2.0技术栈)",
5
5
  "keywords": [
6
6
  "自定义组件模板",
@@ -10,7 +10,7 @@
10
10
  "author": "wibetter",
11
11
  "license": "MIT",
12
12
  "scripts": {
13
- "preview": "neo preview",
13
+ "preview": "neo preview --cmpType=info-card",
14
14
  "linkDebug": "neo linkDebug",
15
15
  "publish2oss": "neo publish2oss",
16
16
  "format": "prettier --write \"src/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
@@ -44,13 +44,12 @@
44
44
  "devDependencies": {
45
45
  "@commitlint/cli": "^8.3.5",
46
46
  "@commitlint/config-conventional": "^9.1.1",
47
- "neo-cmp-cli": "^1.0.15",
47
+ "neo-cmp-cli": "^1.1.0",
48
48
  "husky": "^4.2.5",
49
49
  "lint-staged": "^10.2.9",
50
50
  "prettier": "^2.0.5",
51
51
  "react": "^16.9.0",
52
- "react-dom": "^16.9.0",
53
- "babel-plugin-component": "^1.1.1"
52
+ "react-dom": "^16.9.0"
54
53
  },
55
54
  "engines": {
56
55
  "node": ">= 10.13.0",
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @file 自定义组件对接编辑器的描述文件
3
3
  */
4
- // @ts-ignore
5
- import { registerNeoEditorModel } from 'neo-register';
6
-
7
4
  export class InfoCardModel {
8
- // 自定义组件名称,用于标识组件的唯一性
9
- cmpType = 'vue-info-card';
5
+ /**
6
+ * cmpType 为自定义组件名称,用于标识组件的唯一性
7
+ * 在构建时根据当前组件目录名称自动生成
8
+ */
9
+ // cmpType: string = 'vue-info-card';
10
10
 
11
11
  // 组件名称,用于设置在编辑器左侧组件面板中展示的名称
12
12
  label = 'vue 信息卡片';
@@ -76,6 +76,4 @@ export class InfoCardModel {
76
76
  */
77
77
  }
78
78
 
79
- registerNeoEditorModel(InfoCardModel);
80
-
81
79
  export default InfoCardModel;
@@ -51,7 +51,7 @@ const MFPlugins = [
51
51
  neoreact: 'neoreact@[window.neoEntrys.neoreact]'
52
52
  }
53
53
  }),
54
- new ExternalTemplateRemotesPlugin(),
54
+ new ExternalTemplateRemotesPlugin()
55
55
  ];
56
56
 
57
57
  module.exports = {
package/test/demo.js CHANGED
@@ -1,5 +1,10 @@
1
- const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp} = require('../src/module/main');
1
+ const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp, } = require('../src/module/main');
2
+ const getEntries = require('../src/cmpUtils/getEntries');
3
+ const getEntriesWithAutoRegister = require('../src/cmpUtils/getEntriesWithAutoRegister');
2
4
  // inspect('dev');
3
5
  // neoInitByCopy('react-ts', 'test123');
4
6
 
5
- // previewCmp('info-card');
7
+ // previewCmp('info-card');
8
+
9
+ // const entries = getEntriesWithAutoRegister('linkDebug');
10
+ // console.log(entries);
@@ -1,4 +0,0 @@
1
- import InfoCard from './index';
2
- import { registerNeoCmp } from 'neo-register';
3
-
4
- registerNeoCmp(InfoCard, 'info-card');
@@ -1,5 +0,0 @@
1
- // @ts-ignore
2
- import { registerNeoCmp } from 'neo-register';
3
- import InfoCard from './index';
4
-
5
- registerNeoCmp(InfoCard, 'info-card');
@@ -1,5 +0,0 @@
1
- // @ts-ignore
2
- import { registerNeoCmp } from 'neo-register';
3
- import ListWidget from './index';
4
-
5
- registerNeoCmp(ListWidget, 'list-widget');
@@ -1,8 +0,0 @@
1
- import InfoCard from './index';
2
- // @ts-ignore
3
- import { registerNeoCmp } from 'neo-register';
4
-
5
- /* 引入公共的静态资源 */
6
- // import '$public/css/base.css'; // 备注: 全局样式要注意不要干扰平台和编辑器端的正常展示
7
-
8
- registerNeoCmp(InfoCard, 'vue-info-card');
@@ -1,26 +0,0 @@
1
- const { resolveToCurrentRoot } = require('./pathUtils');
2
-
3
- const getCmpPreview = (cmpsDir,cmpName) => {
4
- const cpmDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}`);
5
- const cpmModelDir = resolveToCurrentRoot(`${cmpsDir}/${cmpName}/model`);
6
- return `
7
- import * as React from 'react';
8
- import ReactDOM from 'react-dom';
9
- import CustomCmp from '${cpmDir}';
10
- import CustomCmpModel from '${cpmModelDir}';
11
-
12
- // 获取组件模型中的默认属性
13
- const curDefaultComProps = new CustomCmpModel().defaultComProps;
14
-
15
- /* 引入公共的静态资源 */
16
- import '$public/css/base.css';
17
-
18
- // 预览 自定义组件
19
- ReactDOM.render(
20
- <CustomCmp {...curDefaultComProps} />,
21
- document.getElementById('root'),
22
- );
23
- `;
24
- }
25
-
26
- module.exports = getCmpPreview;