@widget-js/cli 1.0.5 → 1.0.6

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/bin/widget.js CHANGED
@@ -2,6 +2,7 @@ import {program} from 'commander';
2
2
 
3
3
  import packageJson from '../package.json' assert {type: 'json'};
4
4
  import createWidget from "../lib/createWidget.js";
5
+ import release from "../lib/release/release.js";
5
6
 
6
7
  program
7
8
  .version(`@widget-js/cli ${packageJson.version}`)
@@ -12,7 +13,16 @@ program
12
13
  .action(async () => {
13
14
  await createWidget()
14
15
  })
16
+ program
17
+ .command('release')
18
+ .description('发布应用,仅内部使用')
19
+ .action(async () => {
20
+ await release()
21
+ })
15
22
 
23
+ //TODO init 初始化项目
24
+ //TODO publish 发布
25
+ //TODO delete 删除
16
26
  program.parse(process.argv);
17
27
 
18
28
 
@@ -0,0 +1,47 @@
1
+ import OSS from "ali-oss";
2
+ import {chalk} from "@vue/cli-shared-utils";
3
+ import fs from "fs";
4
+
5
+ let packageData = JSON.parse(fs.readFileSync("./package.json").toString());
6
+ export const AccessKeyID = packageData.oss.id;
7
+ export const AccessKeySecret = packageData.oss.secret;
8
+
9
+ const headers = {
10
+ // 指定Object的存储类型。
11
+ 'x-oss-storage-class': 'Standard',
12
+ // 指定Object的访问权限。
13
+ 'x-oss-object-acl': 'public-read',
14
+ 'x-oss-forbid-overwrite': 'false',
15
+ 'Cache-Control': 'no-cache'
16
+ };
17
+
18
+ const clinet = new OSS({
19
+ // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
20
+ region: 'oss-cn-hangzhou',
21
+ // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
22
+ accessKeyId: AccessKeyID,
23
+ accessKeySecret: AccessKeySecret,
24
+ bucket: 'widget-fun',
25
+ });
26
+
27
+ export async function put(ossPath, file) {
28
+ try {
29
+ // 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
30
+ // 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
31
+ const result = await clinet.put(ossPath, file, {headers});
32
+ console.log(chalk.green(`上传成功:${file}->${ossPath}`));
33
+ } catch (e) {
34
+ console.log(e);
35
+ }
36
+ }
37
+
38
+ export async function copy(dist, src) {
39
+ try {
40
+ // 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
41
+ // 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
42
+ const result = await clinet.copy(dist, src, {headers});
43
+ console.log(chalk.green(`复制成功:${src}->${dist}`));
44
+ } catch (e) {
45
+ console.error(e);
46
+ }
47
+ }
@@ -0,0 +1,73 @@
1
+ import {chalk} from "@vue/cli-shared-utils";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import promptChecker from "../promts/promptChecker.js";
5
+ import zipDirectory from "./update-zip.js";
6
+ import {copy, put} from "./oss.js";
7
+
8
+ const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
9
+ const changelogJSON = JSON.parse(fs.readFileSync('changelog.json', 'utf-8'))
10
+ const version = packageJSON["version"]
11
+ const changelog = changelogJSON[version]
12
+
13
+ async function delay(time) {
14
+ return new Promise((resolve, reject) => {
15
+ setTimeout(() => {
16
+ resolve();
17
+ }, time);
18
+ });
19
+ }
20
+
21
+ const release = async () => {
22
+ let needUpdateElectron = await promptChecker({
23
+ type: "confirm",
24
+ name: 'electron',
25
+ message: chalk.blue("用户是否需要更新Electron?")
26
+ });
27
+
28
+ let needUpdateNodeModule = await promptChecker({
29
+ type: "confirm",
30
+ name: 'electron',
31
+ message: chalk.blue("用户是否需要更新node_module?")
32
+ });
33
+
34
+ const versionInfo = {
35
+ version: version,
36
+ releaseNote: changelog,
37
+ updateElectron: needUpdateElectron,
38
+ updateNodeModule: needUpdateNodeModule,
39
+ updateWindowsApi: false,
40
+ downloadLink: ''
41
+ };
42
+
43
+ let installerPath = path.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
44
+ if (!fs.existsSync(installerPath)) {
45
+ installerPath = path.join(`./packaged/electron-${version}-setup-win-x64.exe`);
46
+ }
47
+ const updateZipPath = path.join(`./packaged/update.zip`)
48
+
49
+ console.log(chalk.blue("压缩更新文件中"))
50
+ if (needUpdateNodeModule) {
51
+ await zipDirectory("packaged/win-unpacked/resources/app", updateZipPath);
52
+ } else {
53
+ await zipDirectory("release", updateZipPath);
54
+ }
55
+
56
+ console.log(chalk.blue("上传installer.exe到OSS"))
57
+ await put("version/installer.exe", installerPath)
58
+
59
+ console.log(chalk.blue("上传update.zip到OSS"))
60
+ await put("version/update.zip", updateZipPath)
61
+
62
+ console.log(chalk.blue("更新版本信息"))
63
+ versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip"
64
+ const versionJSON = JSON.stringify(versionInfo, null, 2)
65
+ await put("version/version.json", Buffer.from(versionJSON))
66
+
67
+ copy(`version/history/${version}.exe`, "version/installer.exe")
68
+ copy(`version/history/update-${version}.zip`, "version/update.zip")
69
+
70
+ console.log(chalk.yellow(versionJSON))
71
+ }
72
+
73
+ export default release;
@@ -0,0 +1,20 @@
1
+ import fs from "fs";
2
+ import archiver from "archiver";
3
+
4
+
5
+ function zipDirectory(sourceDir, outPath) {
6
+ const archive = archiver('zip', { zlib: { level: 9 }});
7
+ const stream = fs.createWriteStream(outPath);
8
+
9
+ return new Promise((resolve, reject) => {
10
+ archive
11
+ .directory(sourceDir, false)
12
+ .on('error', err => reject(err))
13
+ .pipe(stream)
14
+ ;
15
+
16
+ stream.on('close', () => resolve());
17
+ archive.finalize();
18
+ });
19
+ }
20
+ export default zipDirectory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "bin/widget.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
@@ -18,6 +18,8 @@
18
18
  "dependencies": {
19
19
  "@vue/cli-shared-utils": "^5.0.8",
20
20
  "@widget-js/core": "^0.1.14",
21
+ "ali-oss": "^6.17.1",
22
+ "archiver": "^5.3.1",
21
23
  "chalk": "^5.2.0",
22
24
  "change-case": "^4.1.2",
23
25
  "commander": "^9.4.1",
@@ -28,21 +30,21 @@
28
30
  "ws": "^8.11.0"
29
31
  },
30
32
  "devDependencies": {
31
- "@types/inquirer": "latest",
32
- "@types/ejs": "latest",
33
- "@types/shelljs": "latest",
34
- "@types/node": "^18.11.13",
35
33
  "@babel/cli": "^7.19.3",
36
34
  "@babel/core": "^7.20.2",
37
35
  "@babel/node": "^7.20.2",
38
36
  "@babel/preset-env": "^7.20.2",
39
- "webpack": "^5.75.0",
40
- "webpack-cli": "^5.0.0",
37
+ "@types/ejs": "latest",
38
+ "@types/inquirer": "latest",
39
+ "@types/jest": "^29.2.3",
40
+ "@types/node": "^18.11.13",
41
+ "@types/shelljs": "latest",
42
+ "pinst": "^3.0.0",
41
43
  "ts-jest": "^29.0.3",
42
44
  "ts-loader": "^9.4.1",
43
45
  "typescript": "^4.9.3",
44
- "pinst": "^3.0.0",
45
- "@types/jest": "^29.2.3"
46
+ "webpack": "^5.75.0",
47
+ "webpack-cli": "^5.0.0"
46
48
  },
47
49
  "scripts": {
48
50
  "widget": "node ./bin/widget.js",