fix: cli使用异常 #147

This commit is contained in:
msojocs 2025-07-15 22:43:17 +08:00
parent 8c9eeed51f
commit 322de01a35
5 changed files with 42 additions and 9 deletions

View File

@ -1,3 +1,6 @@
# 1.06.2504010-2 / 2025-07-15
- fix: cli使用异常。#147
# 1.06.2504010-1 / 2025-07-05
- fix: 更新弹窗无法关闭。
- update: devtools to v1.06.2504010

View File

@ -8,7 +8,7 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
root_dir="$( cd -P "$( dirname "$SOURCE" )"/.. >/dev/null 2>&1 && pwd )"
cd $root_dir
cd $root_dir/bin
export WECHAT_DEVTOOLS_DIR="$root_dir/nwjs"
export APPDATA="$root_dir/nwjs"

29
res/scripts/cli.js Normal file
View File

@ -0,0 +1,29 @@
(() => {
process.argv[0] = 'wechat-devtools-cli'
process.env.USERPROFILE = require('os').homedir()
Object.defineProperty(global, 'userDirPath', {
set: function(value) {
if (value.includes('AppData/Local')) {
value = value.replace('AppData/Local', '.config')
value = value.replace(/User Data\/.*?\//, '')
// value = value.replace('~', require('os').homedir())
}
this._userDirPath = value
},
get: function() {
return this._userDirPath
}
})
// appPath
Object.defineProperty(global, 'appPath', {
set: function(value) {
if (value.includes('.exe')) {
value = value.replace('.exe', '')
}
this._appPath = value
},
get: function() {
return this._appPath
}
})
})();

View File

@ -1,11 +1,11 @@
(() => {
const http = require('http')
const originaleListen = http.Server.prototype.listen
http.Server.prototype.listen = function(port) {
if (port == 33233) {
console.warn('block port of http server:', port)
http.Server.prototype.listen = function(...args) {
if (args[0] == 33233) {
console.warn('block port of http server:', args[0])
return
}
return originaleListen.apply(this, [port])
return originaleListen.apply(this, args)
}
})();

View File

@ -11,7 +11,8 @@ fi
cd "$NW_PACKAGE_DIR"
sed -i 's#AppData/Local/\${global.userDirName}/User Data/\${global.productHash}/Default#.config/\${global.userDirName}/Default#g' js/common/cli/index.js
sed -i 's#USERPROFILE#HOME#g' js/common/cli/index.js
sed -i 's#`./\${global.appname}.exe`#`./bin/\${global.appname}`#g' js/common/cli/index.js
sed -i 's#,""));const T#,""));_.$0="wechat-devtools-cli";const T#' js/common/cli/index.js
cd $root_dir/package.nw/js/common/cli
cat $root_dir/res/scripts/cli.js > temp.js
cat index.js >> temp.js
rm index.js
mv temp.js index.js