@pixui-dev/pxw 0.1.21 → 0.1.22
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 +7 -14
- package/config/devops.js +12 -24
- package/config/pfbs.js +36 -30
- package/config/util.js +10 -14
- package/config/webpack.js +1 -2
- package/package.json +2 -1
- package/scripts/postinstall.js +1 -1
- package/scripts/run-pxw.js +2 -2
package/bin/pxw.js
CHANGED
|
@@ -129,15 +129,13 @@ if (isDaemonMode) {
|
|
|
129
129
|
if (!isSelf) {
|
|
130
130
|
if (argv.me) {
|
|
131
131
|
cp.execSync('taskkill /F /PID ' + tpid);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
132
|
+
} else {
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
138
|
+
} else {
|
|
141
139
|
console.log('pgrep stdout\n', stdout);
|
|
142
140
|
let lines = stdout.trim().split('\n');
|
|
143
141
|
for (let line of lines) {
|
|
@@ -158,12 +156,10 @@ if (isDaemonMode) {
|
|
|
158
156
|
process.stdout.write('', () => {
|
|
159
157
|
cp.execSync('kill ' + tpid);
|
|
160
158
|
});
|
|
161
|
-
}
|
|
162
|
-
catch (e) {
|
|
159
|
+
} catch (e) {
|
|
163
160
|
console.log(e);
|
|
164
161
|
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
162
|
+
} else {
|
|
167
163
|
// cp.execSync('ps -ef|grep test/html/app.js', { stdio: 'inherit' });
|
|
168
164
|
// cp.execSync(`ps -ef|grep ${stdout}`, { stdio: 'inherit' });
|
|
169
165
|
return console.log('process already exist, pid:', tpid);
|
|
@@ -177,23 +173,20 @@ if (isDaemonMode) {
|
|
|
177
173
|
if (argv.fg || process.env.restart) {
|
|
178
174
|
if (argv.fg) {
|
|
179
175
|
oldWrite(`pid[${process.pid}] run in fg,log已重定向到 ${logFile} \n`);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
176
|
+
} else {
|
|
182
177
|
let rc = parseInt(process.env.restart);
|
|
183
178
|
process.env.restart = rc + 1;
|
|
184
179
|
console.log(`pid[${process.pid}] run in restart: ${rc}`);
|
|
185
180
|
}
|
|
186
181
|
main();
|
|
187
182
|
watchSelf();
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
183
|
+
} else {
|
|
190
184
|
console.log(`pid[${process.pid}] run in bg`);
|
|
191
185
|
oldWrite('pxtest-admin 默认后台运行,加--fg参数可前台运行,log已重定向到' + logFile + '\n');
|
|
192
186
|
process.env.restart = 1;
|
|
193
187
|
restart();
|
|
194
188
|
}
|
|
195
189
|
});
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
190
|
+
} else {
|
|
198
191
|
main();
|
|
199
192
|
}
|
package/config/devops.js
CHANGED
|
@@ -87,8 +87,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
87
87
|
watcher?.removeListener('change', changeHandler);
|
|
88
88
|
console.log('ws connection closed', url.pathname, url.searchParams);
|
|
89
89
|
});
|
|
90
|
-
}
|
|
91
|
-
else if (url.pathname == '/devops') {
|
|
90
|
+
} else if (url.pathname == '/devops') {
|
|
92
91
|
devopsConn = conn;
|
|
93
92
|
let notifySubProcesses = () => {
|
|
94
93
|
conn.send(
|
|
@@ -125,8 +124,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
125
124
|
detached: true,
|
|
126
125
|
env: { ...process.env, ...withEnv },
|
|
127
126
|
});
|
|
128
|
-
}
|
|
129
|
-
else if (command == 'buildAndroid') {
|
|
127
|
+
} else if (command == 'buildAndroid') {
|
|
130
128
|
let withEnv = { redirectLogcat: 1 };
|
|
131
129
|
let tasks = [];
|
|
132
130
|
if (options.java) withEnv['JAVA_HOME'] = options.java;
|
|
@@ -144,8 +142,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
144
142
|
shell: true,
|
|
145
143
|
env: { ...process.env, ...withEnv },
|
|
146
144
|
});
|
|
147
|
-
}
|
|
148
|
-
else if (command == 'buildHarmony') {
|
|
145
|
+
} else if (command == 'buildHarmony') {
|
|
149
146
|
let withEnv = {};
|
|
150
147
|
if (options.java) {
|
|
151
148
|
withEnv['JAVA_HOME'] = options.java;
|
|
@@ -164,8 +161,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
164
161
|
windowsHide: true,
|
|
165
162
|
env: { ...process.env, ...withEnv },
|
|
166
163
|
});
|
|
167
|
-
}
|
|
168
|
-
else if (command == 'buildMac') {
|
|
164
|
+
} else if (command == 'buildMac') {
|
|
169
165
|
let cfg = `--CFG=${options.debug ? 'Debug' : 'Release'}`;
|
|
170
166
|
let clean = `${options.rebuild ? '--clean' : ''}`;
|
|
171
167
|
let clfile = dirConfig.pxapp + '/cmake.local';
|
|
@@ -176,8 +172,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
176
172
|
detached: true,
|
|
177
173
|
env: { ...process.env, echo: 1, xPX_TEST_FORCE_ALL: 1 },
|
|
178
174
|
});
|
|
179
|
-
}
|
|
180
|
-
else if (command == 'buildWin') {
|
|
175
|
+
} else if (command == 'buildWin') {
|
|
181
176
|
let cfg = `--CFG=${options.debug ? 'Debug' : 'Release'}`;
|
|
182
177
|
let clean = `${options.rebuild ? '--clean' : ''}`;
|
|
183
178
|
let clfile = dirConfig.pxapp + '/cmake.local';
|
|
@@ -190,16 +185,14 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
190
185
|
windowsHide: true,
|
|
191
186
|
shell: true,
|
|
192
187
|
});
|
|
193
|
-
}
|
|
194
|
-
else if (command == 'buildWinMinGW') {
|
|
188
|
+
} else if (command == 'buildWinMinGW') {
|
|
195
189
|
subprocess = cp.spawn('jtx', `build --mingw --build ${options.debug ? '--debug' : '--release'}`.split(' '), {
|
|
196
190
|
detached: !runInWindows,
|
|
197
191
|
env: { ...process.env, xPX_TEST_FORCE_ALL: 1 },
|
|
198
192
|
windowsHide: true,
|
|
199
193
|
shell: true,
|
|
200
194
|
});
|
|
201
|
-
}
|
|
202
|
-
else if (command == 'setDir') {
|
|
195
|
+
} else if (command == 'setDir') {
|
|
203
196
|
let { id, value } = options;
|
|
204
197
|
try {
|
|
205
198
|
if (id == 'pxkit') {
|
|
@@ -208,15 +201,13 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
208
201
|
if (value && id in { pxkit: 1, pxembed: 1, pxapp: 1 }) {
|
|
209
202
|
let br = cp.execSync('git branch --show-current', { stdio: 'pipe', cwd: value, windowsHide: true });
|
|
210
203
|
devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, value, result: br.toString() }));
|
|
211
|
-
}
|
|
212
|
-
else if (id in { java: 1 }) {
|
|
204
|
+
} else if (id in { java: 1 }) {
|
|
213
205
|
// let ver = cp.spawnSync('java', ['-version'], { stdio: 'pipe' }).stderr.toString().split('\n')[0];
|
|
214
206
|
// console.log(value, ver);
|
|
215
207
|
// devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, value, result: ver }));
|
|
216
208
|
}
|
|
217
209
|
dirConfig[id] = value;
|
|
218
|
-
}
|
|
219
|
-
catch (e) {
|
|
210
|
+
} catch (e) {
|
|
220
211
|
devopsConn?.send(JSON.stringify({ type: 'setDirResult', id, result: e.message }));
|
|
221
212
|
}
|
|
222
213
|
}
|
|
@@ -240,8 +231,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
240
231
|
devopsConn?.send(JSON.stringify({ type: 'stderr', data: data.toString() }));
|
|
241
232
|
});
|
|
242
233
|
notifySubProcesses();
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
234
|
+
} else {
|
|
245
235
|
// devopsConn?.send(JSON.stringify({ type: 'return', name: command, value: -1, err: 'unknown command' }));
|
|
246
236
|
}
|
|
247
237
|
});
|
|
@@ -289,8 +279,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
289
279
|
console.log('compareImage', 'diffNum', num, 'threshold', threshold, req.file.path, baseFile);
|
|
290
280
|
if (num) {
|
|
291
281
|
fs.writeFileSync(diffFile, PNG.sync.write(diff));
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
282
|
+
} else {
|
|
294
283
|
if (fs.existsSync(diffFile)) fs.unlinkSync(diffFile);
|
|
295
284
|
if (fs.existsSync(baseFile)) fs.unlinkSync(baseFile);
|
|
296
285
|
}
|
|
@@ -311,8 +300,7 @@ module.exports.setupDevops = async function (server, app) {
|
|
|
311
300
|
console.log('req proxy', url, data.byteLength);
|
|
312
301
|
// res.setHeader('Content-Type', response.headers['Content-Type']);
|
|
313
302
|
res.send(data);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
303
|
+
} catch (error) {
|
|
316
304
|
console.log('req proxy failed', url, error);
|
|
317
305
|
res.sendStatus(500);
|
|
318
306
|
}
|
package/config/pfbs.js
CHANGED
|
@@ -40,13 +40,12 @@ let pfbsConvert = async (ver, isJS, input, fn) => {
|
|
|
40
40
|
if (typeof fetch !== 'undefined') {
|
|
41
41
|
let res = await fetch(url);
|
|
42
42
|
buffer = await res.arrayBuffer();
|
|
43
|
-
}
|
|
44
|
-
else if (typeof XMLHttpRequest !== 'undefined') {
|
|
43
|
+
} else if (typeof XMLHttpRequest !== 'undefined') {
|
|
45
44
|
buffer = await new Promise((resolve, reject) => {
|
|
46
45
|
const xhr = new XMLHttpRequest();
|
|
47
46
|
xhr.open('GET', url, true);
|
|
48
47
|
xhr.responseType = 'arraybuffer';
|
|
49
|
-
|
|
48
|
+
|
|
50
49
|
xhr.onload = () => {
|
|
51
50
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
52
51
|
resolve(xhr.response);
|
|
@@ -54,25 +53,25 @@ let pfbsConvert = async (ver, isJS, input, fn) => {
|
|
|
54
53
|
reject(new Error(`XHR failed with status ${xhr.status}`));
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
xhr.onerror = () => reject(new Error('Network Error'));
|
|
59
58
|
xhr.send();
|
|
60
59
|
});
|
|
61
|
-
}else if (typeof require !== 'undefined' && require('http')) {
|
|
60
|
+
} else if (typeof require !== 'undefined' && require('http')) {
|
|
62
61
|
const http = require('http');
|
|
63
|
-
console.log('http: ', url)
|
|
62
|
+
console.log('http: ', url);
|
|
64
63
|
buffer = await new Promise((resolve, reject) => {
|
|
65
64
|
http.get(url, (res) => {
|
|
66
65
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
67
66
|
return resolve(this._fetchBuffer(res.headers.location));
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
|
|
70
69
|
const chunks = [];
|
|
71
70
|
res.on('data', (chunk) => chunks.push(chunk));
|
|
72
71
|
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
73
72
|
}).on('error', reject);
|
|
74
73
|
});
|
|
75
|
-
}else {
|
|
74
|
+
} else {
|
|
76
75
|
throw new Error('No supported HTTP client available');
|
|
77
76
|
}
|
|
78
77
|
|
|
@@ -145,6 +144,27 @@ module.exports.getMiddleware = () => {
|
|
|
145
144
|
return 'text/plain';
|
|
146
145
|
};
|
|
147
146
|
|
|
147
|
+
//往html中插入websocket控制脚本,插在body最后,注意不要重复插入
|
|
148
|
+
let appendWebsocketScript = (data) => {
|
|
149
|
+
let c1 = data.toString('utf-8');
|
|
150
|
+
let c2 = c1.replace(
|
|
151
|
+
'</body>',
|
|
152
|
+
`<script>
|
|
153
|
+
(function() {
|
|
154
|
+
var ws = new WebSocket('ws://' + window.location.host+ '/notify?reloadMode=RELOAD_ON_SAVE&referrer=' + encodeURIComponent(window.location.pathname))
|
|
155
|
+
ws.onmessage = function (msg) {
|
|
156
|
+
if (msg.data === 'reload') {
|
|
157
|
+
window.location.reload();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
})();
|
|
161
|
+
</script></body>`,
|
|
162
|
+
);
|
|
163
|
+
console.log('insert hotreload to html', data.length, c1.length, c2.length);
|
|
164
|
+
// console.log(c1);
|
|
165
|
+
return c2;
|
|
166
|
+
};
|
|
167
|
+
|
|
148
168
|
let mime = '';
|
|
149
169
|
let _setHeader = res.setHeader;
|
|
150
170
|
res.setHeader = function (k, v) {
|
|
@@ -183,24 +203,8 @@ module.exports.getMiddleware = () => {
|
|
|
183
203
|
let isHTML = type.indexOf('text/html') >= 0;
|
|
184
204
|
let isJS = type.indexOf('javascript') >= 0;
|
|
185
205
|
let isCSS = type.indexOf('text/css') >= 0;
|
|
186
|
-
if (isHTML && !isAlreadyPfbs) {
|
|
187
|
-
|
|
188
|
-
let c2 = c1.replace(
|
|
189
|
-
'</body>',
|
|
190
|
-
`<script>
|
|
191
|
-
(function() {
|
|
192
|
-
var ws = new WebSocket('ws://' + window.location.host+ '/notify?reloadMode=RELOAD_ON_SAVE&referrer=' + encodeURIComponent(window.location.pathname))
|
|
193
|
-
ws.onmessage = function (msg) {
|
|
194
|
-
if (msg.data === 'reload') {
|
|
195
|
-
window.location.reload();
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
})();
|
|
199
|
-
</script></body>`,
|
|
200
|
-
);
|
|
201
|
-
console.log('insert hotreload to html', data.length, c1.length, c2.length);
|
|
202
|
-
// console.log(c1);
|
|
203
|
-
data = c2;
|
|
206
|
+
if (isHTML && !isAlreadyPfbs && !res.appendWebsocketScript) {
|
|
207
|
+
data = appendWebsocketScript(data);
|
|
204
208
|
}
|
|
205
209
|
if (isPixUI && !isAlreadyPfbs && !disablePFBS && (isHTML || isJS)) {
|
|
206
210
|
let ver = /(\d)\.(\d)\.(\d+)/.exec(ua); // 0.2.*以上
|
|
@@ -210,8 +214,7 @@ module.exports.getMiddleware = () => {
|
|
|
210
214
|
res.end = _end;
|
|
211
215
|
_end.call(this, out);
|
|
212
216
|
});
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
217
|
+
} else {
|
|
215
218
|
console.log('directly call end...', data.length, type, _end);
|
|
216
219
|
_end.call(this, data);
|
|
217
220
|
}
|
|
@@ -226,6 +229,10 @@ module.exports.getMiddleware = () => {
|
|
|
226
229
|
let isCSS = type.indexOf('text/css') >= 0;
|
|
227
230
|
if (isPixUI && !disablePFBS && (isHTML || isJS)) {
|
|
228
231
|
log('hook send...', c.length, type);
|
|
232
|
+
if (isHTML) {
|
|
233
|
+
res.appendWebsocketScript = true;
|
|
234
|
+
c = appendWebsocketScript(c);
|
|
235
|
+
}
|
|
229
236
|
let ver = /(\d)\.(\d)\.(\d+)/.exec(ua); // 0.2.*以上
|
|
230
237
|
pfbsConvert(ver.splice(1), isJS, c, (out) => {
|
|
231
238
|
res.send = _send;
|
|
@@ -234,8 +241,7 @@ module.exports.getMiddleware = () => {
|
|
|
234
241
|
res.setHeader('Content-Type', 'application/octet-stream');
|
|
235
242
|
_send.call(res, out);
|
|
236
243
|
});
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
244
|
+
} else {
|
|
239
245
|
console.log('directly call send...', c.length, type, _send);
|
|
240
246
|
_send.call(this, c);
|
|
241
247
|
}
|
package/config/util.js
CHANGED
|
@@ -49,8 +49,7 @@ module.exports.readRegKey = function (path, key) {
|
|
|
49
49
|
windowsHide: true,
|
|
50
50
|
});
|
|
51
51
|
return out.toString();
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
52
|
+
} catch (error) {
|
|
54
53
|
console.error('Error executing PowerShell script:', error.message);
|
|
55
54
|
return '';
|
|
56
55
|
}
|
|
@@ -82,33 +81,31 @@ module.exports.loadProjectConfig = function () {
|
|
|
82
81
|
Object.entries(env || {}).forEach(([k, v]) => {
|
|
83
82
|
pienv['process.env.' + k] = JSON.stringify(v);
|
|
84
83
|
});
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
84
|
+
} catch (e) {
|
|
87
85
|
console.warn('read entry.js failed');
|
|
88
86
|
if (!/Cannot find module/.test(e.message)) {
|
|
89
87
|
console.error(e);
|
|
90
88
|
}
|
|
91
89
|
projectConfig = { pages: [] };
|
|
92
|
-
}
|
|
93
|
-
finally {
|
|
90
|
+
} finally {
|
|
94
91
|
}
|
|
95
92
|
return projectConfig;
|
|
96
93
|
};
|
|
97
94
|
|
|
98
|
-
module.exports.getH5esType = function() {
|
|
95
|
+
module.exports.getH5esType = function () {
|
|
99
96
|
const { parse } = require('comment-json');
|
|
100
97
|
const tsconfigPath = path.resolve(process.cwd(), 'tsconfig.json');
|
|
101
98
|
const fileContent = fs.readFileSync(tsconfigPath, 'utf8');
|
|
102
99
|
const tsconfig = parse(fileContent);
|
|
103
100
|
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
|
|
104
101
|
const existingTypeRoots = tsconfig.compilerOptions.typeRoots || [];
|
|
105
|
-
const h5esTypeRoot = existingTypeRoots.find(root => root.includes('h5es-types'));
|
|
102
|
+
const h5esTypeRoot = existingTypeRoots.find((root) => root.includes('h5es-types'));
|
|
106
103
|
let slashIndex = h5esTypeRoot.lastIndexOf('/');
|
|
107
104
|
if (slashIndex !== -1) {
|
|
108
105
|
h5esType = h5esTypeRoot.substring(slashIndex + 1);
|
|
109
106
|
}
|
|
110
107
|
return h5esType;
|
|
111
|
-
}
|
|
108
|
+
};
|
|
112
109
|
|
|
113
110
|
module.exports.setH5esType = function (newType) {
|
|
114
111
|
const { stringify, parse } = require('comment-json');
|
|
@@ -117,18 +114,17 @@ module.exports.setH5esType = function (newType) {
|
|
|
117
114
|
const tsconfig = parse(fileContent);
|
|
118
115
|
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
|
|
119
116
|
const existingTypeRoots = tsconfig.compilerOptions.typeRoots || [];
|
|
120
|
-
let h5esTypeRoot = existingTypeRoots.find(root => root.includes('h5es-types'));
|
|
121
|
-
const updateTypeRoots = existingTypeRoots.filter(root => !root.includes('h5es-types'));
|
|
117
|
+
let h5esTypeRoot = existingTypeRoots.find((root) => root.includes('h5es-types'));
|
|
118
|
+
const updateTypeRoots = existingTypeRoots.filter((root) => !root.includes('h5es-types'));
|
|
122
119
|
if (h5esTypeRoot === undefined || h5esTypeRoot != newType) {
|
|
123
120
|
updateTypeRoots.push(newType);
|
|
124
|
-
console.log('newType ', newType)
|
|
121
|
+
console.log('newType ', newType);
|
|
125
122
|
h5esTypeRoot = newType;
|
|
126
123
|
tsconfig.compilerOptions.typeRoots = updateTypeRoots;
|
|
127
124
|
fs.writeFileSync(tsconfigPath, stringify(tsconfig, null, 2));
|
|
128
125
|
try {
|
|
129
126
|
cp.execSync('npx prettier-eslint --write tsconfig.json', {});
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
127
|
+
} catch (e) {
|
|
132
128
|
console.error('prettier-eslint failed:', e.message);
|
|
133
129
|
}
|
|
134
130
|
}
|
package/config/webpack.js
CHANGED
|
@@ -292,8 +292,7 @@ var getMiddleware = function (appPort, notifyAppReload) {
|
|
|
292
292
|
restartRecommended: true,
|
|
293
293
|
newConfig: h5esType,
|
|
294
294
|
});
|
|
295
|
-
}
|
|
296
|
-
catch (error) {
|
|
295
|
+
} catch (error) {
|
|
297
296
|
console.log(error);
|
|
298
297
|
res.status(500).json({
|
|
299
298
|
error: `更新配置失败: ${error.message}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixui-dev/pxw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"directories": {
|
|
6
6
|
"lib": "lib"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"b": "npx webpack --mode=production --config config/webpack.js",
|
|
27
27
|
"d": "node scripts/run-pxw.js",
|
|
28
28
|
"p": "node scripts/pack.js",
|
|
29
|
+
"lint": "yarn prettier-eslint --write bin/*.js config/*.js scripts/*.js",
|
|
29
30
|
"postinstall": "node scripts/postinstall.js"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
package/scripts/postinstall.js
CHANGED
package/scripts/run-pxw.js
CHANGED