@pisell/common 1.0.58 → 1.0.60

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 +16 -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,255 +1,255 @@
1
- import archiver from 'archiver';
2
- import path from 'path';
3
- import { checkPackages, isSsrMap, outPathMap } from '../constants/index.js';
4
- import {
5
- checkPkgVersion,
6
- connectServer,
7
- getGitCurrentBranch,
8
- getServerConfig,
9
- isWorkingTreeClean,
10
- serverUnpack,
11
- serverUpload,
12
- } from '../utils/index.js';
13
-
14
- /**
15
- * @Title: 上传代码至服务器类
16
- * @Describe:
17
- * @Author: Zsj
18
- */
19
- class UploadCode {
20
- constructor(props) {
21
- const { project, env, version, changelog, is_release } = props;
22
- this.projectName = project.fileName;
23
- this.projectRelativePath = project.path;
24
- this.env = env;
25
- this.version = version;
26
- this.changelog = changelog;
27
- this.is_release = is_release;
28
-
29
- this.currentVersion = '';
30
- this.projectAbsolutePath = '';
31
- this.conn = null;
32
- this.serverConfig = null;
33
- // 是否是ssr项目
34
- this.isSSR = isSsrMap[this.projectName];
35
-
36
- this.outPath = outPathMap[this.projectName][this.env];
37
- }
38
-
39
- /**
40
- * @Title: 设置服务器连接配置
41
- * @Describe:
42
- * @Author: Zsj
43
- */
44
- setConfig(serverConfig) {
45
- this.serverConfig = serverConfig;
46
- return this.serverConfig;
47
- }
48
-
49
- /**
50
- * @Title: 发布前检查环境和参数是否正确
51
- * @Describe:
52
- * @Author: Zsj
53
- */
54
- async check() {
55
- const serverConfigMap = await getServerConfig(this.projectName);
56
-
57
- if (!serverConfigMap) {
58
- console.log('未找到发布脚本!');
59
- return false;
60
- }
61
-
62
- cd(this.projectRelativePath);
63
-
64
- // const path = await $`pwd`;
65
-
66
- // windows 下有问题
67
- // this.projectAbsolutePath = path.stdout.replace('\n','');
68
-
69
- this.projectAbsolutePath = process.cwd();
70
-
71
- if (!(await isWorkingTreeClean())) {
72
- console.log('工作区不干净, 请先提交代码');
73
- return false;
74
- }
75
-
76
- const { success, message } = await checkPkgVersion(checkPackages);
77
-
78
- if (!success) {
79
- console.log(message);
80
- return false;
81
- }
82
-
83
- let serverConfig = this.setConfig(serverConfigMap[this.env]);
84
-
85
- // 选择release默认用国内cn服务器
86
- if (this.env === 'release') {
87
- serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
88
- }
89
-
90
- if (this.env === 'prod') {
91
- serverConfig = this.setConfig(serverConfigMap['prod3']);
92
- // serverConfig.privateKey = fs.readFileSync(
93
- // path.join(process.env.HOME, '.ssh', 'id_rsa'),
94
- // );
95
- }
96
-
97
- if (
98
- this.env === 'prod' &&
99
- [
100
- 'xzero',
101
- 'saas_admin',
102
- 'saas_shop',
103
- 'saas_shop_pos',
104
- 'saas_kds',
105
- 'saas_ads',
106
- 'saas_home',
107
- ].includes(this.projectName)
108
- ) {
109
- serverConfig = serverConfigMap.aws.service[this.env];
110
- serverConfig.privateKey = fs.readFileSync(serverConfig.privateKey);
111
- }
112
-
113
- // pisell2.0正式环境使用亚马逊服务器
114
- if (this.env === 'prod' && ['admin', 'docs'].includes(this.projectName)) {
115
- serverConfig = serverConfigMap.aws.service[this.env];
116
- serverConfig.privateKey = fs.readFileSync('../../../pem/pisell-pro.pem');
117
- }
118
-
119
- console.log(serverConfig, 'serverConfig');
120
-
121
- this.setConfig(serverConfig);
122
-
123
- if (!serverConfig) {
124
- console.log('您当前没有权限!');
125
- return false;
126
- }
127
-
128
- console.log('当前主项目分支', await getGitCurrentBranch());
129
-
130
- return true;
131
- }
132
-
133
- /**
134
- * @Title: 更新项目中version 并加入changelog
135
- * @Describe:
136
- * @Author: Zsj
137
- */
138
- async updateVersion() {
139
- if (this.env === 'prod') {
140
- await $`npm version ${this.version} -m "%s ${this.changelog}"`;
141
- let { version } = await fs.readJson('./package.json');
142
- this.currentVersion = version;
143
- }
144
- if (this.env !== 'prod') {
145
- await $`npm version ${this.version} --no-git-tag-version`;
146
- await $`git add package.json`;
147
- let { version } = await fs.readJson('./package.json');
148
- this.currentVersion = version;
149
- await $`git commit -m "chore: ${this.currentVersion} ${this.changelog}"`;
150
- }
151
- return this.currentVersion;
152
- }
153
-
154
- /**
155
- * @Title: 根据env执行打包
156
- * @Describe:
157
- * @Author: Zsj
158
- */
159
- async build() {
160
- await $`npm run build:${this.env}`;
161
- }
162
-
163
- /**
164
- * @Title: 压缩dist文件为zip
165
- * @Describe:
166
- * @Author: Zsj
167
- */
168
- async compress() {
169
- return new Promise((resolve, reject) => {
170
- const __dirname = process.cwd();
171
- const zipFile = path.resolve(__dirname, `${this.currentVersion}.zip`);
172
- const originFilePath = path.resolve(__dirname, 'dist');
173
- const output = fs.createWriteStream(zipFile);
174
- const archive = archiver('zip', {
175
- zlib: { level: 9 }, // 设置压缩级别
176
- });
177
- archive.on('error', function (err) {
178
- reject(err);
179
- });
180
-
181
- output.on('close', function () {
182
- resolve(true);
183
- });
184
-
185
- archive.pipe(output);
186
-
187
- archive.directory(originFilePath, '/dist'); //将srcPath路径对应的内容添加到zip包中/dist路径
188
-
189
- archive.finalize();
190
- });
191
- }
192
-
193
- /**
194
- * @Title: 连接服务器
195
- * @Describe:
196
- * @Author: Zsj
197
- */
198
- async connectServer() {
199
- if (!this.serverConfig) {
200
- console.log('未找到发布配置!');
201
- return null;
202
- }
203
- this.conn = await connectServer(this.serverConfig);
204
- return this.conn;
205
- }
206
-
207
- /**
208
- * @Title: 本地zip文件上传到服务器
209
- * @Describe:
210
- * @Author: Zsj
211
- */
212
- async serverUpload() {
213
- const localPath = path.resolve(
214
- this.projectAbsolutePath,
215
- `${this.currentVersion}.zip`
216
- );
217
- const remotePath = `/tmp/${this.projectName}-${this.currentVersion}.zip`;
218
- return await serverUpload(this.conn, { localPath, remotePath });
219
- }
220
-
221
- /**
222
- * @Title: 服务器中解压文件
223
- * @Describe:
224
- * @Author: Zsj
225
- */
226
- async serverUnpack() {
227
- return await serverUnpack(this.conn, {
228
- path: this.outPath,
229
- fileName: `${this.currentVersion}`,
230
- fullFileName: `${this.projectName}-${this.currentVersion}.zip`,
231
- changelog: this.changelog,
232
- env: this.env,
233
- });
234
- }
235
-
236
- /**
237
- * @Title: 删除本地zip文件
238
- * @Describe:
239
- * @Author: Zsj
240
- */
241
- deleteLocalZip() {
242
- return $`rm -rf ${this.currentVersion}.zip`;
243
- }
244
-
245
- /**
246
- * @Title: 断开服务连接
247
- * @Describe:
248
- * @Author: Zsj
249
- */
250
- async disconnectServer() {
251
- return await this.conn.end();
252
- }
253
- }
254
-
255
- export default UploadCode;
1
+ import archiver from 'archiver';
2
+ import path from 'path';
3
+ import { checkPackages, isSsrMap, outPathMap } from '../constants/index.js';
4
+ import {
5
+ checkPkgVersion,
6
+ connectServer,
7
+ getGitCurrentBranch,
8
+ getServerConfig,
9
+ isWorkingTreeClean,
10
+ serverUnpack,
11
+ serverUpload,
12
+ } from '../utils/index.js';
13
+
14
+ /**
15
+ * @Title: 上传代码至服务器类
16
+ * @Describe:
17
+ * @Author: Zsj
18
+ */
19
+ class UploadCode {
20
+ constructor(props) {
21
+ const { project, env, version, changelog, is_release } = props;
22
+ this.projectName = project.fileName;
23
+ this.projectRelativePath = project.path;
24
+ this.env = env;
25
+ this.version = version;
26
+ this.changelog = changelog;
27
+ this.is_release = is_release;
28
+
29
+ this.currentVersion = '';
30
+ this.projectAbsolutePath = '';
31
+ this.conn = null;
32
+ this.serverConfig = null;
33
+ // 是否是ssr项目
34
+ this.isSSR = isSsrMap[this.projectName];
35
+
36
+ this.outPath = outPathMap[this.projectName][this.env];
37
+ }
38
+
39
+ /**
40
+ * @Title: 设置服务器连接配置
41
+ * @Describe:
42
+ * @Author: Zsj
43
+ */
44
+ setConfig(serverConfig) {
45
+ this.serverConfig = serverConfig;
46
+ return this.serverConfig;
47
+ }
48
+
49
+ /**
50
+ * @Title: 发布前检查环境和参数是否正确
51
+ * @Describe:
52
+ * @Author: Zsj
53
+ */
54
+ async check() {
55
+ const serverConfigMap = await getServerConfig(this.projectName);
56
+
57
+ if (!serverConfigMap) {
58
+ console.log('未找到发布脚本!');
59
+ return false;
60
+ }
61
+
62
+ cd(this.projectRelativePath);
63
+
64
+ // const path = await $`pwd`;
65
+
66
+ // windows 下有问题
67
+ // this.projectAbsolutePath = path.stdout.replace('\n','');
68
+
69
+ this.projectAbsolutePath = process.cwd();
70
+
71
+ if (!(await isWorkingTreeClean())) {
72
+ console.log('工作区不干净, 请先提交代码');
73
+ return false;
74
+ }
75
+
76
+ const { success, message } = await checkPkgVersion(checkPackages);
77
+
78
+ if (!success) {
79
+ console.log(message);
80
+ return false;
81
+ }
82
+
83
+ let serverConfig = this.setConfig(serverConfigMap[this.env]);
84
+
85
+ // 选择release默认用国内cn服务器
86
+ if (this.env === 'release') {
87
+ serverConfig = this.setConfig(serverConfigMap.cn[this.env]);
88
+ }
89
+
90
+ if (this.env === 'prod') {
91
+ serverConfig = this.setConfig(serverConfigMap['prod3']);
92
+ // serverConfig.privateKey = fs.readFileSync(
93
+ // path.join(process.env.HOME, '.ssh', 'id_rsa'),
94
+ // );
95
+ }
96
+
97
+ if (
98
+ this.env === 'prod' &&
99
+ [
100
+ 'xzero',
101
+ 'saas_admin',
102
+ 'saas_shop',
103
+ 'saas_shop_pos',
104
+ 'saas_kds',
105
+ 'saas_ads',
106
+ 'saas_home',
107
+ ].includes(this.projectName)
108
+ ) {
109
+ serverConfig = serverConfigMap.aws.service[this.env];
110
+ serverConfig.privateKey = fs.readFileSync(serverConfig.privateKey);
111
+ }
112
+
113
+ // pisell2.0正式环境使用亚马逊服务器
114
+ if (this.env === 'prod' && ['admin', 'docs'].includes(this.projectName)) {
115
+ serverConfig = serverConfigMap.aws.service[this.env];
116
+ serverConfig.privateKey = fs.readFileSync('../../../pem/pisell-pro.pem');
117
+ }
118
+
119
+ console.log(serverConfig, 'serverConfig');
120
+
121
+ this.setConfig(serverConfig);
122
+
123
+ if (!serverConfig) {
124
+ console.log('您当前没有权限!');
125
+ return false;
126
+ }
127
+
128
+ console.log('当前主项目分支', await getGitCurrentBranch());
129
+
130
+ return true;
131
+ }
132
+
133
+ /**
134
+ * @Title: 更新项目中version 并加入changelog
135
+ * @Describe:
136
+ * @Author: Zsj
137
+ */
138
+ async updateVersion() {
139
+ if (this.env === 'prod') {
140
+ await $`npm version ${this.version} -m "%s ${this.changelog}"`;
141
+ let { version } = await fs.readJson('./package.json');
142
+ this.currentVersion = version;
143
+ }
144
+ if (this.env !== 'prod') {
145
+ await $`npm version ${this.version} --no-git-tag-version`;
146
+ await $`git add package.json`;
147
+ let { version } = await fs.readJson('./package.json');
148
+ this.currentVersion = version;
149
+ await $`git commit -m "chore: ${this.currentVersion} ${this.changelog}"`;
150
+ }
151
+ return this.currentVersion;
152
+ }
153
+
154
+ /**
155
+ * @Title: 根据env执行打包
156
+ * @Describe:
157
+ * @Author: Zsj
158
+ */
159
+ async build() {
160
+ await $`npm run build:${this.env}`;
161
+ }
162
+
163
+ /**
164
+ * @Title: 压缩dist文件为zip
165
+ * @Describe:
166
+ * @Author: Zsj
167
+ */
168
+ async compress() {
169
+ return new Promise((resolve, reject) => {
170
+ const __dirname = process.cwd();
171
+ const zipFile = path.resolve(__dirname, `${this.currentVersion}.zip`);
172
+ const originFilePath = path.resolve(__dirname, 'dist');
173
+ const output = fs.createWriteStream(zipFile);
174
+ const archive = archiver('zip', {
175
+ zlib: { level: 9 }, // 设置压缩级别
176
+ });
177
+ archive.on('error', function (err) {
178
+ reject(err);
179
+ });
180
+
181
+ output.on('close', function () {
182
+ resolve(true);
183
+ });
184
+
185
+ archive.pipe(output);
186
+
187
+ archive.directory(originFilePath, '/dist'); //将srcPath路径对应的内容添加到zip包中/dist路径
188
+
189
+ archive.finalize();
190
+ });
191
+ }
192
+
193
+ /**
194
+ * @Title: 连接服务器
195
+ * @Describe:
196
+ * @Author: Zsj
197
+ */
198
+ async connectServer() {
199
+ if (!this.serverConfig) {
200
+ console.log('未找到发布配置!');
201
+ return null;
202
+ }
203
+ this.conn = await connectServer(this.serverConfig);
204
+ return this.conn;
205
+ }
206
+
207
+ /**
208
+ * @Title: 本地zip文件上传到服务器
209
+ * @Describe:
210
+ * @Author: Zsj
211
+ */
212
+ async serverUpload() {
213
+ const localPath = path.resolve(
214
+ this.projectAbsolutePath,
215
+ `${this.currentVersion}.zip`
216
+ );
217
+ const remotePath = `/tmp/${this.projectName}-${this.currentVersion}.zip`;
218
+ return await serverUpload(this.conn, { localPath, remotePath });
219
+ }
220
+
221
+ /**
222
+ * @Title: 服务器中解压文件
223
+ * @Describe:
224
+ * @Author: Zsj
225
+ */
226
+ async serverUnpack() {
227
+ return await serverUnpack(this.conn, {
228
+ path: this.outPath,
229
+ fileName: `${this.currentVersion}`,
230
+ fullFileName: `${this.projectName}-${this.currentVersion}.zip`,
231
+ changelog: this.changelog,
232
+ env: this.env,
233
+ });
234
+ }
235
+
236
+ /**
237
+ * @Title: 删除本地zip文件
238
+ * @Describe:
239
+ * @Author: Zsj
240
+ */
241
+ deleteLocalZip() {
242
+ return $`rm -rf ${this.currentVersion}.zip`;
243
+ }
244
+
245
+ /**
246
+ * @Title: 断开服务连接
247
+ * @Describe:
248
+ * @Author: Zsj
249
+ */
250
+ async disconnectServer() {
251
+ return await this.conn.end();
252
+ }
253
+ }
254
+
255
+ export default UploadCode;