@widget-js/cli 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,423 +1,28 @@
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 consola from "consola";
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 - it2.order);
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
- spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
329
- await ftpClient.rcopy(item.src, item.dest);
330
- } else {
331
- const localFile = path2.resolve(process2.cwd(), item.src);
332
- if (!item.remoteCopy && !fs4.existsSync(localFile)) {
333
- spinner.warn(`Skip not exists file:${localFile}`);
334
- continue;
335
- }
336
- if (fs4.lstatSync(localFile).isDirectory()) {
337
- spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
338
- await ftpClient.uploadDir(localFile, item.dest);
339
- } else {
340
- await checkParentDir(ftpClient, item.dest, (dir) => {
341
- spinner.warn(`Create Dir: ${dir}`);
342
- });
343
- spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
344
- await ftpClient.put(localFile, item.dest);
345
- }
346
- }
347
- } else {
348
- await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
349
- }
350
- }
351
- spinner.succeed("Files uploaded!");
352
- await ftpClient.end();
353
- } catch (e) {
354
- spinner.fail(`Connection error:${e}`);
355
- await ftpClient.end();
356
- }
357
- });
358
- }
359
-
360
- // src/release/release.ts
361
- var release = async (options) => {
362
- console.log();
363
- if (options.type == "ftp") {
364
- await ftpUpload();
365
- return;
366
- }
367
- const packageJSON = JSON.parse(fs5.readFileSync("package.json", "utf-8"));
368
- const changelogJSON = JSON.parse(fs5.readFileSync("changelog.json", "utf-8"));
369
- const version = packageJSON["version"];
370
- const changelog = changelogJSON[version];
371
- let needUpdateElectron = await promptChecker_default({
372
- type: "confirm",
373
- name: "electron",
374
- message: chalk3.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
375
- });
376
- const versionInfo = {
377
- version,
378
- releaseNote: changelog,
379
- updateElectron: needUpdateElectron,
380
- updateNodeModule: false,
381
- updateWindowsApi: false,
382
- downloadLink: ""
383
- };
384
- let installerPath = path3.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
385
- if (!fs5.existsSync(installerPath)) {
386
- installerPath = path3.join(`./packaged/electron-${version}-setup-win-x64.exe`);
387
- }
388
- const updateZipPath = path3.join(`./packaged/update.zip`);
389
- console.log(chalk3.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
390
- await update_zip_default("./release", updateZipPath);
391
- console.log(chalk3.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
392
- await put("version/installer.exe", installerPath);
393
- console.log(chalk3.blue("\u4E0A\u4F20update.zip\u5230OSS"));
394
- await put("version/update.zip", updateZipPath);
395
- console.log(chalk3.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
396
- versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
397
- const versionJSON = JSON.stringify(versionInfo, null, 2);
398
- await put("version/version.json", Buffer.from(versionJSON));
399
- copy(`version/history/${version}.exe`, "version/installer.exe");
400
- copy(`version/history/update-${version}.zip`, "version/update.zip");
401
- console.log(chalk3.yellow(versionJSON));
402
- };
403
- var release_default = release;
404
-
405
- // src/index.ts
406
- import { fileURLToPath as fileURLToPath2 } from "url";
407
7
  import figlet from "figlet";
408
8
  import gradient from "gradient-string";
409
- var __filename = fileURLToPath2(import.meta.url);
410
- var __dirname = path4.dirname(__filename);
411
- var packageJsonPath = path4.join(__dirname, "../package.json");
412
- var cliPackage = JSON.parse(fs6.readFileSync(packageJsonPath).toString());
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());
413
13
  console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
414
14
  program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
415
15
  program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
416
- await createWidget();
16
+ const createWidget = await import("./createWidget-AX4QC5FV.js");
17
+ await createWidget.default();
18
+ });
19
+ program.command("build").description("\u6267\u884C\u7F16\u8BD1\u4EFB\u52A1").action(async () => {
20
+ const build = await import("./build-BTARJMCZ.js");
21
+ await build.build();
417
22
  });
418
23
  var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
419
24
  program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
420
- console.log(options);
421
- await release_default(options);
25
+ let release = await import("./release-CEWJTX3Q.js");
26
+ await release.default(options);
422
27
  });
