@pisell/common 1.0.1 → 1.0.2
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/CHANGELOG.md +7 -0
- package/es/bin/pisell.js +2 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +1 -0
- package/es/script/constants/index.js +13 -0
- package/es/script/deploy.js +47 -0
- package/es/script/index.js +40 -0
- package/es/script/package.json +4 -0
- package/es/script/release/index.js +161 -0
- package/es/script/release/release.js +163 -0
- package/es/script/uploadCode/index.js +278 -0
- package/es/script/uploadCode/uploadCode.js +401 -0
- package/es/script/utils/index.js +336 -0
- package/lib/bin/pisell.js +26 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +25 -0
- package/lib/script/constants/index.js +40 -0
- package/lib/{button/index.js → script/deploy.js} +28 -14
- package/lib/script/index.js +61 -0
- package/lib/script/package.json +4 -0
- package/lib/script/release/index.js +114 -0
- package/lib/script/release/release.js +87 -0
- package/lib/script/uploadCode/index.js +200 -0
- package/lib/script/uploadCode/uploadCode.js +206 -0
- package/lib/script/utils/index.js +252 -0
- package/package.json +10 -4
- package/src/bin/pisell.js +3 -0
- package/src/index.ts +1 -0
- package/src/script/constants/index.js +14 -0
- package/src/script/deploy.js +29 -0
- package/src/script/index.js +45 -0
- package/src/script/package.json +4 -0
- package/src/script/release/index.js +119 -0
- package/src/script/release/release.js +84 -0
- package/src/script/uploadCode/index.js +244 -0
- package/src/script/uploadCode/uploadCode.js +217 -0
- package/src/script/utils/index.js +275 -0
- package/es/button/index.d.ts +0 -18
- package/es/button/index.d.ts.map +0 -1
- package/es/button/index.js +0 -33
- package/lib/button/index.d.ts +0 -18
- package/lib/button/index.d.ts.map +0 -1
- package/src/button/index.md +0 -17
- package/src/button/index.tsx +0 -38
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env zx
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/script/release/index.js
|
|
31
|
+
var release_exports = {};
|
|
32
|
+
__export(release_exports, {
|
|
33
|
+
default: () => release_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(release_exports);
|
|
36
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
37
|
+
var import_utils = require("../utils/index.js");
|
|
38
|
+
var import_release = __toESM(require("./release.js"));
|
|
39
|
+
var selectProject = () => {
|
|
40
|
+
return import_inquirer.default.prompt([
|
|
41
|
+
// {
|
|
42
|
+
// type: "list",
|
|
43
|
+
// message: "请选择项目",
|
|
44
|
+
// name: "project",
|
|
45
|
+
// choices: [
|
|
46
|
+
// {
|
|
47
|
+
// value: {
|
|
48
|
+
// fileName: "my_pisel_shop",
|
|
49
|
+
// path:"./",
|
|
50
|
+
// },
|
|
51
|
+
// name: "my_pisel_shop"
|
|
52
|
+
// },
|
|
53
|
+
// ],
|
|
54
|
+
// },
|
|
55
|
+
{
|
|
56
|
+
type: "list",
|
|
57
|
+
message: "请选择发布环境",
|
|
58
|
+
name: "env",
|
|
59
|
+
choices: ["release", "pre", "prod"]
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
};
|
|
63
|
+
var inquirerResult = (versionList) => {
|
|
64
|
+
return import_inquirer.default.prompt([
|
|
65
|
+
{
|
|
66
|
+
type: "list",
|
|
67
|
+
message: "请选择发布版本号",
|
|
68
|
+
name: "version",
|
|
69
|
+
default: versionList,
|
|
70
|
+
choices: versionList
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "confirm",
|
|
74
|
+
message: "确认发布",
|
|
75
|
+
name: "is_release",
|
|
76
|
+
default: true
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
};
|
|
80
|
+
var ignoreName = ["master", ".git", "pre-master"];
|
|
81
|
+
var getVersionList = async ({ env, project }) => {
|
|
82
|
+
const config = await (0, import_utils.getServerConfig)(project.fileName);
|
|
83
|
+
let host = config[env].host;
|
|
84
|
+
if (env === "release") {
|
|
85
|
+
host = config.cn[env].host;
|
|
86
|
+
}
|
|
87
|
+
let projectName = project.fileName;
|
|
88
|
+
if (projectName === "my_pisel_shop" && env === "prod") {
|
|
89
|
+
projectName = "mypisel_shop";
|
|
90
|
+
}
|
|
91
|
+
const versionList = await fetch(
|
|
92
|
+
`http://${host}:3600/version?projectName=${projectName}`
|
|
93
|
+
).then((res) => res.json());
|
|
94
|
+
return (0, import_utils.versionSort)(versionList.filter((item) => !ignoreName.includes(item)));
|
|
95
|
+
};
|
|
96
|
+
async function init() {
|
|
97
|
+
let projectAndEnv = await selectProject();
|
|
98
|
+
projectAndEnv.project = {
|
|
99
|
+
path: "./",
|
|
100
|
+
fileName: (0, import_utils.getCurrentProjectName)()
|
|
101
|
+
};
|
|
102
|
+
const versionList = await getVersionList(projectAndEnv);
|
|
103
|
+
const res = await inquirerResult(versionList);
|
|
104
|
+
const releaseInstance = new import_release.default({ ...res, ...projectAndEnv });
|
|
105
|
+
try {
|
|
106
|
+
await releaseInstance.setConfig();
|
|
107
|
+
await releaseInstance.connectServer();
|
|
108
|
+
await releaseInstance.release();
|
|
109
|
+
await releaseInstance.disconnectServer();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log(error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
var release_default = init;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/script/release/release.js
|
|
20
|
+
var release_exports = {};
|
|
21
|
+
__export(release_exports, {
|
|
22
|
+
default: () => release_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(release_exports);
|
|
25
|
+
var import_constants = require("../constants/index.js");
|
|
26
|
+
var import_utils = require("../utils/index.js");
|
|
27
|
+
var Release = class {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
const { project, env, version, conn } = props;
|
|
30
|
+
this.projectName = project.fileName;
|
|
31
|
+
this.env = env;
|
|
32
|
+
this.version = version;
|
|
33
|
+
this.conn = conn;
|
|
34
|
+
this.outPath = import_constants.outPathMap[this.projectName][this.env];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @Title: 设置连接服务器配置
|
|
38
|
+
* @Describe:
|
|
39
|
+
* @Author: Zsj
|
|
40
|
+
*/
|
|
41
|
+
async setConfig() {
|
|
42
|
+
const serverConfigMap = await (0, import_utils.getServerConfig)(this.projectName);
|
|
43
|
+
let serverConfig = serverConfigMap[this.env];
|
|
44
|
+
if (this.env === "release") {
|
|
45
|
+
serverConfig = serverConfigMap.cn[this.env];
|
|
46
|
+
}
|
|
47
|
+
if (this.env === "prod") {
|
|
48
|
+
serverConfig.privateKey = fs.readFileSync(
|
|
49
|
+
path.join(process.env.HOME, ".ssh", "id_rsa")
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
this.serverConfig = serverConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @Title: 连接服务器
|
|
56
|
+
* @Describe:
|
|
57
|
+
* @Author: Zsj
|
|
58
|
+
*/
|
|
59
|
+
async connectServer() {
|
|
60
|
+
if (!this.serverConfig) {
|
|
61
|
+
console.log("未找到发布配置!");
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
this.conn = await (0, import_utils.connectServer)(this.serverConfig);
|
|
65
|
+
return this.conn;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @Title: 执行发布操作
|
|
69
|
+
* @Describe:
|
|
70
|
+
* @Author: Zsj
|
|
71
|
+
*/
|
|
72
|
+
async release() {
|
|
73
|
+
return await (0, import_utils.releaseProject)(this.conn, {
|
|
74
|
+
path: this.outPath,
|
|
75
|
+
fileName: `${this.version}`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @Title: 断开服务连接
|
|
80
|
+
* @Describe:
|
|
81
|
+
* @Author: Zsj
|
|
82
|
+
*/
|
|
83
|
+
async disconnectServer() {
|
|
84
|
+
return await this.conn.end();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var release_default = Release;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env zx
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/script/uploadCode/index.js
|
|
31
|
+
var uploadCode_exports = {};
|
|
32
|
+
__export(uploadCode_exports, {
|
|
33
|
+
default: () => uploadCode_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(uploadCode_exports);
|
|
36
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
37
|
+
var import_globals = require("zx/globals");
|
|
38
|
+
var import_release = __toESM(require("../release/release.js"));
|
|
39
|
+
var import_utils = require("../utils/index.js");
|
|
40
|
+
var import_uploadCode = __toESM(require("./uploadCode.js"));
|
|
41
|
+
var inquirerResult = () => {
|
|
42
|
+
return import_inquirer.default.prompt([
|
|
43
|
+
// {
|
|
44
|
+
// type: "list",
|
|
45
|
+
// message: "请选择项目",
|
|
46
|
+
// name: "project",
|
|
47
|
+
// choices: [
|
|
48
|
+
// {
|
|
49
|
+
// value: {
|
|
50
|
+
// path: "./",
|
|
51
|
+
// fileName: "my_pisel_shop"
|
|
52
|
+
// },
|
|
53
|
+
// name: "my_pisel_shop"
|
|
54
|
+
// },
|
|
55
|
+
// ],
|
|
56
|
+
// },
|
|
57
|
+
{
|
|
58
|
+
type: "list",
|
|
59
|
+
message: "请选择发布环境",
|
|
60
|
+
name: "env",
|
|
61
|
+
choices: ["release", "pre", "prod"]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "rawlist",
|
|
65
|
+
message: "请选择当前更新版本号",
|
|
66
|
+
name: "version",
|
|
67
|
+
default: false,
|
|
68
|
+
choices: ["patch", "minor", "major"]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "input",
|
|
72
|
+
message: "请输入更新内容",
|
|
73
|
+
name: "changelog",
|
|
74
|
+
default: "update"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: "list",
|
|
78
|
+
message: "上传之后是否执行发布",
|
|
79
|
+
name: "is_release",
|
|
80
|
+
choices: [
|
|
81
|
+
{ value: true, name: "上传并发布" },
|
|
82
|
+
{ value: false, name: "只上传" }
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "confirm",
|
|
87
|
+
message: "确认信息无误",
|
|
88
|
+
name: "is_confirm",
|
|
89
|
+
default: true
|
|
90
|
+
}
|
|
91
|
+
]);
|
|
92
|
+
};
|
|
93
|
+
async function init() {
|
|
94
|
+
let res = await inquirerResult();
|
|
95
|
+
if (!res.is_confirm) {
|
|
96
|
+
console.log("取消发布");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
res.project = {
|
|
100
|
+
path: "./",
|
|
101
|
+
fileName: (0, import_utils.getCurrentProjectName)()
|
|
102
|
+
};
|
|
103
|
+
await $`git fetch --prune-tags`;
|
|
104
|
+
const uploadCode = new import_uploadCode.default(res);
|
|
105
|
+
if (!await uploadCode.check()) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log("开始更新版本号");
|
|
109
|
+
const version = await uploadCode.updateVersion();
|
|
110
|
+
console.log("✅ 版本更新完成");
|
|
111
|
+
const currentUserName = await (0, import_utils.getCurrentUserName)();
|
|
112
|
+
const result = await (0, import_utils.sendWebhook)({
|
|
113
|
+
title: `${res.project.fileName} ${res.env}环境开始${res.is_release ? "上传并发布" : "上传"}`,
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
key: "发布人",
|
|
117
|
+
value: currentUserName.replace("\n", "")
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "更新内容",
|
|
121
|
+
value: res.changelog
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "版本号",
|
|
125
|
+
value: version || ""
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
console.log(result, "result");
|
|
130
|
+
try {
|
|
131
|
+
console.log("开始打包");
|
|
132
|
+
await uploadCode.build();
|
|
133
|
+
console.log("✅ 打包完成");
|
|
134
|
+
console.log("开始压缩");
|
|
135
|
+
await uploadCode.compress();
|
|
136
|
+
console.log("✅ 压缩完成");
|
|
137
|
+
console.log("开始连接服务器");
|
|
138
|
+
const conn = await uploadCode.connectServer();
|
|
139
|
+
console.log("✅ 连接服务器完成");
|
|
140
|
+
console.log("开始上传");
|
|
141
|
+
await uploadCode.serverUpload();
|
|
142
|
+
console.log("✅ 上传完成");
|
|
143
|
+
console.log("开始解压");
|
|
144
|
+
await uploadCode.serverUnpack();
|
|
145
|
+
if (res.is_release) {
|
|
146
|
+
const releaseInstance = new import_release.default({
|
|
147
|
+
project: res.project,
|
|
148
|
+
env: res.env,
|
|
149
|
+
version,
|
|
150
|
+
conn
|
|
151
|
+
});
|
|
152
|
+
console.log("开始发布");
|
|
153
|
+
await releaseInstance.release();
|
|
154
|
+
}
|
|
155
|
+
await uploadCode.disconnectServer();
|
|
156
|
+
await $`git pull --no-edit`;
|
|
157
|
+
await $`git push --follow-tags`;
|
|
158
|
+
console.log("✅ 成功后推送到git");
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.log(error, "执行出错 请排查重试");
|
|
161
|
+
await $`git reset HEAD~1`;
|
|
162
|
+
await $`git tag -d v${uploadCode.currentVersion}`;
|
|
163
|
+
await (0, import_utils.sendWebhook)({
|
|
164
|
+
title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}失败`,
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
key: "发布人",
|
|
168
|
+
value: currentUserName.replace("\n", "")
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: "更新内容",
|
|
172
|
+
value: res.changelog
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: "版本号",
|
|
176
|
+
value: version || ""
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
await (0, import_utils.sendWebhook)({
|
|
182
|
+
title: `${res.project.fileName} ${res.env}环境${res.is_release ? "上传并发布" : "上传"}成功`,
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
key: "发布人",
|
|
186
|
+
value: currentUserName.replace("\n", "")
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: "更新内容",
|
|
190
|
+
value: res.changelog
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: "版本号",
|
|
194
|
+
value: version || ""
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
uploadCode.deleteLocalZip();
|
|
199
|
+
}
|
|
200
|
+
var uploadCode_default = init;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/script/uploadCode/uploadCode.js
|
|
30
|
+
var uploadCode_exports = {};
|
|
31
|
+
__export(uploadCode_exports, {
|
|
32
|
+
default: () => uploadCode_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(uploadCode_exports);
|
|
35
|
+
var import_archiver = __toESM(require("archiver"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_constants = require("../constants/index.js");
|
|
38
|
+
var import_utils = require("../utils/index.js");
|
|
39
|
+
var UploadCode = class {
|
|
40
|
+
constructor(props) {
|
|
41
|
+
const { project, env, version, changelog, is_release } = props;
|
|
42
|
+
this.projectName = project.fileName;
|
|
43
|
+
this.projectRelativePath = project.path;
|
|
44
|
+
this.env = env;
|
|
45
|
+
this.version = version;
|
|
46
|
+
this.changelog = changelog;
|
|
47
|
+
this.is_release = is_release;
|
|
48
|
+
this.currentVersion = "";
|
|
49
|
+
this.projectAbsolutePath = "";
|
|
50
|
+
this.conn = null;
|
|
51
|
+
this.serverConfig = null;
|
|
52
|
+
this.outPath = import_constants.outPathMap[this.projectName][this.env];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @Title: 设置服务器连接配置
|
|
56
|
+
* @Describe:
|
|
57
|
+
* @Author: Zsj
|
|
58
|
+
*/
|
|
59
|
+
setConfig(serverConfig) {
|
|
60
|
+
this.serverConfig = serverConfig;
|
|
61
|
+
return this.serverConfig;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @Title: 发布前检查环境和参数是否正确
|
|
65
|
+
* @Describe:
|
|
66
|
+
* @Author: Zsj
|
|
67
|
+
*/
|
|
68
|
+
async check() {
|
|
69
|
+
const serverConfigMap = await (0, import_utils.getServerConfig)(this.projectName);
|
|
70
|
+
if (!serverConfigMap) {
|
|
71
|
+
console.log("未找到发布脚本!");
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
cd(this.projectRelativePath);
|
|
75
|
+
this.projectAbsolutePath = process.cwd();
|
|
76
|
+
if (!await (0, import_utils.isWorkingTreeClean)()) {
|
|
77
|
+
console.log("工作区不干净, 请先提交代码");
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
let serverConfig = this.setConfig(serverConfigMap[this.env]);
|
|
81
|
+
if (this.env === "prod") {
|
|
82
|
+
serverConfig.privateKey = fs.readFileSync(
|
|
83
|
+
import_path.default.join(process.env.HOME, ".ssh", "id_rsa")
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (this.env === "release") {
|
|
87
|
+
serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
|
|
88
|
+
}
|
|
89
|
+
if (!serverConfig) {
|
|
90
|
+
console.log("您当前没有权限!");
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
console.log("当前主项目分支", await (0, import_utils.getGitCurrentBranch)());
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @Title: 更新项目中version 并加入changelog
|
|
98
|
+
* @Describe:
|
|
99
|
+
* @Author: Zsj
|
|
100
|
+
*/
|
|
101
|
+
async updateVersion() {
|
|
102
|
+
if (this.env === "prod") {
|
|
103
|
+
await $`npm version ${this.version} -m "%s ${this.changelog}"`;
|
|
104
|
+
let { version } = await fs.readJson("./package.json");
|
|
105
|
+
this.currentVersion = version;
|
|
106
|
+
}
|
|
107
|
+
if (this.env !== "prod") {
|
|
108
|
+
await $`npm version ${this.version} --no-git-tag-version`;
|
|
109
|
+
await $`git add package.json`;
|
|
110
|
+
let { version } = await fs.readJson("./package.json");
|
|
111
|
+
this.currentVersion = version;
|
|
112
|
+
await $`git commit -m "chore: ${this.currentVersion} ${this.changelog}"`;
|
|
113
|
+
}
|
|
114
|
+
return this.currentVersion;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @Title: 根据env执行打包
|
|
118
|
+
* @Describe:
|
|
119
|
+
* @Author: Zsj
|
|
120
|
+
*/
|
|
121
|
+
async build() {
|
|
122
|
+
await $`npm run build:${this.env}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @Title: 压缩dist文件为zip
|
|
126
|
+
* @Describe:
|
|
127
|
+
* @Author: Zsj
|
|
128
|
+
*/
|
|
129
|
+
async compress() {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const __dirname = process.cwd();
|
|
132
|
+
const zipFile = import_path.default.resolve(__dirname, `${this.currentVersion}.zip`);
|
|
133
|
+
const originFilePath = import_path.default.resolve(__dirname, "dist");
|
|
134
|
+
const output = fs.createWriteStream(zipFile);
|
|
135
|
+
const archive = (0, import_archiver.default)("zip", {
|
|
136
|
+
zlib: { level: 9 }
|
|
137
|
+
// 设置压缩级别
|
|
138
|
+
});
|
|
139
|
+
archive.on("error", function(err) {
|
|
140
|
+
reject(err);
|
|
141
|
+
});
|
|
142
|
+
output.on("close", function() {
|
|
143
|
+
resolve(true);
|
|
144
|
+
});
|
|
145
|
+
archive.pipe(output);
|
|
146
|
+
archive.directory(originFilePath, "/dist");
|
|
147
|
+
archive.finalize();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @Title: 连接服务器
|
|
152
|
+
* @Describe:
|
|
153
|
+
* @Author: Zsj
|
|
154
|
+
*/
|
|
155
|
+
async connectServer() {
|
|
156
|
+
if (!this.serverConfig) {
|
|
157
|
+
console.log("未找到发布配置!");
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
this.conn = await (0, import_utils.connectServer)(this.serverConfig);
|
|
161
|
+
return this.conn;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @Title: 本地zip文件上传到服务器
|
|
165
|
+
* @Describe:
|
|
166
|
+
* @Author: Zsj
|
|
167
|
+
*/
|
|
168
|
+
async serverUpload() {
|
|
169
|
+
const localPath = import_path.default.resolve(
|
|
170
|
+
this.projectAbsolutePath,
|
|
171
|
+
`${this.currentVersion}.zip`
|
|
172
|
+
);
|
|
173
|
+
const remotePath = `${this.outPath}/${this.currentVersion}.zip`;
|
|
174
|
+
return await (0, import_utils.serverUpload)(this.conn, { localPath, remotePath });
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @Title: 服务器中解压文件
|
|
178
|
+
* @Describe:
|
|
179
|
+
* @Author: Zsj
|
|
180
|
+
*/
|
|
181
|
+
async serverUnpack() {
|
|
182
|
+
return await (0, import_utils.serverUnpack)(this.conn, {
|
|
183
|
+
path: this.outPath,
|
|
184
|
+
fileName: `${this.currentVersion}`,
|
|
185
|
+
fullFileName: `${this.currentVersion}.zip`,
|
|
186
|
+
changelog: this.changelog
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @Title: 删除本地zip文件
|
|
191
|
+
* @Describe:
|
|
192
|
+
* @Author: Zsj
|
|
193
|
+
*/
|
|
194
|
+
deleteLocalZip() {
|
|
195
|
+
return $`rm -rf ${this.currentVersion}.zip`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @Title: 断开服务连接
|
|
199
|
+
* @Describe:
|
|
200
|
+
* @Author: Zsj
|
|
201
|
+
*/
|
|
202
|
+
async disconnectServer() {
|
|
203
|
+
return await this.conn.end();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var uploadCode_default = UploadCode;
|