@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.
@@ -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.15",
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
@@ -1,5 +1,10 @@
1
1
  {
2
2
  "fileMap": [
3
+ {
4
+ "src": "./dist/youlu-${version}-setup-win-ia32.exe",
5
+ "dest": "/www/wwwroot/download.tool-vip.com/youlu/youlu.exe",
6
+ "order": 0
7
+ },
3
8
  {
4
9
  "src": ".gitignore",
5
10
  "dest": "/www/wwwroot/template/aa/.gitignore"
@@ -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 'commander'
2
- import fs from 'fs'
3
- import path from 'path'
4
- import * as process from 'process'
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 'url'
9
- import figlet from 'figlet'
10
- import gradient from 'gradient-string'
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, '../package.json')
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('widget-cli', {horizontalLayout: 'full'})))
19
- program.version(`@widget-js/cli ${cliPackage.version}`).usage('<command> [options]')
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('create')
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('release')
30
- .description('通过FTP/OSS发布文件,仅内部使用')
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
- console.log(options)
35
- await release(options)
36
- })
51
+ let release = await import("./release/release");
52
+ await release.default(options);
53
+ });
37
54
 
38
- //TODO init 初始化项目
39
- //TODO publish 发布
40
- program.parse(process.argv)
55
+ program.parse(process.argv);
@@ -1,13 +1,14 @@
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 * as console from 'console'
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 file = path.join(process.cwd(), 'release.json')
28
- const releaseConfig = JSON.parse(fs.readFileSync(file).toString()) as ReleaseConfig
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
- console.log('SSH Config file:', sshConfigFile)
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
- export default function exit(code:number = 0) {
2
- if (exports.exitProcess) {
3
- process.exit(code)
4
- } else if (code > 0) {
5
- throw new Error(`Process exited with code ${code}`)
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
@@ -1,5 +1,6 @@
1
1
  import { defineConfig } from 'tsup';
2
2
 
3
3
  export default defineConfig({
4
- outDir: 'lib'
4
+ outDir: 'lib',
5
+ format: 'none'
5
6
  });
package/babel.config.js DELETED
@@ -1,20 +0,0 @@
1
- module.exports = {
2
- env: {
3
- test: {
4
- presets: [
5
- '@babel/preset-env'
6
- ]
7
- },
8
- build: {
9
- presets: [
10
- [
11
- '@babel/preset-env',
12
- {
13
- modules: false,
14
- loose: true
15
- }
16
- ]
17
- ]
18
- }
19
- }
20
- }