@plugin-light/cli 1.0.2
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/LICENSE +9 -0
- package/README.md +58 -0
- package/bin/cli.js +34 -0
- package/lib/config.d.ts +5 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +31 -0
- package/lib/loader.d.ts +1 -0
- package/lib/loader.js +41 -0
- package/lib/loader.prod.js +1 -0
- package/lib/publish-inner.d.ts +7 -0
- package/package.json +33 -0
- package/script/docs-demo/helper.js +180 -0
- package/script/docs-demo/watch.js +10 -0
- package/script/generate-component-config/1.docs-sidebar.js +48 -0
- package/script/generate-component-config/2.demo-index.js +56 -0
- package/script/generate-component-config/3.demo-pages.js +78 -0
- package/script/generate-component-config/4.demo-title.js +41 -0
- package/script/generate-component-config/5.build-config.js +34 -0
- package/script/generate-component-config/6.docs-url.js +67 -0
- package/script/generate-component-config/core.js +43 -0
- package/script/generate-component-config/generate-entry.js +215 -0
- package/script/generate-component-config/helper.js +29 -0
- package/script/generate-new-component/copy-dir.js +158 -0
- package/script/generate-new-component/generate-new-component.js +128 -0
- package/script/generate-new-component/sort.js +23 -0
- package/script/post-install/index.js +100 -0
- package/script/release/prepare.js +59 -0
- package/script/release/release.js +31 -0
- package/script/release/version.js +39 -0
- package/script/utils/utils.js +114 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 novlan1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# 本地发布
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/dw/@plugin-light/plugin-light-cli">
|
|
5
|
+
<img src="https://img.shields.io/npm/unpacked-size/@plugin-light/plugin-light-cli">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@plugin-light/plugin-light-cli">
|
|
7
|
+
<img src="https://img.shields.io/npm/l/@plugin-light/plugin-light-cli">
|
|
8
|
+
<img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
|
|
9
|
+
<img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
可以在 `nodejs` 或 `bash` 中使用。
|
|
13
|
+
|
|
14
|
+
# 如何使用
|
|
15
|
+
|
|
16
|
+
安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @plugin-light/cli -D
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
在 `nodejs` 中使用
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const { PUBLISH_SCRIPT: publishUtil } = require('@plugin-light/cli');
|
|
26
|
+
|
|
27
|
+
publishUtil [prod|test]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
在 `bash` 中使用
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 工具暴露 light-cli 命令
|
|
34
|
+
npx light-cli publish `[prod|test]`
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 默认值
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
export const DEFAULT_PUBLISH_OPTIONS = {
|
|
41
|
+
port: '3005',
|
|
42
|
+
method: 'POST',
|
|
43
|
+
path: '/web-publish/publish',
|
|
44
|
+
} as const;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 环境变量
|
|
48
|
+
|
|
49
|
+
| 变量 | 对应名称 |
|
|
50
|
+
| ---------------------------- | -------- |
|
|
51
|
+
| VUE_APP_LOCAL_PUBLISH_HOST | host |
|
|
52
|
+
| VUE_APP_LOCAL_PUBLISH_PORT | port |
|
|
53
|
+
| VUE_APP_LOCAL_PUBLISH_METHOD | method |
|
|
54
|
+
| VUE_APP_LOCAL_PUBLISH_PATH | path |
|
|
55
|
+
|
|
56
|
+
## 更新日志
|
|
57
|
+
|
|
58
|
+
[点此查看](./CHANGELOG.md)
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { program } = require('commander');
|
|
3
|
+
|
|
4
|
+
const { innerPublish } = require('../lib/index');
|
|
5
|
+
const { version } = require('../package.json');
|
|
6
|
+
|
|
7
|
+
const VALID_ENV_LIST = ['test', 'prod', 'devcloud'];
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.name('light-cli')
|
|
11
|
+
.description('CLI for plugin-light')
|
|
12
|
+
.version(version);
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
program.command('publish')
|
|
16
|
+
.description('Publish to server with bash script')
|
|
17
|
+
.option('-e, --env <string>', 'publish environment')
|
|
18
|
+
.action((options) => {
|
|
19
|
+
const { env = 'test' } = options;
|
|
20
|
+
console.log('[env] ', env);
|
|
21
|
+
|
|
22
|
+
if (VALID_ENV_LIST.indexOf(env) === -1) {
|
|
23
|
+
console.error('[publish] failed. env 参数不合法,请检查!');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
innerPublish({
|
|
28
|
+
publishEnv: env,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program.parse();
|
|
33
|
+
|
|
34
|
+
|
package/lib/config.d.ts
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shared = require('@plugin-light/shared');
|
|
6
|
+
var tComm = require('t-comm');
|
|
7
|
+
|
|
8
|
+
const DEFAULT_PUBLISH_OPTIONS = {
|
|
9
|
+
port: '3005',
|
|
10
|
+
method: 'POST',
|
|
11
|
+
path: '/web-publish/publish',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function innerPublish({ publishEnv, host, port = DEFAULT_PUBLISH_OPTIONS.port, method = DEFAULT_PUBLISH_OPTIONS.method, path = DEFAULT_PUBLISH_OPTIONS.path, }) {
|
|
15
|
+
if (!host && publishEnv !== 'devcloud') {
|
|
16
|
+
console.log('请从环境变量注入 `host`,如 process.env.VUE_APP_LOCAL_PUBLISH_HOST');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
tComm.localPublish({
|
|
20
|
+
host,
|
|
21
|
+
port,
|
|
22
|
+
method,
|
|
23
|
+
path,
|
|
24
|
+
publishEnv,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const PUBLISH_SCRIPT = shared.getLoaderFile(__dirname);
|
|
29
|
+
|
|
30
|
+
exports.PUBLISH_SCRIPT = PUBLISH_SCRIPT;
|
|
31
|
+
exports.innerPublish = innerPublish;
|
package/lib/loader.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function main(): void;
|
package/lib/loader.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tComm = require('t-comm');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_PUBLISH_OPTIONS = {
|
|
6
|
+
port: '3005',
|
|
7
|
+
method: 'POST',
|
|
8
|
+
path: '/web-publish/publish',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function innerPublish({ publishEnv, host, port = DEFAULT_PUBLISH_OPTIONS.port, method = DEFAULT_PUBLISH_OPTIONS.method, path = DEFAULT_PUBLISH_OPTIONS.path, }) {
|
|
12
|
+
if (!host && publishEnv !== 'devcloud') {
|
|
13
|
+
console.log('请从环境变量注入 `host`,如 process.env.VUE_APP_LOCAL_PUBLISH_HOST');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
tComm.localPublish({
|
|
17
|
+
host,
|
|
18
|
+
port,
|
|
19
|
+
method,
|
|
20
|
+
path,
|
|
21
|
+
publishEnv,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getPublishEnv() {
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
const publishEnv = args[0];
|
|
28
|
+
return publishEnv;
|
|
29
|
+
}
|
|
30
|
+
function main() {
|
|
31
|
+
innerPublish({
|
|
32
|
+
publishEnv: getPublishEnv(),
|
|
33
|
+
host: process.env.VUE_APP_LOCAL_PUBLISH_HOST || '',
|
|
34
|
+
port: process.env.VUE_APP_LOCAL_PUBLISH_PORT || DEFAULT_PUBLISH_OPTIONS.port,
|
|
35
|
+
method: process.env.VUE_APP_LOCAL_PUBLISH_METHOD || DEFAULT_PUBLISH_OPTIONS.method,
|
|
36
|
+
path: process.env.VUE_APP_LOCAL_PUBLISH_PATH || DEFAULT_PUBLISH_OPTIONS.path,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
main();
|
|
40
|
+
|
|
41
|
+
module.exports = main;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=require("t-comm");const o="3005",e="POST",t="/web-publish/publish";function _(){!function({publishEnv:_,host:P,port:p=o,method:h=e,path:c=t}){P||"devcloud"===_?s.localPublish({host:P,port:p,method:h,path:c,publishEnv:_}):console.log("请从环境变量注入 `host`,如 process.env.VUE_APP_LOCAL_PUBLISH_HOST")}({publishEnv:process.argv.slice(2)[0],host:process.env.VUE_APP_LOCAL_PUBLISH_HOST||"",port:process.env.VUE_APP_LOCAL_PUBLISH_PORT||o,method:process.env.VUE_APP_LOCAL_PUBLISH_METHOD||e,path:process.env.VUE_APP_LOCAL_PUBLISH_PATH||t})}_(),module.exports=_;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plugin-light/cli",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"homepage": "https://novlan1.github.io/docs/plugin-light/zh/plugin-light-cli.html",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/novlan1/plugin-light"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "novlan1",
|
|
14
|
+
"main": "./lib/index",
|
|
15
|
+
"bin": {
|
|
16
|
+
"light-cli": "./bin/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"script/",
|
|
20
|
+
"lib/",
|
|
21
|
+
"bin"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"t-comm": "^1.5.40",
|
|
25
|
+
"@plugin-light/shared": "^1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rm -rf lib && rollup -c",
|
|
29
|
+
"bump": "node ../../script/monorepo/version-simple $PWD",
|
|
30
|
+
"changelog": "node ../../script/monorepo/changelog $PWD",
|
|
31
|
+
"release": "node ../../script/monorepo/release $PWD"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const { mkDirsSync, getPureCompName, execCommand } = require('t-comm');
|
|
5
|
+
|
|
6
|
+
const { getActPageDir, COMP_PREFIX, IS_INNER_DOCS } = require('../utils/utils');
|
|
7
|
+
|
|
8
|
+
let gComponentConfig;
|
|
9
|
+
|
|
10
|
+
const PATH_MAP = {
|
|
11
|
+
DOC_PATH: `./${IS_INNER_DOCS ? 'docs/' : ''}docs/components/press`,
|
|
12
|
+
DOC_EN_PATH: `./${IS_INNER_DOCS ? 'docs/' : ''}docs/en/components/press`,
|
|
13
|
+
DEMO_PATH: './src/pages/',
|
|
14
|
+
COMPONENT_DIR: './src/packages',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const FILENAME_MAP = {
|
|
18
|
+
LOCAL_DOC_NAME: 'README.md',
|
|
19
|
+
LOCAL_DOC_EN_NAME: 'README.en-US.md',
|
|
20
|
+
LOCAL_DEMO_NAME: 'demo.vue',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 获取组件文件夹
|
|
26
|
+
*/
|
|
27
|
+
function getComps() {
|
|
28
|
+
const dirs = fs.readdirSync(PATH_MAP.COMPONENT_DIR);
|
|
29
|
+
|
|
30
|
+
const comps = dirs
|
|
31
|
+
.filter((dir) => {
|
|
32
|
+
const vuePath = path.resolve(PATH_MAP.COMPONENT_DIR, dir, `${dir}.vue`);
|
|
33
|
+
const vueListPath = path.resolve(PATH_MAP.COMPONENT_DIR, dir, `${dir}-list.vue`);
|
|
34
|
+
return fs.existsSync(vuePath) || fs.existsSync(vueListPath);
|
|
35
|
+
})
|
|
36
|
+
.map(dir => ({
|
|
37
|
+
path: path.resolve(PATH_MAP.COMPONENT_DIR, dir),
|
|
38
|
+
name: dir,
|
|
39
|
+
}));
|
|
40
|
+
return comps;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 获取组件附近的文档列表
|
|
45
|
+
*/
|
|
46
|
+
function getLocalDocOrDemo(comps, postfix) {
|
|
47
|
+
const docs = comps
|
|
48
|
+
.filter((comp) => {
|
|
49
|
+
const { path: dir } = comp;
|
|
50
|
+
const readmePath = path.resolve(dir, postfix);
|
|
51
|
+
return fs.existsSync(readmePath);
|
|
52
|
+
})
|
|
53
|
+
.map((comp) => {
|
|
54
|
+
const { path: dir } = comp;
|
|
55
|
+
return {
|
|
56
|
+
...comp,
|
|
57
|
+
path: path.resolve(dir, postfix),
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return docs;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 移动文档
|
|
65
|
+
*/
|
|
66
|
+
function moveDocs(cb) {
|
|
67
|
+
const comps = getComps();
|
|
68
|
+
const docs = getLocalDocOrDemo(comps, FILENAME_MAP.LOCAL_DOC_NAME);
|
|
69
|
+
const docsEn = getLocalDocOrDemo(comps, FILENAME_MAP.LOCAL_DOC_EN_NAME);
|
|
70
|
+
const docsPath = path.resolve(PATH_MAP.DOC_PATH);
|
|
71
|
+
const docsEnPath = path.resolve(PATH_MAP.DOC_EN_PATH);
|
|
72
|
+
|
|
73
|
+
execCommand(`rm -rf ${docsPath}`, process.cwd(), 'inherit');
|
|
74
|
+
console.log(`>>> 已删除:${docsPath}`);
|
|
75
|
+
execCommand(`rm -rf ${docsEnPath}`, process.cwd(), 'inherit');
|
|
76
|
+
console.log(`>>> 已删除:${docsEnPath}\n`);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
console.log(`>> 共有${docs.length}个组件文档`);
|
|
80
|
+
console.log(`>> 共有${docsEn.length}个英文组件文档\n`);
|
|
81
|
+
|
|
82
|
+
for (const doc of docs) {
|
|
83
|
+
const { path: dir, name } = doc;
|
|
84
|
+
const data = fs.readFileSync(dir, {
|
|
85
|
+
encoding: 'utf-8',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
writeCompDoc(data, name, PATH_MAP.DOC_PATH);
|
|
89
|
+
}
|
|
90
|
+
for (const doc of docsEn) {
|
|
91
|
+
const { path: dir, name } = doc;
|
|
92
|
+
const data = fs.readFileSync(dir, {
|
|
93
|
+
encoding: 'utf-8',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
writeCompDoc(data, name, PATH_MAP.DOC_EN_PATH);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (typeof cb === 'function') {
|
|
100
|
+
cb();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 将文档写入docs目录
|
|
107
|
+
*/
|
|
108
|
+
function writeCompDoc(data, name, docPath) {
|
|
109
|
+
console.log(`>> 正在写入 ${name} 文档...`);
|
|
110
|
+
if (!fs.existsSync(docPath)) {
|
|
111
|
+
mkDirsSync(docPath);
|
|
112
|
+
}
|
|
113
|
+
fs.writeFileSync(path.resolve(docPath, `${name}.md`), data, {
|
|
114
|
+
encoding: 'utf-8',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 将demo写入pages目录
|
|
121
|
+
*/
|
|
122
|
+
function writeCompDemo(data, name) {
|
|
123
|
+
const pureName = getPureCompName(name, COMP_PREFIX);
|
|
124
|
+
const demoPath = `${PATH_MAP.DEMO_PATH}${getActPageDir(pureName, gComponentConfig)}`;
|
|
125
|
+
|
|
126
|
+
console.log(`>> 正在写入 ${pureName} demo...`);
|
|
127
|
+
if (!fs.existsSync(demoPath)) {
|
|
128
|
+
mkDirsSync(demoPath);
|
|
129
|
+
}
|
|
130
|
+
const dir = path.resolve(
|
|
131
|
+
demoPath,
|
|
132
|
+
pureName,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (!fs.existsSync(dir)) {
|
|
136
|
+
mkDirsSync(dir);
|
|
137
|
+
}
|
|
138
|
+
fs.writeFileSync(path.resolve(dir, `${pureName}.vue`), data, {
|
|
139
|
+
encoding: 'utf-8',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
function moveDemo(cb, config, options) {
|
|
145
|
+
if (Array.isArray(options?.toDeleteDirs)) {
|
|
146
|
+
options.toDeleteDirs.forEach((dir) => {
|
|
147
|
+
console.log(`>>> 已删除:${dir}\n`);
|
|
148
|
+
execCommand(`rm -rf ${dir}`, process.cwd(), 'inherit');
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const comps = getComps();
|
|
152
|
+
const demos = getLocalDocOrDemo(comps, FILENAME_MAP.LOCAL_DEMO_NAME);
|
|
153
|
+
|
|
154
|
+
console.log(`>> 共有${demos.length}个组件demo\n`);
|
|
155
|
+
|
|
156
|
+
if (config) {
|
|
157
|
+
gComponentConfig = config;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (const doc of demos) {
|
|
161
|
+
const { path: dir, name } = doc;
|
|
162
|
+
const data = fs.readFileSync(dir, {
|
|
163
|
+
encoding: 'utf-8',
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
writeCompDemo(data, name);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (typeof cb === 'function') {
|
|
170
|
+
cb();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
module.exports = {
|
|
176
|
+
moveDocs,
|
|
177
|
+
moveDemo,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const { mkDirsSync, hyphenate } = require('t-comm');
|
|
4
|
+
|
|
5
|
+
const { PATH_MAP, saveJsonToFile } = require('./helper');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function writeDocSidebar(componentConfig) {
|
|
9
|
+
const sidebarConfig = getSidebarConfig(false, componentConfig);
|
|
10
|
+
const sidebarEnConfig = getSidebarConfig(true, componentConfig);
|
|
11
|
+
|
|
12
|
+
mkDirsSync(path.dirname(PATH_MAP.DOC_SIDE_BAR_CONFIG));
|
|
13
|
+
saveJsonToFile(PATH_MAP.DOC_SIDE_BAR_CONFIG, sidebarConfig);
|
|
14
|
+
saveJsonToFile(PATH_MAP.DOC_SIDE_BAR_EN_CONFIG, sidebarEnConfig);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function getSidebarConfig(isEn, componentConfig) {
|
|
19
|
+
const keys = Object.keys(componentConfig);
|
|
20
|
+
const list = keys
|
|
21
|
+
.map((key) => {
|
|
22
|
+
const value = componentConfig[key];
|
|
23
|
+
const { title, name, list } = value;
|
|
24
|
+
|
|
25
|
+
const newList = list.map(item => (isEn ? {
|
|
26
|
+
title: item.name,
|
|
27
|
+
path: `/en/components/press/press-${hyphenate(item.name)}.md`,
|
|
28
|
+
} : {
|
|
29
|
+
title: item.name,
|
|
30
|
+
subTitle: item.title,
|
|
31
|
+
path: `/components/press/press-${hyphenate(item.name)}.md`,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
title: isEn ? name : title,
|
|
36
|
+
collapsable: false,
|
|
37
|
+
children: newList,
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
.filter(item => item.children.length);
|
|
41
|
+
|
|
42
|
+
return { sidebar: list };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
writeDocSidebar,
|
|
48
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const {
|
|
2
|
+
DEMO_DIR_MAP,
|
|
3
|
+
} = require('../utils/utils');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
hyphenate,
|
|
7
|
+
} = require('./generate-entry');
|
|
8
|
+
const { PATH_MAP, saveJsonToFile } = require('./helper');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function writeDemoIndexConfig(componentConfig) {
|
|
12
|
+
const pages = getCompDemoPages(componentConfig);
|
|
13
|
+
saveJsonToFile(PATH_MAP.DEMO_INDEX_CONFIG, pages);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function getCompDemoPages(componentConfig) {
|
|
18
|
+
const list = Object.keys(componentConfig)
|
|
19
|
+
.map((key) => {
|
|
20
|
+
const value = componentConfig[key];
|
|
21
|
+
const { name, list, showInMP } = value;
|
|
22
|
+
const newList = list.map(item => ({
|
|
23
|
+
// name: `${item.name} ${item.title}`,
|
|
24
|
+
url: getCompUrl(item),
|
|
25
|
+
navigationStyle: item?.style?.navigationStyle || '',
|
|
26
|
+
showInMP: showInMP === false || item.showInMP === false ? false : undefined,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
list: newList,
|
|
32
|
+
};
|
|
33
|
+
})
|
|
34
|
+
.filter(item => item.list.length);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
return { pages: list };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function getCompUrl(comp) {
|
|
42
|
+
const { name, demoRedirect, subPackage = DEMO_DIR_MAP.PRESS } = comp;
|
|
43
|
+
|
|
44
|
+
const demoName = demoRedirect || name;
|
|
45
|
+
const newName = hyphenate(demoName);
|
|
46
|
+
const prefix = subPackage;
|
|
47
|
+
const corePage = `/${prefix}/${newName}/${newName}`;
|
|
48
|
+
if (demoRedirect) {
|
|
49
|
+
return `${corePage}?comp=${hyphenate(name)}`;
|
|
50
|
+
}
|
|
51
|
+
return corePage;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
writeDemoIndexConfig,
|
|
56
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const { getPagesJsonCondition } = require('t-comm');
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
DEMO_DIR_MAP,
|
|
8
|
+
} = require('../utils/utils');
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
hyphenate,
|
|
12
|
+
} = require('./generate-entry');
|
|
13
|
+
const { PATH_MAP } = require('./helper');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function writeDemoPagesJson(componentConfig, needAct = false) {
|
|
17
|
+
const pagesJsonConfig = getPagesJsonConfig(componentConfig, needAct);
|
|
18
|
+
const configPath = path.resolve(process.cwd(), PATH_MAP.DEMO_PAGES_JSON);
|
|
19
|
+
const data = fs.readFileSync(configPath, {
|
|
20
|
+
encoding: 'utf-8',
|
|
21
|
+
});
|
|
22
|
+
const condition = getPagesJsonCondition(componentConfig);
|
|
23
|
+
const newData = data
|
|
24
|
+
.replace(/"subPackages":\s*\[[\s\S]+(?="preloadRule)/m, `"subPackages": ${JSON.stringify(pagesJsonConfig, null, 2)},
|
|
25
|
+
`)
|
|
26
|
+
.replace(/"condition":\s*\{[\s\S]+\]\s*\}/, `"condition": ${JSON.stringify(condition, null, 4)}`);
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
fs.writeFileSync(configPath, newData, {
|
|
30
|
+
encoding: 'utf-8',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function getPagesJsonConfig(componentConfig) {
|
|
36
|
+
let list = [];
|
|
37
|
+
list = Object.values(DEMO_DIR_MAP).map(type => ({
|
|
38
|
+
root: `pages/${type}`,
|
|
39
|
+
pages: getPagesJsonPages(componentConfig, type),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
list = list.filter(item => item.pages.length);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
return list;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function getPagesJsonPages(config, subPackage) {
|
|
50
|
+
const list = Object.values(config)
|
|
51
|
+
.map((item) => {
|
|
52
|
+
const { list = [] } = item;
|
|
53
|
+
const newList = list
|
|
54
|
+
.filter(item => !item.demoRedirect)
|
|
55
|
+
.filter(item => (item.subPackage || DEMO_DIR_MAP.PRESS) === subPackage)
|
|
56
|
+
.map((item) => {
|
|
57
|
+
const hyphenatedName = hyphenate(item.name);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
path: `${hyphenatedName}/${hyphenatedName}`,
|
|
61
|
+
style: {
|
|
62
|
+
...(item.style || {}),
|
|
63
|
+
navigationBarTitleText: '',
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return newList;
|
|
69
|
+
})
|
|
70
|
+
.flat();
|
|
71
|
+
|
|
72
|
+
return list;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
writeDemoPagesJson,
|
|
78
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
const {
|
|
3
|
+
hyphenate,
|
|
4
|
+
} = require('./generate-entry');
|
|
5
|
+
const { PATH_MAP, saveJsonToFile } = require('./helper');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function getTitleI18nConfig(componentConfig) {
|
|
9
|
+
const res = {
|
|
10
|
+
'zh-CN': {},
|
|
11
|
+
'en-US': {},
|
|
12
|
+
};
|
|
13
|
+
Object.keys(componentConfig)
|
|
14
|
+
.forEach((key) => {
|
|
15
|
+
const value = componentConfig[key];
|
|
16
|
+
const { list, name, title } = value;
|
|
17
|
+
|
|
18
|
+
res['zh-CN'][name] = title;
|
|
19
|
+
res['en-US'][name] = name;
|
|
20
|
+
|
|
21
|
+
list.forEach((item) => {
|
|
22
|
+
const hyphenatedName = hyphenate(item.name);
|
|
23
|
+
res['zh-CN'][hyphenatedName] = `${item.name} ${item.title}`;
|
|
24
|
+
res['en-US'][hyphenatedName] = `${item.name}`;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function writeDemoTitleI18n(componentConfig) {
|
|
33
|
+
const title = getTitleI18nConfig(componentConfig);
|
|
34
|
+
|
|
35
|
+
saveJsonToFile(PATH_MAP.DEMO_I18N, title);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
writeDemoTitleI18n,
|
|
41
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
const {
|
|
3
|
+
hyphenate,
|
|
4
|
+
getComponentPath,
|
|
5
|
+
} = require('./generate-entry');
|
|
6
|
+
const { PATH_MAP, saveJsonToFile } = require('./helper');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function getBuildConfigJson(componentConfig) {
|
|
10
|
+
const res = {};
|
|
11
|
+
Object.keys(componentConfig)
|
|
12
|
+
.forEach((key) => {
|
|
13
|
+
const value = componentConfig[key];
|
|
14
|
+
const { list } = value;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
list.forEach((item) => {
|
|
18
|
+
const hyphenatedName = hyphenate(item.name);
|
|
19
|
+
const compPath = getComponentPath(hyphenatedName);
|
|
20
|
+
res[hyphenatedName] = `./src/packages/press-${hyphenatedName}/press-${compPath}.vue`;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function writeBuildConfig(componentConfig) {
|
|
28
|
+
const json = getBuildConfigJson(componentConfig);
|
|
29
|
+
saveJsonToFile(PATH_MAP.BUILD_CONFIG, json);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
writeBuildConfig,
|
|
34
|
+
};
|