423
- program.parse(process3.argv);
28
+ program.parse(process.argv);
@@ -0,0 +1,200 @@
1
+ import {
2
+ getPackageVersion,
3
+ promptChecker_default
4
+ } from "./chunk-VOTZXZ5O.js";
5
+
6
+ // src/release/release.ts
7
+ import fs4 from "fs";
8
+ import path2 from "path";
9
+
10
+ // src/release/update-zip.ts
11
+ import fs from "fs";
12
+ import archiver from "archiver";
13
+ function zipDirectory(sourceDir, outPath, ignoreDir) {
14
+ const archive = archiver("zip", { zlib: { level: 9 } });
15
+ const stream = fs.createWriteStream(outPath);
16
+ return new Promise((resolve, reject) => {
17
+ archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
18
+ stream.on("close", () => resolve());
19
+ archive.finalize();
20
+ });
21
+ }
22
+ var update_zip_default = zipDirectory;
23
+
24
+ // src/release/oss.ts
25
+ import OSS from "ali-oss";
26
+ import fs2 from "fs";
27
+ import chalk from "chalk";
28
+ var packageData = JSON.parse(fs2.readFileSync("./package.json").toString());
29
+ var AccessKeyID = packageData.oss?.id ?? "default";
30
+ var AccessKeySecret = packageData.oss?.secret ?? "default";
31
+ var headers = {
32
+ "x-oss-storage-class": "Standard",
33
+ "x-oss-object-acl": "public-read",
34
+ "x-oss-forbid-overwrite": "false",
35
+ "Cache-Control": "no-cache"
36
+ };
37
+ var clinet = new OSS({
38
+ region: "oss-cn-hangzhou",
39
+ accessKeyId: AccessKeyID,
40
+ accessKeySecret: AccessKeySecret,
41
+ bucket: "widget-fun"
42
+ });
43
+ async function put(ossPath, file) {
44
+ try {
45
+ const result = await clinet.put(ossPath, file, { headers });
46
+ console.log(chalk.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
47
+ } catch (e) {
48
+ console.log(e);
49
+ }
50
+ }
51
+ async function copy(dist, src) {
52
+ try {
53
+ const result = await clinet.copy(dist, src, { headers });
54
+ console.log(chalk.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
55
+ } catch (e) {
56
+ console.error(e);
57
+ }
58
+ }
59
+
60
+ // src/release/release.ts
61
+ import chalk2 from "chalk";
62
+
63
+ // src/release/ftp.ts
64
+ import path from "path";
65
+ import fs3 from "fs";
66
+ import SSHConfig from "@widget-js/ssh-config";
67
+ import os from "os";
68
+ import Client from "ssh2-sftp-client";
69
+ import consola from "consola";
70
+ import inquirer from "inquirer";
71
+ import ora from "ora";
72
+ import * as process from "process";
73
+ async function checkParentDir(ftpClient, file, onMkdir) {
74
+ let dir = path.dirname(file);
75
+ const dirExists = await ftpClient.exists(dir);
76
+ if (!dirExists) {
77
+ onMkdir(dir);
78
+ await ftpClient.mkdir(dir, true);
79
+ }
80
+ }
81
+ function ftpUpload() {
82
+ const releaseJsonFilePath = path.join(process.cwd(), "release.json");
83
+ const packageVersion = getPackageVersion();
84
+ consola.info("Package Version:", packageVersion);
85
+ let releaseJson = fs3.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
86
+ const releaseConfig = JSON.parse(releaseJson);
87
+ const sshConfigFile = path.resolve(os.homedir(), ".ssh/config");
88
+ consola.info("SSH Config File Path:", sshConfigFile);
89
+ const sshConfigs = SSHConfig.parse(fs3.readFileSync(sshConfigFile).toString());
90
+ let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
91
+ if (!sshConfig) {
92
+ consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
93
+ return;
94
+ }
95
+ consola.info(sshConfig);
96
+ inquirer.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
97
+ let ftpClient = new Client();
98
+ const port = sshConfig["Port"];
99
+ const key = fs3.readFileSync(path.resolve(os.homedir(), ".ssh/id_rsa"));
100
+ const spinner = ora("Connecting");
101
+ try {
102
+ spinner.start();
103
+ await ftpClient.connect({
104
+ host: sshConfig["HostName"],
105
+ port: port ? parseInt(port) : 22,
106
+ username: sshConfig["User"],
107
+ passphrase: answer.password,
108
+ privateKey: key
109
+ });
110
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
111
+ for (let item of releaseConfig.fileMap) {
112
+ if (typeof item.src == "string") {
113
+ if (item.remoteCopy) {
114
+ await checkParentDir(ftpClient, item.dest, (dir) => {
115
+ spinner.warn(`Create Dir: ${dir}`);
116
+ });
117
+ let destExists = await ftpClient.exists(item.dest);
118
+ if (destExists) {
119
+ spinner.warn(`Delete exists file:${item.dest}`);
120
+ await ftpClient.delete(item.dest);
121
+ }
122
+ spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
123
+ await ftpClient.rcopy(item.src, item.dest);
124
+ } else {
125
+ const localFile = path.resolve(process.cwd(), item.src);
126
+ if (!item.remoteCopy && !fs3.existsSync(localFile)) {
127
+ spinner.warn(`Skip not exists file:${localFile}`);
128
+ continue;
129
+ }
130
+ if (fs3.lstatSync(localFile).isDirectory()) {
131
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
132
+ await ftpClient.uploadDir(localFile, item.dest);
133
+ } else {
134
+ await checkParentDir(ftpClient, item.dest, (dir) => {
135
+ spinner.warn(`Create Dir: ${dir}`);
136
+ });
137
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
138
+ await ftpClient.put(localFile, item.dest);
139
+ }
140
+ }
141
+ } else {
142
+ await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
143
+ }
144
+ }
145
+ spinner.succeed("Files uploaded!");
146
+ await ftpClient.end();
147
+ } catch (e) {
148
+ spinner.fail(`Connection error:${e}`);
149
+ await ftpClient.end();
150
+ }
151
+ });
152
+ }
153
+
154
+ // src/release/release.ts
155
+ var release = async (options) => {
156
+ console.log();
157
+ if (options.type == "ftp") {
158
+ await ftpUpload();
159
+ return;
160
+ }
161
+ const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
162
+ const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
163
+ const version = packageJSON["version"];
164
+ const changelog = changelogJSON[version];
165
+ let needUpdateElectron = await promptChecker_default({
166
+ type: "confirm",
167
+ name: "electron",
168
+ message: chalk2.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
169
+ });
170
+ const versionInfo = {
171
+ version,
172
+ releaseNote: changelog,
173
+ updateElectron: needUpdateElectron,
174
+ updateNodeModule: false,
175
+ updateWindowsApi: false,
176
+ downloadLink: ""
177
+ };
178
+ let installerPath = path2.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
179
+ if (!fs4.existsSync(installerPath)) {
180
+ installerPath = path2.join(`./packaged/electron-${version}-setup-win-x64.exe`);
181
+ }
182
+ const updateZipPath = path2.join(`./packaged/update.zip`);
183
+ console.log(chalk2.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
184
+ await update_zip_default("./release", updateZipPath);
185
+ console.log(chalk2.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
186
+ await put("version/installer.exe", installerPath);
187
+ console.log(chalk2.blue("\u4E0A\u4F20update.zip\u5230OSS"));
188
+ await put("version/update.zip", updateZipPath);
189
+ console.log(chalk2.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
190
+ versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
191
+ const versionJSON = JSON.stringify(versionInfo, null, 2);
192
+ await put("version/version.json", Buffer.from(versionJSON));
193
+ copy(`version/history/${version}.exe`, "version/installer.exe");
194
+ copy(`version/history/update-${version}.zip`, "version/update.zip");
195
+ console.log(chalk2.yellow(versionJSON));
196
+ };
197
+ var release_default = release;
198
+ export {
199
+ release_default as default
200
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "lib/index.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
@@ -10,9 +10,10 @@
10
10
  },
11
11
  "type": "module",
12
12
  "scripts": {
13
- "build": "tsup src/index.ts --dts --format esm,cjs",
13
+ "build": "rimraf ./lib/ && tsup src/index.ts --dts --format esm,cjs",
14
14
  "watch": "tsup src/index.ts --dts --format esm,cjs --watch",
15
15
  "build:run": "npm run build && npm run widget",
16
+ "prebuild": "",
16
17
  "widget": "node ./lib/index.js"
17
18
  },
18
19
  "publishConfig": {
@@ -58,6 +59,7 @@
58
59
  "jest": "^29.5.0",
59
60
  "pinst": "^3.0.0",
60
61
  "prettier": "^2.8.4",
62
+ "rimraf": "^4.4.1",
61
63
  "ts-jest": "^29.0.3",
62
64
  "ts-loader": "^9.4.1",
63
65
  "ts-node": "^10.9.1",
package/release.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "fileMap": [
3
3
  {
4
- "src": ".gitignore",
5
- "dest": "/www/wwwroot/template/aa/.gitignore",
4
+ "src": "./dist/youlu-${version}-setup-win-ia32.exe",
5
+ "dest": "/www/wwwroot/download.tool-vip.com/youlu/youlu.exe",
6
6
  "order": 0
7
7
  },
8
+ {
9
+ "src": ".gitignore",
10
+ "dest": "/www/wwwroot/template/aa/.gitignore"
11
+ },
8
12
  {
9
13
  "src": "/www/wwwroot/template/aa/.gitignore",
10
14
  "dest": "/www/wwwroot/template/bbb/.gitignorexxx",
11
- "remoteCopy": true,
12
- "order": 1
15
+ "remoteCopy": true
13
16
  }
14
17
  ],
15
18
  "ftpConfig": {