@pisell/common 1.0.58 → 1.0.59

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.
Files changed (56) hide show
  1. package/.fatherrc.ts +7 -7
  2. package/CHANGELOG.md +9 -1
  3. package/README.md +2 -2
  4. package/es/bin/pisell.js +1 -5
  5. package/es/index.d.ts +2 -4
  6. package/es/index.js +1 -5
  7. package/es/script/aws/index.js +212 -129
  8. package/es/script/constants/index.js +75 -84
  9. package/es/script/deploy.js +44 -33
  10. package/es/script/index.js +37 -43
  11. package/es/script/package.json +4 -4
  12. package/es/script/release/index.js +152 -85
  13. package/es/script/release/release.js +168 -83
  14. package/es/script/uploadCode/index.js +309 -239
  15. package/es/script/uploadCode/uploadCode.js +433 -220
  16. package/es/script/utils/index.js +381 -265
  17. package/lib/bin/pisell.js +24 -4
  18. package/lib/index.d.ts +2 -3
  19. package/lib/index.js +23 -4
  20. package/lib/script/aws/index.js +124 -139
  21. package/lib/script/constants/index.js +110 -85
  22. package/lib/script/deploy.js +55 -34
  23. package/lib/script/index.js +56 -41
  24. package/lib/script/package.json +4 -4
  25. package/lib/script/release/index.js +108 -90
  26. package/lib/script/release/release.js +85 -82
  27. package/lib/script/uploadCode/index.js +230 -244
  28. package/lib/script/uploadCode/uploadCode.js +225 -222
  29. package/lib/script/utils/index.js +264 -270
  30. package/package.json +2 -2
  31. package/src/bin/pisell.js +3 -3
  32. package/src/script/aws/index.js +138 -138
  33. package/src/script/constants/index.js +86 -86
  34. package/src/script/deploy.js +29 -29
  35. package/src/script/index.js +45 -45
  36. package/src/script/package.json +4 -4
  37. package/src/script/release/index.js +119 -119
  38. package/src/script/release/release.js +87 -87
  39. package/src/script/uploadCode/index.js +284 -284
  40. package/src/script/uploadCode/uploadCode.js +255 -255
  41. package/src/script/utils/index.js +331 -331
  42. package/tsconfig.json +14 -14
  43. package/tsdown.config.ts +93 -93
  44. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/asyncToGenerator.js +0 -28
  45. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/defineProperty.js +0 -14
  46. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/objectSpread2.js +0 -27
  47. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPrimitive.js +0 -16
  48. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPropertyKey.js +0 -11
  49. package/es/_virtual/_@oxc-project_runtime@0.108.0/helpers/typeof.js +0 -12
  50. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/asyncToGenerator.js +0 -29
  51. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/defineProperty.js +0 -14
  52. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/objectSpread2.js +0 -27
  53. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPrimitive.js +0 -16
  54. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/toPropertyKey.js +0 -11
  55. package/lib/_virtual/_@oxc-project_runtime@0.108.0/helpers/typeof.js +0 -18
  56. package/lib/_virtual/rolldown_runtime.js +0 -29
@@ -1,281 +1,397 @@
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";
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _templateObject, _templateObject2, _templateObject3;
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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';
8
17
 
9
- //#region src/script/utils/index.js
10
- /**
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
- };
18
+ /**
19
+ * @Title: 项目工作区是否干净
20
+ * @Describe:
21
+ * @Author: Zsj
22
+ * @returns {Promise<boolean>}
23
+ */
24
+ var isWorkingTreeClean = /*#__PURE__*/function () {
25
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
26
+ var v;
27
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
28
+ while (1) switch (_context.prev = _context.next) {
29
+ case 0:
30
+ _context.next = 2;
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
+ };
23
44
  }();
24
- /**
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
- };
45
+
46
+ /**
47
+ * 获取当前分支
48
+ * @returns {Promise<*>}
49
+ */
50
+ var getGitCurrentBranch = /*#__PURE__*/function () {
51
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
52
+ var v;
53
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
54
+ while (1) switch (_context2.prev = _context2.next) {
55
+ case 0:
56
+ _context2.next = 2;
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
+ };
35
70
  }();
