@widget-js/cli 1.0.15 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/lib/build-BTARJMCZ.js +31 -0
- package/lib/chunk-3GPAHQ6O.js +18 -0
- package/lib/chunk-SIAOIY3B.js +27 -0
- package/lib/createWidget-KWBUF3TN.js +193 -0
- package/lib/index.cjs +347 -166
- package/lib/index.d.ts +1 -0
- package/lib/index.js +20 -415
- package/lib/release-PBOWWLKA.js +206 -0
- package/lib/upgrade-ETO2LGMX.js +52 -0
- package/package.json +13 -13
- package/release.json +5 -0
- package/src/build/build.ts +35 -0
- package/src/index.ts +43 -28
- package/src/release/ftp.ts +18 -13
- package/src/upgrade/upgrade.ts +48 -0
- package/src/utils.ts +22 -6
- package/tsup.config.ts +2 -1
- package/babel.config.js +0 -20
|
@@ -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.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,12 +9,6 @@
|
|
|
9
9
|
"widget": "lib/index.js"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "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
|
-
"widget": "node ./lib/index.js"
|
|
17
|
-
},
|
|
18
12
|
"publishConfig": {
|
|
19
13
|
"access": "public"
|
|
20
14
|
},
|
|
@@ -25,7 +19,6 @@
|
|
|
25
19
|
"@types/archiver": "^5.3.1",
|
|
26
20
|
"@types/gradient-string": "^1.1.2",
|
|
27
21
|
"@vue/cli-shared-utils": "^5.0.8",
|
|
28
|
-
"@widget-js/core": "^0.1.14",
|
|
29
22
|
"@widget-js/ssh-config": "^4.2.1",
|
|
30
23
|
"ali-oss": "^6.17.1",
|
|
31
24
|
"archiver": "^5.3.1",
|
|
@@ -38,26 +31,26 @@
|
|
|
38
31
|
"gradient-string": "^2.0.2",
|
|
39
32
|
"inquirer": "^9.1.4",
|
|
40
33
|
"ora": "^6.2.0",
|
|
34
|
+
"package-json": "^8.1.0",
|
|
35
|
+
"semver": "^7.3.8",
|
|
41
36
|
"shelljs": "^0.8.5",
|
|
42
37
|
"ssh2-sftp-client": "^9.0.4",
|
|
43
38
|
"ws": "^8.11.0"
|
|
44
39
|
},
|
|
45
40
|
"devDependencies": {
|
|
46
|
-
"@babel/cli": "^7.19.3",
|
|
47
|
-
"@babel/core": "^7.20.2",
|
|
48
|
-
"@babel/node": "^7.20.2",
|
|
49
|
-
"@babel/preset-env": "^7.20.2",
|
|
50
41
|
"@types/ali-oss": "^6.16.7",
|
|
51
42
|
"@types/ejs": "latest",
|
|
52
43
|
"@types/figlet": "^1.5.5",
|
|
53
44
|
"@types/inquirer": "latest",
|
|
54
45
|
"@types/jest": "^29.2.3",
|
|
55
46
|
"@types/node": "^18.11.13",
|
|
47
|
+
"@types/semver": "^7.5.0",
|
|
56
48
|
"@types/shelljs": "latest",
|
|
57
49
|
"@types/ssh2-sftp-client": "^9.0.0",
|
|
58
50
|
"jest": "^29.5.0",
|
|
59
51
|
"pinst": "^3.0.0",
|
|
60
52
|
"prettier": "^2.8.4",
|
|
53
|
+
"rimraf": "^4.4.1",
|
|
61
54
|
"ts-jest": "^29.0.3",
|
|
62
55
|
"ts-loader": "^9.4.1",
|
|
63
56
|
"ts-node": "^10.9.1",
|
|
@@ -65,5 +58,12 @@
|
|
|
65
58
|
"typescript": "^4.9.4",
|
|
66
59
|
"webpack": "^5.75.0",
|
|
67
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"
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|
package/release.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ora from 'ora'
|
|
2
|
+
import {exec} from 'child_process'
|
|
3
|
+
import consola from 'consola'
|
|
4
|
+
|
|
5
|
+
export function build() {
|
|
6
|
+
const preloadSpinner = ora('Preload').start()
|
|
7
|
+
const mainSpinner = ora('Main').start()
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
const build = exec('npm run build:preload').on('close', () => {
|
|
10
|
+
consola.success('done')
|
|
11
|
+
})
|
|
12
|
+
//@ts-ignore
|
|
13
|
+
build.stdout.on('data', data => {
|
|
14
|
+
consola.log('data', data)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
exec('npm run build:main', (error, stdout, stderr) => {
|
|
19
|
+
if (error) {
|
|
20
|
+
consola.error('error: ' + error)
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
consola.log('stdout: ' + stdout)
|
|
24
|
+
consola.log('stderr: ' + typeof stderr)
|
|
25
|
+
})
|
|
26
|
+
.on('message', () => {
|
|
27
|
+
consola.log('on-message')
|
|
28
|
+
})
|
|
29
|
+
.on('data', () => {
|
|
30
|
+
consola.log('on-data')
|
|
31
|
+
})
|
|
32
|
+
.on('close', () => {
|
|
33
|
+
consola.log('done')
|
|
34
|
+
})
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,40 +1,55 @@
|
|
|
1
|
-
import {Option, program} from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import * as process from
|
|
5
|
-
import createWidget from './createWidget'
|
|
6
|
-
import release from './release/release'
|
|
1
|
+
import { Option, program } from "commander";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import * as process from "process";
|
|
7
5
|
|
|
8
|
-
import {fileURLToPath} from
|
|
9
|
-
import figlet from
|
|
10
|
-
import gradient from
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import figlet from "figlet";
|
|
8
|
+
import gradient from "gradient-string";
|
|
9
|
+
import consola from "consola";
|
|
11
10
|
|
|
12
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
13
|
-
const __dirname = path.dirname(__filename)
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
14
13
|
//
|
|
15
|
-
const packageJsonPath = path.join(__dirname,
|
|
16
|
-
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());
|
|
17
16
|
|
|
18
|
-
console.log(gradient.pastel.multiline(figlet.textSync(
|
|
19
|
-
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]");
|
|
20
19
|
program
|
|
21
|
-
.command(
|
|
22
|
-
.description(
|
|
20
|
+
.command("create")
|
|
21
|
+
.description("创建新的组件")
|
|
23
22
|
.action(async () => {
|
|
24
|
-
await createWidget
|
|
25
|
-
|
|
23
|
+
const createWidget = await import("./createWidget");
|
|
24
|
+
await createWidget.default();
|
|
25
|
+
});
|
|
26
26
|
|
|
27
|
-
let typeOption = new Option('-t, --type <type>').choices(['ftp', 'oss'])
|
|
28
27
|
program
|
|
29
|
-
.command(
|
|
30
|
-
.description(
|
|
28
|
+
.command("upgrade")
|
|
29
|
+
.description("升级依赖")
|
|
30
|
+
.action(async () => {
|
|
31
|
+
const upgrade = await import("./upgrade/upgrade");
|
|
32
|
+
const instance = new upgrade.Upgrade();
|
|
33
|
+
await instance.start()
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
program
|
|
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发布文件,仅内部使用")
|
|
31
48
|
.addOption(typeOption)
|
|
32
49
|
.action(async (options, command) => {
|
|
33
50
|
// @ts-ignore
|
|
34
|
-
|
|
35
|
-
await release(options)
|
|
36
|
-
})
|
|
51
|
+
let release = await import("./release/release");
|
|
52
|
+
await release.default(options);
|
|
53
|
+
});
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
//TODO publish 发布
|
|
40
|
-
program.parse(process.argv)
|
|
55
|
+
program.parse(process.argv);
|
package/src/release/ftp.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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
|
|
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";
|
|
11
|
+
|
|
11
12
|
|
|
12
13
|
interface PasswordAnswer {
|
|
13
14
|
password: string
|
|
@@ -24,10 +25,14 @@ async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: st
|
|
|
24
25
|
|
|
25
26
|
export function ftpUpload() {
|
|
26
27
|
// 读取
|
|
27
|
-
const
|
|
28
|
-
const
|
|
28
|
+
const releaseJsonFilePath = path.join(process.cwd(), 'release.json')
|
|
29
|
+
const packageVersion = getPackageVersion()
|
|
30
|
+
consola.info('Package Version:', packageVersion)
|
|
31
|
+
|
|
32
|
+
let releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion);
|
|
33
|
+
const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
|
|
29
34
|
const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
|
|
30
|
-
|
|
35
|
+
consola.info('SSH Config File Path:', sshConfigFile)
|
|
31
36
|
const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
|
|
32
37
|
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host)
|
|
33
38
|
if (!sshConfig) {
|
|
@@ -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
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import process from "process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
export default function exit(code: number = 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
|
+
|
|
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
|
+
|
|
21
|
+
export function getPackageVersion() {
|
|
22
|
+
return getPackageJson()["version"];
|
|
7
23
|
}
|
package/tsup.config.ts
CHANGED