@pisell/common 1.0.3 → 1.0.4

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @pisell/common
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [1bd9790]
8
+ - @pisell/utils@1.0.5
9
+
3
10
  ## 1.0.3
4
11
 
5
12
  ### Patch Changes
package/es/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  declare const _default: {};
2
2
  export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,wBAAkB"}
@@ -5,7 +5,7 @@ var outPathMap = {
5
5
  pre: '../data/release/project/my_pisel_shop'
6
6
  },
7
7
  admin: {
8
- prod: '../data/release/project/pisell_v2',
8
+ prod: '../../data/project/pisell2',
9
9
  release: '../data/release/project/pisell_v2',
10
10
  pre: '../data/release/project/pisell_v2'
11
11
  }
@@ -9,8 +9,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
9
9
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
10
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
11
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
- import archiver from 'archiver';
13
- import path from 'path';
12
+ import archiver from "archiver";
13
+ import path from "path";
14
14
  import { outPathMap } from "../constants/index.js";
15
15
  import { connectServer as _connectServer, getGitCurrentBranch, getServerConfig, isWorkingTreeClean, serverUnpack as _serverUnpack, serverUpload as _serverUpload } from "../utils/index.js";
16
16
 
@@ -33,8 +33,8 @@ var UploadCode = /*#__PURE__*/function () {
33
33
  this.version = version;
34
34
  this.changelog = changelog;
35
35
  this.is_release = is_release;
36
- this.currentVersion = '';
37
- this.projectAbsolutePath = '';
36
+ this.currentVersion = "";
37
+ this.projectAbsolutePath = "";
38
38
  this.conn = null;
39
39
  this.serverConfig = null;
40
40
  this.outPath = outPathMap[this.projectName][this.env];
@@ -73,7 +73,7 @@ var UploadCode = /*#__PURE__*/function () {
73
73
  _context.next = 6;
74
74
  break;
75
75
  }
76
- console.log('未找到发布脚本!');
76
+ console.log("未找到发布脚本!");
77
77
  return _context.abrupt("return", false);
78
78
  case 6:
79
79
  cd(this.projectRelativePath);
@@ -91,33 +91,38 @@ var UploadCode = /*#__PURE__*/function () {
91
91
  _context.next = 13;
92
92
  break;
93
93
  }
94
- console.log('工作区不干净, 请先提交代码');
94
+ console.log("工作区不干净, 请先提交代码");
95
95
  return _context.abrupt("return", false);
96
96
  case 13:
97
- serverConfig = this.setConfig(serverConfigMap[this.env]);
98
- if (this.env === 'prod') {
99
- serverConfig.privateKey = fs.readFileSync(path.join(process.env.HOME, '.ssh', 'id_rsa'));
97
+ serverConfig = this.setConfig(serverConfigMap[this.env]); // 选择release默认用国内cn服务器
98
+ if (this.env === "release") {
99
+ serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
100
+ }
101
+ if (this.env === "prod") {
102
+ serverConfig.privateKey = fs.readFileSync(path.join(process.env.HOME, ".ssh", "id_rsa"));
100
103
  }
101
104
 
102
- // 选择release默认用国内cn服务器
103
- if (this.env === 'release') {
104
- serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
105
+ // pisell2.0正式环境使用亚马逊服务器
106
+ if (this.env === "prod" && this.projectName === "admin") {
107
+ serverConfig = serverConfigMap.aws[this.env];
108
+ serverConfig.privateKey = fs.readFileSync("../../../pisell2.0.pem");
105
109
  }
110
+ this.setConfig(serverConfig);
106
111
  if (serverConfig) {
107
- _context.next = 19;
112
+ _context.next = 21;
108
113
  break;
109
114
  }
110
- console.log('您当前没有权限!');
115
+ console.log("您当前没有权限!");
111
116
  return _context.abrupt("return", false);
112
- case 19:
117
+ case 21:
113
118
  _context.t0 = console;
114
- _context.next = 22;
119
+ _context.next = 24;
115
120
  return getGitCurrentBranch();
116
- case 22:
121
+ case 24:
117
122
  _context.t1 = _context.sent;
118
- _context.t0.log.call(_context.t0, '当前主项目分支', _context.t1);
123
+ _context.t0.log.call(_context.t0, "当前主项目分支", _context.t1);
119
124
  return _context.abrupt("return", true);
120
- case 25:
125
+ case 27:
121
126
  case "end":
122
127
  return _context.stop();
123
128
  }
@@ -141,7 +146,7 @@ var UploadCode = /*#__PURE__*/function () {
141
146
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
142
147
  while (1) switch (_context2.prev = _context2.next) {
143
148
  case 0:
144
- if (!(this.env === 'prod')) {
149
+ if (!(this.env === "prod")) {
145
150
  _context2.next = 8;
146
151
  break;
147
152
  }
@@ -149,13 +154,13 @@ var UploadCode = /*#__PURE__*/function () {
149
154
  return $(_templateObject || (_templateObject = _taggedTemplateLiteral(["npm version ", " -m \"%s ", "\""])), this.version, this.changelog);
150
155
  case 3:
151
156
  _context2.next = 5;
152
- return fs.readJson('./package.json');
157
+ return fs.readJson("./package.json");
153
158
  case 5:
154
159
  _yield$fs$readJson = _context2.sent;
155
160
  version = _yield$fs$readJson.version;
156
161
  this.currentVersion = version;
157
162
  case 8:
158
- if (!(this.env !== 'prod')) {
163
+ if (!(this.env !== "prod")) {
159
164
  _context2.next = 20;
160
165
  break;
161
166
  }
@@ -166,7 +171,7 @@ var UploadCode = /*#__PURE__*/function () {
166
171
  return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git add package.json"])));
167
172
  case 13:
168
173
  _context2.next = 15;
169
- return fs.readJson('./package.json');
174
+ return fs.readJson("./package.json");
170
175
  case 15:
171
176
  _yield$fs$readJson2 = _context2.sent;
172
177
  _version = _yield$fs$readJson2.version;
@@ -227,22 +232,22 @@ var UploadCode = /*#__PURE__*/function () {
227
232
  return _context4.abrupt("return", new Promise(function (resolve, reject) {
228
233
  var __dirname = process.cwd();
229
234
  var zipFile = path.resolve(__dirname, "".concat(_this.currentVersion, ".zip"));
230
- var originFilePath = path.resolve(__dirname, 'dist');
235
+ var originFilePath = path.resolve(__dirname, "dist");
231
236
  var output = fs.createWriteStream(zipFile);
232
- var archive = archiver('zip', {
237
+ var archive = archiver("zip", {
233
238
  zlib: {
234
239
  level: 9
235
240
  } // 设置压缩级别
236
241
  });
237
242
 
238
- archive.on('error', function (err) {
243
+ archive.on("error", function (err) {
239
244
  reject(err);
240
245
  });
241
- output.on('close', function () {
246
+ output.on("close", function () {
242
247
  resolve(true);
243
248
  });
244
249
  archive.pipe(output);
245
- archive.directory(originFilePath, '/dist'); //将srcPath路径对应的内容添加到zip包中/dist路径
250
+ archive.directory(originFilePath, "/dist"); //将srcPath路径对应的内容添加到zip包中/dist路径
246
251
 
247
252
  archive.finalize();
248
253
  }));
@@ -273,7 +278,7 @@ var UploadCode = /*#__PURE__*/function () {
273
278
  _context5.next = 3;
274
279
  break;
275
280
  }
276
- console.log('未找到发布配置!');
281
+ console.log("未找到发布配置!");
277
282
  return _context5.abrupt("return", null);
278
283
  case 3:
279
284
  _context5.next = 5;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  declare const _default: {};
2
2
  export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,wBAAkB"}
@@ -29,7 +29,7 @@ var outPathMap = {
29
29
  pre: "../data/release/project/my_pisel_shop"
30
30
  },
31
31
  admin: {
32
- prod: "../data/release/project/pisell_v2",
32
+ prod: "../../data/project/pisell2",
33
33
  release: "../data/release/project/pisell_v2",
34
34
  pre: "../data/release/project/pisell_v2"
35
35
  }
@@ -78,14 +78,19 @@ var UploadCode = class {
78
78
  return false;
79
79
  }
80
80
  let serverConfig = this.setConfig(serverConfigMap[this.env]);
81
+ if (this.env === "release") {
82
+ serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
83
+ }
81
84
  if (this.env === "prod") {
82
85
  serverConfig.privateKey = fs.readFileSync(
83
86
  import_path.default.join(process.env.HOME, ".ssh", "id_rsa")
84
87
  );
85
88
  }
86
- if (this.env === "release") {
87
- serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
89
+ if (this.env === "prod" && this.projectName === "admin") {
90
+ serverConfig = serverConfigMap.aws[this.env];
91
+ serverConfig.privateKey = fs.readFileSync("../../../pisell2.0.pem");
88
92
  }
93
+ this.setConfig(serverConfig);
89
94
  if (!serverConfig) {
90
95
  console.log("您当前没有权限!");
91
96
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/common",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "sideEffects": [
5
5
  "*.less"
6
6
  ],
@@ -17,7 +17,7 @@
17
17
  "archiver": "^5.3.1",
18
18
  "dotenv": "^16.0.3",
19
19
  "ssh2": "^1.13.0",
20
- "@pisell/utils": "1.0.3"
20
+ "@pisell/utils": "1.0.5"
21
21
  },
22
22
  "devDependencies": {
23
23
  "father": "^4.1.6"
@@ -5,7 +5,7 @@ const outPathMap = {
5
5
  pre: '../data/release/project/my_pisel_shop',
6
6
  },
7
7
  admin: {
8
- prod: '../data/release/project/pisell_v2',
8
+ prod: '../../data/project/pisell2',
9
9
  release: '../data/release/project/pisell_v2',
10
10
  pre: '../data/release/project/pisell_v2',
11
11
  },
@@ -1,6 +1,6 @@
1
- import archiver from 'archiver';
2
- import path from 'path';
3
- import { outPathMap } from '../constants/index.js';
1
+ import archiver from "archiver";
2
+ import path from "path";
3
+ import { outPathMap } from "../constants/index.js";
4
4
  import {
5
5
  connectServer,
6
6
  getGitCurrentBranch,
@@ -8,7 +8,7 @@ import {
8
8
  isWorkingTreeClean,
9
9
  serverUnpack,
10
10
  serverUpload,
11
- } from '../utils/index.js';
11
+ } from "../utils/index.js";
12
12
 
13
13
  /**
14
14
  * @Title: 上传代码至服务器类
@@ -25,8 +25,8 @@ class UploadCode {
25
25
  this.changelog = changelog;
26
26
  this.is_release = is_release;
27
27
 
28
- this.currentVersion = '';
29
- this.projectAbsolutePath = '';
28
+ this.currentVersion = "";
29
+ this.projectAbsolutePath = "";
30
30
  this.conn = null;
31
31
  this.serverConfig = null;
32
32
 
@@ -52,7 +52,7 @@ class UploadCode {
52
52
  const serverConfigMap = await getServerConfig(this.projectName);
53
53
 
54
54
  if (!serverConfigMap) {
55
- console.log('未找到发布脚本!');
55
+ console.log("未找到发布脚本!");
56
56
  return false;
57
57
  }
58
58
 
@@ -66,29 +66,37 @@ class UploadCode {
66
66
  this.projectAbsolutePath = process.cwd();
67
67
 
68
68
  if (!(await isWorkingTreeClean())) {
69
- console.log('工作区不干净, 请先提交代码');
69
+ console.log("工作区不干净, 请先提交代码");
70
70
  return false;
71
71
  }
72
72
 
73
73
  let serverConfig = this.setConfig(serverConfigMap[this.env]);
74
74
 
75
- if (this.env === 'prod') {
75
+ // 选择release默认用国内cn服务器
76
+ if (this.env === "release") {
77
+ serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
78
+ }
79
+
80
+ if (this.env === "prod") {
76
81
  serverConfig.privateKey = fs.readFileSync(
77
- path.join(process.env.HOME, '.ssh', 'id_rsa'),
82
+ path.join(process.env.HOME, ".ssh", "id_rsa")
78
83
  );
79
84
  }
80
85
 
81
- // 选择release默认用国内cn服务器
82
- if (this.env === 'release') {
83
- serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
86
+ // pisell2.0正式环境使用亚马逊服务器
87
+ if (this.env === "prod" && this.projectName === "admin") {
88
+ serverConfig = serverConfigMap.aws[this.env];
89
+ serverConfig.privateKey = fs.readFileSync("../../../pisell2.0.pem");
84
90
  }
85
91
 
92
+ this.setConfig(serverConfig);
93
+
86
94
  if (!serverConfig) {
87
- console.log('您当前没有权限!');
95
+ console.log("您当前没有权限!");
88
96
  return false;
89
97
  }
90
98
 
91
- console.log('当前主项目分支', await getGitCurrentBranch());
99
+ console.log("当前主项目分支", await getGitCurrentBranch());
92
100
 
93
101
  return true;
94
102
  }
@@ -99,15 +107,15 @@ class UploadCode {
99
107
  * @Author: Zsj
100
108
  */
101
109
  async updateVersion() {
102
- if (this.env === 'prod') {
110
+ if (this.env === "prod") {
103
111
  await $`npm version ${this.version} -m "%s ${this.changelog}"`;
104
- let { version } = await fs.readJson('./package.json');
112
+ let { version } = await fs.readJson("./package.json");
105
113
  this.currentVersion = version;
106
114
  }
107
- if (this.env !== 'prod') {
115
+ if (this.env !== "prod") {
108
116
  await $`npm version ${this.version} --no-git-tag-version`;
109
117
  await $`git add package.json`;
110
- let { version } = await fs.readJson('./package.json');
118
+ let { version } = await fs.readJson("./package.json");
111
119
  this.currentVersion = version;
112
120
  await $`git commit -m "chore: ${this.currentVersion} ${this.changelog}"`;
113
121
  }
@@ -132,22 +140,22 @@ class UploadCode {
132
140
  return new Promise((resolve, reject) => {
133
141
  const __dirname = process.cwd();
134
142
  const zipFile = path.resolve(__dirname, `${this.currentVersion}.zip`);
135
- const originFilePath = path.resolve(__dirname, 'dist');
143
+ const originFilePath = path.resolve(__dirname, "dist");
136
144
  const output = fs.createWriteStream(zipFile);
137
- const archive = archiver('zip', {
145
+ const archive = archiver("zip", {
138
146
  zlib: { level: 9 }, // 设置压缩级别
139
147
  });
140
- archive.on('error', function (err) {
148
+ archive.on("error", function (err) {
141
149
  reject(err);
142
150
  });
143
151
 
144
- output.on('close', function () {
152
+ output.on("close", function () {
145
153
  resolve(true);
146
154
  });
147
155
 
148
156
  archive.pipe(output);
149
157
 
150
- archive.directory(originFilePath, '/dist'); //将srcPath路径对应的内容添加到zip包中/dist路径
158
+ archive.directory(originFilePath, "/dist"); //将srcPath路径对应的内容添加到zip包中/dist路径
151
159
 
152
160
  archive.finalize();
153
161
  });
@@ -160,7 +168,7 @@ class UploadCode {
160
168
  */
161
169
  async connectServer() {
162
170
  if (!this.serverConfig) {
163
- console.log('未找到发布配置!');
171
+ console.log("未找到发布配置!");
164
172
  return null;
165
173
  }
166
174
  this.conn = await connectServer(this.serverConfig);
@@ -175,7 +183,7 @@ class UploadCode {
175
183
  async serverUpload() {
176
184
  const localPath = path.resolve(
177
185
  this.projectAbsolutePath,
178
- `${this.currentVersion}.zip`,
186
+ `${this.currentVersion}.zip`
179
187
  );
180
188
  const remotePath = `${this.outPath}/${this.currentVersion}.zip`;
181
189
  return await serverUpload(this.conn, { localPath, remotePath });