@widget-js/cli 1.0.16 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/vcs.xml +1 -1
- package/lib/chunk-3GPAHQ6O.js +18 -0
- package/lib/chunk-SIAOIY3B.js +27 -0
- package/lib/{createWidget-AX4QC5FV.js → createWidget-KWBUF3TN.js} +4 -2
- package/lib/index.cjs +112 -38
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -2
- package/lib/{release-CEWJTX3Q.js → release-PBOWWLKA.js} +8 -2
- package/lib/upgrade-ETO2LGMX.js +52 -0
- package/package.json +12 -14
- package/src/index.ts +40 -32
- package/src/release/ftp.ts +10 -11
- package/src/upgrade/upgrade.ts +48 -0
- package/src/utils.ts +11 -4
- package/template/WidgetConfig.ejs +4 -10
- package/tsup.config.ts +2 -1
- package/babel.config.js +0 -20
- package/lib/chunk-VOTZXZ5O.js +0 -36
package/.idea/vcs.xml
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/promts/promptChecker.ts
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
var promptChecker = async (prompt, checker) => {
|
|
4
|
+
const answer = await inquirer.prompt([prompt]);
|
|
5
|
+
if (checker) {
|
|
6
|
+
if (checker(answer)) {
|
|
7
|
+
return answer[prompt.name];
|
|
8
|
+
} else {
|
|
9
|
+
return promptChecker(prompt, checker);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return answer[prompt.name];
|
|
13
|
+
};
|
|
14
|
+
var promptChecker_default = promptChecker;
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
promptChecker_default
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import process from "process";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
function exit(code = 0) {
|
|
6
|
+
if (exports.exitProcess) {
|
|
7
|
+
process.exit(code);
|
|
8
|
+
} else if (code > 0) {
|
|
9
|
+
throw new Error(`Process exited with code ${code}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getPackagePath() {
|
|
13
|
+
return path.join(process.cwd(), "package.json");
|
|
14
|
+
}
|
|
15
|
+
function getPackageJson() {
|
|
16
|
+
return JSON.parse(fs.readFileSync(getPackagePath()).toString());
|
|
17
|
+
}
|
|
18
|
+
function getPackageVersion() {
|
|
19
|
+
return getPackageJson()["version"];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
exit,
|
|
24
|
+
getPackagePath,
|
|
25
|
+
getPackageJson,
|
|
26
|
+
getPackageVersion
|
|
27
|
+
};
|
package/lib/index.cjs
CHANGED
|
@@ -21,6 +21,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
21
21
|
return to;
|
|
22
22
|
};
|
|
23
23
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
28
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
29
|
mod
|
|
26
30
|
));
|
|
@@ -54,9 +58,14 @@ function exit(code = 0) {
|
|
|
54
58
|
throw new Error(`Process exited with code ${code}`);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
61
|
+
function getPackagePath() {
|
|
62
|
+
return import_path.default.join(import_process.default.cwd(), "package.json");
|
|
63
|
+
}
|
|
64
|
+
function getPackageJson() {
|
|
65
|
+
return JSON.parse(import_fs.default.readFileSync(getPackagePath()).toString());
|
|
66
|
+
}
|
|
57
67
|
function getPackageVersion() {
|
|
58
|
-
|
|
59
|
-
return JSON.parse(import_fs.default.readFileSync(packagePath).toString())["version"];
|
|
68
|
+
return getPackageJson()["version"];
|
|
60
69
|
}
|
|
61
70
|
var import_path, import_process, import_fs;
|
|
62
71
|
var init_utils = __esm({
|
|
@@ -265,14 +274,70 @@ var init_createWidget = __esm({
|
|
|
265
274
|
}
|
|
266
275
|
});
|
|
267
276
|
|
|
277
|
+
// src/upgrade/upgrade.ts
|
|
278
|
+
var upgrade_exports = {};
|
|
279
|
+
__export(upgrade_exports, {
|
|
280
|
+
Upgrade: () => Upgrade
|
|
281
|
+
});
|
|
282
|
+
var import_package_json, import_ora, import_fs3, packages, spinner, Upgrade;
|
|
283
|
+
var init_upgrade = __esm({
|
|
284
|
+
"src/upgrade/upgrade.ts"() {
|
|
285
|
+
"use strict";
|
|
286
|
+
import_package_json = __toESM(require("package-json"), 1);
|
|
287
|
+
import_ora = __toESM(require("ora"), 1);
|
|
288
|
+
init_utils();
|
|
289
|
+
import_fs3 = __toESM(require("fs"), 1);
|
|
290
|
+
packages = {
|
|
291
|
+
"@widget-js/core": "",
|
|
292
|
+
"@widget-js/vue3": "",
|
|
293
|
+
"@widget-js/cli": "",
|
|
294
|
+
"@widget-js/vite-plugin-widget": ""
|
|
295
|
+
};
|
|
296
|
+
spinner = (0, import_ora.default)("Connecting");
|
|
297
|
+
Upgrade = class {
|
|
298
|
+
async start() {
|
|
299
|
+
spinner.start();
|
|
300
|
+
let json = getPackageJson();
|
|
301
|
+
let packageNames = Object.keys(packages);
|
|
302
|
+
let dependencies = json["dependencies"];
|
|
303
|
+
let devDependencies = json["devDependencies"];
|
|
304
|
+
await this.upgradePackage(dependencies, packageNames);
|
|
305
|
+
await this.upgradePackage(devDependencies, packageNames);
|
|
306
|
+
import_fs3.default.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
307
|
+
spinner.succeed("Upgraded!");
|
|
308
|
+
}
|
|
309
|
+
async upgradePackage(dependencies, packageNames) {
|
|
310
|
+
let localPackages = Object.keys(dependencies);
|
|
311
|
+
for (let localPackage of localPackages) {
|
|
312
|
+
if (packageNames.indexOf(localPackage) > -1) {
|
|
313
|
+
let packageVersion = packages[localPackage];
|
|
314
|
+
if (!packageVersion) {
|
|
315
|
+
packageVersion = await this.getRemoteVersion(localPackage);
|
|
316
|
+
packages[localPackage] = packageVersion;
|
|
317
|
+
}
|
|
318
|
+
dependencies[localPackage] = `^${packageVersion}`;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async getRemoteVersion(packageName) {
|
|
323
|
+
spinner.info(`Fetching package version:${packageName}`);
|
|
324
|
+
const metadata = await (0, import_package_json.default)(packageName);
|
|
325
|
+
let version = metadata["version"];
|
|
326
|
+
spinner.info(`version:${version}`);
|
|
327
|
+
return version;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
268
333
|
// src/build/build.ts
|
|
269
334
|
var build_exports = {};
|
|
270
335
|
__export(build_exports, {
|
|
271
336
|
build: () => build
|
|
272
337
|
});
|
|
273
338
|
function build() {
|
|
274
|
-
const preloadSpinner = (0,
|
|
275
|
-
const mainSpinner = (0,
|
|
339
|
+
const preloadSpinner = (0, import_ora2.default)("Preload").start();
|
|
340
|
+
const mainSpinner = (0, import_ora2.default)("Main").start();
|
|
276
341
|
const build2 = (0, import_child_process.exec)("npm run build:preload").on("close", () => {
|
|
277
342
|
import_consola2.default.success("done");
|
|
278
343
|
});
|
|
@@ -294,11 +359,11 @@ function build() {
|
|
|
294
359
|
import_consola2.default.log("done");
|
|
295
360
|
});
|
|
296
361
|
}
|
|
297
|
-
var
|
|
362
|
+
var import_ora2, import_child_process, import_consola2;
|
|
298
363
|
var init_build = __esm({
|
|
299
364
|
"src/build/build.ts"() {
|
|
300
365
|
"use strict";
|
|
301
|
-
|
|
366
|
+
import_ora2 = __toESM(require("ora"), 1);
|
|
302
367
|
import_child_process = require("child_process");
|
|
303
368
|
import_consola2 = __toESM(require("consola"), 1);
|
|
304
369
|
}
|
|
@@ -307,18 +372,18 @@ var init_build = __esm({
|
|
|
307
372
|
// src/release/update-zip.ts
|
|
308
373
|
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
309
374
|
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
310
|
-
const stream =
|
|
375
|
+
const stream = import_fs4.default.createWriteStream(outPath);
|
|
311
376
|
return new Promise((resolve, reject) => {
|
|
312
377
|
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
313
378
|
stream.on("close", () => resolve());
|
|
314
379
|
archive.finalize();
|
|
315
380
|
});
|
|
316
381
|
}
|
|
317
|
-
var
|
|
382
|
+
var import_fs4, import_archiver, update_zip_default;
|
|
318
383
|
var init_update_zip = __esm({
|
|
319
384
|
"src/release/update-zip.ts"() {
|
|
320
385
|
"use strict";
|
|
321
|
-
|
|
386
|
+
import_fs4 = __toESM(require("fs"), 1);
|
|
322
387
|
import_archiver = __toESM(require("archiver"), 1);
|
|
323
388
|
update_zip_default = zipDirectory;
|
|
324
389
|
}
|
|
@@ -341,24 +406,28 @@ async function copy(dist, src) {
|
|
|
341
406
|
console.error(e);
|
|
342
407
|
}
|
|
343
408
|
}
|
|
344
|
-
var import_ali_oss,
|
|
409
|
+
var import_ali_oss, import_fs5, import_chalk2, packageData, AccessKeyID, AccessKeySecret, headers, clinet;
|
|
345
410
|
var init_oss = __esm({
|
|
346
411
|
"src/release/oss.ts"() {
|
|
347
412
|
"use strict";
|
|
348
413
|
import_ali_oss = __toESM(require("ali-oss"), 1);
|
|
349
|
-
|
|
414
|
+
import_fs5 = __toESM(require("fs"), 1);
|
|
350
415
|
import_chalk2 = __toESM(require("chalk"), 1);
|
|
351
|
-
packageData = JSON.parse(
|
|
416
|
+
packageData = JSON.parse(import_fs5.default.readFileSync("./package.json").toString());
|
|
352
417
|
AccessKeyID = packageData.oss?.id ?? "default";
|
|
353
418
|
AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
354
419
|
headers = {
|
|
420
|
+
// 指定Object的存储类型。
|
|
355
421
|
"x-oss-storage-class": "Standard",
|
|
422
|
+
// 指定Object的访问权限。
|
|
356
423
|
"x-oss-object-acl": "public-read",
|
|
357
424
|
"x-oss-forbid-overwrite": "false",
|
|
358
425
|
"Cache-Control": "no-cache"
|
|
359
426
|
};
|
|
360
427
|
clinet = new import_ali_oss.default({
|
|
428
|
+
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
361
429
|
region: "oss-cn-hangzhou",
|
|
430
|
+
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
362
431
|
accessKeyId: AccessKeyID,
|
|
363
432
|
accessKeySecret: AccessKeySecret,
|
|
364
433
|
bucket: "widget-fun"
|
|
@@ -379,11 +448,11 @@ function ftpUpload() {
|
|
|
379
448
|
const releaseJsonFilePath = import_path3.default.join(process3.cwd(), "release.json");
|
|
380
449
|
const packageVersion = getPackageVersion();
|
|
381
450
|
import_consola3.default.info("Package Version:", packageVersion);
|
|
382
|
-
let releaseJson =
|
|
451
|
+
let releaseJson = import_fs6.default.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
|
|
383
452
|
const releaseConfig = JSON.parse(releaseJson);
|
|
384
453
|
const sshConfigFile = import_path3.default.resolve(import_os.default.homedir(), ".ssh/config");
|
|
385
454
|
import_consola3.default.info("SSH Config File Path:", sshConfigFile);
|
|
386
|
-
const sshConfigs = import_ssh_config.default.parse(
|
|
455
|
+
const sshConfigs = import_ssh_config.default.parse(import_fs6.default.readFileSync(sshConfigFile).toString());
|
|
387
456
|
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
388
457
|
if (!sshConfig) {
|
|
389
458
|
import_consola3.default.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
@@ -393,10 +462,10 @@ function ftpUpload() {
|
|
|
393
462
|
import_inquirer3.default.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
394
463
|
let ftpClient = new import_ssh2_sftp_client.default();
|
|
395
464
|
const port = sshConfig["Port"];
|
|
396
|
-
const key =
|
|
397
|
-
const
|
|
465
|
+
const key = import_fs6.default.readFileSync(import_path3.default.resolve(import_os.default.homedir(), ".ssh/id_rsa"));
|
|
466
|
+
const spinner2 = (0, import_ora3.default)("Connecting");
|
|
398
467
|
try {
|
|
399
|
-
|
|
468
|
+
spinner2.start();
|
|
400
469
|
await ftpClient.connect({
|
|
401
470
|
host: sshConfig["HostName"],
|
|
402
471
|
port: port ? parseInt(port) : 22,
|
|
@@ -409,29 +478,29 @@ function ftpUpload() {
|
|
|
409
478
|
if (typeof item.src == "string") {
|
|
410
479
|
if (item.remoteCopy) {
|
|
411
480
|
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
412
|
-
|
|
481
|
+
spinner2.warn(`Create Dir: ${dir}`);
|
|
413
482
|
});
|
|
414
483
|
let destExists = await ftpClient.exists(item.dest);
|
|
415
484
|
if (destExists) {
|
|
416
|
-
|
|
485
|
+
spinner2.warn(`Delete exists file:${item.dest}`);
|
|
417
486
|
await ftpClient.delete(item.dest);
|
|
418
487
|
}
|
|
419
|
-
|
|
488
|
+
spinner2.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
420
489
|
await ftpClient.rcopy(item.src, item.dest);
|
|
421
490
|
} else {
|
|
422
491
|
const localFile = import_path3.default.resolve(process3.cwd(), item.src);
|
|
423
|
-
if (!item.remoteCopy && !
|
|
424
|
-
|
|
492
|
+
if (!item.remoteCopy && !import_fs6.default.existsSync(localFile)) {
|
|
493
|
+
spinner2.warn(`Skip not exists file:${localFile}`);
|
|
425
494
|
continue;
|
|
426
495
|
}
|
|
427
|
-
if (
|
|
428
|
-
|
|
496
|
+
if (import_fs6.default.lstatSync(localFile).isDirectory()) {
|
|
497
|
+
spinner2.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
429
498
|
await ftpClient.uploadDir(localFile, item.dest);
|
|
430
499
|
} else {
|
|
431
500
|
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
432
|
-
|
|
501
|
+
spinner2.warn(`Create Dir: ${dir}`);
|
|
433
502
|
});
|
|
434
|
-
|
|
503
|
+
spinner2.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
435
504
|
await ftpClient.put(localFile, item.dest);
|
|
436
505
|
}
|
|
437
506
|
}
|
|
@@ -439,26 +508,26 @@ function ftpUpload() {
|
|
|
439
508
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
440
509
|
}
|
|
441
510
|
}
|
|
442
|
-
|
|
511
|
+
spinner2.succeed("Files uploaded!");
|
|
443
512
|
await ftpClient.end();
|
|
444
513
|
} catch (e) {
|
|
445
|
-
|
|
514
|
+
spinner2.fail(`Connection error:${e}`);
|
|
446
515
|
await ftpClient.end();
|
|
447
516
|
}
|
|
448
517
|
});
|
|
449
518
|
}
|
|
450
|
-
var import_path3,
|
|
519
|
+
var import_path3, import_fs6, import_ssh_config, import_os, import_ssh2_sftp_client, import_consola3, import_inquirer3, import_ora3, process3;
|
|
451
520
|
var init_ftp = __esm({
|
|
452
521
|
"src/release/ftp.ts"() {
|
|
453
522
|
"use strict";
|
|
454
523
|
import_path3 = __toESM(require("path"), 1);
|
|
455
|
-
|
|
524
|
+
import_fs6 = __toESM(require("fs"), 1);
|
|
456
525
|
import_ssh_config = __toESM(require("@widget-js/ssh-config"), 1);
|
|
457
526
|
import_os = __toESM(require("os"), 1);
|
|
458
527
|
import_ssh2_sftp_client = __toESM(require("ssh2-sftp-client"), 1);
|
|
459
528
|
import_consola3 = __toESM(require("consola"), 1);
|
|
460
529
|
import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
461
|
-
|
|
530
|
+
import_ora3 = __toESM(require("ora"), 1);
|
|
462
531
|
process3 = __toESM(require("process"), 1);
|
|
463
532
|
init_utils();
|
|
464
533
|
}
|
|
@@ -469,11 +538,11 @@ var release_exports = {};
|
|
|
469
538
|
__export(release_exports, {
|
|
470
539
|
default: () => release_default
|
|
471
540
|
});
|
|
472
|
-
var
|
|
541
|
+
var import_fs7, import_path4, import_chalk3, release, release_default;
|
|
473
542
|
var init_release = __esm({
|
|
474
543
|
"src/release/release.ts"() {
|
|
475
544
|
"use strict";
|
|
476
|
-
|
|
545
|
+
import_fs7 = __toESM(require("fs"), 1);
|
|
477
546
|
import_path4 = __toESM(require("path"), 1);
|
|
478
547
|
init_promptChecker();
|
|
479
548
|
init_update_zip();
|
|
@@ -486,8 +555,8 @@ var init_release = __esm({
|
|
|
486
555
|
await ftpUpload();
|
|
487
556
|
return;
|
|
488
557
|
}
|
|
489
|
-
const packageJSON = JSON.parse(
|
|
490
|
-
const changelogJSON = JSON.parse(
|
|
558
|
+
const packageJSON = JSON.parse(import_fs7.default.readFileSync("package.json", "utf-8"));
|
|
559
|
+
const changelogJSON = JSON.parse(import_fs7.default.readFileSync("changelog.json", "utf-8"));
|
|
491
560
|
const version = packageJSON["version"];
|
|
492
561
|
const changelog = changelogJSON[version];
|
|
493
562
|
let needUpdateElectron = await promptChecker_default({
|
|
@@ -504,7 +573,7 @@ var init_release = __esm({
|
|
|
504
573
|
downloadLink: ""
|
|
505
574
|
};
|
|
506
575
|
let installerPath = import_path4.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
507
|
-
if (!
|
|
576
|
+
if (!import_fs7.default.existsSync(installerPath)) {
|
|
508
577
|
installerPath = import_path4.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
509
578
|
}
|
|
510
579
|
const updateZipPath = import_path4.default.join(`./packaged/update.zip`);
|
|
@@ -528,7 +597,7 @@ var init_release = __esm({
|
|
|
528
597
|
|
|
529
598
|
// src/index.ts
|
|
530
599
|
var import_commander = require("commander");
|
|
531
|
-
var
|
|
600
|
+
var import_fs8 = __toESM(require("fs"), 1);
|
|
532
601
|
var import_path5 = __toESM(require("path"), 1);
|
|
533
602
|
var process4 = __toESM(require("process"), 1);
|
|
534
603
|
var import_url2 = require("url");
|
|
@@ -538,13 +607,18 @@ var import_meta2 = {};
|
|
|
538
607
|
var __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
539
608
|
var __dirname = import_path5.default.dirname(__filename);
|
|
540
609
|
var packageJsonPath = import_path5.default.join(__dirname, "../package.json");
|
|
541
|
-
var cliPackage = JSON.parse(
|
|
610
|
+
var cliPackage = JSON.parse(import_fs8.default.readFileSync(packageJsonPath).toString());
|
|
542
611
|
console.log(import_gradient_string.default.pastel.multiline(import_figlet.default.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
543
612
|
import_commander.program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
544
613
|
import_commander.program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
545
614
|
const createWidget2 = await Promise.resolve().then(() => (init_createWidget(), createWidget_exports));
|
|
546
615
|
await createWidget2.default();
|
|
547
616
|
});
|
|
617
|
+
import_commander.program.command("upgrade").description("\u5347\u7EA7\u4F9D\u8D56").action(async () => {
|
|
618
|
+
const upgrade = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
619
|
+
const instance = new upgrade.Upgrade();
|
|
620
|
+
await instance.start();
|
|
621
|
+
});
|
|
548
622
|
import_commander.program.command("build").description("\u6267\u884C\u7F16\u8BD1\u4EFB\u52A1").action(async () => {
|
|
549
623
|
const build2 = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
550
624
|
await build2.build();
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -13,16 +13,21 @@ var cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
|
13
13
|
console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
14
14
|
program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
15
15
|
program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
16
|
-
const createWidget = await import("./createWidget-
|
|
16
|
+
const createWidget = await import("./createWidget-KWBUF3TN.js");
|
|
17
17
|
await createWidget.default();
|
|
18
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
|
+
});
|
|
19
24
|
program.command("build").description("\u6267\u884C\u7F16\u8BD1\u4EFB\u52A1").action(async () => {
|
|
20
25
|
const build = await import("./build-BTARJMCZ.js");
|
|
21
26
|
await build.build();
|
|
22
27
|
});
|
|
23
28
|
var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
24
29
|
program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
|
|
25
|
-
let release = await import("./release-
|
|
30
|
+
let release = await import("./release-PBOWWLKA.js");
|
|
26
31
|
await release.default(options);
|
|
27
32
|
});
|
|
28
33
|
program.parse(process.argv);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getPackageVersion,
|
|
3
2
|
promptChecker_default
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3GPAHQ6O.js";
|
|
4
|
+
import {
|
|
5
|
+
getPackageVersion
|
|
6
|
+
} from "./chunk-SIAOIY3B.js";
|
|
5
7
|
|
|
6
8
|
// src/release/release.ts
|
|
7
9
|
import fs4 from "fs";
|
|
@@ -29,13 +31,17 @@ var packageData = JSON.parse(fs2.readFileSync("./package.json").toString());
|
|
|
29
31
|
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
30
32
|
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
31
33
|
var headers = {
|
|
34
|
+
// 指定Object的存储类型。
|
|
32
35
|
"x-oss-storage-class": "Standard",
|
|
36
|
+
// 指定Object的访问权限。
|
|
33
37
|
"x-oss-object-acl": "public-read",
|
|
34
38
|
"x-oss-forbid-overwrite": "false",
|
|
35
39
|
"Cache-Control": "no-cache"
|
|
36
40
|
};
|
|
37
41
|
var clinet = new OSS({
|
|
42
|
+
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
38
43
|
region: "oss-cn-hangzhou",
|
|
44
|
+
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
39
45
|
accessKeyId: AccessKeyID,
|
|
40
46
|
accessKeySecret: AccessKeySecret,
|
|
41
47
|
bucket: "widget-fun"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPackageJson,
|
|
3
|
+
getPackagePath
|
|
4
|
+
} from "./chunk-SIAOIY3B.js";
|
|
5
|
+
|
|
6
|
+
// src/upgrade/upgrade.ts
|
|
7
|
+
import packageJson from "package-json";
|
|
8
|
+
import ora from "ora";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
var packages = {
|
|
11
|
+
"@widget-js/core": "",
|
|
12
|
+
"@widget-js/vue3": "",
|
|
13
|
+
"@widget-js/cli": "",
|
|
14
|
+
"@widget-js/vite-plugin-widget": ""
|
|
15
|
+
};
|
|
16
|
+
var spinner = ora("Connecting");
|
|
17
|
+
var Upgrade = class {
|
|
18
|
+
async start() {
|
|
19
|
+
spinner.start();
|
|
20
|
+
let json = getPackageJson();
|
|
21
|
+
let packageNames = Object.keys(packages);
|
|
22
|
+
let dependencies = json["dependencies"];
|
|
23
|
+
let devDependencies = json["devDependencies"];
|
|
24
|
+
await this.upgradePackage(dependencies, packageNames);
|
|
25
|
+
await this.upgradePackage(devDependencies, packageNames);
|
|
26
|
+
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
27
|
+
spinner.succeed("Upgraded!");
|
|
28
|
+
}
|
|
29
|
+
async upgradePackage(dependencies, packageNames) {
|
|
30
|
+
let localPackages = Object.keys(dependencies);
|
|
31
|
+
for (let localPackage of localPackages) {
|
|
32
|
+
if (packageNames.indexOf(localPackage) > -1) {
|
|
33
|
+
let packageVersion = packages[localPackage];
|
|
34
|
+
if (!packageVersion) {
|
|
35
|
+
packageVersion = await this.getRemoteVersion(localPackage);
|
|
36
|
+
packages[localPackage] = packageVersion;
|
|
37
|
+
}
|
|
38
|
+
dependencies[localPackage] = `^${packageVersion}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async getRemoteVersion(packageName) {
|
|
43
|
+
spinner.info(`Fetching package version:${packageName}`);
|
|
44
|
+
const metadata = await packageJson(packageName);
|
|
45
|
+
let version = metadata["version"];
|
|
46
|
+
spinner.info(`version:${version}`);
|
|
47
|
+
return version;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
Upgrade
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,13 +9,6 @@
|
|
|
9
9
|
"widget": "lib/index.js"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "rimraf ./lib/ && tsup src/index.ts --dts --format esm,cjs",
|
|
14
|
-
"watch": "tsup src/index.ts --dts --format esm,cjs --watch",
|
|
15
|
-
"build:run": "npm run build && npm run widget",
|
|
16
|
-
"prebuild": "",
|
|
17
|
-
"widget": "node ./lib/index.js"
|
|
18
|
-
},
|
|
19
12
|
"publishConfig": {
|
|
20
13
|
"access": "public"
|
|
21
14
|
},
|
|
@@ -26,7 +19,6 @@
|
|
|
26
19
|
"@types/archiver": "^5.3.1",
|
|
27
20
|
"@types/gradient-string": "^1.1.2",
|
|
28
21
|
"@vue/cli-shared-utils": "^5.0.8",
|
|
29
|
-
"@widget-js/core": "^0.1.14",
|
|
30
22
|
"@widget-js/ssh-config": "^4.2.1",
|
|
31
23
|
"ali-oss": "^6.17.1",
|
|
32
24
|
"archiver": "^5.3.1",
|
|
@@ -39,21 +31,20 @@
|
|
|
39
31
|
"gradient-string": "^2.0.2",
|
|
40
32
|
"inquirer": "^9.1.4",
|
|
41
33
|
"ora": "^6.2.0",
|
|
34
|
+
"package-json": "^8.1.0",
|
|
35
|
+
"semver": "^7.3.8",
|
|
42
36
|
"shelljs": "^0.8.5",
|
|
43
37
|
"ssh2-sftp-client": "^9.0.4",
|
|
44
38
|
"ws": "^8.11.0"
|
|
45
39
|
},
|
|
46
40
|
"devDependencies": {
|
|
47
|
-
"@babel/cli": "^7.19.3",
|
|
48
|
-
"@babel/core": "^7.20.2",
|
|
49
|
-
"@babel/node": "^7.20.2",
|
|
50
|
-
"@babel/preset-env": "^7.20.2",
|
|
51
41
|
"@types/ali-oss": "^6.16.7",
|
|
52
42
|
"@types/ejs": "latest",
|
|
53
43
|
"@types/figlet": "^1.5.5",
|
|
54
44
|
"@types/inquirer": "latest",
|
|
55
45
|
"@types/jest": "^29.2.3",
|
|
56
46
|
"@types/node": "^18.11.13",
|
|
47
|
+
"@types/semver": "^7.5.0",
|
|
57
48
|
"@types/shelljs": "latest",
|
|
58
49
|
"@types/ssh2-sftp-client": "^9.0.0",
|
|
59
50
|
"jest": "^29.5.0",
|
|
@@ -67,5 +58,12 @@
|
|
|
67
58
|
"typescript": "^4.9.4",
|
|
68
59
|
"webpack": "^5.75.0",
|
|
69
60
|
"webpack-cli": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "rimraf ./lib/ && tsup src/index.ts --dts --format esm,cjs",
|
|
64
|
+
"watch": "tsup src/index.ts --dts --format esm,cjs --watch",
|
|
65
|
+
"build:run": "npm run build && npm run widget",
|
|
66
|
+
"prebuild": "",
|
|
67
|
+
"widget": "node ./lib/index.js"
|
|
70
68
|
}
|
|
71
|
-
}
|
|
69
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
import {Option, program} from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import * as process from
|
|
1
|
+
import { Option, program } from "commander";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import * as process from "process";
|
|
5
5
|
|
|
6
|
-
import {fileURLToPath} from
|
|
7
|
-
import figlet from
|
|
8
|
-
import gradient from
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import figlet from "figlet";
|
|
8
|
+
import gradient from "gradient-string";
|
|
9
|
+
import consola from "consola";
|
|
9
10
|
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
-
const __dirname = path.dirname(__filename)
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
12
13
|
//
|
|
13
|
-
const packageJsonPath = path.join(__dirname,
|
|
14
|
-
let cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString())
|
|
14
|
+
const packageJsonPath = path.join(__dirname, "../package.json");
|
|
15
|
+
let cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
15
16
|
|
|
16
|
-
console.log(gradient.pastel.multiline(figlet.textSync(
|
|
17
|
-
program.version(`@widget-js/cli ${cliPackage.version}`).usage(
|
|
17
|
+
console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
18
|
+
program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
18
19
|
program
|
|
19
|
-
.command(
|
|
20
|
-
.description(
|
|
20
|
+
.command("create")
|
|
21
|
+
.description("创建新的组件")
|
|
21
22
|
.action(async () => {
|
|
22
|
-
const createWidget = await import(
|
|
23
|
-
await createWidget.default()
|
|
24
|
-
})
|
|
23
|
+
const createWidget = await import("./createWidget");
|
|
24
|
+
await createWidget.default();
|
|
25
|
+
});
|
|
25
26
|
|
|
26
27
|
program
|
|
27
|
-
.command(
|
|
28
|
-
.description(
|
|
28
|
+
.command("upgrade")
|
|
29
|
+
.description("升级依赖")
|
|
29
30
|
.action(async () => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const upgrade = await import("./upgrade/upgrade");
|
|
32
|
+
const instance = new upgrade.Upgrade();
|
|
33
|
+
await instance.start()
|
|
34
|
+
});
|
|
33
35
|
|
|
34
|
-
let typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
35
36
|
program
|
|
36
|
-
.command(
|
|
37
|
-
.description(
|
|
37
|
+
.command("build")
|
|
38
|
+
.description("执行编译任务")
|
|
39
|
+
.action(async () => {
|
|
40
|
+
const build = await import("./build/build");
|
|
41
|
+
await build.build();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
let typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
45
|
+
program
|
|
46
|
+
.command("release")
|
|
47
|
+
.description("通过FTP/OSS发布文件,仅内部使用")
|
|
38
48
|
.addOption(typeOption)
|
|
39
49
|
.action(async (options, command) => {
|
|
40
50
|
// @ts-ignore
|
|
41
|
-
let release = await import(
|
|
42
|
-
await release.default(options)
|
|
43
|
-
})
|
|
51
|
+
let release = await import("./release/release");
|
|
52
|
+
await release.default(options);
|
|
53
|
+
});
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
//TODO publish 发布
|
|
47
|
-
program.parse(process.argv)
|
|
55
|
+
program.parse(process.argv);
|
package/src/release/ftp.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import SSHConfig from
|
|
4
|
-
import os from
|
|
5
|
-
import Client from
|
|
6
|
-
import consola from
|
|
7
|
-
import inquirer from
|
|
8
|
-
import ora from
|
|
9
|
-
import * as process from
|
|
10
|
-
import
|
|
11
|
-
import {getPackageVersion} from "../utils";
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import SSHConfig from "@widget-js/ssh-config";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import Client from "ssh2-sftp-client";
|
|
6
|
+
import consola from "consola";
|
|
7
|
+
import inquirer from "inquirer";
|
|
8
|
+
import ora from "ora";
|
|
9
|
+
import * as process from "process";
|
|
10
|
+
import { getPackageVersion } from "../utils";
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
interface PasswordAnswer {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import packageJson from "package-json";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import { getPackageJson, getPackagePath } from "../utils";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
|
|
6
|
+
const packages: { [key: string]: string } = {
|
|
7
|
+
"@widget-js/core": "", "@widget-js/vue3": "", "@widget-js/cli": "", "@widget-js/vite-plugin-widget": ""
|
|
8
|
+
};
|
|
9
|
+
const spinner = ora("Connecting");
|
|
10
|
+
|
|
11
|
+
export class Upgrade {
|
|
12
|
+
|
|
13
|
+
async start() {
|
|
14
|
+
spinner.start();
|
|
15
|
+
let json = getPackageJson();
|
|
16
|
+
let packageNames = Object.keys(packages);
|
|
17
|
+
let dependencies = json["dependencies"];
|
|
18
|
+
let devDependencies = json["devDependencies"];
|
|
19
|
+
await this.upgradePackage(dependencies, packageNames);
|
|
20
|
+
await this.upgradePackage(devDependencies, packageNames);
|
|
21
|
+
fs.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
22
|
+
spinner.succeed("Upgraded!");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
private async upgradePackage(dependencies: { [key: string]: string }, packageNames: string[]) {
|
|
27
|
+
let localPackages = Object.keys(dependencies);
|
|
28
|
+
for (let localPackage of localPackages) {
|
|
29
|
+
if (packageNames.indexOf(localPackage) > -1) {
|
|
30
|
+
let packageVersion = packages[localPackage];
|
|
31
|
+
if (!packageVersion) {
|
|
32
|
+
packageVersion = await this.getRemoteVersion(localPackage);
|
|
33
|
+
packages[localPackage] = packageVersion;
|
|
34
|
+
}
|
|
35
|
+
dependencies[localPackage] = `^${packageVersion}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async getRemoteVersion(packageName: string): Promise<string> {
|
|
41
|
+
spinner.info(`Fetching package version:${packageName}`);
|
|
42
|
+
const metadata = await packageJson(packageName);
|
|
43
|
+
let version = metadata["version"];
|
|
44
|
+
spinner.info(`version:${version}`);
|
|
45
|
+
return version as string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -4,13 +4,20 @@ import fs from "fs";
|
|
|
4
4
|
|
|
5
5
|
export default function exit(code: number = 0) {
|
|
6
6
|
if (exports.exitProcess) {
|
|
7
|
-
process.exit(code)
|
|
7
|
+
process.exit(code);
|
|
8
8
|
} else if (code > 0) {
|
|
9
|
-
throw new Error(`Process exited with code ${code}`)
|
|
9
|
+
throw new Error(`Process exited with code ${code}`);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function getPackagePath() {
|
|
14
|
+
return path.join(process.cwd(), "package.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getPackageJson() {
|
|
18
|
+
return JSON.parse(fs.readFileSync(getPackagePath()).toString());
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
export function getPackageVersion() {
|
|
14
|
-
|
|
15
|
-
return JSON.parse(fs.readFileSync(packagePath).toString())['version']
|
|
22
|
+
return getPackageJson()["version"];
|
|
16
23
|
}
|
|
@@ -3,13 +3,6 @@
|
|
|
3
3
|
<widget-edit-dialog :widget-params="widgetParams" :option="widgetConfigOption"
|
|
4
4
|
:widget-data="widgetData"
|
|
5
5
|
@confirm="onSaveClick()">
|
|
6
|
-
<template v-slot:widget>
|
|
7
|
-
<!-- 组件配置内容 -->
|
|
8
|
-
<<%= paramCaseName %>-widget :style="{
|
|
9
|
-
width:`${widgetParams.widthPx}px`,
|
|
10
|
-
height:`${widgetParams.heightPx}px`
|
|
11
|
-
}" :background-color="widgetData.backgroundColor"></<%= paramCaseName %>-widget>
|
|
12
|
-
</template>
|
|
13
6
|
<template v-slot:form>
|
|
14
7
|
<!-- TODO 这里写自定义表单内容 -->
|
|
15
8
|
</template>
|
|
@@ -20,7 +13,7 @@
|
|
|
20
13
|
|
|
21
14
|
import <%= name %>Widget from "./<%= name%>Widget.vue";
|
|
22
15
|
import {useWidget, WidgetConfigOption, WidgetEditDialog} from "@widget-js/vue3";
|
|
23
|
-
import {WidgetData,
|
|
16
|
+
import {WidgetData, WidgetDataApi} from "@widget-js/core";
|
|
24
17
|
import {reactive} from "vue";
|
|
25
18
|
|
|
26
19
|
export default {
|
|
@@ -33,14 +26,15 @@ export default {
|
|
|
33
26
|
const widgetConfigOption = reactive(new WidgetConfigOption({
|
|
34
27
|
custom: true,
|
|
35
28
|
backgroundColor: true,
|
|
36
|
-
borderRadius: true
|
|
29
|
+
borderRadius: true,
|
|
30
|
+
preview: false
|
|
37
31
|
}));
|
|
38
32
|
|
|
39
33
|
return {widgetData, widgetParams, widgetConfigOption}
|
|
40
34
|
},
|
|
41
35
|
methods: {
|
|
42
36
|
async onSaveClick() {
|
|
43
|
-
await
|
|
37
|
+
await WidgetDataApi.save(this.widgetData);
|
|
44
38
|
window.close();
|
|
45
39
|
}
|
|
46
40
|
}
|
package/tsup.config.ts
CHANGED
package/babel.config.js
DELETED
package/lib/chunk-VOTZXZ5O.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// src/promts/promptChecker.ts
|
|
2
|
-
import inquirer from "inquirer";
|
|
3
|
-
var promptChecker = async (prompt, checker) => {
|
|
4
|
-
const answer = await inquirer.prompt([prompt]);
|
|
5
|
-
if (checker) {
|
|
6
|
-
if (checker(answer)) {
|
|
7
|
-
return answer[prompt.name];
|
|
8
|
-
} else {
|
|
9
|
-
return promptChecker(prompt, checker);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return answer[prompt.name];
|
|
13
|
-
};
|
|
14
|
-
var promptChecker_default = promptChecker;
|
|
15
|
-
|
|
16
|
-
// src/utils.ts
|
|
17
|
-
import path from "path";
|
|
18
|
-
import process from "process";
|
|
19
|
-
import fs from "fs";
|
|
20
|
-
function exit(code = 0) {
|
|
21
|
-
if (exports.exitProcess) {
|
|
22
|
-
process.exit(code);
|
|
23
|
-
} else if (code > 0) {
|
|
24
|
-
throw new Error(`Process exited with code ${code}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function getPackageVersion() {
|
|
28
|
-
const packagePath = path.join(process.cwd(), "package.json");
|
|
29
|
-
return JSON.parse(fs.readFileSync(packagePath).toString())["version"];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
promptChecker_default,
|
|
34
|
-
exit,
|
|
35
|
-
getPackageVersion
|
|
36
|
-
};
|