@widget-js/cli 1.0.11 → 1.0.13

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.cjs CHANGED
@@ -238,8 +238,8 @@ async function createWidget() {
238
238
  }
239
239
 
240
240
  // src/release/release.ts
241
- var import_fs4 = __toESM(require("fs"), 1);
242
- var import_path2 = __toESM(require("path"), 1);
241
+ var import_fs5 = __toESM(require("fs"), 1);
242
+ var import_path3 = __toESM(require("path"), 1);
243
243
 
244
244
  // src/release/update-zip.ts
245
245
  var import_fs2 = __toESM(require("fs"), 1);
@@ -293,67 +293,24 @@ async function copy(dist, src) {
293
293
 
294
294
  // src/release/release.ts
295
295
  var import_chalk3 = __toESM(require("chalk"), 1);
296
- var release = async () => {
297
- const packageJSON = JSON.parse(import_fs4.default.readFileSync("package.json", "utf-8"));
298
- const changelogJSON = JSON.parse(import_fs4.default.readFileSync("changelog.json", "utf-8"));
299
- const version = packageJSON["version"];
300
- const changelog = changelogJSON[version];
301
- let needUpdateElectron = await promptChecker_default({
302
- type: "confirm",
303
- name: "electron",
304
- message: import_chalk3.default.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
305
- });
306
- const versionInfo = {
307
- version,
308
- releaseNote: changelog,
309
- updateElectron: needUpdateElectron,
310
- updateNodeModule: false,
311
- updateWindowsApi: false,
312
- downloadLink: ""
313
- };
314
- let installerPath = import_path2.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
315
- if (!import_fs4.default.existsSync(installerPath)) {
316
- installerPath = import_path2.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
317
- }
318
- const updateZipPath = import_path2.default.join(`./packaged/update.zip`);
319
- console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
320
- await update_zip_default("./release", updateZipPath);
321
- console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
322
- await put("version/installer.exe", installerPath);
323
- console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
324
- await put("version/update.zip", updateZipPath);
325
- console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
326
- versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
327
- const versionJSON = JSON.stringify(versionInfo, null, 2);
328
- await put("version/version.json", Buffer.from(versionJSON));
329
- copy(`version/history/${version}.exe`, "version/installer.exe");
330
- copy(`version/history/update-${version}.zip`, "version/update.zip");
331
- console.log(import_chalk3.default.yellow(versionJSON));
332
- };
333
- var release_default = release;
334
-
335
- // src/index.ts
336
- var import_url2 = require("url");
337
- var import_figlet = __toESM(require("figlet"), 1);
338
- var import_gradient_string = __toESM(require("gradient-string"), 1);
339
296
 
340
- // src/ftp/ftp.ts
341
- var import_path3 = __toESM(require("path"), 1);
342
- var import_fs5 = __toESM(require("fs"), 1);
343
- var import_ssh_config = __toESM(require("ssh-config"), 1);
297
+ // src/release/ftp/ftp.ts
298
+ var import_path2 = __toESM(require("path"), 1);
299
+ var import_fs4 = __toESM(require("fs"), 1);
300
+ var import_ssh_config = __toESM(require("@widget-js/ssh-config"), 1);
344
301
  var import_os = __toESM(require("os"), 1);
345
302
  var import_ssh2_sftp_client = __toESM(require("ssh2-sftp-client"), 1);
346
303
  var import_consola2 = __toESM(require("consola"), 1);
347
304
  var import_inquirer3 = __toESM(require("inquirer"), 1);
348
- var import_nanospinner = require("nanospinner");
305
+ var import_ora = __toESM(require("ora"), 1);
349
306
  var process2 = __toESM(require("process"), 1);
350
307
  var console2 = __toESM(require("console"), 1);
351
308
  function ftpUpload() {
352
- const file = import_path3.default.join(process2.cwd(), "release.json");
353
- const releaseConfig = JSON.parse(import_fs5.default.readFileSync(file).toString());
354
- const sshConfigFile = import_path3.default.resolve(import_os.default.homedir(), ".ssh/config");
309
+ const file = import_path2.default.join(process2.cwd(), "release.json");
310
+ const releaseConfig = JSON.parse(import_fs4.default.readFileSync(file).toString());
311
+ const sshConfigFile = import_path2.default.resolve(import_os.default.homedir(), ".ssh/config");
355
312
  console2.log("SSH Config file:", sshConfigFile);
356
- const sshConfigs = import_ssh_config.default.parse(import_fs5.default.readFileSync(sshConfigFile).toString());
313
+ const sshConfigs = import_ssh_config.default.parse(import_fs4.default.readFileSync(sshConfigFile).toString());
357
314
  let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
358
315
  if (!sshConfig) {
359
316
  import_consola2.default.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
@@ -363,8 +320,8 @@ function ftpUpload() {
363
320
  import_inquirer3.default.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
364
321
  let ftpClient = new import_ssh2_sftp_client.default();
365
322
  const port = sshConfig["Port"];
366
- const key = import_fs5.default.readFileSync(import_path3.default.resolve(import_os.default.homedir(), ".ssh/id_rsa"));
367
- const spinner = (0, import_nanospinner.createSpinner)("Connecting");
323
+ const key = import_fs4.default.readFileSync(import_path2.default.resolve(import_os.default.homedir(), ".ssh/id_rsa"));
324
+ const spinner = (0, import_ora.default)("Connecting");
368
325
  try {
369
326
  spinner.start();
370
327
  await ftpClient.connect({
@@ -374,37 +331,82 @@ function ftpUpload() {
374
331
  passphrase: answer.password,
375
332
  privateKey: key
376
333
  });
377
- ftpClient.on("upload", (info) => {
378
- spinner.update({ text: `Uploading: ${info.source}` });
379
- });
380
334
  for (let item of releaseConfig.fileMap) {
381
335
  if (typeof item.src == "string") {
382
- const localFile = import_path3.default.resolve(process2.cwd(), item.src);
383
- if (!import_fs5.default.existsSync(localFile)) {
384
- spinner.warn({ text: `Skip not exists file:${localFile}` });
336
+ const localFile = import_path2.default.resolve(process2.cwd(), item.src);
337
+ if (!import_fs4.default.existsSync(localFile)) {
338
+ spinner.warn(`Skip not exists file:${localFile}`);
385
339
  continue;
386
340
  }
387
- if (import_fs5.default.lstatSync(localFile).isDirectory()) {
388
- spinner.update({ text: `Uploading Dir: ${localFile} -> ${item.dest}` });
341
+ if (import_fs4.default.lstatSync(localFile).isDirectory()) {
342
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
389
343
  await ftpClient.uploadDir(localFile, item.dest);
390
344
  } else {
391
- spinner.update({ text: `Uploading File: ${localFile} -> ${item.dest}` });
345
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
392
346
  await ftpClient.put(localFile, item.dest);
393
347
  }
394
348
  } else {
395
349
  await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
396
350
  }
397
351
  }
398
- spinner.success({ text: "Files uploaded!" });
352
+ spinner.succeed("Files uploaded!");
399
353
  await ftpClient.end();
400
354
  } catch (e) {
401
- spinner.error({ text: `Connection error:${e}` });
355
+ spinner.fail(`Connection error:${e}`);
402
356
  await ftpClient.end();
403
357
  }
404
358
  });
405
359
  }
406
360
 
361
+ // src/release/release.ts
362
+ var release = async (options) => {
363
+ console.log();
364
+ if (options.type == "ftp") {
365
+ await ftpUpload();
366
+ return;
367
+ }
368
+ const packageJSON = JSON.parse(import_fs5.default.readFileSync("package.json", "utf-8"));
369
+ const changelogJSON = JSON.parse(import_fs5.default.readFileSync("changelog.json", "utf-8"));
370
+ const version = packageJSON["version"];
371
+ const changelog = changelogJSON[version];
372
+ let needUpdateElectron = await promptChecker_default({
373
+ type: "confirm",
374
+ name: "electron",
375
+ message: import_chalk3.default.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
376
+ });
377
+ const versionInfo = {
378
+ version,
379
+ releaseNote: changelog,
380
+ updateElectron: needUpdateElectron,
381
+ updateNodeModule: false,
382
+ updateWindowsApi: false,
383
+ downloadLink: ""
384
+ };
385
+ let installerPath = import_path3.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
386
+ if (!import_fs5.default.existsSync(installerPath)) {
387
+ installerPath = import_path3.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
388
+ }
389
+ const updateZipPath = import_path3.default.join(`./packaged/update.zip`);
390
+ console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
391
+ await update_zip_default("./release", updateZipPath);
392
+ console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
393
+ await put("version/installer.exe", installerPath);
394
+ console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
395
+ await put("version/update.zip", updateZipPath);
396
+ console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
397
+ versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
398
+ const versionJSON = JSON.stringify(versionInfo, null, 2);
399
+ await put("version/version.json", Buffer.from(versionJSON));
400
+ copy(`version/history/${version}.exe`, "version/installer.exe");
401
+ copy(`version/history/update-${version}.zip`, "version/update.zip");
402
+ console.log(import_chalk3.default.yellow(versionJSON));
403
+ };
404
+ var release_default = release;
405
+
407
406
  // src/index.ts
407
+ var import_url2 = require("url");
408
+ var import_figlet = __toESM(require("figlet"), 1);
409
+ var import_gradient_string = __toESM(require("gradient-string"), 1);
408
410
  var import_meta2 = {};
409
411
  var __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
410
412
  var __dirname = import_path4.default.dirname(__filename);
@@ -415,10 +417,9 @@ import_commander.program.version(`@widget-js/cli ${cliPackage.version}`).usage("
415
417
  import_commander.program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
416
418
  await createWidget();
417
419
  });
418
- import_commander.program.command("release").description("\u901A\u8FC7OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
419
- await release_default();
420
- });
421
- import_commander.program.command("ftp").description("\u901A\u8FC7FTP\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
422
- await ftpUpload();
420
+ var typeOption = new import_commander.Option("-t, --type <type>").choices(["ftp", "oss"]);
421
+ import_commander.program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
422
+ console.log(options);
423
+ await release_default(options);
423
424
  });
424
425
  import_commander.program.parse(process3.argv);
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { program } from "commander";
2
+ import { Option, program } from "commander";
3
3
  import fs6 from "fs";
4
4
  import path4 from "path";
5
5
  import * as process3 from "process";
@@ -217,8 +217,8 @@ async function createWidget() {
217
217
  }
218
218
 
219
219
  // src/release/release.ts
220
- import fs4 from "fs";
221
- import path2 from "path";
220
+ import fs5 from "fs";
221
+ import path3 from "path";
222
222
 
223
223
  // src/release/update-zip.ts
224
224
  import fs2 from "fs";
@@ -272,67 +272,24 @@ async function copy(dist, src) {
272
272
 
273
273
  // src/release/release.ts
274
274
  import chalk3 from "chalk";
275
- var release = async () => {
276
- const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
277
- const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
278
- const version = packageJSON["version"];
279
- const changelog = changelogJSON[version];
280
- let needUpdateElectron = await promptChecker_default({
281
- type: "confirm",
282
- name: "electron",
283
- message: chalk3.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
284
- });
285
- const versionInfo = {
286
- version,
287
- releaseNote: changelog,
288
- updateElectron: needUpdateElectron,
289
- updateNodeModule: false,
290
- updateWindowsApi: false,
291
- downloadLink: ""
292
- };
293
- let installerPath = path2.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
294
- if (!fs4.existsSync(installerPath)) {
295
- installerPath = path2.join(`./packaged/electron-${version}-setup-win-x64.exe`);
296
- }
297
- const updateZipPath = path2.join(`./packaged/update.zip`);
298
- console.log(chalk3.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
299
- await update_zip_default("./release", updateZipPath);
300
- console.log(chalk3.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
301
- await put("version/installer.exe", installerPath);
302
- console.log(chalk3.blue("\u4E0A\u4F20update.zip\u5230OSS"));
303
- await put("version/update.zip", updateZipPath);
304
- console.log(chalk3.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
305
- versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
306
- const versionJSON = JSON.stringify(versionInfo, null, 2);
307
- await put("version/version.json", Buffer.from(versionJSON));
308
- copy(`version/history/${version}.exe`, "version/installer.exe");
309
- copy(`version/history/update-${version}.zip`, "version/update.zip");
310
- console.log(chalk3.yellow(versionJSON));
311
- };
312
- var release_default = release;
313
-
314
- // src/index.ts
315
- import { fileURLToPath as fileURLToPath2 } from "url";
316
- import figlet from "figlet";
317
- import gradient from "gradient-string";
318
275
 
319
- // src/ftp/ftp.ts
320
- import path3 from "path";
321
- import fs5 from "fs";
322
- import SSHConfig from "ssh-config";
276
+ // src/release/ftp/ftp.ts
277
+ import path2 from "path";
278
+ import fs4 from "fs";
279
+ import SSHConfig from "@widget-js/ssh-config";
323
280
  import os from "os";
324
281
  import Client from "ssh2-sftp-client";
325
282
  import consola2 from "consola";
326
283
  import inquirer3 from "inquirer";
327
- import { createSpinner } from "nanospinner";
284
+ import ora from "ora";
328
285
  import * as process2 from "process";
329
286
  import * as console2 from "console";
330
287
  function ftpUpload() {
331
- const file = path3.join(process2.cwd(), "release.json");
332
- const releaseConfig = JSON.parse(fs5.readFileSync(file).toString());
333
- const sshConfigFile = path3.resolve(os.homedir(), ".ssh/config");
288
+ const file = path2.join(process2.cwd(), "release.json");
289
+ const releaseConfig = JSON.parse(fs4.readFileSync(file).toString());
290
+ const sshConfigFile = path2.resolve(os.homedir(), ".ssh/config");
334
291
  console2.log("SSH Config file:", sshConfigFile);
335
- const sshConfigs = SSHConfig.parse(fs5.readFileSync(sshConfigFile).toString());
292
+ const sshConfigs = SSHConfig.parse(fs4.readFileSync(sshConfigFile).toString());
336
293
  let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
337
294
  if (!sshConfig) {
338
295
  consola2.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
@@ -342,8 +299,8 @@ function ftpUpload() {
342
299
  inquirer3.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
343
300
  let ftpClient = new Client();
344
301
  const port = sshConfig["Port"];
345
- const key = fs5.readFileSync(path3.resolve(os.homedir(), ".ssh/id_rsa"));
346
- const spinner = createSpinner("Connecting");
302
+ const key = fs4.readFileSync(path2.resolve(os.homedir(), ".ssh/id_rsa"));
303
+ const spinner = ora("Connecting");
347
304
  try {
348
305
  spinner.start();
349
306
  await ftpClient.connect({
@@ -353,37 +310,82 @@ function ftpUpload() {
353
310
  passphrase: answer.password,
354
311
  privateKey: key
355
312
  });
356
- ftpClient.on("upload", (info) => {
357
- spinner.update({ text: `Uploading: ${info.source}` });
358
- });
359
313
  for (let item of releaseConfig.fileMap) {
360
314
  if (typeof item.src == "string") {
361
- const localFile = path3.resolve(process2.cwd(), item.src);
362
- if (!fs5.existsSync(localFile)) {
363
- spinner.warn({ text: `Skip not exists file:${localFile}` });
315
+ const localFile = path2.resolve(process2.cwd(), item.src);
316
+ if (!fs4.existsSync(localFile)) {
317
+ spinner.warn(`Skip not exists file:${localFile}`);
364
318
  continue;
365
319
  }
366
- if (fs5.lstatSync(localFile).isDirectory()) {
367
- spinner.update({ text: `Uploading Dir: ${localFile} -> ${item.dest}` });
320
+ if (fs4.lstatSync(localFile).isDirectory()) {
321
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
368
322
  await ftpClient.uploadDir(localFile, item.dest);
369
323
  } else {
370
- spinner.update({ text: `Uploading File: ${localFile} -> ${item.dest}` });
324
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
371
325
  await ftpClient.put(localFile, item.dest);
372
326
  }
373
327
  } else {
374
328
  await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
375
329
  }
376
330
  }
377
- spinner.success({ text: "Files uploaded!" });
331
+ spinner.succeed("Files uploaded!");
378
332
  await ftpClient.end();
379
333
  } catch (e) {
380
- spinner.error({ text: `Connection error:${e}` });
334
+ spinner.fail(`Connection error:${e}`);
381
335
  await ftpClient.end();
382
336
  }
383
337
  });
384
338
  }
385
339
 
340
+ // src/release/release.ts
341
+ var release = async (options) => {
342
+ console.log();
343
+ if (options.type == "ftp") {
344
+ await ftpUpload();
345
+ return;
346
+ }
347
+ const packageJSON = JSON.parse(fs5.readFileSync("package.json", "utf-8"));
348
+ const changelogJSON = JSON.parse(fs5.readFileSync("changelog.json", "utf-8"));
349
+ const version = packageJSON["version"];
350
+ const changelog = changelogJSON[version];
351
+ let needUpdateElectron = await promptChecker_default({
352
+ type: "confirm",
353
+ name: "electron",
354
+ message: chalk3.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
355
+ });
356
+ const versionInfo = {
357
+ version,
358
+ releaseNote: changelog,
359
+ updateElectron: needUpdateElectron,
360
+ updateNodeModule: false,
361
+ updateWindowsApi: false,
362
+ downloadLink: ""
363
+ };
364
+ let installerPath = path3.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
365
+ if (!fs5.existsSync(installerPath)) {
366
+ installerPath = path3.join(`./packaged/electron-${version}-setup-win-x64.exe`);
367
+ }
368
+ const updateZipPath = path3.join(`./packaged/update.zip`);
369
+ console.log(chalk3.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
370
+ await update_zip_default("./release", updateZipPath);
371
+ console.log(chalk3.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
372
+ await put("version/installer.exe", installerPath);
373
+ console.log(chalk3.blue("\u4E0A\u4F20update.zip\u5230OSS"));
374
+ await put("version/update.zip", updateZipPath);
375
+ console.log(chalk3.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
376
+ versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
377
+ const versionJSON = JSON.stringify(versionInfo, null, 2);
378
+ await put("version/version.json", Buffer.from(versionJSON));
379
+ copy(`version/history/${version}.exe`, "version/installer.exe");
380
+ copy(`version/history/update-${version}.zip`, "version/update.zip");
381
+ console.log(chalk3.yellow(versionJSON));
382
+ };
383
+ var release_default = release;
384
+
386
385
  // src/index.ts
386
+ import { fileURLToPath as fileURLToPath2 } from "url";
387
+ import figlet from "figlet";
388
+ import gradient from "gradient-string";
387
389
  var __filename = fileURLToPath2(import.meta.url);
388
390
  var __dirname = path4.dirname(__filename);
389
391
  var packageJsonPath = path4.join(__dirname, "../package.json");
@@ -393,10 +395,9 @@ program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [option
393
395
  program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
394
396
  await createWidget();
395
397
  });
396
- program.command("release").description("\u901A\u8FC7OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
397
- await release_default();
398
- });
399
- program.command("ftp").description("\u901A\u8FC7FTP\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
400
- await ftpUpload();
398
+ var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
399
+ program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
400
+ console.log(options);
401
+ await release_default(options);
401
402
  });
402
403
  program.parse(process3.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "main": "lib/index.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
@@ -26,6 +26,7 @@
26
26
  "@types/gradient-string": "^1.1.2",
27
27
  "@vue/cli-shared-utils": "^5.0.8",
28
28
  "@widget-js/core": "^0.1.14",
29
+ "@widget-js/ssh-config": "^4.2.1",
29
30
  "ali-oss": "^6.17.1",
30
31
  "archiver": "^5.3.1",
31
32
  "chalk": "^5.2.0",
@@ -36,9 +37,8 @@
36
37
  "figlet": "^1.5.2",
37
38
  "gradient-string": "^2.0.2",
38
39
  "inquirer": "^9.1.4",
39
- "nanospinner": "^1.1.0",
40
+ "ora": "^6.2.0",
40
41
  "shelljs": "^0.8.5",
41
- "ssh-config": "file://D:\\workspace\\ssh-config",
42
42
  "ssh2-sftp-client": "^9.0.4",
43
43
  "ws": "^8.11.0"
44
44
  },
@@ -55,6 +55,7 @@
55
55
  "@types/node": "^18.11.13",
56
56
  "@types/shelljs": "latest",
57
57
  "@types/ssh2-sftp-client": "^9.0.0",
58
+ "jest": "^29.5.0",
58
59
  "pinst": "^3.0.0",
59
60
  "prettier": "^2.8.4",
60
61
  "ts-jest": "^29.0.3",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {program} from 'commander'
1
+ import {Option, program} from 'commander'
2
2
  import fs from 'fs'
3
3
  import path from 'path'
4
4
  import * as process from 'process'
@@ -8,7 +8,7 @@ import release from './release/release'
8
8
  import {fileURLToPath} from 'url'
9
9
  import figlet from 'figlet'
10
10
  import gradient from 'gradient-string'
11
- import {ftpUpload} from './ftp/ftp'
11
+ import {ftpUpload} from './release/ftp/ftp'
12
12
 
13
13
  const __filename = fileURLToPath(import.meta.url)
14
14
  const __dirname = path.dirname(__filename)
@@ -24,17 +24,16 @@ program
24
24
  .action(async () => {
25
25
  await createWidget()
26
26
  })
27
+
28
+ let typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
27
29
  program
28
30
  .command('release')
29
- .description('通过OSS发布文件,仅内部使用')
30
- .action(async () => {
31
- await release()
32
- })
33
- program
34
- .command('ftp')
35
- .description('通过FTP发布文件,仅内部使用')
36
- .action(async () => {
37
- await ftpUpload()
31
+ .description('通过FTP/OSS发布文件,仅内部使用')
32
+ .addOption(typeOption)
33
+ .action(async (options, command) => {
34
+ // @ts-ignore
35
+ console.log(options)
36
+ await release(options)
38
37
  })
39
38
 
40
39
  //TODO init 初始化项目
@@ -1,11 +1,11 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
- import SSHConfig from 'ssh-config'
3
+ import SSHConfig from '@widget-js/ssh-config'
4
4
  import os from 'os'
5
5
  import Client from 'ssh2-sftp-client'
6
6
  import consola from 'consola'
7
7
  import inquirer from 'inquirer'
8
- import {createSpinner} from 'nanospinner'
8
+ import ora from 'ora'
9
9
  import * as process from 'process'
10
10
  import * as console from 'console'
11
11
 
@@ -31,7 +31,7 @@ export function ftpUpload() {
31
31
  let ftpClient = new Client()
32
32
  const port = sshConfig['Port']
33
33
  const key = fs.readFileSync(path.resolve(os.homedir(), '.ssh/id_rsa'))
34
- const spinner = createSpinner('Connecting')
34
+ const spinner = ora('Connecting')
35
35
  try {
36
36
  spinner.start()
37
37
  await ftpClient.connect({
@@ -41,32 +41,29 @@ export function ftpUpload() {
41
41
  passphrase: answer.password,
42
42
  privateKey: key,
43
43
  })
44
- ftpClient.on('upload', info => {
45
- spinner.update({text: `Uploading: ${info.source}`})
46
- })
47
44
  // upload files
48
45
  for (let item of releaseConfig.fileMap) {
49
46
  if (typeof item.src == 'string') {
50
47
  const localFile = path.resolve(process.cwd(), item.src as string)
51
48
  if (!fs.existsSync(localFile)) {
52
- spinner.warn({text: `Skip not exists file:${localFile}`})
49
+ spinner.warn(`Skip not exists file:${localFile}`)
53
50
  continue
54
51
  }
55
52
  if (fs.lstatSync(localFile).isDirectory()) {
56
- spinner.update({text: `Uploading Dir: ${localFile} -> ${item.dest}`})
53
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
57
54
  await ftpClient.uploadDir(localFile, item.dest)
58
55
  } else {
59
- spinner.update({text: `Uploading File: ${localFile} -> ${item.dest}`})
56
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
60
57
  await ftpClient.put(localFile, item.dest)
61
58
  }
62
59
  } else {
63
60
  await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
64
61
  }
65
62
  }
66
- spinner.success({text: 'Files uploaded!'})
63
+ spinner.succeed('Files uploaded!')
67
64
  await ftpClient.end()
68
65
  } catch (e) {
69
- spinner.error({text: `Connection error:${e}`})
66
+ spinner.fail(`Connection error:${e}`)
70
67
  await ftpClient.end()
71
68
  }
72
69
  })
@@ -1,69 +1,75 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import promptChecker from "../promts/promptChecker.js";
4
- import zipDirectory from "./update-zip.js";
5
- import {copy, put} from "./oss.js";
6
- import chalk from "chalk";
7
-
8
- async function delay(time:number) {
9
- return new Promise<void>((resolve, reject) => {
10
- setTimeout(() => {
11
- resolve();
12
- }, time);
13
- });
14
- }
15
-
16
- const release = async () => {
17
- const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
18
- const changelogJSON = JSON.parse(fs.readFileSync('changelog.json', 'utf-8'))
19
- const version = packageJSON["version"]
20
- const changelog = changelogJSON[version]
21
-
22
- let needUpdateElectron = await promptChecker({
23
- type: "confirm",
24
- name: 'electron',
25
- message: chalk.blue("用户是否需要更新Electron?")
26
- });
27
- //
28
- // let needUpdateNodeModule = await promptChecker({
29
- // type: "confirm",
30
- // name: 'electron',
31
- // message: chalk.blue("用户是否需要更新node_module?")
32
- // });
33
-
34
- const versionInfo = {
35
- version: version,
36
- releaseNote: changelog,
37
- updateElectron: needUpdateElectron,
38
- updateNodeModule: false,
39
- updateWindowsApi: false,
40
- downloadLink: ''
41
- };
42
-
43
- let installerPath = path.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
44
- if (!fs.existsSync(installerPath)) {
45
- installerPath = path.join(`./packaged/electron-${version}-setup-win-x64.exe`);
46
- }
47
- const updateZipPath = path.join(`./packaged/update.zip`)
48
-
49
- console.log(chalk.blue("压缩更新文件中"))
50
- await zipDirectory("./release", updateZipPath);
51
-
52
- console.log(chalk.blue("上传installer.exe到OSS"))
53
- await put("version/installer.exe", installerPath)
54
-
55
- console.log(chalk.blue("上传update.zip到OSS"))
56
- await put("version/update.zip", updateZipPath)
57
-
58
- console.log(chalk.blue("更新版本信息"))
59
- versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip"
60
- const versionJSON = JSON.stringify(versionInfo, null, 2)
61
- await put("version/version.json", Buffer.from(versionJSON))
62
-
63
- copy(`version/history/${version}.exe`, "version/installer.exe")
64
- copy(`version/history/update-${version}.zip`, "version/update.zip")
65
-
66
- console.log(chalk.yellow(versionJSON))
67
- }
68
-
69
- export default release;
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import promptChecker from '../promts/promptChecker.js'
4
+ import zipDirectory from './update-zip.js'
5
+ import {copy, put} from './oss.js'
6
+ import chalk from 'chalk'
7
+ import {ftpUpload} from './ftp/ftp'
8
+
9
+ async function delay(time: number) {
10
+ return new Promise<void>((resolve, reject) => {
11
+ setTimeout(() => {
12
+ resolve()
13
+ }, time)
14
+ })
15
+ }
16
+
17
+ const release = async (options: any) => {
18
+ console.log()
19
+ if (options.type == 'ftp') {
20
+ await ftpUpload()
21
+ return
22
+ }
23
+ const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
24
+ const changelogJSON = JSON.parse(fs.readFileSync('changelog.json', 'utf-8'))
25
+ const version = packageJSON['version']
26
+ const changelog = changelogJSON[version]
27
+
28
+ let needUpdateElectron = await promptChecker({
29
+ type: 'confirm',
30
+ name: 'electron',
31
+ message: chalk.blue('用户是否需要更新Electron?'),
32
+ })
33
+ //
34
+ // let needUpdateNodeModule = await promptChecker({
35
+ // type: "confirm",
36
+ // name: 'electron',
37
+ // message: chalk.blue("用户是否需要更新node_module?")
38
+ // });
39
+
40
+ const versionInfo = {
41
+ version: version,
42
+ releaseNote: changelog,
43
+ updateElectron: needUpdateElectron,
44
+ updateNodeModule: false,
45
+ updateWindowsApi: false,
46
+ downloadLink: '',
47
+ }
48
+
49
+ let installerPath = path.join(`./packaged/widgets-${version}-setup-win-x64.exe`)
50
+ if (!fs.existsSync(installerPath)) {
51
+ installerPath = path.join(`./packaged/electron-${version}-setup-win-x64.exe`)
52
+ }
53
+ const updateZipPath = path.join(`./packaged/update.zip`)
54
+
55
+ console.log(chalk.blue('压缩更新文件中'))
56
+ await zipDirectory('./release', updateZipPath)
57
+
58
+ console.log(chalk.blue('上传installer.exe到OSS'))
59
+ await put('version/installer.exe', installerPath)
60
+
61
+ console.log(chalk.blue('上传update.zip到OSS'))
62
+ await put('version/update.zip', updateZipPath)
63
+
64
+ console.log(chalk.blue('更新版本信息'))
65
+ versionInfo.downloadLink = 'https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip'
66
+ const versionJSON = JSON.stringify(versionInfo, null, 2)
67
+ await put('version/version.json', Buffer.from(versionJSON))
68
+
69
+ copy(`version/history/${version}.exe`, 'version/installer.exe')
70
+ copy(`version/history/update-${version}.zip`, 'version/update.zip')
71
+
72
+ console.log(chalk.yellow(versionJSON))
73
+ }
74
+
75
+ export default release