@peng_kai/kit 0.1.16 → 0.1.17

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,67 @@
1
+ import fs from 'node:fs';
2
+ import process from 'node:process';
3
+ import path from 'node:path';
4
+ import { execa } from 'execa';
5
+ import archiver from 'archiver';
6
+
7
+ const DIST_DIR = 'dist';
8
+ const DEV_BRANCH = 'develop';
9
+
10
+ const distPath = path.join(process.cwd(), DIST_DIR);
11
+ const distZipName = `${DIST_DIR}.zip`;
12
+ const distZipPath = `${distPath}.zip`;
13
+
14
+ const { stdout } = await execa(`git branch --show-current`);
15
+ const currentBranch = stdout;
16
+
17
+ if (currentBranch !== DEV_BRANCH) {
18
+ await build();
19
+ await execa(`git stash push -u -m "部署"`);
20
+ await execa(`git checkout ${DEV_BRANCH}`);
21
+ console.log('⏬ 拉取代码成功!');
22
+ await execa(`git pull`);
23
+ }
24
+ else {
25
+ console.log('⏬ 拉取代码成功!');
26
+ await execa(`git pull`);
27
+ await build();
28
+ }
29
+
30
+ if (fs.existsSync(distZipPath)) {
31
+ fs.unlinkSync(distZipPath);
32
+ console.log('🗑️ 删除旧 dist.zip');
33
+ }
34
+
35
+ await zipDirectory(path.join(process.cwd(), DIST_DIR));
36
+ console.log('✨ 生成新 dist.zip');
37
+
38
+ await execa(`git add ${distZipName}`);
39
+ await execa(`git commit -m "部署"`);
40
+ await execa(`git push`);
41
+ console.log('✅ 推送代码成功!\n');
42
+
43
+ if (currentBranch !== DEV_BRANCH) {
44
+ await execa(`git checkout ${currentBranch}`);
45
+ await execa(`git stash pop`);
46
+ }
47
+
48
+ async function build() {
49
+ process.stdout.write('📦 打包中...');
50
+ await execa(`pnpm run build@script`);
51
+ process.stdout.write('\r📦 打包成功!\n');
52
+ }
53
+
54
+ function zipDirectory(dir: string) {
55
+ const archive = archiver('zip', { zlib: { level: 5 } });
56
+ const stream = fs.createWriteStream(`${dir}.zip`);
57
+
58
+ return new Promise((resolve, reject) => {
59
+ archive
60
+ .directory(dir, DIST_DIR)
61
+ .on('error', err => reject(err))
62
+ .pipe(stream);
63
+
64
+ stream.on('close', () => resolve(1));
65
+ archive.finalize();
66
+ });
67
+ }
package/package.json CHANGED
@@ -1,53 +1,58 @@
1
- {
2
- "name": "@peng_kai/kit",
3
- "type": "module",
4
- "version": "0.1.16",
5
- "description": "",
6
- "author": "",
7
- "license": "ISC",
8
- "keywords": [],
9
- "main": "index.js",
10
- "scripts": {
11
- "lint": "eslint .",
12
- "lint:fix": "eslint . --fix"
13
- },
14
- "peerDependencies": {
15
- "@tanstack/vue-query": "4.37.1",
16
- "@vueuse/core": "10.7.2",
17
- "ant-design-vue": "4.1.1",
18
- "axios": "1.6.5",
19
- "bignumber.js": "9.1.2",
20
- "dayjs": "1.11.10",
21
- "lodash-es": "4.17.21",
22
- "vue": "3.4.15",
23
- "vue-router": "4.2.5"
24
- },
25
- "dependencies": {
26
- "@babel/generator": "^7.23.6",
27
- "@babel/parser": "^7.23.6",
28
- "@babel/traverse": "^7.23.7",
29
- "@babel/types": "^7.23.6",
30
- "@tanstack/vue-query": "^4.37.1",
31
- "@vueuse/core": "^10.7.2",
32
- "a-calc": "^1.3.8",
33
- "ant-design-vue": "^4.1.1",
34
- "axios": "^1.6.5",
35
- "bignumber.js": "^9.1.2",
36
- "chokidar": "^3.5.3",
37
- "dayjs": "^1.11.10",
38
- "fast-glob": "^3.3.2",
39
- "lodash-es": "^4.17.21",
40
- "nprogress": "^0.2.0",
41
- "vue": "^3.4.15",
42
- "vue-router": "^4.2.5"
43
- },
44
- "devDependencies": {
45
- "@peng_kai/lint": "^0.1.0",
46
- "@types/lodash-es": "^4.17.12",
47
- "@types/node": "18",
48
- "@types/nprogress": "^0.2.3",
49
- "type-fest": "^4.9.0",
50
- "typescript": "^5.3.3",
51
- "vue-component-type-helpers": "^1.8.27"
52
- }
53
- }
1
+ {
2
+ "name": "@peng_kai/kit",
3
+ "type": "module",
4
+ "version": "0.1.17",
5
+ "description": "",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "keywords": [],
9
+ "main": "index.js",
10
+ "scripts": {
11
+ "dev:js": "tsx ./admin/scripts/deploy.ts",
12
+ "lint": "eslint .",
13
+ "lint:fix": "eslint . --fix"
14
+ },
15
+ "peerDependencies": {
16
+ "@tanstack/vue-query": "4.37.1",
17
+ "@vueuse/core": "10.7.2",
18
+ "ant-design-vue": "4.1.1",
19
+ "axios": "1.6.5",
20
+ "bignumber.js": "9.1.2",
21
+ "dayjs": "1.11.10",
22
+ "lodash-es": "4.17.21",
23
+ "vue": "3.4.15",
24
+ "vue-router": "4.2.5"
25
+ },
26
+ "dependencies": {
27
+ "@babel/generator": "^7.23.6",
28
+ "@babel/parser": "^7.23.6",
29
+ "@babel/traverse": "^7.23.7",
30
+ "@babel/types": "^7.23.6",
31
+ "@tanstack/vue-query": "^4.37.1",
32
+ "@vueuse/core": "^10.7.2",
33
+ "a-calc": "^1.3.8",
34
+ "ant-design-vue": "^4.1.1",
35
+ "archiver": "^6.0.1",
36
+ "axios": "^1.6.5",
37
+ "bignumber.js": "^9.1.2",
38
+ "chokidar": "^3.5.3",
39
+ "dayjs": "^1.11.10",
40
+ "execa": "^8.0.1",
41
+ "fast-glob": "^3.3.2",
42
+ "lodash-es": "^4.17.21",
43
+ "nprogress": "^0.2.0",
44
+ "tsx": "^4.7.0",
45
+ "vue": "^3.4.15",
46
+ "vue-router": "^4.2.5"
47
+ },
48
+ "devDependencies": {
49
+ "@peng_kai/lint": "^0.1.0",
50
+ "@types/archiver": "^6.0.2",
51
+ "@types/lodash-es": "^4.17.12",
52
+ "@types/node": "18",
53
+ "@types/nprogress": "^0.2.3",
54
+ "type-fest": "^4.9.0",
55
+ "typescript": "^5.3.3",
56
+ "vue-component-type-helpers": "^1.8.27"
57
+ }
58
+ }
@@ -9,13 +9,13 @@ export function checkCode(): Parameters<AxiosInterceptorManager<any>['use']> {
9
9
  return [
10
10
  (resp) => {
11
11
  if (
12
- resp.config.checkCode
12
+ resp?.config?.checkCode
13
13
  && !resp.config.ignoreCode?.includes(resp?.data?.code)
14
14
  && resp?.data?.code !== ApiCode.NORMAL
15
15
  ) {
16
16
  throw new axios.AxiosError(
17
- resp?.data?.msg ?? 'Unknown Error',
18
- resp?.data?.code ?? ApiCode.UNKNOWN,
17
+ resp.data?.msg ?? 'Unknown Error',
18
+ resp.data?.code ?? ApiCode.UNKNOWN,
19
19
  resp.config,
20
20
  resp.request,
21
21
  resp,
@@ -7,7 +7,7 @@ import { ApiCode, ApiError, isTimeout } from '../helpers';
7
7
  export function returnResultType(): Parameters<AxiosInterceptorManager<any>['use']> {
8
8
  return [
9
9
  (resp) => {
10
- const { resultType } = resp.config;
10
+ const { resultType } = resp?.config;
11
11
 
12
12
  if (resultType === 'api')
13
13
  return resp.data;
@@ -30,4 +30,4 @@ export function returnResultType(): Parameters<AxiosInterceptorManager<any>['use
30
30
  throw new ApiError({ code, msg, data });
31
31
  },
32
32
  ];
33
- }
33
+ }