36
- /**
37
- * monorepo项目名称
38
- * @type {string[]}
39
- */
40
- const monorepoProjectNameArr = [
41
- "admin",
42
- "my_pisell_v2",
43
- "docs"
44
- ];
45
- /**
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
- };
71
+
72
+ /**
73
+ * monorepo项目名称
74
+ * @type {string[]}
75
+ */
76
+ var monorepoProjectNameArr = ['admin', 'my_pisell_v2', 'docs'];
77
+
78
+ /**
79
+ * @Title: 获取本地lm_config.json配置信息
80
+ * @Describe: 从项目根目录读取配置文件,支持错误处理
81
+ * @Author: Zsj
82
+ * @param {string} project - 项目名称
83
+ * @returns {Object} 配置对象
84
+ */
85
+ var getServerConfig = /*#__PURE__*/function () {
86
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(project) {
87
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
88
+ while (1) switch (_context3.prev = _context3.next) {
89
+ case 0:
90
+ console.log(project, 'project');
91
+ if (!monorepoProjectNameArr.includes(project)) {
92
+ _context3.next = 5;
93
+ break;
94
+ }
95
+ _context3.next = 4;
96
+ return JSON.parse(fs.readFileSync('../../../lm_config.json', 'utf8'));
97
+ case 4:
98
+ return _context3.abrupt("return", _context3.sent);
99
+ case 5:
100
+ _context3.next = 7;
101
+ return JSON.parse(fs.readFileSync('../lm_config.json', 'utf8'));
102
+ case 7:
103
+ return _context3.abrupt("return", _context3.sent);
104
+ case 8:
105
+ case "end":
106
+ return _context3.stop();
107
+ }
108
+ }, _callee3);
109
+ }));
110
+ return function getServerConfig(_x) {
111
+ return _ref3.apply(this, arguments);
112
+ };
61
113
  }();
62
- /**
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
- });
114
+
115
+ /**
116
+ * @Title: 连接服务器
117
+ * @Describe:
118
+ * @Author: Zsj
119
+ */
120
+ var connectServer = function connectServer(config) {
121
+ var conn = new ssh2.Client();
122
+ return new Promise(function (resolve, reject) {
123
+ conn.on('ready', function () {
124
+ resolve(conn);
125
+ }).on('error', function (err) {
126
+ console.log(err, 'connect error');
127
+ reject();
128
+ }).connect(config);
129
+ });
130
+ };
131
+
132
+ /**
133
+ * @Title: 文件上传至服务器
134
+ * @Describe:
135
+ * @Author: Zsj
136
+ */
137
+ var serverUpload = function serverUpload(conn, _ref4) {
138
+ var localPath = _ref4.localPath,
139
+ remotePath = _ref4.remotePath;
140
+ if (!conn) return Promise.reject('未连接服务器');
141
+ return new Promise(function (resolve, reject) {
142
+ conn.sftp(function (err, sftp) {
143
+ if (err) {
144
+ console.log(err);
145
+ reject(err);
146
+ return;
147
+ }
148
+ sftp.fastPut(localPath, remotePath, {
149
+ step: function step(total, nb, fsize) {
150
+ console.table([{
151
+ 标题: '当前已上传',
152
+ 值: "".concat((total / fsize * 100).toFixed(2), "%")
153
+ }, {
154
+ 标题: '每次上传',
155
+ 值: "".concat((nb / 1024 / 1024).toFixed(2), "M")
156
+ }, {
157
+ 标题: '总大小',
158
+ 值: "".concat((fsize / 1024 / 1024).toFixed(2), "M")
159
+ }]);
160
+ }
161
+ }, function (err) {
162
+ if (err) {
163
+ console.log(err);
164
+ reject(err);
165
+ return;
166
+ }
167
+ console.log('上传成功');
168
+ resolve(conn);
169
+ });
170
+ });
171
+ });
77
172
  };
78
- /**
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
- });
173
+
174
+ /**
175
+ * @Title: 服务器中解压文件
176
+ * @Describe:
177
+ * @Author: Zsj
178
+ */
179
+ var serverUnpack = function serverUnpack(conn, _ref5) {
180
+ var path = _ref5.path,
181
+ fileName = _ref5.fileName,
182
+ fullFileName = _ref5.fullFileName,
183
+ changelog = _ref5.changelog,
184
+ env = _ref5.env;
185
+ if (!conn) return Promise.reject('未连接服务器');
186
+ // 文件全名
187
+ return new Promise(function (resolve, reject) {
188
+ conn.shell(function (err, stream) {
189
+ if (err) {
190
+ console.log(err);
191
+ reject(err);
192
+ return;
193
+ }
194
+ stream.end(" ".concat(env === 'prod' ? 'sudo -i' : '', "\n cd /tmp\n mv ").concat(fullFileName, " ").concat(path, "\n cd ").concat(path, "\n unzip ").concat(fullFileName, " -d ").concat(fileName, " && mv ").concat(fileName, "/dist/* ").concat(fileName, "/ && rmdir ").concat(fileName, "/dist\n rm -rf ").concat(fullFileName, "\n echo \"").concat(changelog, "\" > ./").concat(fileName, "/changelog.md\n sh deleteOldVersion.sh\n exit\n ").concat(env === 'prod' ? 'exit' : '', "\n ") // 打开到path
195
+ // 解压 1.0.0.zip 文件到 1.0.0 移动dist中内容到 1.0.0内 删除dist
196
+ // 删除1.0.0.zip
197
+ // 写入changelog到changelog.md
198
+ // 执行deleteOldVersion脚本 删除过早版本
199
+ ).on('data', function (data) {
200
+ console.log(data.toString());
201
+ }).on('close', function () {
202
+ console.log('✅上传完成');
203
+ resolve();
204
+ });
205
+ });
206
+ });
118
207
  };
