@widget-js/cli 1.1.5 → 1.1.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.
- package/lib/index.js +155695 -28
- package/package.json +12 -10
- package/src/createWidget.ts +199 -194
- package/src/index.ts +1 -4
- package/template/Widget.ejs +1 -4
- package/template/WidgetConfig.ejs +13 -25
- package/template/WidgetDefine.ejs +26 -27
- package/template/WidgetRoutes.ejs +3 -3
- package/template/WidgetView.ejs +3 -10
- package/widget.ts +24 -0
- package/lib/build-BTARJMCZ.js +0 -31
- package/lib/chunk-3GPAHQ6O.js +0 -18
- package/lib/chunk-NJPDF23X.js +0 -34
- package/lib/createWidget-LWD7JPGR.js +0 -193
- package/lib/dependencies-J3BZI237.js +0 -87
- package/lib/index.cjs +0 -689
- package/lib/index.d.ts +0 -2
- package/lib/release-W3SP4YSR.js +0 -212
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"widget": "lib/index.js"
|
|
10
10
|
},
|
|
11
|
-
"type": "module",
|
|
12
11
|
"publishConfig": {
|
|
13
12
|
"access": "public"
|
|
14
13
|
},
|
|
@@ -22,20 +21,21 @@
|
|
|
22
21
|
"@widget-js/ssh-config": "^4.2.1",
|
|
23
22
|
"ali-oss": "^6.17.1",
|
|
24
23
|
"archiver": "^5.3.1",
|
|
25
|
-
"chalk": "^
|
|
24
|
+
"chalk": "^4.1.2",
|
|
26
25
|
"change-case": "^4.1.2",
|
|
27
26
|
"commander": "^9.4.1",
|
|
28
27
|
"consola": "^2.15.3",
|
|
29
28
|
"ejs": "^3.1.8",
|
|
30
29
|
"figlet": "^1.5.2",
|
|
31
30
|
"gradient-string": "^2.0.2",
|
|
32
|
-
"inquirer": "^
|
|
33
|
-
"ora": "^
|
|
31
|
+
"inquirer": "^8.0.0",
|
|
32
|
+
"ora": "^5.4.1",
|
|
34
33
|
"package-json": "^8.1.0",
|
|
35
34
|
"semver": "^7.3.8",
|
|
36
35
|
"shelljs": "^0.8.5",
|
|
37
36
|
"ssh2-sftp-client": "^9.0.4",
|
|
38
|
-
"ws": "^8.11.0"
|
|
37
|
+
"ws": "^8.11.0",
|
|
38
|
+
"@widget-js/utils": "0.7.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/ali-oss": "^6.16.7",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/ssh2-sftp-client": "^9.0.0",
|
|
50
50
|
"jest": "^29.5.0",
|
|
51
51
|
"pinst": "^3.0.0",
|
|
52
|
-
"prettier": "^2.8.
|
|
52
|
+
"prettier": "^2.8.8",
|
|
53
53
|
"rimraf": "^4.4.1",
|
|
54
54
|
"ts-jest": "^29.0.3",
|
|
55
55
|
"ts-loader": "^9.4.1",
|
|
@@ -57,15 +57,17 @@
|
|
|
57
57
|
"tsup": "^6.5.0",
|
|
58
58
|
"typescript": "^4.9.4",
|
|
59
59
|
"webpack": "^5.75.0",
|
|
60
|
-
"webpack-cli": "^5.0.0"
|
|
60
|
+
"webpack-cli": "^5.0.0",
|
|
61
|
+
"@widget-js/core": "0.7.2"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
|
-
"build": "rimraf ./lib/ && tsup src/index.ts --
|
|
64
|
-
"watch": "tsup src/index.ts --
|
|
64
|
+
"build": "rimraf ./lib/ && tsup src/index.ts --format cjs",
|
|
65
|
+
"watch": "tsup src/index.ts --format cjs --watch",
|
|
65
66
|
"build:run": "npm run build && npm run widget",
|
|
66
67
|
"prebuild": "",
|
|
67
68
|
"widget": "node ./lib/index.js",
|
|
68
69
|
"widget:ftp": "node ./lib/index.js release -t ftp",
|
|
70
|
+
"widget:create": "npm run build && node ./lib/index.js create",
|
|
69
71
|
"pnpm:publish": "pnpm publish --no-git-checks"
|
|
70
72
|
}
|
|
71
73
|
}
|
package/src/createWidget.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import consola from "consola";
|
|
4
|
-
import {fileURLToPath} from "url";
|
|
5
4
|
import promptChecker from "./promts/promptChecker";
|
|
6
5
|
import {paramCase, snakeCase} from "change-case";
|
|
7
6
|
import inquirer from "inquirer";
|
|
@@ -9,213 +8,219 @@ import ejs from "ejs";
|
|
|
9
8
|
import shell from "shelljs";
|
|
10
9
|
import exit from "./utils.js";
|
|
11
10
|
import chalk from "chalk";
|
|
11
|
+
import {WidgetUtils} from "@widget-js/utils";
|
|
12
|
+
import prettier, {BuiltInParserName} from "prettier";
|
|
13
|
+
|
|
14
|
+
// import vm from "vm";
|
|
15
|
+
|
|
12
16
|
interface RenderOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
name: string,
|
|
18
|
+
snakeCaseName: string,
|
|
19
|
+
paramCaseName: string,
|
|
20
|
+
packageName: string,
|
|
21
|
+
widgetName: string,
|
|
22
|
+
title: string,
|
|
23
|
+
configurable: string,
|
|
24
|
+
width: number,
|
|
25
|
+
height: number,
|
|
26
|
+
maxWidth: number,
|
|
27
|
+
minHeight: number,
|
|
28
|
+
maxHeight: number,
|
|
29
|
+
minWidth: number,
|
|
25
30
|
}
|
|
26
|
-
export default async function createWidget() {
|
|
27
|
-
let widgetJson = path.join(process.cwd(), "widget.json");
|
|
28
|
-
if (!fs.existsSync(widgetJson)) {
|
|
29
|
-
consola.error("没有在根目录找到widget.json文件")
|
|
30
|
-
exit();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let widgetPackage = JSON.parse(fs.readFileSync(widgetJson).toString());
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
export default async function createWidget() {
|
|
33
|
+
let widgetPackage = await WidgetUtils.scanWidgetPackage(process.cwd());
|
|
34
|
+
if (!widgetPackage) {
|
|
35
|
+
consola.error("widget.ts or widget.json not found")
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let widgetFolder = path.join(process.cwd(), "./src/widgets");
|
|
39
|
+
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
40
|
+
if (devOptions["folder"]) {
|
|
41
|
+
widgetFolder = devOptions["folder"];
|
|
42
|
+
consola.info(`组件路径:${widgetFolder}`);
|
|
43
|
+
} else {
|
|
44
|
+
consola.info(`没有配置devOptions.folder,使用默认路径${widgetFolder}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(widgetFolder)) {
|
|
48
|
+
fs.mkdirSync(widgetFolder, {recursive: true});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getMiddleValue = (arr: number[]) => {
|
|
52
|
+
if (arr.length === 1) {
|
|
53
|
+
return arr[0];
|
|
54
|
+
} else if (arr.length === 2) {
|
|
55
|
+
return Math.max(...arr);
|
|
40
56
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fs.mkdirSync(widgetFolder, {recursive: true});
|
|
57
|
+
const max = Math.max(...arr);
|
|
58
|
+
const min = Math.min(...arr);
|
|
59
|
+
const sum = arr[0] + arr[1] + arr[2];
|
|
60
|
+
return sum - max - min;
|
|
46
61
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const min = Math.min(...arr);
|
|
59
|
-
const sum = arr[0] + arr[1] + arr[2];
|
|
60
|
-
return sum - max - min;
|
|
61
|
-
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let name = await promptChecker({
|
|
65
|
+
type: "input",
|
|
66
|
+
name: 'name',
|
|
67
|
+
message: chalk.blue("请输入组件名(大驼峰式),如:CountdownClock")
|
|
68
|
+
}, (answer) => {
|
|
69
|
+
const name = answer.name;
|
|
70
|
+
if (name == null || name === '') {
|
|
71
|
+
consola.log(chalk.red('组件名不能为空'));
|
|
72
|
+
return false;
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
consola.log(chalk.green(title))
|
|
85
|
-
let answerW = await promptChecker({
|
|
86
|
-
type: "checkbox",
|
|
87
|
-
name: 'w',
|
|
88
|
-
message: chalk.blue("请选择组件宽度,最多选3个,例如选中2,4,6,代表组件最小宽为2,默认宽为4,最大宽为6,单选代表不可拉伸"),
|
|
89
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
90
|
-
}, (answer) => {
|
|
91
|
-
if (answer.w.length === 0) {
|
|
92
|
-
consola.log(chalk.red('宽度必须选择'));
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (answer.w.length > 3) {
|
|
97
|
-
consola.log(chalk.red('宽度最多选择3个'));
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
})
|
|
102
|
-
consola.log(chalk.green(answerW))
|
|
103
|
-
|
|
104
|
-
let answerH = await promptChecker({
|
|
105
|
-
type: "checkbox",
|
|
106
|
-
name: 'h',
|
|
107
|
-
message: chalk.blue("请选择组件高度,最多选3个,例如选中1,2,代表组件最小高为1,默认高为2,最大高为2,单选代表不可拉伸"),
|
|
108
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
109
|
-
}, (answer) => {
|
|
110
|
-
if (answer.h.length === 0) {
|
|
111
|
-
consola.log(chalk.red('高度必须选择'));
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (answer.h.length > 3) {
|
|
116
|
-
consola.log(chalk.red('高度最多选择3个'));
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
consola.log(chalk.green(answerH))
|
|
123
|
-
|
|
124
|
-
let configurable = await promptChecker({
|
|
125
|
-
type: "confirm",
|
|
126
|
-
name: 'configurable',
|
|
127
|
-
message: chalk.blue("组件是否可配置,例如修改背景颜色,字体大小等")
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
consola.log(chalk.green(configurable))
|
|
131
|
-
|
|
132
|
-
const width = getMiddleValue(answerW);
|
|
133
|
-
const height = getMiddleValue(answerH);
|
|
134
|
-
const minWidth = Math.min(...answerW);
|
|
135
|
-
const maxWidth = Math.max(...answerW);
|
|
136
|
-
const minHeight = Math.min(...answerH);
|
|
137
|
-
const maxHeight = Math.max(...answerH);
|
|
138
|
-
const snakeCaseName = snakeCase(name);
|
|
139
|
-
const paramCaseName = paramCase(name);
|
|
140
|
-
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
141
|
-
|
|
142
|
-
const widgetDir = path.join(widgetFolder, paramCaseName)
|
|
143
|
-
if (!fs.existsSync(widgetDir)) {
|
|
144
|
-
fs.mkdirSync(widgetDir);
|
|
145
|
-
} else {
|
|
146
|
-
let answer = await inquirer.prompt([{
|
|
147
|
-
type: 'confirm',
|
|
148
|
-
name: 'override',
|
|
149
|
-
message: chalk.red('组件名已存在,是否继续?')
|
|
150
|
-
}])
|
|
151
|
-
if (!answer.override) {
|
|
152
|
-
exit()
|
|
153
|
-
}
|
|
74
|
+
return true;
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
consola.log(chalk.green(name))
|
|
78
|
+
|
|
79
|
+
let title = await promptChecker({
|
|
80
|
+
type: "input",
|
|
81
|
+
name: 'title',
|
|
82
|
+
message: chalk.blue("请输入组件标题,如:倒计时")
|
|
83
|
+
})
|
|
84
|
+
consola.log(chalk.green(title))
|
|
85
|
+
let answerW = await promptChecker({
|
|
86
|
+
type: "checkbox",
|
|
87
|
+
name: 'w',
|
|
88
|
+
message: chalk.blue("请选择组件宽度,最多选3个,例如选中2,4,6,代表组件最小宽为2,默认宽为4,最大宽为6,单选代表不可拉伸"),
|
|
89
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
90
|
+
}, (answer) => {
|
|
91
|
+
if (answer.w.length === 0) {
|
|
92
|
+
consola.log(chalk.red('宽度必须选择'));
|
|
93
|
+
return false;
|
|
154
94
|
}
|
|
155
95
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
paramCaseName: paramCaseName,
|
|
160
|
-
packageName: packageName,
|
|
161
|
-
title: title,
|
|
162
|
-
configurable: configurable,
|
|
163
|
-
width: width,
|
|
164
|
-
height: height,
|
|
165
|
-
maxWidth: maxWidth,
|
|
166
|
-
minHeight: minHeight,
|
|
167
|
-
maxHeight: maxHeight,
|
|
168
|
-
minWidth: minWidth
|
|
96
|
+
if (answer.w.length > 3) {
|
|
97
|
+
consola.log(chalk.red('宽度最多选择3个'));
|
|
98
|
+
return false;
|
|
169
99
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
100
|
+
return true;
|
|
101
|
+
})
|
|
102
|
+
consola.log(chalk.green(answerW))
|
|
103
|
+
|
|
104
|
+
let answerH = await promptChecker({
|
|
105
|
+
type: "checkbox",
|
|
106
|
+
name: 'h',
|
|
107
|
+
message: chalk.blue("请选择组件高度,最多选3个,例如选中1,2,代表组件最小高为1,默认高为2,最大高为2,单选代表不可拉伸"),
|
|
108
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
109
|
+
}, (answer) => {
|
|
110
|
+
if (answer.h.length === 0) {
|
|
111
|
+
consola.log(chalk.red('高度必须选择'));
|
|
112
|
+
return false;
|
|
175
113
|
}
|
|
176
114
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`)
|
|
181
|
-
|
|
182
|
-
renderToFile('WidgetDefine.ejs', widgetDefineFile, renderOptions);
|
|
183
|
-
renderToFile('Widget.ejs', widgetFile, renderOptions);
|
|
184
|
-
renderToFile('WidgetView.ejs', widgetViewFile, renderOptions);
|
|
185
|
-
renderToFile('WidgetRoutes.ejs', widgetRoutesFile, renderOptions);
|
|
186
|
-
if (configurable) {
|
|
187
|
-
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`)
|
|
188
|
-
renderToFile('WidgetConfig.ejs', configFile, renderOptions);
|
|
115
|
+
if (answer.h.length > 3) {
|
|
116
|
+
consola.log(chalk.red('高度最多选择3个'));
|
|
117
|
+
return false;
|
|
189
118
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
119
|
+
return true;
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
consola.log(chalk.green(answerH))
|
|
123
|
+
|
|
124
|
+
let configurable = await promptChecker({
|
|
125
|
+
type: "confirm",
|
|
126
|
+
name: 'configurable',
|
|
127
|
+
message: chalk.blue("组件是否可配置,例如修改背景颜色,字体大小等")
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
consola.log(chalk.green(configurable))
|
|
131
|
+
|
|
132
|
+
const width = getMiddleValue(answerW);
|
|
133
|
+
const height = getMiddleValue(answerH);
|
|
134
|
+
const minWidth = Math.min(...answerW);
|
|
135
|
+
const maxWidth = Math.max(...answerW);
|
|
136
|
+
const minHeight = Math.min(...answerH);
|
|
137
|
+
const maxHeight = Math.max(...answerH);
|
|
138
|
+
const snakeCaseName = snakeCase(name);
|
|
139
|
+
const paramCaseName = paramCase(name);
|
|
140
|
+
|
|
141
|
+
const widgetName = widgetPackage.name + '.' + snakeCaseName;
|
|
142
|
+
|
|
143
|
+
const widgetDir = path.join(widgetFolder, paramCaseName)
|
|
144
|
+
if (!fs.existsSync(widgetDir)) {
|
|
145
|
+
fs.mkdirSync(widgetDir);
|
|
146
|
+
} else {
|
|
147
|
+
let answer = await inquirer.prompt([{
|
|
148
|
+
type: 'confirm',
|
|
149
|
+
name: 'override',
|
|
150
|
+
message: chalk.red('组件名已存在,是否继续?')
|
|
151
|
+
}])
|
|
152
|
+
if (!answer.override) {
|
|
153
|
+
exit()
|
|
193
154
|
}
|
|
194
|
-
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const renderOptions: RenderOptions = {
|
|
158
|
+
name: name,
|
|
159
|
+
snakeCaseName: snakeCaseName,
|
|
160
|
+
paramCaseName: paramCaseName,
|
|
161
|
+
packageName: widgetPackage.name,
|
|
162
|
+
widgetName: widgetName,
|
|
163
|
+
title: title,
|
|
164
|
+
configurable: configurable,
|
|
165
|
+
width: width,
|
|
166
|
+
height: height,
|
|
167
|
+
maxWidth: maxWidth,
|
|
168
|
+
minHeight: minHeight,
|
|
169
|
+
maxHeight: maxHeight,
|
|
170
|
+
minWidth: minWidth
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function renderToFile(templateFile: string, outputFile: string, parser: BuiltInParserName, renderOptions: RenderOptions) {
|
|
174
|
+
const defineTemplatePath = path.join(__dirname, '../template', templateFile)
|
|
175
|
+
let defineTemplate = fs.readFileSync(defineTemplatePath, 'utf8');
|
|
176
|
+
// Format the EJS code using Prettier
|
|
177
|
+
|
|
178
|
+
let code = ejs.render(defineTemplate, renderOptions);
|
|
179
|
+
let fileFormat = outputFile.split('.');
|
|
180
|
+
const formattedEJSCode = prettier.format(code, {
|
|
181
|
+
parser: parser, tabWidth: 2, singleQuote: true
|
|
182
|
+
});
|
|
183
|
+
fs.writeFileSync(outputFile, formattedEJSCode)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`)
|
|
187
|
+
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
|
|
188
|
+
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`)
|
|
189
|
+
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`)
|
|
190
|
+
|
|
191
|
+
renderToFile('WidgetDefine.ejs', widgetDefineFile, 'typescript', renderOptions);
|
|
192
|
+
renderToFile('Widget.ejs', widgetFile, 'vue', renderOptions);
|
|
193
|
+
renderToFile('WidgetView.ejs', widgetViewFile, 'vue', renderOptions);
|
|
194
|
+
renderToFile('WidgetRoutes.ejs', widgetRoutesFile, 'typescript', renderOptions);
|
|
195
|
+
if (configurable) {
|
|
196
|
+
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`)
|
|
197
|
+
renderToFile('WidgetConfig.ejs', configFile, 'vue', renderOptions)
|
|
198
|
+
;
|
|
199
|
+
}
|
|
195
200
|
// 注册路由
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
const routeFile = path.join(widgetFolder, 'widget-router.ts');
|
|
202
|
+
let routeContent;
|
|
203
|
+
if (fs.existsSync(routeFile)) {
|
|
204
|
+
routeContent = fs.readFileSync(routeFile, 'utf8');
|
|
205
|
+
} else {
|
|
206
|
+
routeContent = fs.readFileSync(path.join(__dirname, "../template/widget-router.ts"), 'utf8');
|
|
207
|
+
}
|
|
208
|
+
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`
|
|
209
|
+
const routeStr = `...${name}WidgetRoutes,`
|
|
210
|
+
if (!routeContent.includes(importRouteStr)) {
|
|
211
|
+
routeContent = routeContent.replaceAll("//FBI WANING! IMPORT PLACE", `${importRouteStr}\n//FBI WANING! IMPORT PLACE`)
|
|
212
|
+
}
|
|
213
|
+
if (!routeContent.includes(routeStr)) {
|
|
214
|
+
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}\n //FBI WANING! ROUTE PLACE`)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
fs.writeFileSync(routeFile, routeContent)
|
|
213
218
|
|
|
214
219
|
//添加到版本控制
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
let gitAdd = `git add ${widgetDir}`;
|
|
221
|
+
consola.info(chalk.grey(gitAdd))
|
|
222
|
+
shell.exec(gitAdd);
|
|
223
|
+
consola.log("=================")
|
|
224
|
+
consola.info(`已创建组件:${widgetDir}`)
|
|
225
|
+
consola.success("Happy coding!")
|
|
221
226
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,14 +3,11 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import * as process from "process";
|
|
5
5
|
|
|
6
|
-
import {fileURLToPath} from "url";
|
|
7
6
|
import figlet from "figlet";
|
|
8
7
|
import gradient from "gradient-string";
|
|
9
8
|
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = path.dirname(__filename);
|
|
12
9
|
//
|
|
13
|
-
const packageJsonPath = path.join(
|
|
10
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
14
11
|
let cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
15
12
|
|
|
16
13
|
console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", {horizontalLayout: "full"})));
|
package/template/Widget.ejs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
2
|
<widget-edit-dialog :widget-params="widgetParams" :option="widgetConfigOption"
|
|
4
3
|
:widget-data="widgetData"
|
|
5
4
|
@confirm="onSaveClick()">
|
|
@@ -9,35 +8,24 @@
|
|
|
9
8
|
</widget-edit-dialog>
|
|
10
9
|
</template>
|
|
11
10
|
|
|
12
|
-
<script lang="ts">
|
|
13
|
-
|
|
14
|
-
import <%= name %>Widget from "./<%= name%>Widget.vue";
|
|
15
|
-
import {useWidget, WidgetConfigOption, WidgetEditDialog} from "@widget-js/vue3";
|
|
11
|
+
<script lang="ts" setup>
|
|
12
|
+
import {useWidget, WidgetConfigOption,WidgetEditDialog} from "@widget-js/vue3";
|
|
16
13
|
import {WidgetData, WidgetDataApi} from "@widget-js/core";
|
|
17
14
|
import {reactive} from "vue";
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
name: "",
|
|
21
|
-
components: {<%= name %>Widget, WidgetEditDialog},
|
|
22
|
-
setup() {
|
|
23
|
-
const {widgetData, widgetParams} = useWidget(WidgetData)
|
|
16
|
+
const {widgetData, widgetParams} = useWidget(WidgetData)
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
//修改成需要设置组件参数配置
|
|
19
|
+
const widgetConfigOption = reactive(new WidgetConfigOption({
|
|
20
|
+
custom: true,
|
|
21
|
+
backgroundColor: true,
|
|
22
|
+
borderRadius: true,
|
|
23
|
+
preview: false
|
|
24
|
+
}));
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
async onSaveClick() {
|
|
37
|
-
await WidgetDataApi.save(this.widgetData);
|
|
38
|
-
window.close();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
26
|
+
const onSaveClick = async () => {
|
|
27
|
+
await WidgetDataApi.save(widgetData);
|
|
28
|
+
window.close();
|
|
41
29
|
}
|
|
42
30
|
</script>
|
|
43
31
|
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import {Widget, WidgetKeyword} from "@widget-js/core";
|
|
2
2
|
//TODO 修改组件信息,标题,描述,关键词
|
|
3
|
-
const name = "
|
|
3
|
+
const name = "<%= widgetName %>";
|
|
4
4
|
//组件标题
|
|
5
|
-
const title = {"zh-CN": "<%= title%>"};
|
|
5
|
+
const title = {"zh-CN": "<%= title %>"};
|
|
6
6
|
//组件描述
|
|
7
7
|
const description = {"zh-CN": ""};
|
|
8
8
|
//组件关键词
|
|
9
9
|
const keywords = [WidgetKeyword.RECOMMEND];
|
|
10
10
|
//组件路由地址
|
|
11
|
-
const url = "/widget/<%= snakeCaseName%>";
|
|
11
|
+
const url = "/widget/<%= snakeCaseName %>";
|
|
12
12
|
//配置页路由地址
|
|
13
|
-
const configUrl = <% if (configurable) { %>"/widget/config/<%= snakeCaseName%>"<% } else { %>undefined<% }
|
|
13
|
+
const configUrl = <% if (configurable) { %>"/widget/config/<%= snakeCaseName %>"<% } else { %>undefined<% } %>;
|
|
14
14
|
//组件关键词
|
|
15
15
|
const <%= name %>WidgetDefine = new Widget({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<% if (configurable) { %>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
]
|
|
16
|
+
name: name,
|
|
17
|
+
title: title,
|
|
18
|
+
description: description,
|
|
19
|
+
keywords: keywords,
|
|
20
|
+
lang: "zh-CN",
|
|
21
|
+
width: <%= width %>,
|
|
22
|
+
height: <%= height %>,
|
|
23
|
+
minWidth: <%= minWidth %>,
|
|
24
|
+
maxWidth: <%= maxWidth %>,
|
|
25
|
+
minHeight: <%= minHeight %>,
|
|
26
|
+
maxHeight: <%= maxHeight %>,
|
|
27
|
+
routes: [
|
|
28
|
+
{
|
|
29
|
+
url: url,
|
|
30
|
+
name: 'index'
|
|
31
|
+
},
|
|
32
|
+
<% if (configurable) { %> {
|
|
33
|
+
url: configUrl,
|
|
34
|
+
name: 'config'
|
|
35
|
+
},
|
|
36
|
+
<% } %>
|
|
37
|
+
]
|
|
39
38
|
})
|
|
40
39
|
|
|
41
40
|
export default <%= name %>WidgetDefine;
|
|
@@ -9,12 +9,12 @@ const <%= name %>WidgetRoutes = [
|
|
|
9
9
|
{
|
|
10
10
|
path: url,
|
|
11
11
|
name: `${name}`,
|
|
12
|
-
component: () => import(/* webpackChunkName: "<%=
|
|
12
|
+
component: () => import(/* webpackChunkName: "<%= widgetName %>" */ './<%= name %>WidgetView.vue')
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
path: configUrl,
|
|
16
16
|
name: `${name}.config`,
|
|
17
|
-
component: () => import(/* webpackChunkName: "<%=
|
|
17
|
+
component: () => import(/* webpackChunkName: "<%= widgetName %>.config" */ './<%= name %>ConfigView.vue')
|
|
18
18
|
}
|
|
19
19
|
]
|
|
20
20
|
<% } else { %>
|
|
@@ -22,7 +22,7 @@ const <%= name %>WidgetRoutes = [
|
|
|
22
22
|
{
|
|
23
23
|
path: url,
|
|
24
24
|
name: `${name}`,
|
|
25
|
-
component: () => import(/* webpackChunkName: "<%=
|
|
25
|
+
component: () => import(/* webpackChunkName: "<%= widgetName %>" */ './<%= name %>WidgetView.vue')
|
|
26
26
|
}
|
|
27
27
|
]
|
|
28
28
|
<% } %>
|