@pixui-dev/pxw 0.1.16
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 +217 -0
- package/bin/wpbuild.js +10 -0
- package/config/default.conf +21 -0
- package/config/devops.js +358 -0
- package/config/h5es.js +10 -0
- package/config/index.html +181 -0
- package/config/pfbs.js +207 -0
- package/config/testhelp.js +0 -0
- package/config/util.js +140 -0
- package/config/webpack.js +291 -0
- package/lib/assets/border.png +0 -0
- package/lib/assets/check.html +62 -0
- package/lib/assets/pixui.png +0 -0
- package/lib/assets/preact.js +4354 -0
- package/lib/assets/preact.png +0 -0
- package/lib/check/main.less +63 -0
- package/lib/check/main.tsx +41 -0
- package/lib/check/tool.js +3 -0
- package/lib/check/util.tsx +110 -0
- package/lib/grpc-web/dist/ChunkParser.js +117 -0
- package/lib/grpc-web/dist/ChunkParser.js.map +1 -0
- package/lib/grpc-web/dist/Code.js +58 -0
- package/lib/grpc-web/dist/Code.js.map +1 -0
- package/lib/grpc-web/dist/client.js +299 -0
- package/lib/grpc-web/dist/client.js.map +1 -0
- package/lib/grpc-web/dist/debug.js +16 -0
- package/lib/grpc-web/dist/debug.js.map +1 -0
- package/lib/grpc-web/dist/detach.js +7 -0
- package/lib/grpc-web/dist/detach.js.map +1 -0
- package/lib/grpc-web/dist/index.js +29 -0
- package/lib/grpc-web/dist/index.js.map +1 -0
- package/lib/grpc-web/dist/invoke.js +32 -0
- package/lib/grpc-web/dist/invoke.js.map +1 -0
- package/lib/grpc-web/dist/message.js +3 -0
- package/lib/grpc-web/dist/message.js.map +1 -0
- package/lib/grpc-web/dist/metadata.js +5 -0
- package/lib/grpc-web/dist/metadata.js.map +1 -0
- package/lib/grpc-web/dist/service.js +3 -0
- package/lib/grpc-web/dist/service.js.map +1 -0
- package/lib/grpc-web/dist/transports/Transport.js +15 -0
- package/lib/grpc-web/dist/transports/Transport.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -0
- package/lib/grpc-web/dist/transports/http/fetch.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/http.js +15 -0
- package/lib/grpc-web/dist/transports/http/http.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -0
- package/lib/grpc-web/dist/transports/http/xhr.js.map +1 -0
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -0
- package/lib/grpc-web/dist/transports/http/xhrUtil.js.map +1 -0
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -0
- package/lib/grpc-web/dist/transports/websocket/websocket.js.map +1 -0
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -0
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -0
- package/lib/grpc-web/dist/typings/client.d.ts +25 -0
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -0
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -0
- package/lib/grpc-web/dist/typings/index.d.ts +45 -0
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -0
- package/lib/grpc-web/dist/typings/message.d.ts +8 -0
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -0
- package/lib/grpc-web/dist/typings/service.d.ts +16 -0
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -0
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -0
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -0
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -0
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -0
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -0
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -0
- package/lib/grpc-web/dist/typings/util.d.ts +2 -0
- package/lib/grpc-web/dist/unary.js +44 -0
- package/lib/grpc-web/dist/unary.js.map +1 -0
- package/lib/grpc-web/dist/util.js +11 -0
- package/lib/grpc-web/dist/util.js.map +1 -0
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -0
- package/lib/grpcTransport/PixLuaTransport.ts +82 -0
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -0
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -0
- package/lib/pi_component/tinyList/tinyList.js +483 -0
- package/lib/pi_component/tinyList/tinyList.tsx +517 -0
- package/lib/pika-svelte/compiler.js +29829 -0
- package/lib/pika-svelte/easing/index.js +158 -0
- package/lib/pika-svelte/index.js +72 -0
- package/lib/pika-svelte/internal/index.js +1926 -0
- package/lib/pika-svelte/motion/index.js +210 -0
- package/lib/pika-svelte/package.json +145 -0
- package/lib/pika-svelte/register.js +57 -0
- package/lib/pika-svelte/rollup.config.js +126 -0
- package/lib/pika-svelte/store/index.js +123 -0
- package/lib/pika-svelte/transition/index.js +185 -0
- package/lib/preact-router.js +395 -0
- package/lib/preact.js +4355 -0
- package/lib/preact.tq.js +4385 -0
- package/lib/react-window/src/FixedSizeGrid.js +172 -0
- package/lib/react-window/src/FixedSizeList.js +91 -0
- package/lib/react-window/src/VariableSizeGrid.js +329 -0
- package/lib/react-window/src/VariableSizeList.js +231 -0
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -0
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -0
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -0
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -0
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -0
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -0
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -0
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -0
- package/lib/react-window/src/__tests__/areEqual.js +28 -0
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -0
- package/lib/react-window/src/areEqual.js +13 -0
- package/lib/react-window/src/createGridComponent.js +657 -0
- package/lib/react-window/src/createListComponent.js +574 -0
- package/lib/react-window/src/domHelpers.js +69 -0
- package/lib/react-window/src/index.js +9 -0
- package/lib/react-window/src/shallowDiffers.js +17 -0
- package/lib/react-window/src/shouldComponentUpdate.js +11 -0
- package/lib/react-window/src/test.js.flow +382 -0
- package/lib/react-window/src/timer.js +36 -0
- package/lib/svelte-tab/Tab.svelte +31 -0
- package/lib/svelte-tab/TabList.svelte +10 -0
- package/lib/svelte-tab/TabPanel.svelte +13 -0
- package/lib/svelte-tab/Tabs.svelte +68 -0
- package/lib/svelte-tab/tabs.js +4 -0
- package/lib/types/css.d.ts +7476 -0
- package/lib/types/dom.ts +17 -0
- package/lib/types/ext.d.ts +81 -0
- package/lib/types/internal.d.ts +94 -0
- package/lib/types/jsx.d.ts +309 -0
- package/lib/types/preact.d.ts +340 -0
- package/package.json +111 -0
- package/tsconfig.json +30 -0
package/bin/pxw.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
let fs = require('fs');
|
|
3
|
+
let cp = require('child_process');
|
|
4
|
+
let path = require('path');
|
|
5
|
+
let http = require('http');
|
|
6
|
+
let os = require('os');
|
|
7
|
+
let util = require('../config/util');
|
|
8
|
+
let pfbs = require('../config/pfbs');
|
|
9
|
+
let webpack = require('../config/webpack');
|
|
10
|
+
let argv = require('yargs').argv;
|
|
11
|
+
|
|
12
|
+
let runInWindows = process.platform == 'win32';
|
|
13
|
+
let pr = path.resolve;
|
|
14
|
+
let log = console.log;
|
|
15
|
+
log = () => {};
|
|
16
|
+
|
|
17
|
+
let rootDir = pr(__dirname, '../');
|
|
18
|
+
let testHtmlDir = pr(__dirname, '../pxtest/html');
|
|
19
|
+
let projectConfig = util.loadProjectConfig();
|
|
20
|
+
let appPort = parseInt(process.env['PXW_APP_PORT']) || projectConfig.port || 8001;
|
|
21
|
+
|
|
22
|
+
let isDaemonMode = argv.d;
|
|
23
|
+
|
|
24
|
+
process
|
|
25
|
+
.on('unhandledRejection', (err) => {
|
|
26
|
+
console.log('unhandledRejection', err);
|
|
27
|
+
})
|
|
28
|
+
.on('uncaughtException', (err) => {
|
|
29
|
+
console.log('uncaughtException', err);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
let fetch = require('node-fetch');
|
|
34
|
+
let express = require('express');
|
|
35
|
+
let serveIndex = require('serve-index');
|
|
36
|
+
|
|
37
|
+
let app = express();
|
|
38
|
+
let server = http.createServer(app);
|
|
39
|
+
|
|
40
|
+
require('../config/devops').setupDevops(server, app);
|
|
41
|
+
|
|
42
|
+
app.use(pfbs.getMiddleware());
|
|
43
|
+
app.use(webpack.devServer.getMiddleware()(appPort));
|
|
44
|
+
app.use(express.json());
|
|
45
|
+
app.use('/pxtest', serveIndex(testHtmlDir), express.static(testHtmlDir));
|
|
46
|
+
|
|
47
|
+
app.use(function (err, req, res, next) {
|
|
48
|
+
console.error(err);
|
|
49
|
+
res.status(500).send('Internal Serverless Error');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
app.post('/api/update-tsconfig', async (req, res) => {
|
|
53
|
+
try {
|
|
54
|
+
let h5esType = util.getOrSetH5esType(req.body.typeRoots)
|
|
55
|
+
res.json({
|
|
56
|
+
success: true,
|
|
57
|
+
restartRecommended: true,
|
|
58
|
+
newConfig: h5esType,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.log(error);
|
|
63
|
+
res.status(500).json({
|
|
64
|
+
error: `更新配置失败: ${error.message}`,
|
|
65
|
+
detail: error.stack,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
server.listen(appPort, '0.0.0.0', () => {
|
|
71
|
+
let ipList = [];
|
|
72
|
+
util.getLocalIP().forEach((ip) => {
|
|
73
|
+
console.log(`Server start on http://${ip}:${appPort}`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//以下处理自动重启和单例
|
|
79
|
+
function restart() {
|
|
80
|
+
const scriptPath = process.argv[1];
|
|
81
|
+
let removeArgs = { '--fg': 1 };
|
|
82
|
+
let args = process.argv.slice(2);
|
|
83
|
+
args = args.filter((v) => !removeArgs[v]);
|
|
84
|
+
const subprocess = cp.spawn(process.execPath, [scriptPath, ...args], {
|
|
85
|
+
detached: true,
|
|
86
|
+
windowsHide: true,
|
|
87
|
+
});
|
|
88
|
+
subprocess.unref();
|
|
89
|
+
process.exit();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function watchSelf() {
|
|
93
|
+
//可以通过环境变量设置是否要监视重启
|
|
94
|
+
let restartWatchFile = process.env['PXW_WATCHFILE'];
|
|
95
|
+
if (restartWatchFile == 'none') return;
|
|
96
|
+
if (!restartWatchFile) restartWatchFile = __filename;
|
|
97
|
+
restartWatchFile = pr(restartWatchFile);
|
|
98
|
+
console.log('watchfile:', restartWatchFile);
|
|
99
|
+
let chokidar = require('chokidar');
|
|
100
|
+
let watcher = chokidar.watch(restartWatchFile, { ignored: /^\./, persistent: true });
|
|
101
|
+
watcher
|
|
102
|
+
.on('change', function (path) {
|
|
103
|
+
console.log(`pid[${process.pid}] observing '${path}' changed, will restart!`);
|
|
104
|
+
restart();
|
|
105
|
+
})
|
|
106
|
+
.on('error', function (error) {
|
|
107
|
+
console.error('watchSelf error:', error);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (isDaemonMode) {
|
|
112
|
+
//默认将log重定向到文件,不然在restart后会丢失
|
|
113
|
+
let logFile = pr(`.cache/app${runInWindows ? '.win' : ''}.log`);
|
|
114
|
+
if (!fs.existsSync(path.dirname(logFile))) fs.mkdirSync(path.dirname(logFile));
|
|
115
|
+
let oldWrite = process.stdout.write.bind(process.stdout);
|
|
116
|
+
var access = fs.createWriteStream(logFile, { flags: 'a' });
|
|
117
|
+
if (!process.env['PXW_NOREDIRECT_LOG']) {
|
|
118
|
+
process.stdout.write = process.stderr.write = access.write.bind(access);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let checkBinString = 'pxw/bin/pxw.js';
|
|
122
|
+
let checkCmd =
|
|
123
|
+
process.platform == 'win32' //
|
|
124
|
+
? 'wmic /OUTPUT:STDOUT process get processid,commandline'
|
|
125
|
+
: `ps -ef|grep "node"|grep "${checkBinString.replace(/(.)/, '[$1]')}"`; //第一个字符包在[]里可以避免grep命令自身出现在结果里
|
|
126
|
+
|
|
127
|
+
console.log(`\n*** pxw run: ${new Date().toLocaleString()} ***\npid[${process.pid}] check singleton:`, checkCmd);
|
|
128
|
+
cp.exec(checkCmd, { windowsHide: true, maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => {
|
|
129
|
+
if (error) {
|
|
130
|
+
console.log('pgrep error', error);
|
|
131
|
+
// return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let cpid = process.pid.toString();
|
|
135
|
+
if (process.platform == 'win32') {
|
|
136
|
+
let psl = stdout.trim().split('\n');
|
|
137
|
+
// console.log(psl.splice(300));
|
|
138
|
+
|
|
139
|
+
for (let cmd of psl) {
|
|
140
|
+
cmd = cmd.replace(/\\/g, '/');
|
|
141
|
+
if ((cmd.indexOf('/node.exe') > 0 || cmd.indexOf('node') == 0) && cmd.indexOf(checkBinString) > 0) {
|
|
142
|
+
let info = cmd.trim().replace(/\s+/g, ' ').split(' ');
|
|
143
|
+
console.log('find', info, process.pid);
|
|
144
|
+
let tpid = info[info.length - 1];
|
|
145
|
+
let isSelf = tpid == cpid;
|
|
146
|
+
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
147
|
+
if (!isSelf) {
|
|
148
|
+
if (argv.me) {
|
|
149
|
+
cp.execSync('taskkill /F /PID ' + tpid);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.log('pgrep stdout\n', stdout);
|
|
160
|
+
let lines = stdout.trim().split('\n');
|
|
161
|
+
for (let line of lines) {
|
|
162
|
+
line = line
|
|
163
|
+
.trim()
|
|
164
|
+
.split(' ')
|
|
165
|
+
.filter((x) => !!x);
|
|
166
|
+
// console.log(line);
|
|
167
|
+
if (line.length > 5) {
|
|
168
|
+
let tpid = line[1];
|
|
169
|
+
let isSelf = tpid == cpid;
|
|
170
|
+
console.log(`tpid[${tpid}],isSelf:${isSelf}`);
|
|
171
|
+
if (tpid && !isSelf) {
|
|
172
|
+
console.log(`found exist process:[${tpid}], cur[${process.pid}]`);
|
|
173
|
+
if ((argv.me || argv.kill) && !error) {
|
|
174
|
+
console.log(`force kill other process:[${tpid}]`);
|
|
175
|
+
try {
|
|
176
|
+
process.stdout.write('', () => {
|
|
177
|
+
cp.execSync('kill ' + tpid);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
console.log(e);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// cp.execSync('ps -ef|grep test/html/app.js', { stdio: 'inherit' });
|
|
186
|
+
// cp.execSync(`ps -ef|grep ${stdout}`, { stdio: 'inherit' });
|
|
187
|
+
return console.log('process already exist, pid:', tpid);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (argv.kill) return;
|
|
194
|
+
|
|
195
|
+
if (argv.fg || process.env.restart) {
|
|
196
|
+
if (argv.fg) {
|
|
197
|
+
oldWrite(`pid[${process.pid}] run in fg,log已重定向到 ${logFile} \n`);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
let rc = parseInt(process.env.restart);
|
|
201
|
+
process.env.restart = rc + 1;
|
|
202
|
+
console.log(`pid[${process.pid}] run in restart: ${rc}`);
|
|
203
|
+
}
|
|
204
|
+
main();
|
|
205
|
+
watchSelf();
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
console.log(`pid[${process.pid}] run in bg`);
|
|
209
|
+
oldWrite('pxtest-admin 默认后台运行,加--fg参数可前台运行,log已重定向到' + logFile + '\n');
|
|
210
|
+
process.env.restart = 1;
|
|
211
|
+
restart();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
main();
|
|
217
|
+
}
|
package/bin/wpbuild.js
ADDED
|
@@ -0,0 +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
|
+
|
|
21
|
+
}
|
package/config/devops.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
let ws = require('ws');
|
|
2
|
+
let fs = require('fs');
|
|
3
|
+
let cp = require('child_process');
|
|
4
|
+
let http = require('http');
|
|
5
|
+
let path = require('path');
|
|
6
|
+
let pr = path.resolve;
|
|
7
|
+
|
|
8
|
+
let multer = require('multer');
|
|
9
|
+
let express = require('express');
|
|
10
|
+
|
|
11
|
+
let rootDir = pr(__dirname, '../');
|
|
12
|
+
|
|
13
|
+
let dirConfig = {
|
|
14
|
+
pxkit: '',
|
|
15
|
+
pxembed: '',
|
|
16
|
+
pxapp: '',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function updateFile(file, targetLine) {
|
|
20
|
+
targetLine = '\n' + targetLine;
|
|
21
|
+
fs.existsSync(file) ? fs.readFileSync(file, 'utf8').includes(targetLine) || fs.appendFileSync(file, targetLine) : fs.writeFileSync(file, targetLine);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports.setupDevops = async function (server, app) {
|
|
25
|
+
let si = require('systeminformation');
|
|
26
|
+
let sys = await si.system();
|
|
27
|
+
let runInVM = /Parallels/.test(sys.manufacturer);
|
|
28
|
+
console.log(`system manufacturer:${sys.manufacturer}, runInVM:${runInVM}`);
|
|
29
|
+
|
|
30
|
+
let watcher;
|
|
31
|
+
|
|
32
|
+
if (!runInVM) {
|
|
33
|
+
let chokidar = require('chokidar');
|
|
34
|
+
watcher = chokidar.watch(
|
|
35
|
+
['/**/*.html', '/**/*.js'].map((v) => pr('.') + v),
|
|
36
|
+
{ ignored: [/\.build\//, /node_modules/], persistent: true },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
watcher
|
|
40
|
+
.on('change', function (path) {
|
|
41
|
+
console.log('changetest', path);
|
|
42
|
+
})
|
|
43
|
+
.on('error', function (error) {
|
|
44
|
+
console.error('Error happened', error);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
let pp = cp.execSync('yarn', { cwd: rootDir + '/pxtest/server/', stdio: 'pipe' });
|
|
50
|
+
console.log('yarn for pxtest server:\n', pp.toString());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let subProcesses = {};
|
|
54
|
+
let devopsConn;
|
|
55
|
+
let websocketServer = new ws.Server({ server });
|
|
56
|
+
websocketServer.on('connection', (conn, req) => {
|
|
57
|
+
let url = new URL(req.url, 'http://localhost');
|
|
58
|
+
//去掉第1个字符/,否则在windows上与path比较时会因为\而不一样
|
|
59
|
+
let referrer = url.searchParams.get('referrer')?.substring(1);
|
|
60
|
+
console.log('ws connection', url.pathname, referrer);
|
|
61
|
+
// console.log(url.pathname, url.searchParams);
|
|
62
|
+
if (url.pathname == '/notify') {
|
|
63
|
+
conn.on('message', (message) => {
|
|
64
|
+
// client.send(`{ "message" : ${message} }`);
|
|
65
|
+
});
|
|
66
|
+
let changeHandler;
|
|
67
|
+
watcher?.on(
|
|
68
|
+
'change',
|
|
69
|
+
(changeHandler = (path) => {
|
|
70
|
+
//只响应该页面对应的文件变化
|
|
71
|
+
if (path.endsWith(referrer)) {
|
|
72
|
+
console.log('reload', path);
|
|
73
|
+
conn.send('reload');
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
conn.on('close', () => {
|
|
78
|
+
watcher?.removeListener('change', changeHandler);
|
|
79
|
+
console.log('ws connection closed', url.pathname, url.searchParams);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (url.pathname == '/devops') {
|
|
83
|
+
devopsConn = conn;
|
|
84
|
+
let notifySubProcesses = () => {
|
|
85
|
+
conn.send(
|
|
86
|
+
JSON.stringify({
|
|
87
|
+
type: 'subProcesses',
|
|
88
|
+
data: Object.entries(subProcesses).map(([k, v]) => {
|
|
89
|
+
return {
|
|
90
|
+
name: k,
|
|
91
|
+
pid: v.subprocess.pid,
|
|
92
|
+
startTime: v.startTime,
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
notifySubProcesses();
|
|
99
|
+
conn.on('message', (data) => {
|
|
100
|
+
let { command, options } = JSON.parse(data);
|
|
101
|
+
console.log('devops cmd', command, options);
|
|
102
|
+
|
|
103
|
+
let subprocess;
|
|
104
|
+
if (command == 'buildIOS') {
|
|
105
|
+
let withEnv = {
|
|
106
|
+
withPxKitSource: rootDir.replace(/\\/g, '/'),
|
|
107
|
+
};
|
|
108
|
+
if (options.rebuild) {
|
|
109
|
+
withEnv['rebuild'] = 1;
|
|
110
|
+
}
|
|
111
|
+
subprocess = cp.spawn('node', [dirConfig.pxembed + '/src/script/itest.js'], {
|
|
112
|
+
cwd: dirConfig.pxembed,
|
|
113
|
+
detached: true,
|
|
114
|
+
env: { ...process.env, ...withEnv },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else if (command == 'buildAndroid') {
|
|
118
|
+
let withEnv = { redirectLogcat: 1 };
|
|
119
|
+
let tasks = [];
|
|
120
|
+
if (options.java) withEnv['JAVA_HOME'] = options.java;
|
|
121
|
+
if (options.rebuild) {
|
|
122
|
+
tasks.push('clean');
|
|
123
|
+
}
|
|
124
|
+
tasks.push('test');
|
|
125
|
+
let clfile = dirConfig.pxembed + '/project/android_app/settings.local';
|
|
126
|
+
let targetLine = `gradle.ext.withPxKitSource = '${rootDir.replace(/\\/g, '/')}';`;
|
|
127
|
+
updateFile(clfile, targetLine);
|
|
128
|
+
subprocess = cp.spawn('gradlew' + (runInWindows ? '.bat' : ''), tasks, {
|
|
129
|
+
cwd: dirConfig.pxembed + '/project/android_app',
|
|
130
|
+
detached: !runInWindows,
|
|
131
|
+
windowsHide: true,
|
|
132
|
+
shell: true,
|
|
133
|
+
env: { ...process.env, ...withEnv },
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else if (command == 'buildHarmony') {
|
|
137
|
+
let withEnv = {};
|
|
138
|
+
if (options.java) {
|
|
139
|
+
withEnv['JAVA_HOME'] = options.java;
|
|
140
|
+
withEnv['PATH'] = options.java + '/bin;' + process.env.PATH;
|
|
141
|
+
}
|
|
142
|
+
if (options.rebuild) {
|
|
143
|
+
withEnv['rebuild'] = 1;
|
|
144
|
+
}
|
|
145
|
+
let clfile = dirConfig.pxembed + '/project/hm_app/hvigorlocal.ts';
|
|
146
|
+
let targetLine = `export let withPxKit = '${rootDir.replace(/\\/g, '/')}';`;
|
|
147
|
+
updateFile(clfile, targetLine);
|
|
148
|
+
subprocess = cp.spawn('node', [dirConfig.pxembed + '/src/script/htest.js', '-b', '-i', '-t'], {
|
|
149
|
+
cwd: dirConfig.pxembed,
|
|
150
|
+
detached: !runInWindows,
|
|
151
|
+
shell: true,
|
|
152
|
+
windowsHide: true,
|
|
153
|
+
env: { ...process.env, ...withEnv },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else if (command == 'buildMac') {
|
|
157
|
+
let cfg = `--CFG=${options.debug ? 'Debug' : 'Release'}`;
|
|
158
|
+
let clean = `${options.rebuild ? '--clean' : ''}`;
|
|
159
|
+
let clfile = dirConfig.pxapp + '/cmake.local';
|
|
160
|
+
let targetLine = `set(WITH_PX_SOURCE ${rootDir.replace(/\\/g, '/')})`;
|
|
161
|
+
updateFile(clfile, targetLine);
|
|
162
|
+
subprocess = cp.spawn('jtx', `pxide-build --mac --build ${cfg} ${clean} --test-pxkit`.split(' '), {
|
|
163
|
+
cwd: dirConfig.pxapp,
|
|
164
|
+
detached: true,
|
|
165
|
+
env: { ...process.env, echo: 1, xPX_TEST_FORCE_ALL: 1 },
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else if (command == 'buildWin') {
|
|
169
|
+
let cfg = `--CFG=${options.debug ? 'Debug' : 'Release'}`;
|
|
170
|
+
let clean = `${options.rebuild ? '--clean' : ''}`;
|
|
171
|
+
let clfile = dirConfig.pxapp + '/cmake.local';
|
|
172
|
+
let targetLine = `set(WITH_PX_SOURCE ${rootDir.replace(/\\/g, '/')})`;
|
|
173
|
+
updateFile(clfile, targetLine);
|
|
174
|
+
subprocess = cp.spawn('jtx' + (runInWindows ? '.cmd' : ''), `pxide-build --win --build ${cfg} ${clean} --test-pxkit`.split(' '), {
|
|
175
|
+
cwd: dirConfig.pxapp,
|
|
176
|
+
detached: !runInWindows,
|
|
177
|
+
env: { ...process.env, xPX_TEST_FORCE_ALL: 1 },
|
|
178
|
+
windowsHide: true,
|
|
179
|
+
shell: true,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
else if (command == 'buildWinMinGW') {
|
|
183
|
+
subprocess = cp.spawn('jtx', `build --mingw --build ${options.debug ? '--debug' : '--release'}`.split(' '), {
|
|
184
|
+
detached: !runInWindows,
|
|
185
|
+
env: { ...process.env, xPX_TEST_FORCE_ALL: 1 },
|
|
186
|
+
windowsHide: true,
|
|
187
|
+
shell: true,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else if (command == 'setDir') {
|
|
191
|
+
let { id, value } = options;
|
|
192
|
+
try {
|
|
193
|
+
if (id == 'pxkit') {
|
|
194
|
+
value = rootDir;
|
|
195
|
+
}
|
|
196
|
+
if (value && id in { pxkit: 1, pxembed: 1, pxapp: 1 }) {
|
|
197
|
+
let br = cp.execSync('git branch --show-current', { stdio: 'pipe', cwd: value, windowsHide: true });
|
|
198
|
+
devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, value, result: br.toString() }));
|
|
199
|
+
}
|
|
200
|
+
else if (id in { java: 1 }) {
|
|
201
|
+
// let ver = cp.spawnSync('java', ['-version'], { stdio: 'pipe' }).stderr.toString().split('\n')[0];
|
|
202
|
+
// console.log(value, ver);
|
|
203
|
+
// devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, value, result: ver }));
|
|
204
|
+
}
|
|
205
|
+
dirConfig[id] = value;
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, result: e.message }));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (subprocess) {
|
|
213
|
+
subProcesses[command] = { subprocess, startTime: Date.now() };
|
|
214
|
+
subprocess.on('error', (err) => {
|
|
215
|
+
devopsConn?.send(JSON.stringify({ type: 'return', name: command, value: -1, err: err.message }));
|
|
216
|
+
delete subProcesses[command];
|
|
217
|
+
});
|
|
218
|
+
subprocess.on('exit', (code, signal) => {
|
|
219
|
+
devopsConn?.send(JSON.stringify({ type: 'return', name: command, value: code }));
|
|
220
|
+
delete subProcesses[command];
|
|
221
|
+
});
|
|
222
|
+
subprocess.stdout.on('data', (data) => {
|
|
223
|
+
// console.log(data.toString());
|
|
224
|
+
devopsConn?.send(JSON.stringify({ type: 'stdout', data: data.toString() }));
|
|
225
|
+
});
|
|
226
|
+
subprocess.stderr.on('data', (data) => {
|
|
227
|
+
// console.log(data.toString());
|
|
228
|
+
devopsConn?.send(JSON.stringify({ type: 'stderr', data: data.toString() }));
|
|
229
|
+
});
|
|
230
|
+
notifySubProcesses();
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// devopsConn?.send(JSON.stringify({ type: 'return', name: command, value: -1, err: 'unknown command' }));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
let tCapDir = rootDir + '/.cache/devops/caps';
|
|
240
|
+
if (!fs.existsSync(tCapDir)) fs.mkdirSync(tCapDir, { recursive: true });
|
|
241
|
+
var storage = multer.diskStorage({
|
|
242
|
+
destination: (req, file, cb) => {
|
|
243
|
+
let dir = tCapDir + '/' + req.body.platform;
|
|
244
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
|
245
|
+
cb(null, dir);
|
|
246
|
+
},
|
|
247
|
+
filename: (req, file, cb) => cb(null, file.originalname),
|
|
248
|
+
});
|
|
249
|
+
app.use(express.urlencoded({ extended: true }));
|
|
250
|
+
app.post('/compareImage', multer({ storage }).single('file'), (req, res) => {
|
|
251
|
+
console.log('Uploaded file:', req.file, req.files);
|
|
252
|
+
console.log('body:', req.body);
|
|
253
|
+
|
|
254
|
+
if (!req.file) {
|
|
255
|
+
return res.status(400).send('No files were uploaded.');
|
|
256
|
+
}
|
|
257
|
+
let { platform, threshold, includeAA } = req.body;
|
|
258
|
+
if (!platform) {
|
|
259
|
+
return res.status(400).send('No platform set.');
|
|
260
|
+
}
|
|
261
|
+
threshold = parseFloat(threshold) || 0;
|
|
262
|
+
includeAA = includeAA != 'false';
|
|
263
|
+
|
|
264
|
+
const PNG = require('pngjs').PNG;
|
|
265
|
+
const pixelmatch = require('pixelmatch');
|
|
266
|
+
|
|
267
|
+
let baseFile = `${req.file.path}`.replace('.png', '.base.png');
|
|
268
|
+
fs.copyFileSync(`${dirConfig.pxembed}/project/${platform}_app/caps/${req.file.originalname}`, baseFile);
|
|
269
|
+
|
|
270
|
+
const img1 = PNG.sync.read(fs.readFileSync(req.file.path));
|
|
271
|
+
const img2 = PNG.sync.read(fs.readFileSync(baseFile));
|
|
272
|
+
const { width, height } = img1;
|
|
273
|
+
const diff = new PNG({ width, height });
|
|
274
|
+
|
|
275
|
+
let num = pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold, includeAA });
|
|
276
|
+
let diffFile = `${req.file.path}`.replace('.png', '.diff.png');
|
|
277
|
+
console.log('compareImage', 'diffNum', num, 'threshold', threshold, req.file.path, baseFile);
|
|
278
|
+
if (num) {
|
|
279
|
+
fs.writeFileSync(diffFile, PNG.sync.write(diff));
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
if (fs.existsSync(diffFile)) fs.unlinkSync(diffFile);
|
|
283
|
+
if (fs.existsSync(baseFile)) fs.unlinkSync(baseFile);
|
|
284
|
+
}
|
|
285
|
+
res.setHeader('Content-Type', 'application/json');
|
|
286
|
+
res.send(JSON.stringify({ diff: num }));
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
app.use('/proxy/', async (req, res, next) => {
|
|
290
|
+
let url = req.url.substring(1).replace('@@@', '://');
|
|
291
|
+
console.log('req proxy', url);
|
|
292
|
+
try {
|
|
293
|
+
const response = await fetch(url);
|
|
294
|
+
let data = await response.buffer();
|
|
295
|
+
let headers = Array.from(response.headers.entries());
|
|
296
|
+
headers.forEach(([k, v]) => {
|
|
297
|
+
res.setHeader(k, v);
|
|
298
|
+
});
|
|
299
|
+
console.log('req proxy', url, data.byteLength);
|
|
300
|
+
// res.setHeader('Content-Type', response.headers['Content-Type']);
|
|
301
|
+
res.send(data);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.log('req proxy failed', url, error);
|
|
305
|
+
res.sendStatus(500);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
let mapPort2Process = {};
|
|
310
|
+
app.use('/kill_server', async (req, res, next) => {
|
|
311
|
+
let url = new URL(req.url, 'http://localhost');
|
|
312
|
+
let port = url.searchParams.get('port');
|
|
313
|
+
let child = mapPort2Process[port];
|
|
314
|
+
console.log('kill_server', port, child?.pid);
|
|
315
|
+
devopsConn?.send(JSON.stringify({ type: 'stdout', data: `杀掉服务进程:${child?.pid}:${port}\n` }));
|
|
316
|
+
if (child) {
|
|
317
|
+
child.kill();
|
|
318
|
+
}
|
|
319
|
+
res.end();
|
|
320
|
+
});
|
|
321
|
+
app.use('/run_server', async (req, res, next) => {
|
|
322
|
+
let url = new URL(req.url, 'http://localhost');
|
|
323
|
+
let cmd = JSON.parse(url.searchParams.get('cmd'));
|
|
324
|
+
let command, args;
|
|
325
|
+
if (cmd.node) {
|
|
326
|
+
command = 'node';
|
|
327
|
+
args = [pr(rootDir, 'pxtest/server', cmd.node)];
|
|
328
|
+
if (cmd.args) args = args.concat(cmd.args);
|
|
329
|
+
}
|
|
330
|
+
let child = cp.spawn(command, args, {
|
|
331
|
+
windowsHide: true,
|
|
332
|
+
shell: false,
|
|
333
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'], //注意这里必须使用pipe,如用inherit会导致子进程莫名终止,可能跟自己的stdout被重定向到文件有关
|
|
334
|
+
});
|
|
335
|
+
console.log('run_server', req.url, child.pid);
|
|
336
|
+
devopsConn?.send(JSON.stringify({ type: 'stdout', data: `拉起服务进程:${child.pid}:${req.url}\n` }));
|
|
337
|
+
child.once('close', (code, sig) => {
|
|
338
|
+
console.log(`server[${child.pid}] close`, code, sig);
|
|
339
|
+
});
|
|
340
|
+
child.once('error', (err) => {
|
|
341
|
+
devopsConn?.send(JSON.stringify({ type: 'stdout', data: `服务进程错误:${child.pid}:${err.message}\n` }));
|
|
342
|
+
console.log(`server[${child.pid}] error`, err);
|
|
343
|
+
});
|
|
344
|
+
child.once('message', (port) => {
|
|
345
|
+
console.log(`server[${child.pid}] message`, port);
|
|
346
|
+
devopsConn?.send(JSON.stringify({ type: 'stdout', data: `服务进程报告端口号:${child.pid}:${port}\n` }));
|
|
347
|
+
mapPort2Process[port] = child;
|
|
348
|
+
res.setHeader('content-type', 'text/plain'); //设置类型,避免被pfbs当作html转换(不设的话不知道哪里默认会给它加个text/html))
|
|
349
|
+
res.send(port);
|
|
350
|
+
});
|
|
351
|
+
child.stdout?.on('data', (data) => {
|
|
352
|
+
console.log(`server[${child.pid}] stdout:\n`, data.toString());
|
|
353
|
+
});
|
|
354
|
+
child.stderr?.on('data', (data) => {
|
|
355
|
+
console.log(`server[${child.pid}] stderr:\n`, data.toString());
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
};
|