119
- /**
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
- });
208
+
209
+ /**
210
+ * @Title: 选择名称进行发布操作
211
+ * @Describe:
212
+ * @Author: Zsj
213
+ */
214
+ var releaseProject = function releaseProject(conn, _ref6) {
215
+ var path = _ref6.path,
216
+ fileName = _ref6.fileName,
217
+ isSSR = _ref6.isSSR,
218
+ env = _ref6.env;
219
+ return new Promise(function (resolve, reject) {
220
+ conn.shell(function (err, stream) {
221
+ if (err) {
222
+ console.log(err);
223
+ reject(err);
224
+ return;
225
+ }
226
+ stream.end(" ".concat(env === 'prod' ? 'sudo -i' : '', "\n cd ").concat(path, "\n cp -R -f pre-master next-master\n rm -rf pre-master\n \\cp -R -f ").concat(fileName, "/* next-master\n cp -R -f ").concat(fileName, " pre-master\n rm -rf master\n cp -R next-master master\n rm -rf next-master\n ").concat(isSSR ? 'pm2 restart server.js' : '', "\n exit\n ").concat(env === 'prod' ? 'exit' : '', "\n ") // 打开到path
227
+ // 复制pre-master到next-master
228
+ // 删除pre-master
229
+ // 复制1.0.0到next-master
230
+ // 复制1.0.0到pre-master
231
+ // 删除master
232
+ // 复制next-master到master
233
+ // 删除next-master
234
+ ).on('data', function (data) {
235
+ console.log(data.toString());
236
+ }).on('close', function () {
237
+ console.log('✅发布完成');
238
+ resolve();
239
+ });
240
+ });
241
+ });
151
242
  };
152
- /**
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
- });
243
+
244
+ /**
245
+ * @Title: version进行版本号排序
246
+ * @Describe:
247
+ * @Author: Zsj
248
+ */
249
+ var versionSort = function versionSort(versionList) {
250
+ return versionList.sort(function (a, b) {
251
+ var aParts = a.split('.');
252
+ var bParts = b.split('.');
253
+ for (var i = 0; i < aParts.length && i < bParts.length; i++) {
254
+ var aNum = parseInt(aParts[i]);
255
+ var bNum = parseInt(bParts[i]);
256
+ if (aNum !== bNum) {
257
+ return bNum - aNum;
258
+ }
259
+ }
260
+ return bParts.length - aParts.length;
261
+ });
185
262
  };
186
- /**
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
- });
263
+
264
+ /**
265
+ * 获取当前主项目名称
266
+ * @returns {*}
267
+ */
268
+ var getCurrentProjectName = function getCurrentProjectName() {
269
+ return loadJSON(path.join(process.cwd(), './package.json')).name;
202
270
  };
