@widget-js/cli 1.2.11 → 24.1.1-beta.1
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/jest.config.js +3 -3
- package/lib/{chunk-RAXJBANW.js → chunk-I4ZBPB2S.js} +45 -45
- package/lib/{chunk-IJH6LXRT.js → chunk-RDJH7Z4C.js} +74 -74
- package/lib/{chunk-3GPAHQ6O.js → chunk-XPJ33Y5L.js} +18 -18
- package/lib/{createWidget-UFW26NP6.js → createWidget-4LQ6PVEM.js} +200 -200
- package/lib/{dependencies-MRJDJJ6Q.js → dependencies-AVNHKRF3.js} +81 -81
- package/lib/index.js +35 -32
- package/lib/{init-MQONV3N3.js → init-HCEGKTNF.js} +117 -117
- package/lib/{release-XUYU5WNC.js → release-AQDFL5H3.js} +223 -226
- package/package.json +17 -15
- package/src/build/build.ts +8 -8
- package/src/createWidget.ts +46 -40
- package/src/dependencies/index.ts +6 -5
- package/src/dependencies/localDependencies.ts +17 -18
- package/src/dependencies/remoteDependencies.ts +22 -25
- package/src/index.ts +36 -36
- package/src/init/init.ts +23 -21
- package/src/promts/promptChecker.ts +10 -8
- package/src/release/ftp.ts +31 -27
- package/src/release/oss.ts +40 -38
- package/src/release/release.ts +17 -24
- package/src/release/update-zip.ts +14 -14
- package/src/utils/EJSUtils.ts +10 -9
- package/src/utils/PrettierUtils.ts +3 -2
- package/src/utils/WidgetPackageUtils.ts +5 -5
- package/src/utils.ts +31 -27
- package/template/WidgetConfig.ejs +7 -6
- package/template/widget-router.ts +5 -4
- package/test/index.test.ts +7 -7
- package/tsconfig.json +25 -25
- package/tsup.config.ts +4 -4
- package/vite.config.ts +5 -5
- package/release-xyy.json +0 -7
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EJSUtils,
|
|
3
|
-
WidgetPackageUtils
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
promptChecker_default
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import {
|
|
9
|
-
exit
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
|
|
12
|
-
// src/createWidget.ts
|
|
13
|
-
import path from "path";
|
|
14
|
-
import fs from "fs";
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
22
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
23
|
-
var __dirname = path.dirname(__filename);
|
|
24
|
-
async function createWidget() {
|
|
25
|
-
|
|
26
|
-
if (!widgetPackage) {
|
|
27
|
-
consola.error("widget.ts or widget.json not found");
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (widgetPackage.devOptions && widgetPackage.devOptions.folder) {
|
|
32
|
-
consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetRootDir}`);
|
|
33
|
-
} else {
|
|
34
|
-
consola.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetRootDir}`);
|
|
35
|
-
}
|
|
36
|
-
const getMiddleValue = (arr) => {
|
|
37
|
-
if (arr.length === 1) {
|
|
38
|
-
return arr[0];
|
|
39
|
-
} else if (arr.length === 2) {
|
|
40
|
-
return Math.max(...arr);
|
|
41
|
-
} else {
|
|
42
|
-
const max = Math.max(...arr);
|
|
43
|
-
const min = Math.min(...arr);
|
|
44
|
-
const sum = arr[0] + arr[1] + arr[2];
|
|
45
|
-
return sum - max - min;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
type: "input",
|
|
51
|
-
name: "name",
|
|
52
|
-
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
|
|
53
|
-
},
|
|
54
|
-
(answer) => {
|
|
55
|
-
const name2 = answer.name;
|
|
56
|
-
if (name2 == null || name2 === "") {
|
|
57
|
-
consola.log(chalk.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
consola.log(chalk.green(name));
|
|
64
|
-
|
|
65
|
-
type: "input",
|
|
66
|
-
name: "title",
|
|
67
|
-
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
68
|
-
});
|
|
69
|
-
consola.log(chalk.green(title));
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
type: "checkbox",
|
|
73
|
-
name: "w",
|
|
74
|
-
message: chalk.blue(
|
|
75
|
-
"\u8BF7\u9009\u62E9\u7EC4\u4EF6\u5BBD\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D2,4,6\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u5BBD\u4E3A2\uFF0C\u9ED8\u8BA4\u5BBD\u4E3A4\uFF0C\u6700\u5927\u5BBD\u4E3A6\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"
|
|
76
|
-
),
|
|
77
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
78
|
-
},
|
|
79
|
-
(answer) => {
|
|
80
|
-
if (answer.w.length === 0) {
|
|
81
|
-
consola.log(chalk.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (answer.w.length > 3) {
|
|
85
|
-
consola.log(chalk.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
consola.log(chalk.green(answerW));
|
|
92
|
-
|
|
93
|
-
{
|
|
94
|
-
type: "checkbox",
|
|
95
|
-
name: "h",
|
|
96
|
-
message: chalk.blue(
|
|
97
|
-
"\u8BF7\u9009\u62E9\u7EC4\u4EF6\u9AD8\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D1,2\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u4E3A1\uFF0C\u9ED8\u8BA4\u9AD8\u4E3A2\uFF0C\u6700\u5927\u9AD8\u4E3A2\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"
|
|
98
|
-
),
|
|
99
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
100
|
-
},
|
|
101
|
-
(answer) => {
|
|
102
|
-
if (answer.h.length === 0) {
|
|
103
|
-
consola.log(chalk.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
if (answer.h.length > 3) {
|
|
107
|
-
consola.log(chalk.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
consola.log(chalk.green(answerH));
|
|
114
|
-
|
|
115
|
-
type: "confirm",
|
|
116
|
-
name: "configurable",
|
|
117
|
-
message: chalk.blue("\u7EC4\u4EF6\u662F\u5426\u53EF\u914D\u7F6E\uFF0C\u4F8B\u5982\u4FEE\u6539\u80CC\u666F\u989C\u8272\uFF0C\u5B57\u4F53\u5927\u5C0F\u7B49")
|
|
118
|
-
});
|
|
119
|
-
consola.log(chalk.green(configurable));
|
|
120
|
-
const width = getMiddleValue(answerW);
|
|
121
|
-
const height = getMiddleValue(answerH);
|
|
122
|
-
const minWidth = Math.min(...answerW);
|
|
123
|
-
const maxWidth = Math.max(...answerW);
|
|
124
|
-
const minHeight = Math.min(...answerH);
|
|
125
|
-
const maxHeight = Math.max(...answerH);
|
|
126
|
-
const snakeCaseName = snakeCase(name);
|
|
127
|
-
const paramCaseName = paramCase(name);
|
|
128
|
-
const widgetName = widgetPackage.name
|
|
129
|
-
const widgetDir = path.join(widgetRootDir, paramCaseName);
|
|
130
|
-
if (!fs.existsSync(widgetDir)) {
|
|
131
|
-
fs.mkdirSync(widgetDir);
|
|
132
|
-
} else {
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
type: "confirm",
|
|
136
|
-
name: "override",
|
|
137
|
-
message: chalk.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
|
|
138
|
-
}
|
|
139
|
-
]);
|
|
140
|
-
if (!answer.override) {
|
|
141
|
-
exit();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const renderOptions = {
|
|
145
|
-
name,
|
|
146
|
-
snakeCaseName,
|
|
147
|
-
paramCaseName,
|
|
148
|
-
packageName: widgetPackage.name,
|
|
149
|
-
widgetName,
|
|
150
|
-
title,
|
|
151
|
-
configurable,
|
|
152
|
-
width,
|
|
153
|
-
height,
|
|
154
|
-
maxWidth,
|
|
155
|
-
minHeight,
|
|
156
|
-
maxHeight,
|
|
157
|
-
minWidth
|
|
158
|
-
};
|
|
159
|
-
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`);
|
|
160
|
-
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
|
|
161
|
-
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
162
|
-
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
163
|
-
await EJSUtils.renderToFile("WidgetDefine.ejs", widgetDefineFile, "typescript", renderOptions);
|
|
164
|
-
await EJSUtils.renderToFile("WidgetView.ejs", widgetViewFile, "vue", renderOptions);
|
|
165
|
-
await EJSUtils.renderToFile("WidgetRoutes.ejs", widgetRoutesFile, "typescript", renderOptions);
|
|
166
|
-
if (configurable) {
|
|
167
|
-
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
168
|
-
await EJSUtils.renderToFile("WidgetConfig.ejs", configFile, "vue", renderOptions);
|
|
169
|
-
}
|
|
170
|
-
const routeFile = path.join(widgetRootDir, "widget-router.ts");
|
|
171
|
-
let routeContent;
|
|
172
|
-
if (fs.existsSync(routeFile)) {
|
|
173
|
-
routeContent = fs.readFileSync(routeFile, "utf8");
|
|
174
|
-
} else {
|
|
175
|
-
routeContent = fs.readFileSync(path.join(__dirname, "../template/widget-router.ts"), "utf8");
|
|
176
|
-
}
|
|
177
|
-
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
178
|
-
const routeStr = `...${name}WidgetRoutes,`;
|
|
179
|
-
if (!routeContent.includes(importRouteStr)) {
|
|
180
|
-
routeContent = routeContent.replaceAll(
|
|
181
|
-
"//FBI WANING! IMPORT PLACE",
|
|
182
|
-
`${importRouteStr}
|
|
183
|
-
//FBI WANING! IMPORT PLACE`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
if (!routeContent.includes(routeStr)) {
|
|
187
|
-
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
188
|
-
//FBI WANING! ROUTE PLACE`);
|
|
189
|
-
}
|
|
190
|
-
fs.writeFileSync(routeFile, routeContent);
|
|
191
|
-
|
|
192
|
-
consola.info(chalk.grey(gitAdd));
|
|
193
|
-
shell.exec(gitAdd);
|
|
194
|
-
consola.log("=================");
|
|
195
|
-
consola.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
196
|
-
consola.success("Happy coding!");
|
|
197
|
-
}
|
|
198
|
-
export {
|
|
199
|
-
createWidget as default
|
|
200
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
EJSUtils,
|
|
3
|
+
WidgetPackageUtils
|
|
4
|
+
} from "./chunk-I4ZBPB2S.js";
|
|
5
|
+
import {
|
|
6
|
+
promptChecker_default
|
|
7
|
+
} from "./chunk-XPJ33Y5L.js";
|
|
8
|
+
import {
|
|
9
|
+
exit
|
|
10
|
+
} from "./chunk-RDJH7Z4C.js";
|
|
11
|
+
|
|
12
|
+
// src/createWidget.ts
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import consola from "consola";
|
|
17
|
+
import { paramCase, snakeCase } from "change-case";
|
|
18
|
+
import inquirer from "inquirer";
|
|
19
|
+
import shell from "shelljs";
|
|
20
|
+
import chalk from "chalk";
|
|
21
|
+
import { scanWidgetPackage } from "@widget-js/utils";
|
|
22
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
var __dirname = path.dirname(__filename);
|
|
24
|
+
async function createWidget() {
|
|
25
|
+
const widgetPackage = await scanWidgetPackage();
|
|
26
|
+
if (!widgetPackage) {
|
|
27
|
+
consola.error("widget.ts or widget.json not found");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const widgetRootDir = WidgetPackageUtils.getRootDir(widgetPackage);
|
|
31
|
+
if (widgetPackage.devOptions && widgetPackage.devOptions.folder) {
|
|
32
|
+
consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetRootDir}`);
|
|
33
|
+
} else {
|
|
34
|
+
consola.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetRootDir}`);
|
|
35
|
+
}
|
|
36
|
+
const getMiddleValue = (arr) => {
|
|
37
|
+
if (arr.length === 1) {
|
|
38
|
+
return arr[0];
|
|
39
|
+
} else if (arr.length === 2) {
|
|
40
|
+
return Math.max(...arr);
|
|
41
|
+
} else {
|
|
42
|
+
const max = Math.max(...arr);
|
|
43
|
+
const min = Math.min(...arr);
|
|
44
|
+
const sum = arr[0] + arr[1] + arr[2];
|
|
45
|
+
return sum - max - min;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const name = await promptChecker_default(
|
|
49
|
+
{
|
|
50
|
+
type: "input",
|
|
51
|
+
name: "name",
|
|
52
|
+
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
|
|
53
|
+
},
|
|
54
|
+
(answer) => {
|
|
55
|
+
const name2 = answer.name;
|
|
56
|
+
if (name2 == null || name2 === "") {
|
|
57
|
+
consola.log(chalk.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
consola.log(chalk.green(name));
|
|
64
|
+
const title = await promptChecker_default({
|
|
65
|
+
type: "input",
|
|
66
|
+
name: "title",
|
|
67
|
+
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
68
|
+
});
|
|
69
|
+
consola.log(chalk.green(title));
|
|
70
|
+
const answerW = await promptChecker_default(
|
|
71
|
+
{
|
|
72
|
+
type: "checkbox",
|
|
73
|
+
name: "w",
|
|
74
|
+
message: chalk.blue(
|
|
75
|
+
"\u8BF7\u9009\u62E9\u7EC4\u4EF6\u5BBD\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D2,4,6\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u5BBD\u4E3A2\uFF0C\u9ED8\u8BA4\u5BBD\u4E3A4\uFF0C\u6700\u5927\u5BBD\u4E3A6\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"
|
|
76
|
+
),
|
|
77
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
78
|
+
},
|
|
79
|
+
(answer) => {
|
|
80
|
+
if (answer.w.length === 0) {
|
|
81
|
+
consola.log(chalk.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (answer.w.length > 3) {
|
|
85
|
+
consola.log(chalk.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
consola.log(chalk.green(answerW));
|
|
92
|
+
const answerH = await promptChecker_default(
|
|
93
|
+
{
|
|
94
|
+
type: "checkbox",
|
|
95
|
+
name: "h",
|
|
96
|
+
message: chalk.blue(
|
|
97
|
+
"\u8BF7\u9009\u62E9\u7EC4\u4EF6\u9AD8\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D1,2\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u4E3A1\uFF0C\u9ED8\u8BA4\u9AD8\u4E3A2\uFF0C\u6700\u5927\u9AD8\u4E3A2\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"
|
|
98
|
+
),
|
|
99
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
100
|
+
},
|
|
101
|
+
(answer) => {
|
|
102
|
+
if (answer.h.length === 0) {
|
|
103
|
+
consola.log(chalk.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (answer.h.length > 3) {
|
|
107
|
+
consola.log(chalk.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
consola.log(chalk.green(answerH));
|
|
114
|
+
const configurable = await promptChecker_default({
|
|
115
|
+
type: "confirm",
|
|
116
|
+
name: "configurable",
|
|
117
|
+
message: chalk.blue("\u7EC4\u4EF6\u662F\u5426\u53EF\u914D\u7F6E\uFF0C\u4F8B\u5982\u4FEE\u6539\u80CC\u666F\u989C\u8272\uFF0C\u5B57\u4F53\u5927\u5C0F\u7B49")
|
|
118
|
+
});
|
|
119
|
+
consola.log(chalk.green(configurable));
|
|
120
|
+
const width = getMiddleValue(answerW);
|
|
121
|
+
const height = getMiddleValue(answerH);
|
|
122
|
+
const minWidth = Math.min(...answerW);
|
|
123
|
+
const maxWidth = Math.max(...answerW);
|
|
124
|
+
const minHeight = Math.min(...answerH);
|
|
125
|
+
const maxHeight = Math.max(...answerH);
|
|
126
|
+
const snakeCaseName = snakeCase(name);
|
|
127
|
+
const paramCaseName = paramCase(name);
|
|
128
|
+
const widgetName = `${widgetPackage.name}.${snakeCaseName}`;
|
|
129
|
+
const widgetDir = path.join(widgetRootDir, paramCaseName);
|
|
130
|
+
if (!fs.existsSync(widgetDir)) {
|
|
131
|
+
fs.mkdirSync(widgetDir);
|
|
132
|
+
} else {
|
|
133
|
+
const answer = await inquirer.prompt([
|
|
134
|
+
{
|
|
135
|
+
type: "confirm",
|
|
136
|
+
name: "override",
|
|
137
|
+
message: chalk.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
|
|
138
|
+
}
|
|
139
|
+
]);
|
|
140
|
+
if (!answer.override) {
|
|
141
|
+
exit();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const renderOptions = {
|
|
145
|
+
name,
|
|
146
|
+
snakeCaseName,
|
|
147
|
+
paramCaseName,
|
|
148
|
+
packageName: widgetPackage.name,
|
|
149
|
+
widgetName,
|
|
150
|
+
title,
|
|
151
|
+
configurable,
|
|
152
|
+
width,
|
|
153
|
+
height,
|
|
154
|
+
maxWidth,
|
|
155
|
+
minHeight,
|
|
156
|
+
maxHeight,
|
|
157
|
+
minWidth
|
|
158
|
+
};
|
|
159
|
+
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`);
|
|
160
|
+
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
|
|
161
|
+
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
162
|
+
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
163
|
+
await EJSUtils.renderToFile("WidgetDefine.ejs", widgetDefineFile, "typescript", renderOptions);
|
|
164
|
+
await EJSUtils.renderToFile("WidgetView.ejs", widgetViewFile, "vue", renderOptions);
|
|
165
|
+
await EJSUtils.renderToFile("WidgetRoutes.ejs", widgetRoutesFile, "typescript", renderOptions);
|
|
166
|
+
if (configurable) {
|
|
167
|
+
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
168
|
+
await EJSUtils.renderToFile("WidgetConfig.ejs", configFile, "vue", renderOptions);
|
|
169
|
+
}
|
|
170
|
+
const routeFile = path.join(widgetRootDir, "widget-router.ts");
|
|
171
|
+
let routeContent;
|
|
172
|
+
if (fs.existsSync(routeFile)) {
|
|
173
|
+
routeContent = fs.readFileSync(routeFile, "utf8");
|
|
174
|
+
} else {
|
|
175
|
+
routeContent = fs.readFileSync(path.join(__dirname, "../template/widget-router.ts"), "utf8");
|
|
176
|
+
}
|
|
177
|
+
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
178
|
+
const routeStr = `...${name}WidgetRoutes,`;
|
|
179
|
+
if (!routeContent.includes(importRouteStr)) {
|
|
180
|
+
routeContent = routeContent.replaceAll(
|
|
181
|
+
"//FBI WANING! IMPORT PLACE",
|
|
182
|
+
`${importRouteStr}
|
|
183
|
+
//FBI WANING! IMPORT PLACE`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (!routeContent.includes(routeStr)) {
|
|
187
|
+
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
188
|
+
//FBI WANING! ROUTE PLACE`);
|
|
189
|
+
}
|
|
190
|
+
fs.writeFileSync(routeFile, routeContent);
|
|
191
|
+
const gitAdd = `git add ${widgetDir}`;
|
|
192
|
+
consola.info(chalk.grey(gitAdd));
|
|
193
|
+
shell.exec(gitAdd);
|
|
194
|
+
consola.log("=================");
|
|
195
|
+
consola.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
196
|
+
consola.success("Happy coding!");
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
createWidget as default
|
|
200
|
+
};
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Utils,
|
|
3
|
-
getPackagePath,
|
|
4
|
-
widgetPackages
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
|
|
7
|
-
// src/dependencies/remoteDependencies.ts
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
var spinner = ora("Connecting");
|
|
11
|
-
var RemoteDependencies;
|
|
12
|
-
((RemoteDependencies2) => {
|
|
13
|
-
async function start() {
|
|
14
|
-
spinner.start();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await upgradePackage(dependencies, packageNames);
|
|
20
|
-
await upgradePackage(devDependencies, packageNames);
|
|
21
|
-
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
22
|
-
spinner.succeed("Using remote versions!");
|
|
23
|
-
}
|
|
24
|
-
RemoteDependencies2.start = start;
|
|
25
|
-
async function upgradePackage(dependencies, packageNames) {
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
if (packageNames.
|
|
29
|
-
let packageVersion = widgetPackages[localPackage];
|
|
30
|
-
if (!packageVersion) {
|
|
31
|
-
spinner.info(`Fetching package version:${localPackage}`);
|
|
32
|
-
packageVersion = await Utils.getRemoteVersion(localPackage);
|
|
33
|
-
widgetPackages[localPackage] = packageVersion;
|
|
34
|
-
spinner.info(`version:${packageVersion}`);
|
|
35
|
-
}
|
|
36
|
-
dependencies[localPackage] = `^${packageVersion}`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
})(RemoteDependencies || (RemoteDependencies = {}));
|
|
41
|
-
|
|
42
|
-
// src/dependencies/localDependencies.ts
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
var spinner2 = ora2("Connecting");
|
|
46
|
-
var LocalDependencies;
|
|
47
|
-
((LocalDependencies2) => {
|
|
48
|
-
async function start() {
|
|
49
|
-
spinner2.start();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
await setWorkspaceVersion(dependencies, packageNames);
|
|
55
|
-
await setWorkspaceVersion(devDependencies, packageNames);
|
|
56
|
-
fs2.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
57
|
-
spinner2.succeed("Using local versions(workspace:*)!");
|
|
58
|
-
}
|
|
59
|
-
LocalDependencies2.start = start;
|
|
60
|
-
async function setWorkspaceVersion(dependencies, packageNames) {
|
|
61
|
-
|
|
62
|
-
for (
|
|
63
|
-
if (packageNames.
|
|
64
|
-
dependencies[localPackage] = `workspace:*`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
})(LocalDependencies || (LocalDependencies = {}));
|
|
69
|
-
|
|
70
|
-
// src/dependencies/index.ts
|
|
71
|
-
async function dependencies_default(options) {
|
|
72
|
-
|
|
73
|
-
if (type == "remote") {
|
|
74
|
-
await RemoteDependencies.start();
|
|
75
|
-
} else {
|
|
76
|
-
await LocalDependencies.start();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export {
|
|
80
|
-
dependencies_default as default
|
|
81
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Utils,
|
|
3
|
+
getPackagePath,
|
|
4
|
+
widgetPackages
|
|
5
|
+
} from "./chunk-RDJH7Z4C.js";
|
|
6
|
+
|
|
7
|
+
// src/dependencies/remoteDependencies.ts
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import ora from "ora";
|
|
10
|
+
var spinner = ora("Connecting");
|
|
11
|
+
var RemoteDependencies;
|
|
12
|
+
((RemoteDependencies2) => {
|
|
13
|
+
async function start() {
|
|
14
|
+
spinner.start();
|
|
15
|
+
const json = Utils.getPackageJson();
|
|
16
|
+
const packageNames = Object.keys(widgetPackages);
|
|
17
|
+
const dependencies = json.dependencies;
|
|
18
|
+
const devDependencies = json.devDependencies;
|
|
19
|
+
await upgradePackage(dependencies, packageNames);
|
|
20
|
+
await upgradePackage(devDependencies, packageNames);
|
|
21
|
+
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
22
|
+
spinner.succeed("Using remote versions!");
|
|
23
|
+
}
|
|
24
|
+
RemoteDependencies2.start = start;
|
|
25
|
+
async function upgradePackage(dependencies, packageNames) {
|
|
26
|
+
const localPackages = Object.keys(dependencies);
|
|
27
|
+
for (const localPackage of localPackages) {
|
|
28
|
+
if (packageNames.includes(localPackage)) {
|
|
29
|
+
let packageVersion = widgetPackages[localPackage];
|
|
30
|
+
if (!packageVersion) {
|
|
31
|
+
spinner.info(`Fetching package version:${localPackage}`);
|
|
32
|
+
packageVersion = await Utils.getRemoteVersion(localPackage);
|
|
33
|
+
widgetPackages[localPackage] = packageVersion;
|
|
34
|
+
spinner.info(`version:${packageVersion}`);
|
|
35
|
+
}
|
|
36
|
+
dependencies[localPackage] = `^${packageVersion}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})(RemoteDependencies || (RemoteDependencies = {}));
|
|
41
|
+
|
|
42
|
+
// src/dependencies/localDependencies.ts
|
|
43
|
+
import fs2 from "node:fs";
|
|
44
|
+
import ora2 from "ora";
|
|
45
|
+
var spinner2 = ora2("Connecting");
|
|
46
|
+
var LocalDependencies;
|
|
47
|
+
((LocalDependencies2) => {
|
|
48
|
+
async function start() {
|
|
49
|
+
spinner2.start();
|
|
50
|
+
const json = Utils.getPackageJson();
|
|
51
|
+
const packageNames = Object.keys(widgetPackages);
|
|
52
|
+
const dependencies = json.dependencies;
|
|
53
|
+
const devDependencies = json.devDependencies;
|
|
54
|
+
await setWorkspaceVersion(dependencies, packageNames);
|
|
55
|
+
await setWorkspaceVersion(devDependencies, packageNames);
|
|
56
|
+
fs2.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
57
|
+
spinner2.succeed("Using local versions(workspace:*)!");
|
|
58
|
+
}
|
|
59
|
+
LocalDependencies2.start = start;
|
|
60
|
+
async function setWorkspaceVersion(dependencies, packageNames) {
|
|
61
|
+
const localPackages = Object.keys(dependencies);
|
|
62
|
+
for (const localPackage of localPackages) {
|
|
63
|
+
if (packageNames.includes(localPackage)) {
|
|
64
|
+
dependencies[localPackage] = `workspace:*`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})(LocalDependencies || (LocalDependencies = {}));
|
|
69
|
+
|
|
70
|
+
// src/dependencies/index.ts
|
|
71
|
+
async function dependencies_default(options) {
|
|
72
|
+
const type = options.type;
|
|
73
|
+
if (type == "remote") {
|
|
74
|
+
await RemoteDependencies.start();
|
|
75
|
+
} else {
|
|
76
|
+
await LocalDependencies.start();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
dependencies_default as default
|
|
81
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import figlet from
|
|
7
|
-
import gradient from
|
|
8
|
-
import { dirname } from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import * as process from 'node:process'
|
|
5
|
+
import { Option, program } from 'commander'
|
|
6
|
+
import figlet from 'figlet'
|
|
7
|
+
import gradient from 'gradient-string'
|
|
8
|
+
import { dirname } from 'dirname-filename-esm'
|
|
9
|
+
|
|
10
|
+
const packageJsonPath = path.join(dirname(import.meta), '../package.json')
|
|
11
|
+
const cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString())
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.log(gradient.pastel.multiline(figlet.textSync('widget-cli', { horizontalLayout: 'full' })))
|
|
15
|
+
program.version(`@widget-js/cli ${cliPackage.version}`).usage('<command> [options]')
|
|
16
|
+
program.command('create').description('Create new widget').action(async () => {
|
|
17
|
+
const createWidget = await import('./createWidget-4LQ6PVEM.js')
|
|
18
|
+
await createWidget.default()
|
|
19
|
+
})
|
|
20
|
+
const dependenciesOption = new Option('-t, --type <type>').choices(['remote', 'local'])
|
|
21
|
+
program.command('dependencies').description('Set @widget-js dependencies to local(workspace:*) or remote(^1.0.0 etc)').addOption(dependenciesOption).action(async (options) => {
|
|
22
|
+
const dependencies = await import('./dependencies-AVNHKRF3.js')
|
|
23
|
+
await dependencies.default(options)
|
|
24
|
+
})
|
|
25
|
+
program.command('init').description('Initialize widget-js project').action(async () => {
|
|
26
|
+
const init = await import('./init-HCEGKTNF.js')
|
|
27
|
+
await init.init()
|
|
28
|
+
})
|
|
29
|
+
const typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
30
|
+
const fileOption = new Option('-f, --file <file>')
|
|
31
|
+
program.command('release').description('\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528').addOption(typeOption).addOption(fileOption).action(async (options, _) => {
|
|
32
|
+
const release = await import('./release-AQDFL5H3.js')
|
|
33
|
+
await release.default(options)
|
|
34
|
+
})
|
|
35
|
+
program.parse(process.argv)
|