@widget-js/cli 1.0.12 → 1.0.14
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 +93 -69
- package/lib/index.js +94 -70
- package/package.json +2 -2
- package/release.json +7 -14
- package/src/index.ts +9 -11
- package/src/{ftp → release}/ftp.ts +35 -11
- package/src/release/release.ts +75 -69
package/lib/index.cjs
CHANGED
|
@@ -238,8 +238,8 @@ async function createWidget() {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// src/release/release.ts
|
|
241
|
-
var
|
|
242
|
-
var
|
|
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,54 +293,11 @@ 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/
|
|
341
|
-
var
|
|
342
|
-
var
|
|
343
|
-
var import_ssh_config = __toESM(require("ssh-config"), 1);
|
|
297
|
+
// src/release/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);
|
|
@@ -348,12 +305,20 @@ var import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
|
348
305
|
var import_ora = __toESM(require("ora"), 1);
|
|
349
306
|
var process2 = __toESM(require("process"), 1);
|
|
350
307
|
var console2 = __toESM(require("console"), 1);
|
|
308
|
+
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
309
|
+
let dir = import_path2.default.dirname(file);
|
|
310
|
+
const dirExists = await ftpClient.exists(dir);
|
|
311
|
+
if (!dirExists) {
|
|
312
|
+
onMkdir(dir);
|
|
313
|
+
await ftpClient.mkdir(dir, true);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
351
316
|
function ftpUpload() {
|
|
352
|
-
const file =
|
|
353
|
-
const releaseConfig = JSON.parse(
|
|
354
|
-
const sshConfigFile =
|
|
317
|
+
const file = import_path2.default.join(process2.cwd(), "release.json");
|
|
318
|
+
const releaseConfig = JSON.parse(import_fs4.default.readFileSync(file).toString());
|
|
319
|
+
const sshConfigFile = import_path2.default.resolve(import_os.default.homedir(), ".ssh/config");
|
|
355
320
|
console2.log("SSH Config file:", sshConfigFile);
|
|
356
|
-
const sshConfigs = import_ssh_config.default.parse(
|
|
321
|
+
const sshConfigs = import_ssh_config.default.parse(import_fs4.default.readFileSync(sshConfigFile).toString());
|
|
357
322
|
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
358
323
|
if (!sshConfig) {
|
|
359
324
|
import_consola2.default.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
@@ -363,7 +328,7 @@ function ftpUpload() {
|
|
|
363
328
|
import_inquirer3.default.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
364
329
|
let ftpClient = new import_ssh2_sftp_client.default();
|
|
365
330
|
const port = sshConfig["Port"];
|
|
366
|
-
const key =
|
|
331
|
+
const key = import_fs4.default.readFileSync(import_path2.default.resolve(import_os.default.homedir(), ".ssh/id_rsa"));
|
|
367
332
|
const spinner = (0, import_ora.default)("Connecting");
|
|
368
333
|
try {
|
|
369
334
|
spinner.start();
|
|
@@ -374,19 +339,31 @@ function ftpUpload() {
|
|
|
374
339
|
passphrase: answer.password,
|
|
375
340
|
privateKey: key
|
|
376
341
|
});
|
|
342
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order);
|
|
377
343
|
for (let item of releaseConfig.fileMap) {
|
|
378
344
|
if (typeof item.src == "string") {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
386
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
345
|
+
if (item.remoteCopy) {
|
|
346
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
347
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
348
|
+
});
|
|
349
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
350
|
+
await ftpClient.rcopy(item.src, item.dest);
|
|
387
351
|
} else {
|
|
388
|
-
|
|
389
|
-
|
|
352
|
+
const localFile = import_path2.default.resolve(process2.cwd(), item.src);
|
|
353
|
+
if (!item.remoteCopy && !import_fs4.default.existsSync(localFile)) {
|
|
354
|
+
spinner.warn(`Skip not exists file:${localFile}`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (import_fs4.default.lstatSync(localFile).isDirectory()) {
|
|
358
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
359
|
+
await ftpClient.uploadDir(localFile, item.dest);
|
|
360
|
+
} else {
|
|
361
|
+
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
362
|
+
spinner.warn(`Create Dir: ${dir}`);
|
|
363
|
+
});
|
|
364
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
365
|
+
await ftpClient.put(localFile, item.dest);
|
|
366
|
+
}
|
|
390
367
|
}
|
|
391
368
|
} else {
|
|
392
369
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
@@ -401,7 +378,55 @@ function ftpUpload() {
|
|
|
401
378
|
});
|
|
402
379
|
}
|
|
403
380
|
|
|
381
|
+
// src/release/release.ts
|
|
382
|
+
var release = async (options) => {
|
|
383
|
+
console.log();
|
|
384
|
+
if (options.type == "ftp") {
|
|
385
|
+
await ftpUpload();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const packageJSON = JSON.parse(import_fs5.default.readFileSync("package.json", "utf-8"));
|
|
389
|
+
const changelogJSON = JSON.parse(import_fs5.default.readFileSync("changelog.json", "utf-8"));
|
|
390
|
+
const version = packageJSON["version"];
|
|
391
|
+
const changelog = changelogJSON[version];
|
|
392
|
+
let needUpdateElectron = await promptChecker_default({
|
|
393
|
+
type: "confirm",
|
|
394
|
+
name: "electron",
|
|
395
|
+
message: import_chalk3.default.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
396
|
+
});
|
|
397
|
+
const versionInfo = {
|
|
398
|
+
version,
|
|
399
|
+
releaseNote: changelog,
|
|
400
|
+
updateElectron: needUpdateElectron,
|
|
401
|
+
updateNodeModule: false,
|
|
402
|
+
updateWindowsApi: false,
|
|
403
|
+
downloadLink: ""
|
|
404
|
+
};
|
|
405
|
+
let installerPath = import_path3.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
406
|
+
if (!import_fs5.default.existsSync(installerPath)) {
|
|
407
|
+
installerPath = import_path3.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
408
|
+
}
|
|
409
|
+
const updateZipPath = import_path3.default.join(`./packaged/update.zip`);
|
|
410
|
+
console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
411
|
+
await update_zip_default("./release", updateZipPath);
|
|
412
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
413
|
+
await put("version/installer.exe", installerPath);
|
|
414
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
415
|
+
await put("version/update.zip", updateZipPath);
|
|
416
|
+
console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
417
|
+
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
418
|
+
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
419
|
+
await put("version/version.json", Buffer.from(versionJSON));
|
|
420
|
+
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
421
|
+
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
422
|
+
console.log(import_chalk3.default.yellow(versionJSON));
|
|
423
|
+
};
|
|
424
|
+
var release_default = release;
|
|
425
|
+
|
|
404
426
|
// src/index.ts
|
|
427
|
+
var import_url2 = require("url");
|
|
428
|
+
var import_figlet = __toESM(require("figlet"), 1);
|
|
429
|
+
var import_gradient_string = __toESM(require("gradient-string"), 1);
|
|
405
430
|
var import_meta2 = {};
|
|
406
431
|
var __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
407
432
|
var __dirname = import_path4.default.dirname(__filename);
|
|
@@ -412,10 +437,9 @@ import_commander.program.version(`@widget-js/cli ${cliPackage.version}`).usage("
|
|
|
412
437
|
import_commander.program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
413
438
|
await createWidget();
|
|
414
439
|
});
|
|
415
|
-
import_commander.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
await ftpUpload();
|
|
440
|
+
var typeOption = new import_commander.Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
441
|
+
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) => {
|
|
442
|
+
console.log(options);
|
|
443
|
+
await release_default(options);
|
|
420
444
|
});
|
|
421
445
|
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
|
|
221
|
-
import
|
|
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,54 +272,11 @@ 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/
|
|
320
|
-
import
|
|
321
|
-
import
|
|
322
|
-
import SSHConfig from "ssh-config";
|
|
276
|
+
// src/release/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";
|
|
@@ -327,12 +284,20 @@ import inquirer3 from "inquirer";
|
|
|
327
284
|
import ora from "ora";
|
|
328
285
|
import * as process2 from "process";
|
|
329
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
|
+
}
|
|
330
295
|
function ftpUpload() {
|
|
331
|
-
const file =
|
|
332
|
-
const releaseConfig = JSON.parse(
|
|
333
|
-
const sshConfigFile =
|
|
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");
|
|
334
299
|
console2.log("SSH Config file:", sshConfigFile);
|
|
335
|
-
const sshConfigs = SSHConfig.parse(
|
|
300
|
+
const sshConfigs = SSHConfig.parse(fs4.readFileSync(sshConfigFile).toString());
|
|
336
301
|
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
337
302
|
if (!sshConfig) {
|
|
338
303
|
consola2.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
@@ -342,7 +307,7 @@ function ftpUpload() {
|
|
|
342
307
|
inquirer3.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
343
308
|
let ftpClient = new Client();
|
|
344
309
|
const port = sshConfig["Port"];
|
|
345
|
-
const key =
|
|
310
|
+
const key = fs4.readFileSync(path2.resolve(os.homedir(), ".ssh/id_rsa"));
|
|
346
311
|
const spinner = ora("Connecting");
|
|
347
312
|
try {
|
|
348
313
|
spinner.start();
|
|
@@ -353,19 +318,31 @@ function ftpUpload() {
|
|
|
353
318
|
passphrase: answer.password,
|
|
354
319
|
privateKey: key
|
|
355
320
|
});
|
|
321
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order);
|
|
356
322
|
for (let item of releaseConfig.fileMap) {
|
|
357
323
|
if (typeof item.src == "string") {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
365
|
-
await ftpClient.uploadDir(localFile, item.dest);
|
|
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);
|
|
366
330
|
} else {
|
|
367
|
-
|
|
368
|
-
|
|
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
|
+
}
|
|
369
346
|
}
|
|
370
347
|
} else {
|
|
371
348
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
@@ -380,7 +357,55 @@ function ftpUpload() {
|
|
|
380
357
|
});
|
|
381
358
|
}
|
|
382
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
|
+
|
|
383
405
|
// src/index.ts
|
|
406
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
407
|
+
import figlet from "figlet";
|
|
408
|
+
import gradient from "gradient-string";
|
|
384
409
|
var __filename = fileURLToPath2(import.meta.url);
|
|
385
410
|
var __dirname = path4.dirname(__filename);
|
|
386
411
|
var packageJsonPath = path4.join(__dirname, "../package.json");
|
|
@@ -390,10 +415,9 @@ program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [option
|
|
|
390
415
|
program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
391
416
|
await createWidget();
|
|
392
417
|
});
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
await ftpUpload();
|
|
418
|
+
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
419
|
+
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);
|
|
398
422
|
});
|
|
399
423
|
program.parse(process3.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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",
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
"inquirer": "^9.1.4",
|
|
39
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
|
},
|
package/release.json
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"fileMap": [
|
|
3
3
|
{
|
|
4
|
-
"src": "
|
|
5
|
-
"dest": "/www/wwwroot/template/"
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
"src": {
|
|
9
|
-
"version": "0.1.0",
|
|
10
|
-
"createdAt": "",
|
|
11
|
-
"releaseNote": "1.增加版本更新",
|
|
12
|
-
"downloadLink": "https://download.tool-vip.com/youlu/update.zip",
|
|
13
|
-
"updateElectron": false
|
|
14
|
-
},
|
|
15
|
-
"dest": "/www/wwwroot/template/version.json"
|
|
4
|
+
"src": ".gitignore",
|
|
5
|
+
"dest": "/www/wwwroot/template/aa/.gitignore",
|
|
6
|
+
"order": 0
|
|
16
7
|
},
|
|
17
8
|
{
|
|
18
|
-
"src": "
|
|
19
|
-
"dest": "/www/wwwroot/template/.
|
|
9
|
+
"src": "/www/wwwroot/template/aa/.gitignore",
|
|
10
|
+
"dest": "/www/wwwroot/template/bbb/.gitignorexxx",
|
|
11
|
+
"remoteCopy": true,
|
|
12
|
+
"order": 1
|
|
20
13
|
}
|
|
21
14
|
],
|
|
22
15
|
"ftpConfig": {
|
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,6 @@ 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'
|
|
12
11
|
|
|
13
12
|
const __filename = fileURLToPath(import.meta.url)
|
|
14
13
|
const __dirname = path.dirname(__filename)
|
|
@@ -24,17 +23,16 @@ program
|
|
|
24
23
|
.action(async () => {
|
|
25
24
|
await createWidget()
|
|
26
25
|
})
|
|
26
|
+
|
|
27
|
+
let typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
27
28
|
program
|
|
28
29
|
.command('release')
|
|
29
|
-
.description('通过OSS发布文件,仅内部使用')
|
|
30
|
-
.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.description('通过FTP发布文件,仅内部使用')
|
|
36
|
-
.action(async () => {
|
|
37
|
-
await ftpUpload()
|
|
30
|
+
.description('通过FTP/OSS发布文件,仅内部使用')
|
|
31
|
+
.addOption(typeOption)
|
|
32
|
+
.action(async (options, command) => {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
console.log(options)
|
|
35
|
+
await release(options)
|
|
38
36
|
})
|
|
39
37
|
|
|
40
38
|
//TODO init 初始化项目
|
|
@@ -1,6 +1,6 @@
|
|
|
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'
|
|
@@ -12,6 +12,16 @@ import * as console from 'console'
|
|
|
12
12
|
interface PasswordAnswer {
|
|
13
13
|
password: string
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
|
|
17
|
+
let dir = path.dirname(file)
|
|
18
|
+
const dirExists = await ftpClient.exists(dir)
|
|
19
|
+
if (!dirExists) {
|
|
20
|
+
onMkdir(dir)
|
|
21
|
+
await ftpClient.mkdir(dir, true)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
export function ftpUpload() {
|
|
16
26
|
// 读取
|
|
17
27
|
const file = path.join(process.cwd(), 'release.json')
|
|
@@ -41,20 +51,32 @@ export function ftpUpload() {
|
|
|
41
51
|
passphrase: answer.password,
|
|
42
52
|
privateKey: key,
|
|
43
53
|
})
|
|
54
|
+
releaseConfig.fileMap.sort((it1, it2) => it1.order - it2.order)
|
|
44
55
|
// upload files
|
|
45
56
|
for (let item of releaseConfig.fileMap) {
|
|
46
57
|
if (typeof item.src == 'string') {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
54
|
-
await ftpClient.uploadDir(localFile, item.dest)
|
|
58
|
+
if (item.remoteCopy) {
|
|
59
|
+
await checkParentDir(ftpClient, item.dest, dir => {
|
|
60
|
+
spinner.warn(`Create Dir: ${dir}`)
|
|
61
|
+
})
|
|
62
|
+
spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
|
|
63
|
+
await ftpClient.rcopy(item.src, item.dest)
|
|
55
64
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
const localFile = path.resolve(process.cwd(), item.src as string)
|
|
66
|
+
if (!item.remoteCopy && !fs.existsSync(localFile)) {
|
|
67
|
+
spinner.warn(`Skip not exists file:${localFile}`)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
if (fs.lstatSync(localFile).isDirectory()) {
|
|
71
|
+
spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
|
|
72
|
+
await ftpClient.uploadDir(localFile, item.dest)
|
|
73
|
+
} else {
|
|
74
|
+
await checkParentDir(ftpClient, item.dest, dir => {
|
|
75
|
+
spinner.warn(`Create Dir: ${dir}`)
|
|
76
|
+
})
|
|
77
|
+
spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
|
|
78
|
+
await ftpClient.put(localFile, item.dest)
|
|
79
|
+
}
|
|
58
80
|
}
|
|
59
81
|
} else {
|
|
60
82
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
|
|
@@ -73,6 +95,8 @@ export interface ReleaseConfig {
|
|
|
73
95
|
fileMap: {
|
|
74
96
|
src: string | object
|
|
75
97
|
dest: string
|
|
98
|
+
remoteCopy: boolean
|
|
99
|
+
order: number
|
|
76
100
|
}[]
|
|
77
101
|
ftpConfig: FTPConfig
|
|
78
102
|
}
|
package/src/release/release.ts
CHANGED
|
@@ -1,69 +1,75 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import promptChecker from
|
|
4
|
-
import zipDirectory from
|
|
5
|
-
import {copy, put} from
|
|
6
|
-
import chalk from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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'
|
|
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
|