@pisell/common 0.0.9 → 0.0.11
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/es/bin/pisell.js +2 -0
- package/es/components/datePicker/index.d.ts +0 -1
- package/es/components/inputNumber/index.d.ts +0 -1
- package/es/components/select/index.d.ts +0 -1
- package/es/script/constants/index.js +8 -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 +225 -0
- package/es/script/uploadCode/uploadCode.js +401 -0
- package/es/script/utils/index.js +241 -0
- package/lib/bin/pisell.js +4 -0
- package/lib/components/datePicker/index.d.ts +0 -1
- package/lib/components/inputNumber/index.d.ts +0 -1
- package/lib/components/select/index.d.ts +0 -1
- package/lib/script/constants/index.js +35 -0
- package/lib/script/deploy.js +61 -0
- package/lib/script/index.js +57 -0
- package/lib/script/package.json +4 -0
- package/lib/script/release/index.js +116 -0
- package/lib/script/release/release.js +89 -0
- package/lib/script/uploadCode/index.js +149 -0
- package/lib/script/uploadCode/uploadCode.js +208 -0
- package/lib/script/utils/index.js +208 -0
- package/package.json +9 -2
|
@@ -0,0 +1,149 @@
|
|
|
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: false, name: "只上传" },
|
|
82
|
+
{ value: true, 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 --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
|
+
try {
|
|
112
|
+
console.log("开始打包");
|
|
113
|
+
await uploadCode.build();
|
|
114
|
+
console.log("✅ 打包完成");
|
|
115
|
+
console.log("开始压缩");
|
|
116
|
+
await uploadCode.compress();
|
|
117
|
+
console.log("✅ 压缩完成");
|
|
118
|
+
console.log("开始连接服务器");
|
|
119
|
+
const conn = await uploadCode.connectServer();
|
|
120
|
+
console.log("✅ 连接服务器完成");
|
|
121
|
+
console.log("开始上传");
|
|
122
|
+
await uploadCode.serverUpload();
|
|
123
|
+
console.log("✅ 上传完成");
|
|
124
|
+
console.log("开始解压");
|
|
125
|
+
await uploadCode.serverUnpack();
|
|
126
|
+
if (res.is_release) {
|
|
127
|
+
const releaseInstance = new import_release.default({
|
|
128
|
+
project: res.project,
|
|
129
|
+
env: res.env,
|
|
130
|
+
version,
|
|
131
|
+
conn
|
|
132
|
+
});
|
|
133
|
+
console.log("开始发布");
|
|
134
|
+
await releaseInstance.release();
|
|
135
|
+
}
|
|
136
|
+
await uploadCode.disconnectServer();
|
|
137
|
+
await $`git pull --no-edit`;
|
|
138
|
+
await $`git push --follow-tags`;
|
|
139
|
+
console.log("✅ 成功后推送到git");
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.log(error, "执行出错 请排查重试");
|
|
142
|
+
await $`git reset HEAD~1`;
|
|
143
|
+
await $`git tag -d v${uploadCode.currentVersion}`;
|
|
144
|
+
}
|
|
145
|
+
uploadCode.deleteLocalZip();
|
|
146
|
+
}
|
|
147
|
+
var uploadCode_default = init;
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,208 @@
|
|
|
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)();
|
|
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;
|
|
207
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
208
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,208 @@
|
|
|
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/utils/index.js
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
connectServer: () => connectServer,
|
|
33
|
+
getCurrentProjectName: () => getCurrentProjectName,
|
|
34
|
+
getGitCurrentBranch: () => getGitCurrentBranch,
|
|
35
|
+
getServerConfig: () => getServerConfig,
|
|
36
|
+
isWorkingTreeClean: () => isWorkingTreeClean,
|
|
37
|
+
releaseProject: () => releaseProject,
|
|
38
|
+
serverUnpack: () => serverUnpack,
|
|
39
|
+
serverUpload: () => serverUpload,
|
|
40
|
+
versionSort: () => versionSort
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(utils_exports);
|
|
43
|
+
var import_ssh2 = __toESM(require("ssh2"));
|
|
44
|
+
var isWorkingTreeClean = async () => {
|
|
45
|
+
const v = await $`git status --porcelain`;
|
|
46
|
+
return v.stdout === "";
|
|
47
|
+
};
|
|
48
|
+
var getGitCurrentBranch = async () => {
|
|
49
|
+
const v = await $`git symbolic-ref --short HEAD`;
|
|
50
|
+
return v.stdout;
|
|
51
|
+
};
|
|
52
|
+
var getServerConfig = async () => {
|
|
53
|
+
return await fs.readJson("../lm_config.json");
|
|
54
|
+
};
|
|
55
|
+
var connectServer = (config) => {
|
|
56
|
+
const conn = new import_ssh2.default.Client();
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
conn.on("ready", () => {
|
|
59
|
+
resolve(conn);
|
|
60
|
+
}).on("error", (err) => {
|
|
61
|
+
console.log(err, "connect error");
|
|
62
|
+
reject();
|
|
63
|
+
}).connect(config);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
var serverUpload = (conn, { localPath, remotePath }) => {
|
|
67
|
+
if (!conn)
|
|
68
|
+
return Promise.reject("未连接服务器");
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
conn.sftp((err, sftp) => {
|
|
71
|
+
if (err) {
|
|
72
|
+
console.log(err);
|
|
73
|
+
reject(err);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
sftp.fastPut(
|
|
77
|
+
localPath,
|
|
78
|
+
remotePath,
|
|
79
|
+
{
|
|
80
|
+
step: (total, nb, fsize) => {
|
|
81
|
+
console.table([
|
|
82
|
+
{
|
|
83
|
+
标题: "当前已上传",
|
|
84
|
+
值: `${(total / fsize * 100).toFixed(2)}%`
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
标题: "每次上传",
|
|
88
|
+
值: `${(nb / 1024 / 1024).toFixed(2)}M`
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
标题: "总大小",
|
|
92
|
+
值: `${(fsize / 1024 / 1024).toFixed(2)}M`
|
|
93
|
+
}
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
(err2) => {
|
|
98
|
+
if (err2) {
|
|
99
|
+
console.log(err2);
|
|
100
|
+
reject(err2);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
console.log("上传成功");
|
|
104
|
+
resolve(conn);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
var serverUnpack = (conn, { path, fileName, fullFileName, changelog }) => {
|
|
111
|
+
if (!conn)
|
|
112
|
+
return Promise.reject("未连接服务器");
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
conn.shell((err, stream) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
console.log(err);
|
|
117
|
+
reject(err);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
stream.end(
|
|
121
|
+
`
|
|
122
|
+
cd ${path}
|
|
123
|
+
unzip ${fullFileName} -d ${fileName} && mv ${fileName}/dist/* ${fileName}/ && rmdir ${fileName}/dist
|
|
124
|
+
rm -rf ${fullFileName}
|
|
125
|
+
echo "${changelog}" > ./${fileName}/changelog.md
|
|
126
|
+
sh deleteOldVersion.sh
|
|
127
|
+
exit
|
|
128
|
+
`
|
|
129
|
+
// 打开到path
|
|
130
|
+
// 解压 1.0.0.zip 文件到 1.0.0 移动dist中内容到 1.0.0内 删除dist
|
|
131
|
+
// 删除1.0.0.zip
|
|
132
|
+
// 写入changelog到changelog.md
|
|
133
|
+
// 执行deleteOldVersion脚本 删除过早版本
|
|
134
|
+
).on("data", (data) => {
|
|
135
|
+
console.log(data.toString());
|
|
136
|
+
}).on("close", () => {
|
|
137
|
+
console.log("✅上传完成");
|
|
138
|
+
resolve();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
var releaseProject = (conn, { path, fileName }) => {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
conn.shell((err, stream) => {
|
|
146
|
+
if (err) {
|
|
147
|
+
console.log(err);
|
|
148
|
+
reject(err);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
stream.end(
|
|
152
|
+
`
|
|
153
|
+
cd ${path}
|
|
154
|
+
cp -R -f pre-master next-master
|
|
155
|
+
rm -rf pre-master
|
|
156
|
+
\\cp -R -f ${fileName}/* next-master
|
|
157
|
+
cp -R -f ${fileName} pre-master
|
|
158
|
+
rm -rf master
|
|
159
|
+
cp -R next-master master
|
|
160
|
+
rm -rf next-master
|
|
161
|
+
exit
|
|
162
|
+
`
|
|
163
|
+
// 打开到path
|
|
164
|
+
// 复制pre-master到next-master
|
|
165
|
+
// 删除pre-master
|
|
166
|
+
// 复制1.0.0到next-master
|
|
167
|
+
// 复制1.0.0到pre-master
|
|
168
|
+
// 删除master
|
|
169
|
+
// 复制next-master到master
|
|
170
|
+
// 删除next-master
|
|
171
|
+
).on("data", (data) => {
|
|
172
|
+
console.log(data.toString());
|
|
173
|
+
}).on("close", () => {
|
|
174
|
+
console.log("✅发布完成");
|
|
175
|
+
resolve();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
var versionSort = (versionList) => {
|
|
181
|
+
return versionList.sort((a, b) => {
|
|
182
|
+
const aParts = a.split(".");
|
|
183
|
+
const bParts = b.split(".");
|
|
184
|
+
for (let i = 0; i < aParts.length && i < bParts.length; i++) {
|
|
185
|
+
const aNum = parseInt(aParts[i]);
|
|
186
|
+
const bNum = parseInt(bParts[i]);
|
|
187
|
+
if (aNum !== bNum) {
|
|
188
|
+
return bNum - aNum;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return bParts.length - aParts.length;
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
var getCurrentProjectName = () => {
|
|
195
|
+
return require(`${process.env.PWD}/package.json`).name;
|
|
196
|
+
};
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
connectServer,
|
|
200
|
+
getCurrentProjectName,
|
|
201
|
+
getGitCurrentBranch,
|
|
202
|
+
getServerConfig,
|
|
203
|
+
isWorkingTreeClean,
|
|
204
|
+
releaseProject,
|
|
205
|
+
serverUnpack,
|
|
206
|
+
serverUpload,
|
|
207
|
+
versionSort
|
|
208
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "A collection of reusable UI components for web development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": [
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"module": "./es/index.js",
|
|
11
11
|
"types": "./lib/index.d.ts",
|
|
12
12
|
"typings": "./lib/index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"pisell": "lib/bin/pisell.js"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
17
|
"es",
|
|
15
18
|
"lib",
|
|
@@ -56,9 +59,13 @@
|
|
|
56
59
|
},
|
|
57
60
|
"dependencies": {
|
|
58
61
|
"antd5": "npm:antd@^5.5.0",
|
|
62
|
+
"archiver": "^5.3.1",
|
|
59
63
|
"array-move": "^3.0.1",
|
|
64
|
+
"inquirer": "^9.2.6",
|
|
60
65
|
"react-beautiful-dnd": "^13.1.0",
|
|
61
|
-
"react-color": "^2.19.3"
|
|
66
|
+
"react-color": "^2.19.3",
|
|
67
|
+
"ssh2": "^1.13.0",
|
|
68
|
+
"zx": "^7.2.2"
|
|
62
69
|
},
|
|
63
70
|
"devDependencies": {
|
|
64
71
|
"@ant-design/icons": "^4.8.0",
|