@widget-js/cli 1.0.15 → 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.
- package/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/lib/build-BTARJMCZ.js +31 -0
- package/lib/chunk-3GPAHQ6O.js +18 -0
- package/lib/chunk-SIAOIY3B.js +27 -0
- package/lib/createWidget-KWBUF3TN.js +193 -0
- package/lib/index.cjs +347 -166
- package/lib/index.d.ts +1 -0
- package/lib/index.js +20 -415
- package/lib/release-PBOWWLKA.js +206 -0
- package/lib/upgrade-ETO2LGMX.js +52 -0
- package/package.json +13 -13
- package/release.json +5 -0
- package/src/build/build.ts +35 -0
- package/src/index.ts +43 -28
- package/src/release/ftp.ts +18 -13
- package/src/upgrade/upgrade.ts +48 -0
- package/src/utils.ts +22 -6
- package/tsup.config.ts +2 -1
- package/babel.config.js +0 -20
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,428 +1,33 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Option, program } from "commander";
|
|
3
|
-
import fs6 from "fs";
|
|
4
|
-
import path4 from "path";
|
|
5
|
-
import * as process3 from "process";
|
|
6
|
-
|
|
7
|
-
// src/createWidget.ts
|
|
8
|
-
import path from "path";
|
|
9
3
|
import fs from "fs";
|
|
10
|
-
import
|
|
4
|
+
import path from "path";
|
|
5
|
+
import * as process from "process";
|
|
11
6
|
import { fileURLToPath } from "url";
|
|
12
|
-
|
|
13
|
-
// src/promts/promptChecker.ts
|
|
14
|
-
import inquirer from "inquirer";
|
|
15
|
-
var promptChecker = async (prompt, checker) => {
|
|
16
|
-
const answer = await inquirer.prompt([prompt]);
|
|
17
|
-
if (checker) {
|
|
18
|
-
if (checker(answer)) {
|
|
19
|
-
return answer[prompt.name];
|
|
20
|
-
} else {
|
|
21
|
-
return promptChecker(prompt, checker);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return answer[prompt.name];
|
|
25
|
-
};
|
|
26
|
-
var promptChecker_default = promptChecker;
|
|
27
|
-
|
|
28
|
-
// src/createWidget.ts
|
|
29
|
-
import { paramCase, snakeCase } from "change-case";
|
|
30
|
-
import inquirer2 from "inquirer";
|
|
31
|
-
import ejs from "ejs";
|
|
32
|
-
import shell from "shelljs";
|
|
33
|
-
|
|
34
|
-
// src/utils.ts
|
|
35
|
-
function exit(code = 0) {
|
|
36
|
-
if (exports.exitProcess) {
|
|
37
|
-
process.exit(code);
|
|
38
|
-
} else if (code > 0) {
|
|
39
|
-
throw new Error(`Process exited with code ${code}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/createWidget.ts
|
|
44
|
-
import chalk from "chalk";
|
|
45
|
-
async function createWidget() {
|
|
46
|
-
let widgetJson = path.join(process.cwd(), "widget.json");
|
|
47
|
-
if (!fs.existsSync(widgetJson)) {
|
|
48
|
-
consola.error("\u6CA1\u6709\u5728\u6839\u76EE\u5F55\u627E\u5230widget.json\u6587\u4EF6");
|
|
49
|
-
exit();
|
|
50
|
-
}
|
|
51
|
-
let widgetPackage = JSON.parse(fs.readFileSync(widgetJson).toString());
|
|
52
|
-
let widgetFolder = path.join(process.cwd(), "./src/widgets");
|
|
53
|
-
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
54
|
-
if (devOptions["folder"]) {
|
|
55
|
-
widgetFolder = devOptions["folder"];
|
|
56
|
-
consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetFolder}`);
|
|
57
|
-
} else {
|
|
58
|
-
consola.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetFolder}`);
|
|
59
|
-
}
|
|
60
|
-
if (!fs.existsSync(widgetFolder)) {
|
|
61
|
-
fs.mkdirSync(widgetFolder, { recursive: true });
|
|
62
|
-
}
|
|
63
|
-
const __filename2 = fileURLToPath(import.meta.url);
|
|
64
|
-
const __dirname2 = path.dirname(__filename2);
|
|
65
|
-
const getMiddleValue = (arr) => {
|
|
66
|
-
if (arr.length === 1) {
|
|
67
|
-
return arr[0];
|
|
68
|
-
} else if (arr.length === 2) {
|
|
69
|
-
return Math.max(...arr);
|
|
70
|
-
} else {
|
|
71
|
-
const max = Math.max(...arr);
|
|
72
|
-
const min = Math.min(...arr);
|
|
73
|
-
const sum = arr[0] + arr[1] + arr[2];
|
|
74
|
-
return sum - max - min;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
let name = await promptChecker_default({
|
|
78
|
-
type: "input",
|
|
79
|
-
name: "name",
|
|
80
|
-
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
|
|
81
|
-
}, (answer) => {
|
|
82
|
-
const name2 = answer.name;
|
|
83
|
-
if (name2 == null || name2 === "") {
|
|
84
|
-
consola.log(chalk.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
});
|
|
89
|
-
consola.log(chalk.green(name));
|
|
90
|
-
let title = await promptChecker_default({
|
|
91
|
-
type: "input",
|
|
92
|
-
name: "title",
|
|
93
|
-
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
94
|
-
});
|
|
95
|
-
consola.log(chalk.green(title));
|
|
96
|
-
let answerW = await promptChecker_default({
|
|
97
|
-
type: "checkbox",
|
|
98
|
-
name: "w",
|
|
99
|
-
message: chalk.blue("\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"),
|
|
100
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
101
|
-
}, (answer) => {
|
|
102
|
-
if (answer.w.length === 0) {
|
|
103
|
-
consola.log(chalk.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
if (answer.w.length > 3) {
|
|
107
|
-
consola.log(chalk.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
112
|
-
consola.log(chalk.green(answerW));
|
|
113
|
-
let answerH = await promptChecker_default({
|
|
114
|
-
type: "checkbox",
|
|
115
|
-
name: "h",
|
|
116
|
-
message: chalk.blue("\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"),
|
|
117
|
-
choices: [1, 2, 3, 4, 5, 6]
|
|
118
|
-
}, (answer) => {
|
|
119
|
-
if (answer.h.length === 0) {
|
|
120
|
-
consola.log(chalk.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if (answer.h.length > 3) {
|
|
124
|
-
consola.log(chalk.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
});
|
|
129
|
-
consola.log(chalk.green(answerH));
|
|
130
|
-
let configurable = await promptChecker_default({
|
|
131
|
-
type: "confirm",
|
|
132
|
-
name: "configurable",
|
|
133
|
-
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")
|
|
134
|
-
});
|
|
135
|
-
consola.log(chalk.green(configurable));
|
|
136
|
-
const width = getMiddleValue(answerW);
|
|
137
|
-
const height = getMiddleValue(answerH);
|
|
138
|
-
const minWidth = Math.min(...answerW);
|
|
139
|
-
const maxWidth = Math.max(...answerW);
|
|
140
|
-
const minHeight = Math.min(...answerH);
|
|
141
|
-
const maxHeight = Math.max(...answerH);
|
|
142
|
-
const snakeCaseName = snakeCase(name);
|
|
143
|
-
const paramCaseName = paramCase(name);
|
|
144
|
-
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
145
|
-
const widgetDir = path.join(widgetFolder, paramCaseName);
|
|
146
|
-
if (!fs.existsSync(widgetDir)) {
|
|
147
|
-
fs.mkdirSync(widgetDir);
|
|
148
|
-
} else {
|
|
149
|
-
let answer = await inquirer2.prompt([{
|
|
150
|
-
type: "confirm",
|
|
151
|
-
name: "override",
|
|
152
|
-
message: chalk.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
|
|
153
|
-
}]);
|
|
154
|
-
if (!answer.override) {
|
|
155
|
-
exit();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const renderOptions = {
|
|
159
|
-
name,
|
|
160
|
-
snakeCaseName,
|
|
161
|
-
paramCaseName,
|
|
162
|
-
packageName,
|
|
163
|
-
title,
|
|
164
|
-
configurable,
|
|
165
|
-
width,
|
|
166
|
-
height,
|
|
167
|
-
maxWidth,
|
|
168
|
-
minHeight,
|
|
169
|
-
maxHeight,
|
|
170
|
-
minWidth
|
|
171
|
-
};
|
|
172
|
-
function renderToFile(templateFile, outputFile, renderOptions2) {
|
|
173
|
-
const defineTemplatePath = path.join(__dirname2, "../template", templateFile);
|
|
174
|
-
let defineTemplate = fs.readFileSync(defineTemplatePath, "utf8");
|
|
175
|
-
fs.writeFileSync(outputFile, ejs.render(defineTemplate, renderOptions2));
|
|
176
|
-
}
|
|
177
|
-
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`);
|
|
178
|
-
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
|
|
179
|
-
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
180
|
-
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
181
|
-
renderToFile("WidgetDefine.ejs", widgetDefineFile, renderOptions);
|
|
182
|
-
renderToFile("Widget.ejs", widgetFile, renderOptions);
|
|
183
|
-
renderToFile("WidgetView.ejs", widgetViewFile, renderOptions);
|
|
184
|
-
renderToFile("WidgetRoutes.ejs", widgetRoutesFile, renderOptions);
|
|
185
|
-
if (configurable) {
|
|
186
|
-
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
187
|
-
renderToFile("WidgetConfig.ejs", configFile, renderOptions);
|
|
188
|
-
}
|
|
189
|
-
if (devOptions["useStorybook"]) {
|
|
190
|
-
const storiesFile = path.resolve(widgetDir, `${name}Widget.stories.ts`);
|
|
191
|
-
renderToFile("stories.ejs", storiesFile, renderOptions);
|
|
192
|
-
}
|
|
193
|
-
const routeFile = path.join(widgetFolder, "widget-router.ts");
|
|
194
|
-
let routeContent;
|
|
195
|
-
if (fs.existsSync(routeFile)) {
|
|
196
|
-
routeContent = fs.readFileSync(routeFile, "utf8");
|
|
197
|
-
} else {
|
|
198
|
-
routeContent = fs.readFileSync(path.join(__dirname2, "../template/widget-router.ts"), "utf8");
|
|
199
|
-
}
|
|
200
|
-
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
201
|
-
const routeStr = `...${name}WidgetRoutes,`;
|
|
202
|
-
if (!routeContent.includes(importRouteStr)) {
|
|
203
|
-
routeContent = routeContent.replaceAll("//FBI WANING! IMPORT PLACE", `${importRouteStr}
|
|
204
|
-
//FBI WANING! IMPORT PLACE`);
|
|
205
|
-
}
|
|
206
|
-
if (!routeContent.includes(routeStr)) {
|
|
207
|
-
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
208
|
-
//FBI WANING! ROUTE PLACE`);
|
|
209
|
-
}
|
|
210
|
-
fs.writeFileSync(routeFile, routeContent);
|
|
211
|
-
let gitAdd = `git add ${widgetDir}`;
|
|
212
|
-
consola.info(chalk.grey(gitAdd));
|
|
213
|
-
shell.exec(gitAdd);
|
|
214
|
-
consola.log("=================");
|
|
215
|
-
consola.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
216
|
-
consola.success("Happy coding!");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/release/release.ts
|
|
220
|
-
import fs5 from "fs";
|
|
221
|
-
import path3 from "path";
|
|
222
|
-
|
|
223
|
-
// src/release/update-zip.ts
|
|
224
|
-
import fs2 from "fs";
|
|
225
|
-
import archiver from "archiver";
|
|
226
|
-
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
227
|
-
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
228
|
-
const stream = fs2.createWriteStream(outPath);
|
|
229
|
-
return new Promise((resolve, reject) => {
|
|
230
|
-
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
231
|
-
stream.on("close", () => resolve());
|
|
232
|
-
archive.finalize();
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
var update_zip_default = zipDirectory;
|
|
236
|
-
|
|
237
|
-
// src/release/oss.ts
|
|
238
|
-
import OSS from "ali-oss";
|
|
239
|
-
import fs3 from "fs";
|
|
240
|
-
import chalk2 from "chalk";
|
|
241
|
-
var packageData = JSON.parse(fs3.readFileSync("./package.json").toString());
|
|
242
|
-
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
243
|
-
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
244
|
-
var headers = {
|
|
245
|
-
"x-oss-storage-class": "Standard",
|
|
246
|
-
"x-oss-object-acl": "public-read",
|
|
247
|
-
"x-oss-forbid-overwrite": "false",
|
|
248
|
-
"Cache-Control": "no-cache"
|
|
249
|
-
};
|
|
250
|
-
var clinet = new OSS({
|
|
251
|
-
region: "oss-cn-hangzhou",
|
|
252
|
-
accessKeyId: AccessKeyID,
|
|
253
|
-
accessKeySecret: AccessKeySecret,
|
|
254
|
-
bucket: "widget-fun"
|
|
255
|
-
});
|
|
256
|
-
async function put(ossPath, file) {
|
|
257
|
-
try {
|
|
258
|
-
const result = await clinet.put(ossPath, file, { headers });
|
|
259
|
-
console.log(chalk2.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
|
|
260
|
-
} catch (e) {
|
|
261
|
-
console.log(e);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function copy(dist, src) {
|
|
265
|
-
try {
|
|
266
|
-
const result = await clinet.copy(dist, src, { headers });
|
|
267
|
-
console.log(chalk2.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
|
|
268
|
-
} catch (e) {
|
|
269
|
-
console.error(e);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/release/release.ts
|
|
274
|
-
import chalk3 from "chalk";
|
|
275
|
-
|
|
276
|
-
// src/release/ftp.ts
|
|
277
|
-
import path2 from "path";
|
|
278
|
-
import fs4 from "fs";
|
|
279
|
-
import SSHConfig from "@widget-js/ssh-config";
|
|
280
|
-
import os from "os";
|
|
281
|
-
import Client from "ssh2-sftp-client";
|
|
282
|
-
import consola2 from "consola";
|
|
283
|
-
import inquirer3 from "inquirer";
|
|
284
|
-
import ora from "ora";
|
|
285
|
-
import * as process2 from "process";
|
|
286
|
-
import * as console2 from "console";
|
|
287
|
-
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
288
|
-
let dir = path2.dirname(file);
|
|
289
|
-
const dirExists = await ftpClient.exists(dir);
|
|
290
|
-
if (!dirExists) {
|
|
291
|
-
onMkdir(dir);
|
|
292
|
-
await ftpClient.mkdir(dir, true);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function ftpUpload() {
|
|
296
|
-
const file = path2.join(process2.cwd(), "release.json");
|
|
297
|
-
const releaseConfig = JSON.parse(fs4.readFileSync(file).toString());
|
|
298
|
-
const sshConfigFile = path2.resolve(os.homedir(), ".ssh/config");
|
|
299
|
-
console2.log("SSH Config file:", sshConfigFile);
|
|
300
|
-
const sshConfigs = SSHConfig.parse(fs4.readFileSync(sshConfigFile).toString());
|
|
301
|
-
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
302
|
-
if (!sshConfig) {
|
|
303
|
-
consola2.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
consola2.info(sshConfig);
|
|
307
|
-
inquirer3.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
308
|
-
let ftpClient = new Client();
|
|
309
|
-
const port = sshConfig["Port"];
|
|
310
|
-
const key = fs4.readFileSync(path2.resolve(os.homedir(), ".ssh/id_rsa"));
|
|
311
|
-
const spinner = ora("Connecting");
|
|
312
|
-
try {
|
|
313
|
-
spinner.start();
|
|
314
|
-
await ftpClient.connect({
|
|
315
|
-
host: sshConfig["HostName"],
|
|
316
|
-
port: port ? parseInt(port) : 22,
|
|
317
|
-
username: sshConfig["User"],
|
|
318
|
-
passphrase: answer.password,
|
|
319
|
-
privateKey: key
|
|
320
|
-
});
|
|
321
|
-
releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
|
|
322
|
-
for (let item of releaseConfig.fileMap) {
|
|
323
|
-
if (typeof item.src == "string") {
|
|
324
|
-
if (item.remoteCopy) {
|
|
325
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
326
|
-
spinner.warn(`Create Dir: ${dir}`);
|
|
327
|
-
});
|
|
328
|
-
let destExists = await ftpClient.exists(item.dest);
|
|
329
|
-
if (destExists) {
|
|
330
|
-
spinner.warn(`Delete exists file:${item.dest}`);
|
|
331
|
-
await ftpClient.delete(item.dest);
|
|
332
|
-
}
|
|
333
|
-
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
334
|
-
await ftpClient.rcopy(item.src, item.dest);
|
|
335
|
-
} else {
|
|
336
|
-
const localFile = path2.resolve(process2.cwd(), item.src);
|
|
337
|
-
if (!item.remoteCopy && !fs4.existsSync(localFile)) {
|
|
338
|
-
spinner.warn(`Skip not exists file:${localFile}`);
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (fs4.lstatSync(localFile).isDirectory()) {
|
|
342
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
343
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
344
|
-
} else {
|
|
345
|
-
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
346
|
-
spinner.warn(`Create Dir: ${dir}`);
|
|
347
|
-
});
|
|
348
|
-
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
349
|
-
await ftpClient.put(localFile, item.dest);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
} else {
|
|
353
|
-
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
spinner.succeed("Files uploaded!");
|
|
357
|
-
await ftpClient.end();
|
|
358
|
-
} catch (e) {
|
|
359
|
-
spinner.fail(`Connection error:${e}`);
|
|
360
|
-
await ftpClient.end();
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/release/release.ts
|
|
366
|
-
var release = async (options) => {
|
|
367
|
-
console.log();
|
|
368
|
-
if (options.type == "ftp") {
|
|
369
|
-
await ftpUpload();
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
const packageJSON = JSON.parse(fs5.readFileSync("package.json", "utf-8"));
|
|
373
|
-
const changelogJSON = JSON.parse(fs5.readFileSync("changelog.json", "utf-8"));
|
|
374
|
-
const version = packageJSON["version"];
|
|
375
|
-
const changelog = changelogJSON[version];
|
|
376
|
-
let needUpdateElectron = await promptChecker_default({
|
|
377
|
-
type: "confirm",
|
|
378
|
-
name: "electron",
|
|
379
|
-
message: chalk3.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
380
|
-
});
|
|
381
|
-
const versionInfo = {
|
|
382
|
-
version,
|
|
383
|
-
releaseNote: changelog,
|
|
384
|
-
updateElectron: needUpdateElectron,
|
|
385
|
-
updateNodeModule: false,
|
|
386
|
-
updateWindowsApi: false,
|
|
387
|
-
downloadLink: ""
|
|
388
|
-
};
|
|
389
|
-
let installerPath = path3.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
390
|
-
if (!fs5.existsSync(installerPath)) {
|
|
391
|
-
installerPath = path3.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
392
|
-
}
|
|
393
|
-
const updateZipPath = path3.join(`./packaged/update.zip`);
|
|
394
|
-
console.log(chalk3.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
395
|
-
await update_zip_default("./release", updateZipPath);
|
|
396
|
-
console.log(chalk3.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
397
|
-
await put("version/installer.exe", installerPath);
|
|
398
|
-
console.log(chalk3.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
399
|
-
await put("version/update.zip", updateZipPath);
|
|
400
|
-
console.log(chalk3.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
401
|
-
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
402
|
-
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
403
|
-
await put("version/version.json", Buffer.from(versionJSON));
|
|
404
|
-
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
405
|
-
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
406
|
-
console.log(chalk3.yellow(versionJSON));
|
|
407
|
-
};
|
|
408
|
-
var release_default = release;
|
|
409
|
-
|
|
410
|
-
// src/index.ts
|
|
411
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
412
7
|
import figlet from "figlet";
|
|
413
8
|
import gradient from "gradient-string";
|
|
414
|
-
var __filename =
|
|
415
|
-
var __dirname =
|
|
416
|
-
var packageJsonPath =
|
|
417
|
-
var cliPackage = JSON.parse(
|
|
9
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
var __dirname = path.dirname(__filename);
|
|
11
|
+
var packageJsonPath = path.join(__dirname, "../package.json");
|
|
12
|
+
var cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
418
13
|
console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
419
14
|
program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
420
15
|
program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
421
|
-
await createWidget
|
|
16
|
+
const createWidget = await import("./createWidget-KWBUF3TN.js");
|
|
17
|
+
await createWidget.default();
|
|
18
|
+
});
|
|
19
|
+
program.command("upgrade").description("\u5347\u7EA7\u4F9D\u8D56").action(async () => {
|
|
20
|
+
const upgrade = await import("./upgrade-ETO2LGMX.js");
|
|
21
|
+
const instance = new upgrade.Upgrade();
|
|
22
|
+
await instance.start();
|
|
23
|
+
});
|
|
24
|
+
program.command("build").description("\u6267\u884C\u7F16\u8BD1\u4EFB\u52A1").action(async () => {
|
|
25
|
+
const build = await import("./build-BTARJMCZ.js");
|
|
26
|
+
await build.build();
|
|
422
27
|
});
|
|
423
28
|
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
424
29
|
program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
|
|
425
|
-
|
|
426
|
-
await
|
|
30
|
+
let release = await import("./release-PBOWWLKA.js");
|
|
31
|
+
await release.default(options);
|
|
427
32
|
});
|
|
428
|
-
program.parse(
|
|
33
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
promptChecker_default
|
|
3
|
+
} from "./chunk-3GPAHQ6O.js";
|
|
4
|
+
import {
|
|
5
|
+
getPackageVersion
|
|
6
|
+
} from "./chunk-SIAOIY3B.js";
|
|
7
|
+
|
|
8
|
+
// src/release/release.ts
|
|
9
|
+
import fs4 from "fs";
|
|
10
|
+
import path2 from "path";
|
|
11
|
+
|
|
12
|
+
// src/release/update-zip.ts
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import archiver from "archiver";
|
|
15
|
+
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
16
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
17
|
+
const stream = fs.createWriteStream(outPath);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
20
|
+
stream.on("close", () => resolve());
|
|
21
|
+
archive.finalize();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
var update_zip_default = zipDirectory;
|
|
25
|
+
|
|
26
|
+
// src/release/oss.ts
|
|
27
|
+
import OSS from "ali-oss";
|
|
28
|
+
import fs2 from "fs";
|
|
29
|
+
import chalk from "chalk";
|
|
30
|
+
var packageData = JSON.parse(fs2.readFileSync("./package.json").toString());
|
|
31
|
+
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
32
|
+
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
33
|
+
var headers = {
|
|
34
|
+
// 指定Object的存储类型。
|
|
35
|
+
"x-oss-storage-class": "Standard",
|
|
36
|
+
// 指定Object的访问权限。
|
|
37
|
+
"x-oss-object-acl": "public-read",
|
|
38
|
+
"x-oss-forbid-overwrite": "false",
|
|
39
|
+
"Cache-Control": "no-cache"
|
|
40
|
+
};
|
|
41
|
+
var clinet = new OSS({
|
|
42
|
+
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
43
|
+
region: "oss-cn-hangzhou",
|
|
44
|
+
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
45
|
+
accessKeyId: AccessKeyID,
|
|
46
|
+
accessKeySecret: AccessKeySecret,
|
|
47
|
+
bucket: "widget-fun"
|
|
48
|
+
});
|
|
49
|
+
async function put(ossPath, file) {
|
|
50
|
+
try {
|
|
51
|
+
const result = await clinet.put(ossPath, file, { headers });
|
|
52
|
+
console.log(chalk.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function copy(dist, src) {
|
|
58
|
+
try {
|
|
59
|
+
const result = await clinet.copy(dist, src, { headers });
|
|
60
|
+
console.log(chalk.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(e);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/release/release.ts
|
|
67
|
+
import chalk2 from "chalk";
|
|
68
|
+
|
|
69
|
+
// src/release/ftp.ts
|
|
70
|
+
import path from "path";
|
|
71
|
+
import fs3 from "fs";
|
|
72
|
+
import SSHConfig from "@widget-js/ssh-config";
|
|
73
|
+
import os from "os";
|
|
74
|
+
import Client from "ssh2-sftp-client";
|
|
75
|
+
import consola from "consola";
|
|
76
|
+
import inquirer from "inquirer";
|
|
77
|
+
import ora from "ora";
|
|
78
|
+
import * as process from "process";
|
|
79
|
+
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
80
|
+
let dir = path.dirname(file);
|
|
81
|
+
const dirExists = await ftpClient.exists(dir);
|
|
82
|
+
if (!dirExists) {
|
|
83
|
+
onMkdir(dir);
|
|
84
|
+
await ftpClient.mkdir(dir, true);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function ftpUpload() {
|
|
88
|
+
const releaseJsonFilePath = path.join(process.cwd(), "release.json");
|
|
89
|
+
const packageVersion = getPackageVersion();
|
|
90
|
+
consola.info("Package Version:", packageVersion);
|
|
91
|
+
let releaseJson = fs3.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
|
|
92
|
+
const releaseConfig = JSON.parse(releaseJson);
|
|
93
|
+
const sshConfigFile = path.resolve(os.homedir(), ".ssh/config");
|
|
94
|
+
consola.info("SSH Config File Path:", sshConfigFile);
|
|
95
|
+
const sshConfigs = SSHConfig.parse(fs3.readFileSync(sshConfigFile).toString());
|
|
96
|
+
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
97
|
+
if (!sshConfig) {
|
|
98
|
+
consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
consola.info(sshConfig);
|
|
102
|
+
inquirer.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
103
|
+
let ftpClient = new Client();
|
|
104
|
+
const port = sshConfig["Port"];
|
|
105
|
+
const key = fs3.readFileSync(path.resolve(os.homedir(), ".ssh/id_rsa"));
|
|
106
|
+
const spinner = ora("Connecting");
|
|
107
|
+
try {
|
|
108
|
+
spinner.start();
|
|
109
|
+
await ftpClient.connect({
|
|
110
|
+
host: sshConfig["HostName"],
|
|
111
|
+
port: port ? parseInt(port) : 22,
|
|
112
|
+
username: sshConfig["User"],
|
|
113
|
+
passphrase: answer.password,
|
|
114
|
+
privateKey: key
|
|
115
|
+
});
|
|
116
|
+
releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
|
|
117
|
+
for (let item of releaseConfig.fileMap) {
|
|
118
|
+
if (typeof item.src == "string") {
|
|
119
|
+
if (item.remoteCopy) {
|
|
120
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
121
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
122
|
+
});
|
|
123
|
+
let destExists = await ftpClient.exists(item.dest);
|
|
124
|
+
if (destExists) {
|
|
125
|
+
spinner.warn(`Delete exists file:${item.dest}`);
|
|
126
|
+
await ftpClient.delete(item.dest);
|
|
127
|
+
}
|
|
128
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
129
|
+
await ftpClient.rcopy(item.src, item.dest);
|
|
130
|
+
} else {
|
|
131
|
+
const localFile = path.resolve(process.cwd(), item.src);
|
|
132
|
+
if (!item.remoteCopy && !fs3.existsSync(localFile)) {
|
|
133
|
+
spinner.warn(`Skip not exists file:${localFile}`);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (fs3.lstatSync(localFile).isDirectory()) {
|
|
137
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
138
|
+
await ftpClient.uploadDir(localFile, item.dest);
|
|
139
|
+
} else {
|
|
140
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
141
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
142
|
+
});
|
|
143
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
144
|
+
await ftpClient.put(localFile, item.dest);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
spinner.succeed("Files uploaded!");
|
|
152
|
+
await ftpClient.end();
|
|
153
|
+
} catch (e) {
|
|
154
|
+
spinner.fail(`Connection error:${e}`);
|
|
155
|
+
await ftpClient.end();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/release/release.ts
|
|
161
|
+
var release = async (options) => {
|
|
162
|
+
console.log();
|
|
163
|
+
if (options.type == "ftp") {
|
|
164
|
+
await ftpUpload();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
|
|
168
|
+
const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
|
|
169
|
+
const version = packageJSON["version"];
|
|
170
|
+
const changelog = changelogJSON[version];
|
|
171
|
+
let needUpdateElectron = await promptChecker_default({
|
|
172
|
+
type: "confirm",
|
|
173
|
+
name: "electron",
|
|
174
|
+
message: chalk2.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
175
|
+
});
|
|
176
|
+
const versionInfo = {
|
|
177
|
+
version,
|
|
178
|
+
releaseNote: changelog,
|
|
179
|
+
updateElectron: needUpdateElectron,
|
|
180
|
+
updateNodeModule: false,
|
|
181
|
+
updateWindowsApi: false,
|
|
182
|
+
downloadLink: ""
|
|
183
|
+
};
|
|
184
|
+
let installerPath = path2.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
185
|
+
if (!fs4.existsSync(installerPath)) {
|
|
186
|
+
installerPath = path2.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
187
|
+
}
|
|
188
|
+
const updateZipPath = path2.join(`./packaged/update.zip`);
|
|
189
|
+
console.log(chalk2.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
190
|
+
await update_zip_default("./release", updateZipPath);
|
|
191
|
+
console.log(chalk2.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
192
|
+
await put("version/installer.exe", installerPath);
|
|
193
|
+
console.log(chalk2.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
194
|
+
await put("version/update.zip", updateZipPath);
|
|
195
|
+
console.log(chalk2.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
196
|
+
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
197
|
+
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
198
|
+
await put("version/version.json", Buffer.from(versionJSON));
|
|
199
|
+
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
200
|
+
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
201
|
+
console.log(chalk2.yellow(versionJSON));
|
|
202
|
+
};
|
|
203
|
+
var release_default = release;
|
|
204
|
+
export {
|
|
205
|
+
release_default as default
|
|
206
|
+
};
|