@pisell/common 1.0.56 → 1.0.58
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 +6 -431
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/asyncToGenerator.js +28 -0
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/defineProperty.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/objectSpread2.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPrimitive.js +16 -0
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPropertyKey.js +11 -0
- package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/typeof.js +12 -0
- package/es/bin/pisell.js +5 -1
- package/es/index.d.ts +3 -1
- package/es/index.js +5 -1
- package/es/script/aws/index.js +127 -210
- package/es/script/constants/index.js +84 -63
- package/es/script/deploy.js +33 -44
- package/es/script/index.js +43 -37
- package/es/script/release/index.js +83 -150
- package/es/script/release/release.js +82 -167
- package/es/script/uploadCode/index.js +238 -308
- package/es/script/uploadCode/uploadCode.js +219 -432
- package/es/script/utils/index.js +255 -369
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/asyncToGenerator.js +29 -0
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/defineProperty.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/objectSpread2.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPrimitive.js +16 -0
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPropertyKey.js +11 -0
- package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/typeof.js +18 -0
- package/lib/_virtual/rolldown_runtime.js +29 -0
- package/lib/bin/pisell.js +4 -24
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -23
- package/lib/script/aws/index.js +139 -124
- package/lib/script/constants/index.js +85 -98
- package/lib/script/deploy.js +34 -55
- package/lib/script/index.js +41 -56
- package/lib/script/release/index.js +90 -108
- package/lib/script/release/release.js +82 -85
- package/lib/script/uploadCode/index.js +244 -223
- package/lib/script/uploadCode/uploadCode.js +222 -219
- package/lib/script/utils/index.js +270 -264
- package/package.json +3 -2
- package/src/bin/pisell.js +1 -1
- package/src/script/constants/index.js +12 -0
- package/src/script/uploadCode/index.js +10 -3
- package/src/script/uploadCode/uploadCode.js +10 -4
- package/src/script/utils/index.js +16 -11
- package/tsdown.config.ts +93 -0
package/es/script/utils/index.js
CHANGED
|
@@ -1,395 +1,281 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
10
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
-
import * as dotenv from 'dotenv';
|
|
13
|
-
import npmCheck from 'npm-check';
|
|
14
|
-
import path from 'path';
|
|
15
|
-
import fs from 'fs';
|
|
16
|
-
import ssh2 from 'ssh2';
|
|
1
|
+
import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.108.0/helpers/asyncToGenerator.js";
|
|
2
|
+
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.108.0/helpers/objectSpread2.js";
|
|
3
|
+
import * as dotenv from "dotenv";
|
|
4
|
+
import npmCheck from "npm-check";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import ssh2 from "ssh2";
|
|
17
8
|
|
|
9
|
+
//#region src/script/utils/index.js
|
|
18
10
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return $(_templateObject || (_templateObject = _taggedTemplateLiteral(["git status --porcelain"])));
|
|
32
|
-
case 2:
|
|
33
|
-
v = _context.sent;
|
|
34
|
-
return _context.abrupt("return", v.stdout === '');
|
|
35
|
-
case 4:
|
|
36
|
-
case "end":
|
|
37
|
-
return _context.stop();
|
|
38
|
-
}
|
|
39
|
-
}, _callee);
|
|
40
|
-
}));
|
|
41
|
-
return function isWorkingTreeClean() {
|
|
42
|
-
return _ref.apply(this, arguments);
|
|
43
|
-
};
|
|
11
|
+
* @Title: 项目工作区是否干净
|
|
12
|
+
* @Describe:
|
|
13
|
+
* @Author: Zsj
|
|
14
|
+
* @returns {Promise<boolean>}
|
|
15
|
+
*/
|
|
16
|
+
const isWorkingTreeClean = function() {
|
|
17
|
+
var _ref = _asyncToGenerator(function* () {
|
|
18
|
+
return (yield $`git status --porcelain`).stdout === "";
|
|
19
|
+
});
|
|
20
|
+
return function isWorkingTreeClean() {
|
|
21
|
+
return _ref.apply(this, arguments);
|
|
22
|
+
};
|
|
44
23
|
}();
|
|
45
|
-
|
|
46
24
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git symbolic-ref --short HEAD"])));
|
|
58
|
-
case 2:
|
|
59
|
-
v = _context2.sent;
|
|
60
|
-
return _context2.abrupt("return", v.stdout);
|
|
61
|
-
case 4:
|
|
62
|
-
case "end":
|
|
63
|
-
return _context2.stop();
|
|
64
|
-
}
|
|
65
|
-
}, _callee2);
|
|
66
|
-
}));
|
|
67
|
-
return function getGitCurrentBranch() {
|
|
68
|
-
return _ref2.apply(this, arguments);
|
|
69
|
-
};
|
|
25
|
+
* 获取当前分支
|
|
26
|
+
* @returns {Promise<*>}
|
|
27
|
+
*/
|
|
28
|
+
const getGitCurrentBranch = function() {
|
|
29
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
30
|
+
return (yield $`git symbolic-ref --short HEAD`).stdout;
|
|
31
|
+
});
|
|
32
|
+
return function getGitCurrentBranch() {
|
|
33
|
+
return _ref2.apply(this, arguments);
|
|
34
|
+
};
|
|
70
35
|
}();
|
|
71
|
-
|
|
72
36
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
37
|
+
* monorepo项目名称
|
|
38
|
+
* @type {string[]}
|
|
39
|
+
*/
|
|
40
|
+
const monorepoProjectNameArr = [
|
|
41
|
+
"admin",
|
|
42
|
+
"my_pisell_v2",
|
|
43
|
+
"docs"
|
|
44
|
+
];
|
|
78
45
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return JSON.parse(fs.readFileSync('../../../lm_config.json', 'utf8'));
|
|
95
|
-
case 4:
|
|
96
|
-
return _context3.abrupt("return", _context3.sent);
|
|
97
|
-
case 5:
|
|
98
|
-
_context3.next = 7;
|
|
99
|
-
return JSON.parse(fs.readFileSync('../lm_config.json', 'utf8'));
|
|
100
|
-
case 7:
|
|
101
|
-
return _context3.abrupt("return", _context3.sent);
|
|
102
|
-
case 8:
|
|
103
|
-
case "end":
|
|
104
|
-
return _context3.stop();
|
|
105
|
-
}
|
|
106
|
-
}, _callee3);
|
|
107
|
-
}));
|
|
108
|
-
return function getServerConfig(_x) {
|
|
109
|
-
return _ref3.apply(this, arguments);
|
|
110
|
-
};
|
|
46
|
+
* @Title: 获取本地lm_config.json配置信息
|
|
47
|
+
* @Describe: 从项目根目录读取配置文件,支持错误处理
|
|
48
|
+
* @Author: Zsj
|
|
49
|
+
* @param {string} project - 项目名称
|
|
50
|
+
* @returns {Object} 配置对象
|
|
51
|
+
*/
|
|
52
|
+
const getServerConfig = function() {
|
|
53
|
+
var _ref3 = _asyncToGenerator(function* (project) {
|
|
54
|
+
console.log(project, "project");
|
|
55
|
+
if (monorepoProjectNameArr.includes(project)) return yield JSON.parse(fs.readFileSync("../../../lm_config.json", "utf8"));
|
|
56
|
+
return yield JSON.parse(fs.readFileSync("../lm_config.json", "utf8"));
|
|
57
|
+
});
|
|
58
|
+
return function getServerConfig(_x) {
|
|
59
|
+
return _ref3.apply(this, arguments);
|
|
60
|
+
};
|
|
111
61
|
}();
|
|
112
|
-
|
|
113
62
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
63
|
+
* @Title: 连接服务器
|
|
64
|
+
* @Describe:
|
|
65
|
+
* @Author: Zsj
|
|
66
|
+
*/
|
|
67
|
+
const connectServer = (config) => {
|
|
68
|
+
const conn = new ssh2.Client();
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
conn.on("ready", () => {
|
|
71
|
+
resolve(conn);
|
|
72
|
+
}).on("error", (err) => {
|
|
73
|
+
console.log(err, "connect error");
|
|
74
|
+
reject();
|
|
75
|
+
}).connect(config);
|
|
76
|
+
});
|
|
128
77
|
};
|
|
129
|
-
|
|
130
78
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
79
|
+
* @Title: 文件上传至服务器
|
|
80
|
+
* @Describe:
|
|
81
|
+
* @Author: Zsj
|
|
82
|
+
*/
|
|
83
|
+
const serverUpload = (conn, { localPath, remotePath }) => {
|
|
84
|
+
if (!conn) return Promise.reject("未连接服务器");
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
conn.sftp((err, sftp) => {
|
|
87
|
+
if (err) {
|
|
88
|
+
console.log(err);
|
|
89
|
+
reject(err);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
sftp.fastPut(localPath, remotePath, { step: (total, nb, fsize) => {
|
|
93
|
+
console.table([
|
|
94
|
+
{
|
|
95
|
+
标题: "当前已上传",
|
|
96
|
+
值: `${(total / fsize * 100).toFixed(2)}%`
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
标题: "每次上传",
|
|
100
|
+
值: `${(nb / 1024 / 1024).toFixed(2)}M`
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
标题: "总大小",
|
|
104
|
+
值: `${(fsize / 1024 / 1024).toFixed(2)}M`
|
|
105
|
+
}
|
|
106
|
+
]);
|
|
107
|
+
} }, (err$1) => {
|
|
108
|
+
if (err$1) {
|
|
109
|
+
console.log(err$1);
|
|
110
|
+
reject(err$1);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
console.log("上传成功");
|
|
114
|
+
resolve(conn);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
170
118
|
};
|
|
171
|
-
|
|
172
119
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
120
|
+
* @Title: 服务器中解压文件
|
|
121
|
+
* @Describe:
|
|
122
|
+
* @Author: Zsj
|
|
123
|
+
*/
|
|
124
|
+
const serverUnpack = (conn, { path: path$1, fileName, fullFileName, changelog, env }) => {
|
|
125
|
+
if (!conn) return Promise.reject("未连接服务器");
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
conn.shell((err, stream) => {
|
|
128
|
+
if (err) {
|
|
129
|
+
console.log(err);
|
|
130
|
+
reject(err);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
stream.end(` ${env === "prod" ? "sudo -i" : ""}
|
|
134
|
+
cd /tmp
|
|
135
|
+
mv ${fullFileName} ${path$1}
|
|
136
|
+
cd ${path$1}
|
|
137
|
+
unzip ${fullFileName} -d ${fileName} && mv ${fileName}/dist/* ${fileName}/ && rmdir ${fileName}/dist
|
|
138
|
+
rm -rf ${fullFileName}
|
|
139
|
+
echo "${changelog}" > ./${fileName}/changelog.md
|
|
140
|
+
sh deleteOldVersion.sh
|
|
141
|
+
exit
|
|
142
|
+
${env === "prod" ? "exit" : ""}
|
|
143
|
+
`).on("data", (data) => {
|
|
144
|
+
console.log(data.toString());
|
|
145
|
+
}).on("close", () => {
|
|
146
|
+
console.log("✅上传完成");
|
|
147
|
+
resolve();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
205
151
|
};
|
|
206
|
-
|
|
207
152
|
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
153
|
+
* @Title: 选择名称进行发布操作
|
|
154
|
+
* @Describe:
|
|
155
|
+
* @Author: Zsj
|
|
156
|
+
*/
|
|
157
|
+
const releaseProject = (conn, { path: path$1, fileName, isSSR, env }) => {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
conn.shell((err, stream) => {
|
|
160
|
+
if (err) {
|
|
161
|
+
console.log(err);
|
|
162
|
+
reject(err);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
stream.end(` ${env === "prod" ? "sudo -i" : ""}
|
|
166
|
+
cd ${path$1}
|
|
167
|
+
cp -R -f pre-master next-master
|
|
168
|
+
rm -rf pre-master
|
|
169
|
+
\\cp -R -f ${fileName}/* next-master
|
|
170
|
+
cp -R -f ${fileName} pre-master
|
|
171
|
+
rm -rf master
|
|
172
|
+
cp -R next-master master
|
|
173
|
+
rm -rf next-master
|
|
174
|
+
${isSSR ? "pm2 restart server.js" : ""}
|
|
175
|
+
exit
|
|
176
|
+
${env === "prod" ? "exit" : ""}
|
|
177
|
+
`).on("data", (data) => {
|
|
178
|
+
console.log(data.toString());
|
|
179
|
+
}).on("close", () => {
|
|
180
|
+
console.log("✅发布完成");
|
|
181
|
+
resolve();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
240
185
|
};
|
|
241
|
-
|
|
242
186
|
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return bParts.length - aParts.length;
|
|
259
|
-
});
|
|
187
|
+
* @Title: version进行版本号排序
|
|
188
|
+
* @Describe:
|
|
189
|
+
* @Author: Zsj
|
|
190
|
+
*/
|
|
191
|
+
const versionSort = (versionList) => {
|
|
192
|
+
return versionList.sort((a, b) => {
|
|
193
|
+
const aParts = a.split(".");
|
|
194
|
+
const bParts = b.split(".");
|
|
195
|
+
for (let i = 0; i < aParts.length && i < bParts.length; i++) {
|
|
196
|
+
const aNum = parseInt(aParts[i]);
|
|
197
|
+
const bNum = parseInt(bParts[i]);
|
|
198
|
+
if (aNum !== bNum) return bNum - aNum;
|
|
199
|
+
}
|
|
200
|
+
return bParts.length - aParts.length;
|
|
201
|
+
});
|
|
260
202
|
};
|
|
261
|
-
|
|
262
203
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
204
|
+
* 获取当前主项目名称
|
|
205
|
+
* @returns {*}
|
|
206
|
+
*/
|
|
207
|
+
const getCurrentProjectName = () => {
|
|
208
|
+
return loadJSON(path.join(process.cwd(), "./package.json")).name;
|
|
268
209
|
};
|
|
269
|
-
|
|
270
|
-
|
|
210
|
+
const getCurrentProjectPkg = () => {
|
|
211
|
+
return loadJSON(path.join(process.cwd(), "./package.json"));
|
|
271
212
|
};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
_context4.next = 2;
|
|
282
|
-
return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git config user.name"])));
|
|
283
|
-
case 2:
|
|
284
|
-
_yield = _context4.sent;
|
|
285
|
-
stdout = _yield.stdout;
|
|
286
|
-
return _context4.abrupt("return", stdout);
|
|
287
|
-
case 5:
|
|
288
|
-
case "end":
|
|
289
|
-
return _context4.stop();
|
|
290
|
-
}
|
|
291
|
-
}, _callee4);
|
|
292
|
-
}));
|
|
293
|
-
return function getCurrentUserName() {
|
|
294
|
-
return _ref7.apply(this, arguments);
|
|
295
|
-
};
|
|
213
|
+
const loadJSON = (path$1) => JSON.parse(fs.readFileSync(path$1));
|
|
214
|
+
const getCurrentUserName = function() {
|
|
215
|
+
var _ref4 = _asyncToGenerator(function* () {
|
|
216
|
+
const { stdout } = yield $`git config user.name`;
|
|
217
|
+
return stdout;
|
|
218
|
+
});
|
|
219
|
+
return function getCurrentUserName() {
|
|
220
|
+
return _ref4.apply(this, arguments);
|
|
221
|
+
};
|
|
296
222
|
}();
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
223
|
+
const createFeishuMessageContent = (contentArr) => {
|
|
224
|
+
return JSON.stringify(contentArr.map((item) => {
|
|
225
|
+
return [{
|
|
226
|
+
tag: "text",
|
|
227
|
+
text: `${item.key}: `
|
|
228
|
+
}, {
|
|
229
|
+
tag: "text",
|
|
230
|
+
text: `${item.value}`
|
|
231
|
+
}];
|
|
232
|
+
}));
|
|
307
233
|
};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
var dependencies = _objectSpread(_objectSpread({}, packageData.dependencies), packageData.devDependencies);
|
|
313
|
-
var nonExcludedPackages = Object.keys(dependencies).filter(function (packageName) {
|
|
314
|
-
return !excludedPackages.includes(packageName);
|
|
315
|
-
});
|
|
316
|
-
return nonExcludedPackages;
|
|
234
|
+
const getNonExcludedPackages = (excludedPackages) => {
|
|
235
|
+
const packageData = getCurrentProjectPkg();
|
|
236
|
+
const dependencies = _objectSpread2(_objectSpread2({}, packageData.dependencies), packageData.devDependencies);
|
|
237
|
+
return Object.keys(dependencies).filter((packageName) => !excludedPackages.includes(packageName));
|
|
317
238
|
};
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
headers: {
|
|
336
|
-
'Content-Type': 'application/json'
|
|
337
|
-
},
|
|
338
|
-
method: 'POST',
|
|
339
|
-
body: JSON.stringify({
|
|
340
|
-
msg_type: 'post',
|
|
341
|
-
content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
|
|
342
|
-
})
|
|
343
|
-
});
|
|
344
|
-
case 6:
|
|
345
|
-
response = _context5.sent;
|
|
346
|
-
_context5.next = 9;
|
|
347
|
-
return response.json();
|
|
348
|
-
case 9:
|
|
349
|
-
return _context5.abrupt("return", _context5.sent);
|
|
350
|
-
case 10:
|
|
351
|
-
case "end":
|
|
352
|
-
return _context5.stop();
|
|
353
|
-
}
|
|
354
|
-
}, _callee5);
|
|
355
|
-
}));
|
|
356
|
-
return function sendWebhook(_x2) {
|
|
357
|
-
return _ref9.apply(this, arguments);
|
|
358
|
-
};
|
|
239
|
+
const sendWebhook = function() {
|
|
240
|
+
var _ref5 = _asyncToGenerator(function* ({ title, content }) {
|
|
241
|
+
var _dotenv$config, _dotenv$config2;
|
|
242
|
+
const contentStr = createFeishuMessageContent(content);
|
|
243
|
+
if (!((_dotenv$config = dotenv.config()) === null || _dotenv$config === void 0 || (_dotenv$config = _dotenv$config.parsed) === null || _dotenv$config === void 0 ? void 0 : _dotenv$config.WEBHOOK)) return;
|
|
244
|
+
return yield (yield fetch((_dotenv$config2 = dotenv.config()) === null || _dotenv$config2 === void 0 || (_dotenv$config2 = _dotenv$config2.parsed) === null || _dotenv$config2 === void 0 ? void 0 : _dotenv$config2.WEBHOOK, {
|
|
245
|
+
headers: { "Content-Type": "application/json" },
|
|
246
|
+
method: "POST",
|
|
247
|
+
body: JSON.stringify({
|
|
248
|
+
msg_type: "post",
|
|
249
|
+
content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
|
|
250
|
+
})
|
|
251
|
+
})).json();
|
|
252
|
+
});
|
|
253
|
+
return function sendWebhook(_x2) {
|
|
254
|
+
return _ref5.apply(this, arguments);
|
|
255
|
+
};
|
|
359
256
|
}();
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return _context6.abrupt("return", {
|
|
382
|
-
success: !isWrongVersion,
|
|
383
|
-
message: errorMessage
|
|
384
|
-
});
|
|
385
|
-
case 8:
|
|
386
|
-
case "end":
|
|
387
|
-
return _context6.stop();
|
|
388
|
-
}
|
|
389
|
-
}, _callee6);
|
|
390
|
-
}));
|
|
391
|
-
return function checkPkgVersion(_x3) {
|
|
392
|
-
return _ref10.apply(this, arguments);
|
|
393
|
-
};
|
|
257
|
+
const checkPkgVersion = function() {
|
|
258
|
+
var _ref6 = _asyncToGenerator(function* (checkPackages) {
|
|
259
|
+
const wrongPkg = (yield npmCheck({
|
|
260
|
+
skipUnused: true,
|
|
261
|
+
ignore: getNonExcludedPackages(checkPackages)
|
|
262
|
+
})).get("packages").filter((item) => {
|
|
263
|
+
return checkPackages.includes(item.moduleName) && item.mismatch;
|
|
264
|
+
});
|
|
265
|
+
const errorMessage = wrongPkg.reduce((p, c) => {
|
|
266
|
+
return `${p}
|
|
267
|
+
${c.moduleName}本地版本${c.installed}需升级至${c.packageJson}
|
|
268
|
+
`;
|
|
269
|
+
}, "");
|
|
270
|
+
return {
|
|
271
|
+
success: !wrongPkg.length,
|
|
272
|
+
message: errorMessage
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
return function checkPkgVersion(_x3) {
|
|
276
|
+
return _ref6.apply(this, arguments);
|
|
277
|
+
};
|
|
394
278
|
}();
|
|
395
|
-
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
export { checkPkgVersion, connectServer, getCurrentProjectName, getCurrentUserName, getGitCurrentBranch, getServerConfig, isWorkingTreeClean, loadJSON, releaseProject, sendWebhook, serverUnpack, serverUpload, versionSort };
|