neo-cmp-cli 1.0.13 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/package.json +1 -1
- package/src/module/index.js +30 -1
- package/src/module/main.js +17 -1
- package/src/module/previewCmp.js +56 -0
- package/src/template/react-custom-cmp-template/package.json +1 -1
- package/src/template/react-ts-custom-cmp-template/neo.config.js +0 -6
- package/src/template/react-ts-custom-cmp-template/package.json +1 -1
- package/src/template/react-ts-custom-cmp-template/src/preview.tsx +4 -9
- package/src/template/vue2-custom-cmp-template/package.json +1 -1
- package/src/utils/getCmpPreview.js +26 -0
- package/test/demo.js +4 -2
- package/src/template/react-custom-cmp-template/.editorconfig +0 -10
- package/src/template/react-ts-custom-cmp-template/.editorconfig +0 -10
- package/src/template/vue2-custom-cmp-template/.editorconfig +0 -10
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ npm i neo-cmp-cli --save-dev
|
|
|
54
54
|
```bash
|
|
55
55
|
"preview": "neo preview",
|
|
56
56
|
"linkDebug": "neo linkDebug",
|
|
57
|
-
"
|
|
57
|
+
"publish2oss": "neo publish2oss"
|
|
58
58
|
```
|
|
59
59
|
3) 初始化配置文件
|
|
60
60
|
```bash
|
|
@@ -64,7 +64,7 @@ neo config init
|
|
|
64
64
|
```bash
|
|
65
65
|
npm run preview
|
|
66
66
|
npm run linkDebug
|
|
67
|
-
npm run
|
|
67
|
+
npm run publish2oss
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
## 常用命令
|
|
@@ -90,7 +90,7 @@ module.exports = {
|
|
|
90
90
|
}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
### 2) 构建入口(优先级:preview/linkDebug/build2lib.entry > webpack.entry)
|
|
93
|
+
### 2) 构建入口(优先级:preview/linkDebug/build2lib/publish2oss.entry > webpack.entry)
|
|
94
94
|
```bash
|
|
95
95
|
module.exports = {
|
|
96
96
|
webpack: {
|
|
@@ -99,6 +99,7 @@ module.exports = {
|
|
|
99
99
|
preview: { entry: {} },
|
|
100
100
|
linkDebug: { entry: {} },
|
|
101
101
|
build2lib: { entry: {} },
|
|
102
|
+
publish2oss: { entry: {} },
|
|
102
103
|
}
|
|
103
104
|
```
|
|
104
105
|
备注1: 当未配置 entry 时,cli 会自动根据 src/components 目录自动生成 entry 配置;
|
package/package.json
CHANGED
package/src/module/index.js
CHANGED
|
@@ -133,6 +133,35 @@ yargs
|
|
|
133
133
|
neoConfigInit('neo.config.js');
|
|
134
134
|
}
|
|
135
135
|
)
|
|
136
|
+
.command(
|
|
137
|
+
'preview [options]',
|
|
138
|
+
'预览指定自定义组件(仅预览组件本身内容)',
|
|
139
|
+
(yargs) => {
|
|
140
|
+
yargs
|
|
141
|
+
.reset()
|
|
142
|
+
.usage(titleTip('Usage') + ': $0 init [options]')
|
|
143
|
+
.option('cmpType', {
|
|
144
|
+
alias: 't',
|
|
145
|
+
describe: '自定义组件项目名称'
|
|
146
|
+
})
|
|
147
|
+
.alias('h', 'help');
|
|
148
|
+
},
|
|
149
|
+
(argv) => {
|
|
150
|
+
if (argv.cmpType) {
|
|
151
|
+
mainAction.previewCmp(argv.cmpType);
|
|
152
|
+
} else {
|
|
153
|
+
const questions = [{
|
|
154
|
+
name: 'cmpType',
|
|
155
|
+
type: 'input',
|
|
156
|
+
message: '请输入要预览的自定义组件名称(默认 info-card):',
|
|
157
|
+
default: 'info-card'
|
|
158
|
+
}];
|
|
159
|
+
inquirer.prompt(questions).then((ans) => {
|
|
160
|
+
mainAction.previewCmp(ans.cmpType);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
)
|
|
136
165
|
.command(
|
|
137
166
|
'preview',
|
|
138
167
|
'开启组件预览模式(仅预览组件本身内容)',
|
|
@@ -142,7 +171,7 @@ yargs
|
|
|
142
171
|
.usage(titleTip('Usage') + ': $0 dev')
|
|
143
172
|
.alias('h', 'help');
|
|
144
173
|
},
|
|
145
|
-
(
|
|
174
|
+
() => {
|
|
146
175
|
mainAction.preview();
|
|
147
176
|
}
|
|
148
177
|
)
|
package/src/module/main.js
CHANGED
|
@@ -8,7 +8,8 @@ const { consoleTag } = require('../utils/neoParams');
|
|
|
8
8
|
const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
|
|
9
9
|
const publish2oss = require('../oss/publish2oss');
|
|
10
10
|
const getEntries = require('../utils/getEntries');
|
|
11
|
-
const
|
|
11
|
+
const previewCmp = require('./previewCmp');
|
|
12
|
+
// const { MFPlugins } = require('../utils/webpack.mf');
|
|
12
13
|
|
|
13
14
|
const getValue = (originValue, defaultValue) => {
|
|
14
15
|
return originValue !== undefined ? originValue : defaultValue;
|
|
@@ -30,6 +31,21 @@ module.exports = {
|
|
|
30
31
|
|
|
31
32
|
akfun.dev(curConfig, consoleTag);
|
|
32
33
|
},
|
|
34
|
+
previewCmp: (cmpName) => {
|
|
35
|
+
// 预览组件本身内容
|
|
36
|
+
if (!cmpName) {
|
|
37
|
+
console.error('请输入要预览的组件名称。');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
if (!curConfig.preview) {
|
|
41
|
+
console.error('未找到 preview 相关配置。');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
curConfig.dev = Object.assign(curConfig.dev, curConfig.preview); // 将 preview 设置给 dev
|
|
45
|
+
delete curConfig.preview;
|
|
46
|
+
|
|
47
|
+
previewCmp(curConfig, cmpName);
|
|
48
|
+
},
|
|
33
49
|
linkDebug: () => {
|
|
34
50
|
// 外链调试模式
|
|
35
51
|
if (!curConfig.linkDebug) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const akfun = require('akfun');
|
|
4
|
+
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);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 用于预览指定自定义组件
|
|
15
|
+
*/
|
|
16
|
+
module.exports = (config, cmpName, defaultComponentsDir = './src/components') => {
|
|
17
|
+
const cmpsDir = config.componentsDir || defaultComponentsDir;
|
|
18
|
+
const curCmpsDir = resolveToCurrentRoot(cmpsDir);
|
|
19
|
+
|
|
20
|
+
if (!fs.existsSync(curCmpsDir)) {
|
|
21
|
+
console.error(`未找到组件目录,请检查 ${cmpsDir} 目录是否存在`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 判断当前自定义组件是否存在
|
|
26
|
+
const cpmDir = `${curCmpsDir}/${cmpName}`;
|
|
27
|
+
if (!fs.existsSync(cpmDir)) {
|
|
28
|
+
console.error(`${consoleTag}自定义组件 ${cmpName} 不存在。`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 创建存放预览文件的临时目录
|
|
33
|
+
const tempDir = path.resolve(__dirname, '../../temp');
|
|
34
|
+
if (!fs.existsSync(tempDir)) {
|
|
35
|
+
fs.mkdirSync(tempDir);
|
|
36
|
+
}
|
|
37
|
+
const tempCmpDir = `${tempDir}/${currentPackageJson.name}`;
|
|
38
|
+
if (!fs.existsSync(tempCmpDir)) {
|
|
39
|
+
fs.mkdirSync(tempCmpDir);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cmpPreviewContent = getCmpPreview(cmpsDir, cmpName);
|
|
43
|
+
fs.writeFileSync(`${tempCmpDir}/preview.jsx`, cmpPreviewContent);
|
|
44
|
+
|
|
45
|
+
// 将临时预览文件添加到预览配置中
|
|
46
|
+
config.dev.entry['index'] = `${tempCmpDir}/preview.jsx`;
|
|
47
|
+
if (config.webpack.projectDir) {
|
|
48
|
+
config.webpack.projectDir.push(tempCmpDir);
|
|
49
|
+
} else {
|
|
50
|
+
config.webpack.projectDir = [tempCmpDir];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(`${consoleTag}预览文件已保存至 ${tempCmpDir}/preview.jsx:`, config);
|
|
54
|
+
|
|
55
|
+
akfun.dev(config, consoleTag);
|
|
56
|
+
};
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const webpack = require('webpack');
|
|
4
|
-
const { ModuleFederationPlugin } = require('webpack').container;
|
|
5
|
-
|
|
6
|
-
// 解析 webpack 模块联邦 remotes 中的变量
|
|
7
|
-
const ExternalTemplateRemotesPlugin = require('external-remotes-plugin');
|
|
8
|
-
|
|
9
3
|
|
|
10
4
|
// 统一路径解析
|
|
11
5
|
function resolve(dir) {
|
|
@@ -2,21 +2,16 @@ import * as React from 'react';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import InfoCard from './components/info-card';
|
|
4
4
|
import ListWidget from './components/list-widget';
|
|
5
|
+
import InfoCardModel from './components/info-card/model';
|
|
6
|
+
|
|
7
|
+
const InfoCardDefaultComProps = new InfoCardModel().defaultComProps;
|
|
5
8
|
|
|
6
9
|
/* 引入公共的静态资源 */
|
|
7
10
|
import '$public/css/base.css';
|
|
8
11
|
|
|
9
12
|
// 预览 info-card 组件
|
|
10
13
|
ReactDOM.render(
|
|
11
|
-
<InfoCard
|
|
12
|
-
{...{
|
|
13
|
-
title:
|
|
14
|
-
'neo-widget是开发neo自定义组件的工具集,提供注册neo自定义组件和neo-editor自定义组件模型的方法。',
|
|
15
|
-
backgroundImage: '',
|
|
16
|
-
imgCount: 101,
|
|
17
|
-
commentCount: 2022,
|
|
18
|
-
}}
|
|
19
|
-
/>,
|
|
14
|
+
<InfoCard {...InfoCardDefaultComProps} />,
|
|
20
15
|
document.getElementById('root'),
|
|
21
16
|
);
|
|
22
17
|
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
package/test/demo.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy} = require('../src/module/main');
|
|
1
|
+
const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp} = require('../src/module/main');
|
|
2
2
|
// inspect('dev');
|
|
3
|
-
neoInitByCopy('react-ts', 'test123');
|
|
3
|
+
// neoInitByCopy('react-ts', 'test123');
|
|
4
|
+
|
|
5
|
+
// previewCmp('info-card');
|