@widget-js/cli 1.2.11 → 24.1.1-beta.10

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.
Files changed (43) hide show
  1. package/.idea/codeStyles/Project.xml +60 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/misc.xml +5 -7
  4. package/jest.config.js +3 -3
  5. package/lib/{chunk-RAXJBANW.js → chunk-I4ZBPB2S.js} +6 -6
  6. package/lib/{chunk-IJH6LXRT.js → chunk-RDJH7Z4C.js} +5 -5
  7. package/lib/{chunk-3GPAHQ6O.js → chunk-XPJ33Y5L.js} +2 -2
  8. package/lib/{createWidget-UFW26NP6.js → createWidget-4LQ6PVEM.js} +16 -16
  9. package/lib/{dependencies-MRJDJJ6Q.js → dependencies-AVNHKRF3.js} +18 -18
  10. package/lib/index.js +13 -8
  11. package/lib/{init-MQONV3N3.js → init-HCEGKTNF.js} +15 -15
  12. package/lib/publish-C52GHJWG.js +50 -0
  13. package/lib/{release-XUYU5WNC.js → release-5GS34BAJ.js} +52 -48
  14. package/package.json +29 -18
  15. package/src/build/build.ts +8 -8
  16. package/src/createWidget.ts +232 -226
  17. package/src/dependencies/index.ts +6 -5
  18. package/src/dependencies/localDependencies.ts +17 -18
  19. package/src/dependencies/remoteDependencies.ts +22 -25
  20. package/src/index.ts +47 -38
  21. package/src/init/init.ts +121 -119
  22. package/src/promts/promptChecker.ts +10 -8
  23. package/src/publish/index.ts +60 -0
  24. package/src/release/ftp.ts +31 -27
  25. package/src/release/oss.ts +41 -38
  26. package/src/release/release.ts +17 -24
  27. package/src/release/update-zip.ts +18 -14
  28. package/src/utils/EJSUtils.ts +18 -17
  29. package/src/utils/PrettierUtils.ts +12 -11
  30. package/src/utils/WidgetPackageUtils.ts +13 -13
  31. package/src/utils.ts +31 -27
  32. package/template/WidgetConfig.ejs +7 -6
  33. package/template/WidgetDefine.ejs +6 -18
  34. package/template/widget-router.ts +4 -3
  35. package/test/index.test.ts +7 -7
  36. package/tsconfig.json +25 -25
  37. package/tsup.config.ts +4 -4
  38. package/vite.config.ts +15 -15
  39. package/.editorconfig +0 -16
  40. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  41. package/.idea/jpa-buddy.xml +0 -6
  42. package/.idea/prettier.xml +0 -6
  43. package/release-xyy.json +0 -7
@@ -1,22 +1,29 @@
1
1
  import {
2
2
  promptChecker_default
3
- } from "./chunk-3GPAHQ6O.js";
3
+ } from "./chunk-XPJ33Y5L.js";
4
4
  import {
5
5
  Utils
6
- } from "./chunk-IJH6LXRT.js";
6
+ } from "./chunk-RDJH7Z4C.js";
7
7
 
8
8
  // src/release/release.ts
9
- import fs4 from "fs";
10
- import path2 from "path";
9
+ import fs4 from "node:fs";
10
+ import path2 from "node:path";
11
+ import { Buffer as Buffer2 } from "node:buffer";
12
+ import chalk2 from "chalk";
13
+ import consola3 from "consola";
11
14
 
12
15
  // src/release/update-zip.ts
13
- import fs from "fs";
16
+ import fs from "node:fs";
14
17
  import archiver from "archiver";