203
- /**
204
- * 获取当前主项目名称
205
- * @returns {*}
206
- */
207
- const getCurrentProjectName = () => {
208
- return loadJSON(path.join(process.cwd(), "./package.json")).name;
271
+ var getCurrentProjectPkg = function getCurrentProjectPkg() {
272
+ return loadJSON(path.join(process.cwd(), './package.json'));
209
273
  };
210
- const getCurrentProjectPkg = () => {
211
- return loadJSON(path.join(process.cwd(), "./package.json"));
274
+ var loadJSON = function loadJSON(path) {
275
+ return JSON.parse(fs.readFileSync(path));
212
276
  };
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
- };
277
+ var getCurrentUserName = /*#__PURE__*/function () {
278
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
279
+ var _yield, stdout;
280
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
281
+ while (1) switch (_context4.prev = _context4.next) {
282
+ case 0:
283
+ _context4.next = 2;
284
+ return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git config user.name"])));
285
+ case 2:
286
+ _yield = _context4.sent;
287
+ stdout = _yield.stdout;
288
+ return _context4.abrupt("return", stdout);
289
+ case 5:
290
+ case "end":
291
+ return _context4.stop();
292
+ }
293
+ }, _callee4);
294
+ }));
295
+ return function getCurrentUserName() {
296
+ return _ref7.apply(this, arguments);
297
+ };
222
298
  }();
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
- }));
299
+ var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
300
+ return JSON.stringify(contentArr.map(function (item) {
301
+ return [{
302
+ tag: 'text',
303
+ text: "".concat(item.key, ": ")
304
+ }, {
305
+ tag: 'text',
306
+ text: "".concat(item.value)
307
+ }];
308
+ }));
233
309
  };
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));
310
+
311
+ // 获取除了此pkg的包
312
+ var getNonExcludedPackages = function getNonExcludedPackages(excludedPackages) {
313
+ var packageData = getCurrentProjectPkg();
314
+ var dependencies = _objectSpread(_objectSpread({}, packageData.dependencies), packageData.devDependencies);
315
+ var nonExcludedPackages = Object.keys(dependencies).filter(function (packageName) {
316
+ return !excludedPackages.includes(packageName);
317
+ });
318
+ return nonExcludedPackages;
238
319
  };
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
- };
320
+ var sendWebhook = /*#__PURE__*/function () {
321
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref8) {
322
+ var _dotenv$config, _dotenv$config2;
323
+ var title, content, contentStr, response;
324
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
325
+ while (1) switch (_context5.prev = _context5.next) {
326
+ case 0:
327
+ title = _ref8.title, content = _ref8.content;
328
+ contentStr = createFeishuMessageContent(content);
329
+ if ((_dotenv$config = dotenv.config()) !== null && _dotenv$config !== void 0 && (_dotenv$config = _dotenv$config.parsed) !== null && _dotenv$config !== void 0 && _dotenv$config.WEBHOOK) {
330
+ _context5.next = 4;
331
+ break;
332
+ }
333
+ return _context5.abrupt("return");
334
+ case 4:
335
+ _context5.next = 6;
336
+ return 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, {
337
+ headers: {
338
+ 'Content-Type': 'application/json'
339
+ },
340
+ method: 'POST',
341
+ body: JSON.stringify({
342
+ msg_type: 'post',
343
+ content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
344
+ })
345
+ });
346
+ case 6:
347
+ response = _context5.sent;
348
+ _context5.next = 9;
349
+ return response.json();
350
+ case 9:
351
+ return _context5.abrupt("return", _context5.sent);
352
+ case 10:
353
+ case "end":
354
+ return _context5.stop();
355
+ }
356
+ }, _callee5);
357
+ }));
358
+ return function sendWebhook(_x2) {
359
+ return _ref9.apply(this, arguments);
360
+ };
256
361
  }();
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
- };
362
+ var checkPkgVersion = /*#__PURE__*/function () {
363
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(checkPackages) {
364
+ var currentState, pkgs, wrongPkg, errorMessage, isWrongVersion;
365
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
366
+ while (1) switch (_context6.prev = _context6.next) {
367
+ case 0:
368
+ _context6.next = 2;
369
+ return npmCheck({
370
+ skipUnused: true,
371
+ ignore: getNonExcludedPackages(checkPackages)
372
+ });
373
+ case 2:
374
+ currentState = _context6.sent;
375
+ pkgs = currentState.get('packages');
376
+ wrongPkg = pkgs.filter(function (item) {
377
+ return checkPackages.includes(item.moduleName) && item.mismatch;
378
+ });
379
+ errorMessage = wrongPkg.reduce(function (p, c) {
380
+ return "".concat(p, "\n ").concat(c.moduleName, "\u672C\u5730\u7248\u672C").concat(c.installed, "\u9700\u5347\u7EA7\u81F3").concat(c.packageJson, "\n ");
381
+ }, '');
382
+ isWrongVersion = wrongPkg.length;
383
+ return _context6.abrupt("return", {
384
+ success: !isWrongVersion,
385
+ message: errorMessage
386
+ });
387
+ case 8:
388
+ case "end":
389
+ return _context6.stop();
390
+ }
391
+ }, _callee6);
392
+ }));
393
+ return function checkPkgVersion(_x3) {
394
+ return _ref10.apply(this, arguments);
395
+ };
278
396
  }();
279
-
280
- //#endregion
281
- export { checkPkgVersion, connectServer, getCurrentProjectName, getCurrentUserName, getGitCurrentBranch, getServerConfig, isWorkingTreeClean, loadJSON, releaseProject, sendWebhook, serverUnpack, serverUpload, versionSort };
397
+ export { isWorkingTreeClean, getServerConfig, connectServer, serverUpload, serverUnpack, versionSort, releaseProject, getGitCurrentBranch, getCurrentProjectName, loadJSON, getCurrentUserName, sendWebhook, checkPkgVersion };