@pisell/common 1.0.19 → 1.0.21

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.
@@ -1,6 +1,6 @@
1
1
  const outPathMap = {
2
2
  my_pisel_shop: {
3
- prod: '../data/release/project/mypisel_shop',
3
+ prod: '../data/release/project/my_pisel_shop',
4
4
  release: '../data/release/project/my_pisel_shop',
5
5
  pre: '../data/release/project/my_pisel_shop',
6
6
  },
@@ -9,6 +9,30 @@ const outPathMap = {
9
9
  release: '../data/release/project/pisell_v2',
10
10
  pre: '../data/release/project/pisell_v2',
11
11
  },
12
+ my_pisel_pc_v2: {
13
+ prod: '../data/release/project/my_pisel_pc_v2',
14
+ release: '../data/release/project/my_pisel_pc_v2',
15
+ pre: '../data/release/project/my_pisel_pc_v2',
16
+ },
17
+ my_pisel_h5_v2: {
18
+ prod: '../data/release/project/my_pisel_h5_v2',
19
+ release: '../data/release/project/my_pisel_h5_v2',
20
+ pre: '../data/release/project/my_pisel_h5_v2',
21
+ },
12
22
  };
13
23
 
14
- export { outPathMap };
24
+ const isSsrMap = {
25
+ my_pisel_shop: false,
26
+ admin: false,
27
+ my_pisel_pc_v2: true,
28
+ my_pisel_h5_v2: true,
29
+ };
30
+
31
+ const checkPackages = [
32
+ '@pisell/date-picker',
33
+ '@pisell/lowcode-renderer',
34
+ '@pisell/common',
35
+ '@pisell/utils',
36
+ ];
37
+
38
+ export { outPathMap, isSsrMap, checkPackages };
@@ -1,4 +1,4 @@
1
- import { outPathMap } from '../constants/index.js';
1
+ import { isSsrMap, outPathMap } from '../constants/index.js';
2
2
  import {
3
3
  connectServer,
4
4
  getServerConfig,
@@ -19,6 +19,8 @@ class Release {
19
19
 
20
20
  this.conn = conn;
21
21
  this.outPath = outPathMap[this.projectName][this.env];
22
+ // 是否是ssr项目
23
+ this.isSSR = isSsrMap[this.projectName];
22
24
  }
23
25
 
24
26
  /**
@@ -68,6 +70,7 @@ class Release {
68
70
  return await releaseProject(this.conn, {
69
71
  path: this.outPath,
70
72
  fileName: `${this.version}`,
73
+ isSSR: this.isSSR,
71
74
  });
72
75
  }
73
76
 
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env zx
2
2
  import inquirer from 'inquirer';
3
3
  import 'zx/globals';
4
+ import { uploadStaticToOSS } from '../aws/index.js';
4
5
  import Release from '../release/release.js';
5
6
  import {
6
7
  getCurrentProjectName,
@@ -58,6 +59,15 @@ const inquirerResult = () => {
58
59
  { value: false, name: '只上传' },
59
60
  ],
60
61
  },
62
+ {
63
+ type: 'list',
64
+ message: '是否执行build打包',
65
+ name: 'whether_build',
66
+ choices: [
67
+ { value: true, name: '执行打包' },
68
+ { value: false, name: '不执行打包,使用项目根目录/dist文件夹' },
69
+ ],
70
+ },
61
71
  {
62
72
  type: 'confirm',
63
73
  message: '确认信息无误',
@@ -119,9 +129,26 @@ async function init() {
119
129
  });
120
130
  console.log(result, 'result');
121
131
  try {
122
- console.log('开始打包');
123
- await uploadCode.build();
124
- console.log('✅ 打包完成');
132
+ // 选择false时直接使用本地/dist目录 节省二次构建时间
133
+ if (res.whether_build) {
134
+ console.log('开始打包');
135
+ await uploadCode.build();
136
+ console.log('✅ 打包完成');
137
+ } else {
138
+ console.log('使用本地/dist');
139
+ }
140
+
141
+ if (res.env === 'prod') {
142
+ let _fileName = res.project.fileName;
143
+ if (res.env === 'pre') {
144
+ _fileName = 'pre_' + _fileName;
145
+ }
146
+ if (_fileName === 'admin') {
147
+ _fileName = 'my_pisell_v2'
148
+ }
149
+ // 上传oss
150
+ await uploadStaticToOSS(_fileName);
151
+ }
125
152
 
126
153
  console.log('开始压缩');
127
154
  await uploadCode.compress();
@@ -1,6 +1,6 @@
1
1
  import archiver from "archiver";
2
2
  import path from "path";
3
- import { outPathMap } from "../constants/index.js";
3
+ import { isSsrMap, outPathMap } from "../constants/index.js";
4
4
  import {
5
5
  connectServer,
6
6
  getGitCurrentBranch,
@@ -29,6 +29,8 @@ class UploadCode {
29
29
  this.projectAbsolutePath = "";
30
30
  this.conn = null;
31
31
  this.serverConfig = null;
32
+ // 是否是ssr项目
33
+ this.isSSR = isSsrMap[this.projectName];
32
34
 
33
35
  this.outPath = outPathMap[this.projectName][this.env];
34
36
  }
@@ -78,9 +80,10 @@ class UploadCode {
78
80
  }
79
81
 
80
82
  if (this.env === "prod") {
81
- serverConfig.privateKey = fs.readFileSync(
82
- path.join(process.env.HOME, ".ssh", "id_rsa")
83
- );
83
+ serverConfig = this.setConfig(serverConfigMap['prod3']);
84
+ // serverConfig.privateKey = fs.readFileSync(
85
+ // path.join(process.env.HOME, '.ssh', 'id_rsa'),
86
+ // );
84
87
  }
85
88
 
86
89
  // pisell2.0正式环境使用亚马逊服务器
@@ -1,4 +1,5 @@
1
1
  import * as dotenv from 'dotenv';
2
+ import npmCheck from 'npm-check';
2
3
  import path from 'path';
3
4
  import ssh2 from 'ssh2';
4
5
 
@@ -156,7 +157,7 @@ const serverUnpack = (conn, { path, fileName, fullFileName, changelog }) => {
156
157
  * @Describe:
157
158
  * @Author: Zsj
158
159
  */
159
- const releaseProject = (conn, { path, fileName }) => {
160
+ const releaseProject = (conn, { path, fileName, isSSR }) => {
160
161
  return new Promise((resolve, reject) => {
161
162
  conn.shell((err, stream) => {
162
163
  if (err) {
@@ -175,6 +176,7 @@ const releaseProject = (conn, { path, fileName }) => {
175
176
  rm -rf master
176
177
  cp -R next-master master
177
178
  rm -rf next-master
179
+ ${isSSR ? 'pm2 restart server.js' : ''}
178
180
  exit
179
181
  `,
180
182
  // 打开到path
@@ -225,6 +227,10 @@ const getCurrentProjectName = () => {
225
227
  return loadJSON(path.join(process.cwd(), './package.json')).name;
226
228
  };
227
229
 
230
+ const getCurrentProjectPkg = () => {
231
+ return loadJSON(path.join(process.cwd(), './package.json'));
232
+ };
233
+
228
234
  const loadJSON = (path) => JSON.parse(fs.readFileSync(path));
229
235
 
230
236
  const getCurrentUserName = async () => {
@@ -243,6 +249,21 @@ const createFeishuMessageContent = (contentArr) => {
243
249
  );
244
250
  };
245
251
 
252
+ // 获取除了此pkg的包
253
+ const getNonExcludedPackages = (excludedPackages) => {
254
+ const packageData = getCurrentProjectPkg();
255
+
256
+ const dependencies = {
257
+ ...packageData.dependencies,
258
+ ...packageData.devDependencies,
259
+ };
260
+
261
+ const nonExcludedPackages = Object.keys(dependencies).filter(
262
+ (packageName) => !excludedPackages.includes(packageName),
263
+ );
264
+ return nonExcludedPackages;
265
+ };
266
+
246
267
  const sendWebhook = async ({ title, content }) => {
247
268
  const contentStr = createFeishuMessageContent(content);
248
269
  if (!dotenv.config()?.parsed?.WEBHOOK) return;
@@ -259,6 +280,29 @@ const sendWebhook = async ({ title, content }) => {
259
280
  return await response.json();
260
281
  };
261
282
 
283
+ const checkPkgVersion = async (checkPackages) => {
284
+ const currentState = await npmCheck({
285
+ skipUnused: true,
286
+ ignore: getNonExcludedPackages(checkPackages),
287
+ });
288
+
289
+ const pkgs = currentState.get('packages');
290
+
291
+ const wrongPkg = pkgs.filter((item) => {
292
+ return checkPackages.includes(item.moduleName) && item.mismatch;
293
+ });
294
+ const errorMessage = wrongPkg.reduce((p, c) => {
295
+ return `${p}
296
+ ${c.moduleName}本地版本${c.installed}需升级至${c.packageJson}
297
+ `;
298
+ }, '');
299
+ const isWrongVersion = wrongPkg.length;
300
+ return {
301
+ success: !isWrongVersion,
302
+ message: errorMessage,
303
+ };
304
+ };
305
+
262
306
  export {
263
307
  isWorkingTreeClean,
264
308
  getServerConfig,
@@ -272,4 +316,5 @@ export {
272
316
  loadJSON,
273
317
  getCurrentUserName,
274
318
  sendWebhook,
319
+ checkPkgVersion,
275
320
  };
package/es/index.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,wBAAkB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,wBAAkB"}