15
18
  function zipDirectory(sourceDir, outPath, ignoreDir) {
16
19
  const archive = archiver("zip", { zlib: { level: 9 } });
17
20
  const stream = fs.createWriteStream(outPath);
18
21
  return new Promise((resolve, reject) => {
19
- archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
22
+ const ignore = ["node_modules/**"];
23
+ if (ignoreDir) {
24
+ ignore.push(...ignoreDir);
25
+ }
26
+ archive.glob("**/*", { cwd: sourceDir, ignore }).on("error", (err) => reject(err)).pipe(stream);
20
27
  stream.on("close", () => resolve());
21
28
  archive.finalize();
22
29
  });
@@ -24,9 +31,10 @@ function zipDirectory(sourceDir, outPath, ignoreDir) {
24
31
  var update_zip_default = zipDirectory;
25
32
 
26
33
  // src/release/oss.ts
34
+ import fs2 from "node:fs";
27
35
  import OSS from "ali-oss";
28
- import fs2 from "fs";
29
36
  import chalk from "chalk";
37
+ import consola from "consola";
30
38
  var packageData = JSON.parse(fs2.readFileSync("./package.json").toString());
31
39
  var AccessKeyID = packageData.oss?.id ?? "default";
32
40
  var AccessKeySecret = packageData.oss?.secret ?? "default";
@@ -48,37 +56,34 @@ var clinet = new OSS({
48
56
  });
49
57
  async function put(ossPath, file) {
50
58
  try {
51
- const result = await clinet.put(ossPath, file, { headers });
52
- console.log(chalk.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
59
+ await clinet.put(ossPath, file, { headers });
60
+ consola.log(chalk.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
53
61
  } catch (e) {
54
- console.log(e);
62
+ consola.log(e);
55
63
  }
56
64
  }
57
65
  async function copy(dist, src) {
58
66
  try {
59
- const result = await clinet.copy(dist, src, { headers });
60
- console.log(chalk.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
67
+ await clinet.copy(dist, src, { headers });
68
+ consola.log(chalk.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
61
69
  } catch (e) {
62
70
  console.error(e);
63
71
  }
64
72
  }
65
73
 
66
- // src/release/release.ts
67
- import chalk2 from "chalk";
68
-
69
74
  // src/release/ftp.ts
70
- import path from "path";
71
- import fs3 from "fs";
75
+ import path from "node:path";
76
+ import fs3 from "node:fs";
77
+ import os from "node:os";
78
+ import * as process from "node:process";
72
79
  import SSHConfig from "@widget-js/ssh-config";
73
- import os from "os";
74
80
  import Client from "ssh2-sftp-client";
75
- import consola from "consola";
81
+ import consola2 from "consola";
76
82
  import inquirer from "inquirer";
77
83
  import ora from "ora";
78
- import * as process from "process";
79
84
  import { minimatch } from "minimatch";
80
85
  async function checkParentDir(ftpClient, file, onMkdir) {
81
- let dir = path.dirname(file);
86
+ const dir = path.dirname(file);
82
87
  const dirExists = await ftpClient.exists(dir);
83
88
  if (!dirExists) {
84
89
  onMkdir(dir);
@@ -86,31 +91,31 @@ async function checkParentDir(ftpClient, file, onMkdir) {
86
91
  }
87
92
  }
88
93
  async function runSSH(sshConfig, releaseConfig) {
89
- consola.info("run ssh:", sshConfig);
94
+ consola2.info("run ssh:", sshConfig);
90
95
  const answer = await inquirer.prompt([
91
96
  { type: "password", name: "password", mask: "*", message: "Enter key pair password" }
92
97
  ]);
93
- let ftpClient = new Client();
94
- const port = sshConfig["Port"];
98
+ const ftpClient = new Client();
99
+ const port = sshConfig.Port;
95
100
  const key = fs3.readFileSync(path.resolve(os.homedir(), ".ssh/id_rsa"));
96
101
  const spinner = ora("Connecting");
97
102
  try {
98
103
  spinner.start();
99
104
  await ftpClient.connect({
100
- host: sshConfig["HostName"],
101
- port: port ? parseInt(port) : 22,
102
- username: sshConfig["User"],
105
+ host: sshConfig.HostName,
106
+ port: port ? Number.parseInt(port) : 22,
107
+ username: sshConfig.User,
103
108
  passphrase: answer.password,
104
109
  privateKey: key
105
110
  });
106
111
  releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0));
107
- for (let item of releaseConfig.fileMap) {
112
+ for (const item of releaseConfig.fileMap) {
108
113
  if (typeof item.src == "string") {
109
114
  if (item.remoteCopy) {
110
115
  await checkParentDir(ftpClient, item.dest, (dir) => {
111
116
  spinner.warn(`Create Dir: ${dir}`);
112
117
  });
113
- let destExists = await ftpClient.exists(item.dest);
118
+ const destExists = await ftpClient.exists(item.dest);
114
119
  if (destExists) {
115
120
  spinner.warn(`Delete exists file:${item.dest}`);
116
121
  await ftpClient.delete(item.dest);
@@ -128,7 +133,7 @@ async function runSSH(sshConfig, releaseConfig) {
128
133
  await ftpClient.uploadDir(localFile, item.dest, {
129
134
  filter: (filePath, isDirectory) => {
130
135
  if (item.ignorePattern && !isDirectory) {
131
- let fileName = path.basename(filePath);
136
+ const fileName = path.basename(filePath);
132
137
  if (minimatch(fileName, item.ignorePattern)) {
133
138
  spinner.warn(`Skip file:${filePath}`);
134
139
  return false;
@@ -159,16 +164,16 @@ async function runSSH(sshConfig, releaseConfig) {
159
164
  async function ftpUpload(releaseFile = "release.json") {
160
165
  const releaseJsonFilePath = path.join(process.cwd(), releaseFile);
161
166
  const packageVersion = Utils.getPackageVersion();
162
- consola.info("Package Version:", packageVersion);
163
- let releaseJson = fs3.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
167
+ consola2.info("Package Version:", packageVersion);
168
+ const releaseJson = fs3.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
164
169
  const releaseConfig = JSON.parse(releaseJson);
165
170
  const sshConfigFile = path.resolve(os.homedir(), ".ssh/config");
166
- consola.info("SSH Config File Path:", sshConfigFile);
171
+ consola2.info("SSH Config File Path:", sshConfigFile);
167
172
  const sshConfigs = SSHConfig.parse(fs3.readFileSync(sshConfigFile).toString());
168
- for (let host of releaseConfig.ftpConfig.host) {
169
- let sshConfig = sshConfigs.compute(host);
173
+ for (const host of releaseConfig.ftpConfig.host) {
174
+ const sshConfig = sshConfigs.compute(host);
170
175
  if (!sshConfig) {
171
- consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
176
+ consola2.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
172
177
  return;
173
178
  }
174
179
  await runSSH(sshConfig, releaseConfig);
@@ -176,16 +181,16 @@ async function ftpUpload(releaseFile = "release.json") {
176
181
  }
177
182
 
178
183
  // src/release/release.ts
179
- var release = async (options) => {
184
+ async function release(options) {
180
185
  if (options.type == "ftp") {
181
186
  await ftpUpload(options.file);
182
187
  return;
183
188
  }
184
189
  const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
185
190
  const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
186
- const version = packageJSON["version"];
191
+ const version = packageJSON.version;
187
192
  const changelog = changelogJSON[version];
188
- let needUpdateElectron = await promptChecker_default({
193
+ const needUpdateElectron = await promptChecker_default({
189
194
  type: "confirm",
190
195
  name: "electron",
191
196
  message: chalk2.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
@@ -206,20 +211,19 @@ var release = async (options) => {
206
211
  installerPath = path2.join(`./dist/app-${version}-setup-win-x64.exe`);
207
212
  }
208
213
  const updateZipPath = path2.join(`./dist/update.zip`);
209
- console.log(chalk2.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
214
+ consola3.log(chalk2.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
210
215
  await update_zip_default("./release", updateZipPath);
211
- console.log(chalk2.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
216
+ consola3.log(chalk2.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
212
217
  await put("version/installer.exe", installerPath);
213
- console.log(chalk2.blue("\u4E0A\u4F20update.zip\u5230OSS"));
218
+ consola3.log(chalk2.blue("\u4E0A\u4F20update.zip\u5230OSS"));
214
219
  await put("version/update.zip", updateZipPath);
215
- console.log(chalk2.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
220
+ consola3.log(chalk2.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
216
221
  versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
217
222
  const versionJSON = JSON.stringify(versionInfo, null, 2);
218
- await put("version/version.json", Buffer.from(versionJSON));
219
- copy(`version/history/${version}.exe`, "version/installer.exe");
220
- copy(`version/history/update-${version}.zip`, "version/update.zip");
221
- console.log(chalk2.yellow(versionJSON));
222
- };
223
+ await put("version/version.json", Buffer2.from(versionJSON));
224
+ await Promise.all([copy(`version/history/${version}.exe`, "version/installer.exe"), copy(`version/history/update-${version}.zip`, "version/update.zip")]);
225
+ consola3.log(chalk2.yellow(versionJSON));
226
+ }
223
227
  var release_default = release;
224
228
  export {
225
229
  release_default as default
package/package.json CHANGED
@@ -1,33 +1,37 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.2.11",
4
- "main": "lib/index.js",
3
+ "type": "module",
4
+ "version": "24.1.1-beta.10",
5
+ "private": false,
5
6
  "author": "Neo Fu",
6
7
  "license": "MIT",
7
- "private": false,
8
+ "main": "lib/index.js",
8
9
  "bin": {
9
10
  "widget": "lib/index.js"
10
11
  },
11
- "type": "module",
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
12
  "engines": {
16
13
  "node": "^12.0.0 || >= 14.0.0"
17
14
  },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
18
  "dependencies": {
19
19
  "@types/archiver": "^5.3.1",
20
- "@types/gradient-string": "^1.1.2",
21
20
  "@vue/cli-shared-utils": "^5.0.8",
21
+ "@widget-js/core": "^24.1.1-beta.9",
22
22
  "@widget-js/ssh-config": "^4.2.1",
23
+ "@widget-js/utils": "^24.1.1-beta.9",
24
+ "@widget-js/vue3": "^24.1.1-beta.10",
23
25
  "ali-oss": "^6.17.1",
24
26
  "archiver": "^5.3.1",
27
+ "axios": "^1.7.2",
25
28
  "chalk": "^4.1.2",
26
29
  "change-case": "^4.1.2",
27
30
  "commander": "^9.4.1",
28
31
  "consola": "^2.15.3",
29
32
  "dirname-filename-esm": "^1.1.1",
30
33
  "ejs": "^3.1.8",
34
+ "fast-glob": "^3.3.2",
31
35
  "figlet": "^1.5.2",
32
36
  "gradient-string": "^2.0.2",
33
37
  "inquirer": "^8.0.0",
@@ -35,24 +39,28 @@
35
39
  "ora": "^6.2.0",
36
40
  "package-json": "^8.1.0",
37
41
  "prettier": "^3.1.1",
38
- "semver": "^7.3.8",
42
+ "semver": "^7.5.2",
39
43
  "shelljs": "^0.8.5",
40
44
  "ssh2-sftp-client": "^9.1.0",
41
- "ws": "^8.11.0",
42
- "@widget-js/core": "^0.11.20",
43
- "@widget-js/vue3": "^0.11.20",
44
- "@widget-js/utils": "0.10.21"
45
+ "ws": "^8.11.0"
45
46
  },
46
47
  "devDependencies": {
48
+ "@antfu/eslint-config": "^2.21.1",
47
49
  "@types/ali-oss": "^6.16.7",
48
50
  "@types/ejs": "latest",
49
51
  "@types/figlet": "^1.5.5",
52
+ "@types/gradient-string": "^1.1.2",
50
53
  "@types/inquirer": "latest",
51
54
  "@types/jest": "^29.2.3",
55
+ "@types/minimist": "^1.2.5",
52
56
  "@types/node": "^18.11.13",
53
57
  "@types/semver": "^7.5.0",
54
58
  "@types/shelljs": "latest",
55
59
  "@types/ssh2-sftp-client": "^9.0.1",
60
+ "@widget-js/core": "^24.1.1-beta.9",
61
+ "@widget-js/vite-plugin-widget": "^24.1.1-beta.9",
62
+ "@widget-js/vue3": "^24.1.1-beta.10",
63
+ "eslint": "8.48.0",
56
64
  "jest": "^29.5.0",
57
65
  "pinst": "^3.0.0",
58
66
  "rimraf": "^4.4.1",
@@ -64,10 +72,7 @@
64
72
  "vitest": "^0.34.6",
65
73
  "vue-router": "^4.2.5",
66
74
  "webpack": "^5.75.0",
67
- "webpack-cli": "^5.0.0",
68
- "@widget-js/vite-plugin-widget": "^1.2.8",
69
- "@widget-js/core": "0.11.21",
70
- "@widget-js/vue3": "^0.11.20"
75
+ "webpack-cli": "^5.0.0"
71
76
  },
72
77
  "scripts": {
73
78
  "build": "rimraf ./lib/ && tsup-node src/index.ts --format esm",
@@ -76,8 +81,14 @@
76
81
  "widget": "node ./lib/index.js",
77
82
  "widget:ftp": "node ./lib/index.js release -t ftp",
78
83
  "widget:init": "node ./lib/index.js init",
84
+ "widget:publish": "node ./lib/index.js publish -key 123",
79
85
  "widget:create": "npm run build && node ./lib/index.js create",
80
86
  "widget:local": "npm run build && node ./lib/index.js dependencies -t local",
81
- "pnpm:publish": "npm run build && pnpm publish --no-git-checks"
87
+ "build:publish": "npm run build && npm run pnpm:publish",
88
+ "pnpm:publish": "pnpm publish --no-git-checks",
89
+ "remote": "widget dependencies -t remote && pnpm install",
90
+ "local": "widget dependencies -t local && pnpm install",
91
+ "lint": "eslint .",
92
+ "lint:fix": "eslint . --fix"
82
93
  }
83
94
  }
@@ -1,27 +1,27 @@
1
+ import { exec } from 'node:child_process'
1
2
  import ora from 'ora'
2
- import {exec} from 'child_process'
3
3
  import consola from 'consola'
4
4
 
5
5
  export function build() {
6
6
  const preloadSpinner = ora('Preload').start()
7
7
  const mainSpinner = ora('Main').start()
8
- //@ts-ignore
8
+ // @ts-expect-error
9
9
  const build = exec('npm run build:preload').on('close', () => {
10
10
  consola.success('done')
11
11
  })
12
- //@ts-ignore
13
- build.stdout.on('data', data => {
12
+ // @ts-expect-error
13
+ build.stdout.on('data', (data) => {
14
14
  consola.log('data', data)
15
15
  })
16
16
 
17
- //@ts-ignore
17
+ // @ts-expect-error
18
18
  exec('npm run build:main', (error, stdout, stderr) => {
19
19
  if (error) {
20
- consola.error('error: ' + error)
20
+ consola.error(`error: ${error}`)
21
21
  return
22
22
  }
23
- consola.log('stdout: ' + stdout)
24
- consola.log('stderr: ' + typeof stderr)
23
+ consola.log(`stdout: ${stdout}`)
24
+ consola.log(`stderr: ${typeof stderr}`)
25
25
  })
26
26
  .on('message', () => {
27
27
  consola.log('on-message')