@pixui-dev/pxw 0.1.35 → 0.1.37
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/bin/pxw.js +56 -56
- package/bin/wpbuild.js +10 -10
- package/config/daemon.js +157 -157
- package/config/default.conf +20 -20
- package/config/devops.js +550 -550
- package/config/h5es.js +14 -14
- package/config/index.html +183 -183
- package/config/pfbs.js +259 -259
- package/config/util.js +143 -143
- package/config/webpack.js +325 -325
- package/lib/assets/check.html +62 -62
- package/lib/assets/preact.js +4354 -4354
- package/lib/check/main.less +62 -62
- package/lib/check/main.tsx +41 -41
- package/lib/check/tool.js +3 -3
- package/lib/check/util.tsx +110 -110
- package/lib/grpc-web/dist/ChunkParser.js +117 -117
- package/lib/grpc-web/dist/Code.js +58 -58
- package/lib/grpc-web/dist/client.js +299 -299
- package/lib/grpc-web/dist/debug.js +16 -16
- package/lib/grpc-web/dist/detach.js +7 -7
- package/lib/grpc-web/dist/index.js +29 -29
- package/lib/grpc-web/dist/invoke.js +32 -32
- package/lib/grpc-web/dist/message.js +3 -3
- package/lib/grpc-web/dist/metadata.js +5 -5
- package/lib/grpc-web/dist/service.js +3 -3
- package/lib/grpc-web/dist/transports/Transport.js +15 -15
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
- package/lib/grpc-web/dist/transports/http/http.js +15 -15
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
- package/lib/grpc-web/dist/typings/client.d.ts +25 -25
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
- package/lib/grpc-web/dist/typings/index.d.ts +45 -45
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
- package/lib/grpc-web/dist/typings/message.d.ts +8 -8
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
- package/lib/grpc-web/dist/typings/service.d.ts +16 -16
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
- package/lib/grpc-web/dist/typings/util.d.ts +2 -2
- package/lib/grpc-web/dist/unary.js +44 -44
- package/lib/grpc-web/dist/util.js +11 -11
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
- package/lib/grpcTransport/PixLuaTransport.ts +82 -82
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1756 -1756
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1851 -1851
- package/lib/h5es-types/v3.5.6/h5es.d.ts +1911 -1911
- package/lib/pi_component/tinyList/tinyList.js +483 -483
- package/lib/pi_component/tinyList/tinyList.tsx +517 -517
- package/lib/preact-router.js +395 -395
- package/lib/preact.js +4355 -4355
- package/lib/preact.tq.js +4385 -4385
- package/lib/react-window/src/FixedSizeGrid.js +172 -172
- package/lib/react-window/src/FixedSizeList.js +91 -91
- package/lib/react-window/src/VariableSizeGrid.js +329 -329
- package/lib/react-window/src/VariableSizeList.js +231 -231
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
- package/lib/react-window/src/__tests__/areEqual.js +28 -28
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
- package/lib/react-window/src/areEqual.js +13 -13
- package/lib/react-window/src/createGridComponent.js +657 -657
- package/lib/react-window/src/createListComponent.js +574 -574
- package/lib/react-window/src/domHelpers.js +69 -69
- package/lib/react-window/src/index.js +9 -9
- package/lib/react-window/src/shallowDiffers.js +17 -17
- package/lib/react-window/src/shouldComponentUpdate.js +11 -11
- package/lib/react-window/src/test.js.flow +382 -382
- package/lib/react-window/src/timer.js +36 -36
- package/lib/types/dom.ts +17 -17
- package/lib/types/ext.d.ts +75 -75
- package/lib/types/preact/css.d.ts +7478 -7476
- package/lib/types/preact/index.d.ts +340 -340
- package/lib/types/preact/internal.d.ts +94 -94
- package/lib/types/preact/jsx.d.ts +368 -368
- package/lib/types/preact-router/index.d.ts +84 -84
- package/package.json +127 -127
- package/scripts/pack.js +40 -40
- package/scripts/postinstall.js +12 -12
- package/scripts/run-pxw.js +19 -19
- package/tsconfig.json +30 -30
package/bin/pxw.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
let path = require('path');
|
|
3
|
-
let http = require('http');
|
|
4
|
-
let util = require('../config/util');
|
|
5
|
-
let pfbs = require('../config/pfbs');
|
|
6
|
-
let webpack = require('../config/webpack');
|
|
7
|
-
let argv = require('yargs').argv;
|
|
8
|
-
|
|
9
|
-
let runInWindows = process.platform == 'win32';
|
|
10
|
-
let pr = path.resolve;
|
|
11
|
-
|
|
12
|
-
let rootDir = pr(__dirname, '../');
|
|
13
|
-
let projectConfig = util.loadProjectConfig();
|
|
14
|
-
let appPort = parseInt(process.env['PXW_APP_PORT']) || projectConfig.port || 8001;
|
|
15
|
-
|
|
16
|
-
process
|
|
17
|
-
.on('unhandledRejection', (err) => {
|
|
18
|
-
console.log('unhandledRejection', err);
|
|
19
|
-
})
|
|
20
|
-
.on('uncaughtException', (err) => {
|
|
21
|
-
console.log('uncaughtException', err);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
async function main() {
|
|
25
|
-
let express = require('express');
|
|
26
|
-
|
|
27
|
-
let app = express();
|
|
28
|
-
let server = http.createServer(app);
|
|
29
|
-
|
|
30
|
-
app.use(express.json());
|
|
31
|
-
app.use(pfbs.getMiddleware());
|
|
32
|
-
|
|
33
|
-
let { notifyAppReload } = await require('../config/devops').setupDevops(server, app);
|
|
34
|
-
|
|
35
|
-
if (!argv['no-webpack']) app.use(webpack.devServer.getMiddleware()(appPort, notifyAppReload));
|
|
36
|
-
|
|
37
|
-
app.use(function (err, req, res, next) {
|
|
38
|
-
console.error(err);
|
|
39
|
-
res.status(500).send('Internal Serverless Error');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
server.listen(appPort, '0.0.0.0', () => {
|
|
43
|
-
let ipList = [];
|
|
44
|
-
util.getLocalIP().forEach((ip) => {
|
|
45
|
-
console.log(`Server start on http://${ip}:${appPort}`);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let isDaemonMode = argv.d;
|
|
51
|
-
if (isDaemonMode) {
|
|
52
|
-
require('../config/daemon').start(main);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
main();
|
|
56
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
let path = require('path');
|
|
3
|
+
let http = require('http');
|
|
4
|
+
let util = require('../config/util');
|
|
5
|
+
let pfbs = require('../config/pfbs');
|
|
6
|
+
let webpack = require('../config/webpack');
|
|
7
|
+
let argv = require('yargs').argv;
|
|
8
|
+
|
|
9
|
+
let runInWindows = process.platform == 'win32';
|
|
10
|
+
let pr = path.resolve;
|
|
11
|
+
|
|
12
|
+
let rootDir = pr(__dirname, '../');
|
|
13
|
+
let projectConfig = util.loadProjectConfig();
|
|
14
|
+
let appPort = parseInt(process.env['PXW_APP_PORT']) || projectConfig.port || 8001;
|
|
15
|
+
|
|
16
|
+
process
|
|
17
|
+
.on('unhandledRejection', (err) => {
|
|
18
|
+
console.log('unhandledRejection', err);
|
|
19
|
+
})
|
|
20
|
+
.on('uncaughtException', (err) => {
|
|
21
|
+
console.log('uncaughtException', err);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
let express = require('express');
|
|
26
|
+
|
|
27
|
+
let app = express();
|
|
28
|
+
let server = http.createServer(app);
|
|
29
|
+
|
|
30
|
+
app.use(express.json());
|
|
31
|
+
app.use(pfbs.getMiddleware());
|
|
32
|
+
|
|
33
|
+
let { notifyAppReload } = await require('../config/devops').setupDevops(server, app);
|
|
34
|
+
|
|
35
|
+
if (!argv['no-webpack']) app.use(webpack.devServer.getMiddleware()(appPort, notifyAppReload));
|
|
36
|
+
|
|
37
|
+
app.use(function (err, req, res, next) {
|
|
38
|
+
console.error(err);
|
|
39
|
+
res.status(500).send('Internal Serverless Error');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
server.listen(appPort, '0.0.0.0', () => {
|
|
43
|
+
let ipList = [];
|
|
44
|
+
util.getLocalIP().forEach((ip) => {
|
|
45
|
+
console.log(`Server start on http://${ip}:${appPort}`);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let isDaemonMode = argv.d;
|
|
51
|
+
if (isDaemonMode) {
|
|
52
|
+
require('../config/daemon').start(main);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
main();
|
|
56
|
+
}
|
package/bin/wpbuild.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const webpack = require('webpack');
|
|
2
|
-
|
|
3
|
-
let config = require('../config/webpack');
|
|
4
|
-
webpack(config, (err, stats) => {
|
|
5
|
-
if (err || stats.hasErrors()) {
|
|
6
|
-
console.log(err);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
console.log('done');
|
|
10
|
-
});
|
|
1
|
+
const webpack = require('webpack');
|
|
2
|
+
|
|
3
|
+
let config = require('../config/webpack');
|
|
4
|
+
webpack(config, (err, stats) => {
|
|
5
|
+
if (err || stats.hasErrors()) {
|
|
6
|
+
console.log(err);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
console.log('done');
|
|
10
|
+
});
|
package/config/daemon.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
let fs = require('fs');
|
|
2
|
-
let cp = require('child_process');
|
|
3
|
-
let path = require('path');
|
|
4
|
-
let http = require('http');
|
|
5
|
-
let os = require('os');
|
|
6
|
-
let util = require('./util');
|
|
7
|
-
let pfbs = require('./pfbs');
|
|
8
|
-
let webpack = require('./webpack');
|
|
9
|
-
let argv = require('yargs').argv;
|
|
10
|
-
|
|
11
|
-
let runInWindows = process.platform == 'win32';
|
|
12
|
-
let pr = path.resolve;
|
|
13
|
-
let log = console.log;
|
|
14
|
-
log = () => {};
|
|
15
|
-
|
|
16
|
-
let rootDir = pr(__dirname, '../');
|
|
17
|
-
let projectConfig = util.loadProjectConfig();
|
|
18
|
-
|
|
19
|
-
let isDaemonMode = argv.d;
|
|
20
|
-
|
|
21
|
-
function restart() {
|
|
22
|
-
const scriptPath = process.argv[1];
|
|
23
|
-
let removeArgs = { '--fg': 1 };
|
|
24
|
-
let args = process.argv.slice(2);
|
|
25
|
-
args = args.filter((v) => !removeArgs[v]);
|
|
26
|
-
const subprocess = cp.spawn(process.execPath, [scriptPath, ...args], {
|
|
27
|
-
detached: true,
|
|
28
|
-
windowsHide: true,
|
|
29
|
-
});
|
|
30
|
-
subprocess.unref();
|
|
31
|
-
process.exit();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function watchSelf() {
|
|
35
|
-
//可以通过环境变量设置是否要监视重启
|
|
36
|
-
let restartWatchFile = process.env['PXW_WATCHFILE'];
|
|
37
|
-
if (restartWatchFile == 'none') return;
|
|
38
|
-
if (!restartWatchFile) restartWatchFile = __filename;
|
|
39
|
-
restartWatchFile = pr(restartWatchFile);
|
|
40
|
-
console.log('watchfile:', restartWatchFile);
|
|
41
|
-
let chokidar = require('chokidar');
|
|
42
|
-
let watcher = chokidar.watch(restartWatchFile, { ignored: /^\./, persistent: true });
|
|
43
|
-
watcher
|
|
44
|
-
.on('change', function (path) {
|
|
45
|
-
console.log(`pid[${process.pid}] observing '${path}' changed, will restart!`);
|
|
46
|
-
restart();
|
|
47
|
-
})
|
|
48
|
-
.on('error', function (error) {
|
|
49
|
-
console.error('watchSelf error:', error);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports.start = function (main) {
|
|
54
|
-
//默认将log重定向到文件,不然在restart后会丢失
|
|
55
|
-
let logFile = pr(`.cache/app${runInWindows ? '.win' : ''}.log`);
|
|
56
|
-
if (!fs.existsSync(path.dirname(logFile))) fs.mkdirSync(path.dirname(logFile));
|
|
57
|
-
let oldWrite = process.stdout.write.bind(process.stdout);
|
|
58
|
-
var access = fs.createWriteStream(logFile, { flags: 'a' });
|
|
59
|
-
if (!process.env['PXW_NOREDIRECT_LOG']) {
|
|
60
|
-
process.stdout.write = process.stderr.write = access.write.bind(access);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let checkBinString = 'pxw/bin/pxw.js';
|
|
64
|
-
let checkCmd =
|
|
65
|
-
process.platform == 'win32' //
|
|
66
|
-
? 'wmic /OUTPUT:STDOUT process get processid,commandline'
|
|
67
|
-
: `ps -ef|grep "node"|grep "${checkBinString.replace(/(.)/, '[$1]')}"`; //第一个字符包在[]里可以避免grep命令自身出现在结果里
|
|
68
|
-
|
|
69
|
-
console.log(`\n*** pxw run: ${new Date().toLocaleString()} ***\npid[${process.pid}] check singleton:`, checkCmd);
|
|
70
|
-
cp.exec(checkCmd, { windowsHide: true, maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => {
|
|
71
|
-
if (error) {
|
|
72
|
-
console.log('pgrep error', error);
|
|
73
|
-
// return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let cpid = process.pid.toString();
|
|
77
|
-
if (process.platform == 'win32') {
|
|
78
|
-
let psl = stdout.trim().split('\n');
|
|
79
|
-
// console.log(psl.splice(300));
|
|
80
|
-
|
|
81
|
-
for (let cmd of psl) {
|
|
82
|
-
cmd = cmd.replace(/\\/g, '/');
|
|
83
|
-
if ((cmd.indexOf('/node.exe') > 0 || cmd.indexOf('node') == 0) && cmd.indexOf(checkBinString) > 0) {
|
|
84
|
-
let info = cmd.trim().replace(/\s+/g, ' ').split(' ');
|
|
85
|
-
console.log('find', info, process.pid);
|
|
86
|
-
let tpid = info[info.length - 1];
|
|
87
|
-
let isSelf = tpid == cpid;
|
|
88
|
-
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
89
|
-
if (!isSelf) {
|
|
90
|
-
if (argv.me || argv.kill) {
|
|
91
|
-
cp.execSync('taskkill /F /PID ' + tpid);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (argv.kill) return;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
console.log('pgrep stdout\n', stdout);
|
|
103
|
-
let lines = stdout.trim().split('\n');
|
|
104
|
-
for (let line of lines) {
|
|
105
|
-
line = line
|
|
106
|
-
.trim()
|
|
107
|
-
.split(' ')
|
|
108
|
-
.filter((x) => !!x);
|
|
109
|
-
// console.log(line);
|
|
110
|
-
if (line.length > 5) {
|
|
111
|
-
let tpid = line[1];
|
|
112
|
-
let isSelf = tpid == cpid;
|
|
113
|
-
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
114
|
-
if (tpid && !isSelf) {
|
|
115
|
-
console.log(`found exist process:[${tpid}], cur[${process.pid}]`);
|
|
116
|
-
if ((argv.me || argv.kill) && !error) {
|
|
117
|
-
console.log(`force kill other process:[${tpid}]`);
|
|
118
|
-
try {
|
|
119
|
-
process.stdout.write('', () => {
|
|
120
|
-
cp.execSync('kill ' + tpid);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
console.log(e);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// cp.execSync('ps -ef|grep test/html/app.js', { stdio: 'inherit' });
|
|
129
|
-
// cp.execSync(`ps -ef|grep ${stdout}`, { stdio: 'inherit' });
|
|
130
|
-
return console.log('process already exist, pid:', tpid);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (argv.kill) return;
|
|
137
|
-
|
|
138
|
-
if (argv.fg || process.env.restart) {
|
|
139
|
-
if (argv.fg) {
|
|
140
|
-
oldWrite(`pid[${process.pid}] run in fg,log已重定向到 ${logFile} \n`);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
let rc = parseInt(process.env.restart);
|
|
144
|
-
process.env.restart = rc + 1;
|
|
145
|
-
console.log(`pid[${process.pid}] run in restart: ${rc}`);
|
|
146
|
-
}
|
|
147
|
-
main();
|
|
148
|
-
watchSelf();
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
console.log(`pid[${process.pid}] run in bg`);
|
|
152
|
-
oldWrite('pxtest-admin 默认后台运行,加--fg参数可前台运行,log已重定向到' + logFile + '\n');
|
|
153
|
-
process.env.restart = 1;
|
|
154
|
-
restart();
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
};
|
|
1
|
+
let fs = require('fs');
|
|
2
|
+
let cp = require('child_process');
|
|
3
|
+
let path = require('path');
|
|
4
|
+
let http = require('http');
|
|
5
|
+
let os = require('os');
|
|
6
|
+
let util = require('./util');
|
|
7
|
+
let pfbs = require('./pfbs');
|
|
8
|
+
let webpack = require('./webpack');
|
|
9
|
+
let argv = require('yargs').argv;
|
|
10
|
+
|
|
11
|
+
let runInWindows = process.platform == 'win32';
|
|
12
|
+
let pr = path.resolve;
|
|
13
|
+
let log = console.log;
|
|
14
|
+
log = () => {};
|
|
15
|
+
|
|
16
|
+
let rootDir = pr(__dirname, '../');
|
|
17
|
+
let projectConfig = util.loadProjectConfig();
|
|
18
|
+
|
|
19
|
+
let isDaemonMode = argv.d;
|
|
20
|
+
|
|
21
|
+
function restart() {
|
|
22
|
+
const scriptPath = process.argv[1];
|
|
23
|
+
let removeArgs = { '--fg': 1 };
|
|
24
|
+
let args = process.argv.slice(2);
|
|
25
|
+
args = args.filter((v) => !removeArgs[v]);
|
|
26
|
+
const subprocess = cp.spawn(process.execPath, [scriptPath, ...args], {
|
|
27
|
+
detached: true,
|
|
28
|
+
windowsHide: true,
|
|
29
|
+
});
|
|
30
|
+
subprocess.unref();
|
|
31
|
+
process.exit();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function watchSelf() {
|
|
35
|
+
//可以通过环境变量设置是否要监视重启
|
|
36
|
+
let restartWatchFile = process.env['PXW_WATCHFILE'];
|
|
37
|
+
if (restartWatchFile == 'none') return;
|
|
38
|
+
if (!restartWatchFile) restartWatchFile = __filename;
|
|
39
|
+
restartWatchFile = pr(restartWatchFile);
|
|
40
|
+
console.log('watchfile:', restartWatchFile);
|
|
41
|
+
let chokidar = require('chokidar');
|
|
42
|
+
let watcher = chokidar.watch(restartWatchFile, { ignored: /^\./, persistent: true });
|
|
43
|
+
watcher
|
|
44
|
+
.on('change', function (path) {
|
|
45
|
+
console.log(`pid[${process.pid}] observing '${path}' changed, will restart!`);
|
|
46
|
+
restart();
|
|
47
|
+
})
|
|
48
|
+
.on('error', function (error) {
|
|
49
|
+
console.error('watchSelf error:', error);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports.start = function (main) {
|
|
54
|
+
//默认将log重定向到文件,不然在restart后会丢失
|
|
55
|
+
let logFile = pr(`.cache/app${runInWindows ? '.win' : ''}.log`);
|
|
56
|
+
if (!fs.existsSync(path.dirname(logFile))) fs.mkdirSync(path.dirname(logFile));
|
|
57
|
+
let oldWrite = process.stdout.write.bind(process.stdout);
|
|
58
|
+
var access = fs.createWriteStream(logFile, { flags: 'a' });
|
|
59
|
+
if (!process.env['PXW_NOREDIRECT_LOG']) {
|
|
60
|
+
process.stdout.write = process.stderr.write = access.write.bind(access);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let checkBinString = 'pxw/bin/pxw.js';
|
|
64
|
+
let checkCmd =
|
|
65
|
+
process.platform == 'win32' //
|
|
66
|
+
? 'wmic /OUTPUT:STDOUT process get processid,commandline'
|
|
67
|
+
: `ps -ef|grep "node"|grep "${checkBinString.replace(/(.)/, '[$1]')}"`; //第一个字符包在[]里可以避免grep命令自身出现在结果里
|
|
68
|
+
|
|
69
|
+
console.log(`\n*** pxw run: ${new Date().toLocaleString()} ***\npid[${process.pid}] check singleton:`, checkCmd);
|
|
70
|
+
cp.exec(checkCmd, { windowsHide: true, maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => {
|
|
71
|
+
if (error) {
|
|
72
|
+
console.log('pgrep error', error);
|
|
73
|
+
// return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let cpid = process.pid.toString();
|
|
77
|
+
if (process.platform == 'win32') {
|
|
78
|
+
let psl = stdout.trim().split('\n');
|
|
79
|
+
// console.log(psl.splice(300));
|
|
80
|
+
|
|
81
|
+
for (let cmd of psl) {
|
|
82
|
+
cmd = cmd.replace(/\\/g, '/');
|
|
83
|
+
if ((cmd.indexOf('/node.exe') > 0 || cmd.indexOf('node') == 0) && cmd.indexOf(checkBinString) > 0) {
|
|
84
|
+
let info = cmd.trim().replace(/\s+/g, ' ').split(' ');
|
|
85
|
+
console.log('find', info, process.pid);
|
|
86
|
+
let tpid = info[info.length - 1];
|
|
87
|
+
let isSelf = tpid == cpid;
|
|
88
|
+
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
89
|
+
if (!isSelf) {
|
|
90
|
+
if (argv.me || argv.kill) {
|
|
91
|
+
cp.execSync('taskkill /F /PID ' + tpid);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (argv.kill) return;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.log('pgrep stdout\n', stdout);
|
|
103
|
+
let lines = stdout.trim().split('\n');
|
|
104
|
+
for (let line of lines) {
|
|
105
|
+
line = line
|
|
106
|
+
.trim()
|
|
107
|
+
.split(' ')
|
|
108
|
+
.filter((x) => !!x);
|
|
109
|
+
// console.log(line);
|
|
110
|
+
if (line.length > 5) {
|
|
111
|
+
let tpid = line[1];
|
|
112
|
+
let isSelf = tpid == cpid;
|
|
113
|
+
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
114
|
+
if (tpid && !isSelf) {
|
|
115
|
+
console.log(`found exist process:[${tpid}], cur[${process.pid}]`);
|
|
116
|
+
if ((argv.me || argv.kill) && !error) {
|
|
117
|
+
console.log(`force kill other process:[${tpid}]`);
|
|
118
|
+
try {
|
|
119
|
+
process.stdout.write('', () => {
|
|
120
|
+
cp.execSync('kill ' + tpid);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
console.log(e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// cp.execSync('ps -ef|grep test/html/app.js', { stdio: 'inherit' });
|
|
129
|
+
// cp.execSync(`ps -ef|grep ${stdout}`, { stdio: 'inherit' });
|
|
130
|
+
return console.log('process already exist, pid:', tpid);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (argv.kill) return;
|
|
137
|
+
|
|
138
|
+
if (argv.fg || process.env.restart) {
|
|
139
|
+
if (argv.fg) {
|
|
140
|
+
oldWrite(`pid[${process.pid}] run in fg,log已重定向到 ${logFile} \n`);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
let rc = parseInt(process.env.restart);
|
|
144
|
+
process.env.restart = rc + 1;
|
|
145
|
+
console.log(`pid[${process.pid}] run in restart: ${rc}`);
|
|
146
|
+
}
|
|
147
|
+
main();
|
|
148
|
+
watchSelf();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.log(`pid[${process.pid}] run in bg`);
|
|
152
|
+
oldWrite('pxtest-admin 默认后台运行,加--fg参数可前台运行,log已重定向到' + logFile + '\n');
|
|
153
|
+
process.env.restart = 1;
|
|
154
|
+
restart();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
package/config/default.conf
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
server {
|
|
2
|
-
|
|
3
|
-
listen 80;
|
|
4
|
-
server_name localhost;
|
|
5
|
-
|
|
6
|
-
location / {
|
|
7
|
-
rewrite ^/$ /web/home/;
|
|
8
|
-
rewrite ^/home/(.*)$ /web/home/$1;
|
|
9
|
-
rewrite ^/static/media/(.*)$ /web/static/media/$1;
|
|
10
|
-
|
|
11
|
-
root /usr/share/nginx/html;
|
|
12
|
-
index index.html index.htm;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
error_page 500 502 503 504 /50x.html;
|
|
17
|
-
location = /50x.html {
|
|
18
|
-
root /usr/share/nginx/html;
|
|
19
|
-
}
|
|
20
|
-
|
|
1
|
+
server {
|
|
2
|
+
|
|
3
|
+
listen 80;
|
|
4
|
+
server_name localhost;
|
|
5
|
+
|
|
6
|
+
location / {
|
|
7
|
+
rewrite ^/$ /web/home/;
|
|
8
|
+
rewrite ^/home/(.*)$ /web/home/$1;
|
|
9
|
+
rewrite ^/static/media/(.*)$ /web/static/media/$1;
|
|
10
|
+
|
|
11
|
+
root /usr/share/nginx/html;
|
|
12
|
+
index index.html index.htm;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
error_page 500 502 503 504 /50x.html;
|
|
17
|
+
location = /50x.html {
|
|
18
|
+
root /usr/share/nginx/html;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
21
|
}
|