@jayfong/x-server 2.39.2 → 2.40.0
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.
|
@@ -21,6 +21,7 @@ class BuildUtil {
|
|
|
21
21
|
const tempDir = _nodePath.default.join(options.cwd, 'temp');
|
|
22
22
|
const distMainFile = _nodePath.default.join(distDir, 'main.js');
|
|
23
23
|
const distPkgFile = _nodePath.default.join(distDir, 'package.json');
|
|
24
|
+
const distNvmrcFile = _nodePath.default.join(distDir, '.nvmrc');
|
|
24
25
|
const distPm2File = _nodePath.default.join(distDir, 'pm2.config.js');
|
|
25
26
|
const distNoInstallFile = _nodePath.default.join(distDir, 'no_install.lock');
|
|
26
27
|
const distBundleFile = _nodePath.default.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
@@ -156,9 +157,11 @@ class BuildUtil {
|
|
|
156
157
|
};
|
|
157
158
|
await _fsExtra.default.writeJSON(distPkgFile, distPkgContent);
|
|
158
159
|
|
|
159
|
-
//
|
|
160
|
-
const
|
|
161
|
-
|
|
160
|
+
// .nvmrc
|
|
161
|
+
const nvmrcFile = _nodePath.default.join(options.cwd, '.nvmrc');
|
|
162
|
+
if (await _fsExtra.default.pathExists(nvmrcFile)) {
|
|
163
|
+
await _fsExtra.default.writeFile(distNvmrcFile, await _fsExtra.default.readFile(nvmrcFile));
|
|
164
|
+
}
|
|
162
165
|
|
|
163
166
|
// 写入 pm2 配置
|
|
164
167
|
await _fsExtra.default.writeFile(distPm2File, (0, _vtils.dedent)`
|
|
@@ -166,10 +169,6 @@ class BuildUtil {
|
|
|
166
169
|
apps: [
|
|
167
170
|
{
|
|
168
171
|
name: ${JSON.stringify(pkgContent.name)},
|
|
169
|
-
...(${JSON.stringify(nodeVersion ? {
|
|
170
|
-
interpreter: 'fnm',
|
|
171
|
-
interpreter_args: ['exec', '--using', nodeVersion, 'node']
|
|
172
|
-
} : {})}),
|
|
173
172
|
script: './main.js',
|
|
174
173
|
...(process.env.PM2_MEMORY ? { max_memory_restart: process.env.PM2_MEMORY } : {}),
|
|
175
174
|
},
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.DeployUtil = void 0;
|
|
6
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
6
|
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var
|
|
7
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
8
|
var _nodeSsh = require("node-ssh");
|
|
9
|
+
var _vtils = require("vtils");
|
|
10
10
|
class DeployUtil {
|
|
11
11
|
static async deploy(options) {
|
|
12
12
|
const pkgContent = await _fsExtra.default.readJson(_path.default.join(options.cwd, 'package.json'));
|
|
@@ -38,6 +38,7 @@ class DeployUtil {
|
|
|
38
38
|
tar -zxvf ${remoteAppFile} -C ${appDir}
|
|
39
39
|
cd ${appDir}/dist
|
|
40
40
|
[ -f no_install.lock ] && yarn_disable_self_update_check=true tyn
|
|
41
|
+
[ -f .nvmrc ] && eval "$(fnm env)"
|
|
41
42
|
${options.cmd || ''}
|
|
42
43
|
${options.memory ? `PM2_MEMORY=${options.memory} ` : ''}pm2 startOrReload pm2.config.js
|
|
43
44
|
`, {
|
package/lib/_cjs/services/log.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.LogService = void 0;
|
|
6
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
6
|
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var
|
|
7
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
8
|
var _vtils = require("vtils");
|
|
9
|
+
var _date = require("vtils/date");
|
|
10
10
|
var _x = require("../x");
|
|
11
11
|
class LogService {
|
|
12
12
|
constructor() {
|
|
@@ -27,21 +27,25 @@ class LogService {
|
|
|
27
27
|
get logFile() {
|
|
28
28
|
return this.getLogFile(new Date());
|
|
29
29
|
}
|
|
30
|
-
parseLogLineText(text) {
|
|
30
|
+
parseLogLineText(text, keys) {
|
|
31
31
|
const [time, level, title, ...desc] = text.split(this.separator);
|
|
32
32
|
return {
|
|
33
33
|
time: time,
|
|
34
34
|
level: level,
|
|
35
35
|
title: title,
|
|
36
|
-
desc: desc.reduce((res, item) => {
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
desc: desc.reduce((res, item, index) => {
|
|
37
|
+
if (keys) {
|
|
38
|
+
res[keys[index]] = item;
|
|
39
|
+
} else {
|
|
40
|
+
const i = item.indexOf(':');
|
|
41
|
+
res[item.substring(0, i)] = item.substring(i + 1);
|
|
42
|
+
}
|
|
39
43
|
return res;
|
|
40
44
|
}, {})
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
log(payload) {
|
|
44
|
-
this.getLogWriter(this.logFile).write(`${[(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...Object.keys(payload.desc
|
|
48
|
+
this.getLogWriter(this.logFile).write(`${[(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...(!payload.desc ? [] : Array.isArray(payload.desc) ? payload.desc : Object.keys(payload.desc).map(key => `${key}:${payload.desc[key]}`))].join(this.separator).replace(/[\r\n]+/g, ' ')}\n`);
|
|
45
49
|
}
|
|
46
50
|
info(title, desc) {
|
|
47
51
|
this.log({
|
package/lib/cli/build_util.js
CHANGED
|
@@ -15,6 +15,7 @@ export class BuildUtil {
|
|
|
15
15
|
const tempDir = path.join(options.cwd, 'temp');
|
|
16
16
|
const distMainFile = path.join(distDir, 'main.js');
|
|
17
17
|
const distPkgFile = path.join(distDir, 'package.json');
|
|
18
|
+
const distNvmrcFile = path.join(distDir, '.nvmrc');
|
|
18
19
|
const distPm2File = path.join(distDir, 'pm2.config.js');
|
|
19
20
|
const distNoInstallFile = path.join(distDir, 'no_install.lock');
|
|
20
21
|
const distBundleFile = path.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
@@ -150,9 +151,11 @@ export class BuildUtil {
|
|
|
150
151
|
};
|
|
151
152
|
await fs.writeJSON(distPkgFile, distPkgContent);
|
|
152
153
|
|
|
153
|
-
//
|
|
154
|
-
const
|
|
155
|
-
|
|
154
|
+
// .nvmrc
|
|
155
|
+
const nvmrcFile = path.join(options.cwd, '.nvmrc');
|
|
156
|
+
if (await fs.pathExists(nvmrcFile)) {
|
|
157
|
+
await fs.writeFile(distNvmrcFile, await fs.readFile(nvmrcFile));
|
|
158
|
+
}
|
|
156
159
|
|
|
157
160
|
// 写入 pm2 配置
|
|
158
161
|
await fs.writeFile(distPm2File, dedent`
|
|
@@ -160,10 +163,6 @@ export class BuildUtil {
|
|
|
160
163
|
apps: [
|
|
161
164
|
{
|
|
162
165
|
name: ${JSON.stringify(pkgContent.name)},
|
|
163
|
-
...(${JSON.stringify(nodeVersion ? {
|
|
164
|
-
interpreter: 'fnm',
|
|
165
|
-
interpreter_args: ['exec', '--using', nodeVersion, 'node']
|
|
166
|
-
} : {})}),
|
|
167
166
|
script: './main.js',
|
|
168
167
|
...(process.env.PM2_MEMORY ? { max_memory_restart: process.env.PM2_MEMORY } : {}),
|
|
169
168
|
},
|
package/lib/cli/deploy_util.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
4
3
|
import { NodeSSH } from 'node-ssh';
|
|
4
|
+
import { dedent } from 'vtils';
|
|
5
5
|
export class DeployUtil {
|
|
6
6
|
static async deploy(options) {
|
|
7
7
|
const pkgContent = await fs.readJson(path.join(options.cwd, 'package.json'));
|
|
@@ -33,6 +33,7 @@ export class DeployUtil {
|
|
|
33
33
|
tar -zxvf ${remoteAppFile} -C ${appDir}
|
|
34
34
|
cd ${appDir}/dist
|
|
35
35
|
[ -f no_install.lock ] && yarn_disable_self_update_check=true tyn
|
|
36
|
+
[ -f .nvmrc ] && eval "$(fnm env)"
|
|
36
37
|
${options.cmd || ''}
|
|
37
38
|
${options.memory ? `PM2_MEMORY=${options.memory} ` : ''}pm2 startOrReload pm2.config.js
|
|
38
39
|
`, {
|
package/lib/services/log.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
2
|
export type LogServiceLevel = 'error' | 'info' | 'success';
|
|
3
|
+
export type LogServiceDesc = Record<string, any> | any[];
|
|
3
4
|
export type LogServicePayload = {
|
|
4
5
|
level: LogServiceLevel;
|
|
5
6
|
title: string;
|
|
6
|
-
desc?:
|
|
7
|
+
desc?: LogServiceDesc;
|
|
7
8
|
};
|
|
8
9
|
export type LogServicePayloadWithTime = LogServicePayload & {
|
|
9
10
|
time: string;
|
|
@@ -14,11 +15,11 @@ export declare class LogService implements BaseService {
|
|
|
14
15
|
getLogFile(date: Date): string;
|
|
15
16
|
private get logFile();
|
|
16
17
|
private getLogWriter;
|
|
17
|
-
parseLogLineText(text: string): LogServicePayloadWithTime;
|
|
18
|
+
parseLogLineText(text: string, keys?: string[]): LogServicePayloadWithTime;
|
|
18
19
|
private log;
|
|
19
|
-
info(title: string, desc?:
|
|
20
|
-
success(title: string, desc?:
|
|
21
|
-
error(title: string, desc?:
|
|
20
|
+
info(title: string, desc?: LogServiceDesc): void;
|
|
21
|
+
success(title: string, desc?: LogServiceDesc): void;
|
|
22
|
+
error(title: string, desc?: LogServiceDesc): void;
|
|
22
23
|
}
|
|
23
24
|
declare module '../x' {
|
|
24
25
|
interface X {
|
package/lib/services/log.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
4
3
|
import { memoize } from 'vtils';
|
|
4
|
+
import { formatDate } from 'vtils/date';
|
|
5
5
|
import { x } from "../x";
|
|
6
6
|
export class LogService {
|
|
7
7
|
constructor() {
|
|
@@ -22,21 +22,25 @@ export class LogService {
|
|
|
22
22
|
get logFile() {
|
|
23
23
|
return this.getLogFile(new Date());
|
|
24
24
|
}
|
|
25
|
-
parseLogLineText(text) {
|
|
25
|
+
parseLogLineText(text, keys) {
|
|
26
26
|
const [time, level, title, ...desc] = text.split(this.separator);
|
|
27
27
|
return {
|
|
28
28
|
time: time,
|
|
29
29
|
level: level,
|
|
30
30
|
title: title,
|
|
31
|
-
desc: desc.reduce((res, item) => {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
desc: desc.reduce((res, item, index) => {
|
|
32
|
+
if (keys) {
|
|
33
|
+
res[keys[index]] = item;
|
|
34
|
+
} else {
|
|
35
|
+
const i = item.indexOf(':');
|
|
36
|
+
res[item.substring(0, i)] = item.substring(i + 1);
|
|
37
|
+
}
|
|
34
38
|
return res;
|
|
35
39
|
}, {})
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
log(payload) {
|
|
39
|
-
this.getLogWriter(this.logFile).write(`${[formatDate(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...Object.keys(payload.desc
|
|
43
|
+
this.getLogWriter(this.logFile).write(`${[formatDate(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...(!payload.desc ? [] : Array.isArray(payload.desc) ? payload.desc : Object.keys(payload.desc).map(key => `${key}:${payload.desc[key]}`))].join(this.separator).replace(/[\r\n]+/g, ' ')}\n`);
|
|
40
44
|
}
|
|
41
45
|
info(title, desc) {
|
|
42
46
|
this.log({
|