diff --git a/CHANGELOG.MD b/CHANGELOG.MD index f1e4ba5..c65f20b 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -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 diff --git a/bin/wechat-devtools-cli b/bin/wechat-devtools-cli index 6629772..f0fbe9d 100755 --- a/bin/wechat-devtools-cli +++ b/bin/wechat-devtools-cli @@ -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" diff --git a/res/scripts/cli.js b/res/scripts/cli.js new file mode 100644 index 0000000..fdeb1a2 --- /dev/null +++ b/res/scripts/cli.js @@ -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 + } + }) +})(); \ No newline at end of file diff --git a/res/scripts/entrance.js b/res/scripts/entrance.js index 457f9fc..566f16c 100644 --- a/res/scripts/entrance.js +++ b/res/scripts/entrance.js @@ -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) } })(); \ No newline at end of file diff --git a/tools/fix-cli.sh b/tools/fix-cli.sh index 3cd6479..cb7fd95 100755 --- a/tools/fix-cli.sh +++ b/tools/fix-cli.sh @@ -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 \ No newline at end of file