diff options
author | msojocs | 2022-02-27 20:00:40 +0800 |
---|---|---|
committer | msojocs | 2022-02-27 20:00:40 +0800 |
commit | 01d5045bf9670428550b83927c364b4d00bca2c9 (patch) | |
tree | a8a96a767a051dbcdc37f91aad7fb0c2dfb501e8 | |
parent | c4ee958c0f48edb8cef61953b057d5c1db896117 (diff) | |
download | aur-01d5045bf9670428550b83927c364b4d00bca2c9.tar.gz |
update: 整理,便于移植
-rw-r--r-- | .SRCINFO | 10 | ||||
-rw-r--r-- | PKGBUILD | 33 | ||||
-rwxr-xr-x | fix-cli.sh | 2 | ||||
-rwxr-xr-x | fix-core.sh | 14 | ||||
-rwxr-xr-x | fix-menu.sh | 145 | ||||
-rwxr-xr-x | fix-other.sh | 10 | ||||
-rw-r--r--[-rwxr-xr-x] | fix-package-name.js (renamed from fix-package-name-node) | 9 | ||||
-rw-r--r--[-rwxr-xr-x] | rebuild-node-modules.sh (renamed from rebuild-modules.sh) | 44 | ||||
-rw-r--r-- | wxvpkg_pack.js (renamed from wxvpkg_pack) | 0 | ||||
-rw-r--r-- | wxvpkg_unpack.js (renamed from wxvpkg_unpack) | 0 |
10 files changed, 173 insertions, 94 deletions
@@ -1,7 +1,7 @@ pkgbase = wechat-devtools pkgdesc = WeChat Devtools For Linux. pkgver = 1.05.2201242 - pkgrel = 1 + pkgrel = 2 epoch = 2 url = https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html arch = x86_64 @@ -25,10 +25,10 @@ pkgbase = wechat-devtools source = fix-cli.sh source = fix-menu.sh source = fix-core.sh - source = rebuild-modules.sh - source = fix-package-name-node - source = wxvpkg_pack - source = wxvpkg_unpack + source = rebuild-node-modules.sh + source = fix-package-name.js + source = wxvpkg_pack.js + source = wxvpkg_unpack.js source = fix-other.sh md5sums = b6f49803c51d0abacca2d1e566c7fe19 md5sums = 85552bae33e98eb186c5068419efce03 @@ -18,7 +18,7 @@ _node_version="16.1.0" pkgname=wechat-devtools pkgver="1.05.2201242" # 主版本号 -pkgrel=1 # 次版本号release, 一位数用0n +pkgrel=2 # 次版本号release epoch=2 # 大版本迭代强制更新(维护者变更,尽量不用) pkgdesc="WeChat Devtools For Linux. " arch=("x86_64") @@ -36,10 +36,10 @@ source=("nwjs-v${_nwjs_ver}.tar.gz::https://npm.taobao.org/mirrors/nwjs/v${_nwjs "fix-cli.sh" "fix-menu.sh" "fix-core.sh" - "rebuild-modules.sh" - "fix-package-name-node" - "wxvpkg_pack" - "wxvpkg_unpack" + "rebuild-node-modules.sh" + "fix-package-name.js" + "wxvpkg_pack.js" + "wxvpkg_unpack.js" "fix-other.sh") md5sums=(b6f49803c51d0abacca2d1e566c7fe19 # nwjs "${_wechat_devtools_md5}" @@ -58,7 +58,16 @@ md5sums=(b6f49803c51d0abacca2d1e566c7fe19 # nwjs options=('!strip') prepare() { - 7z x -owechat_devtools ${_wechat_devtools_exe} + 7z x -owechat_devtools ${_wechat_devtools_exe} code/package.nw + mv wechat_devtools/code/package.nw package.nw + rm -rf wechat_devtools + ls | grep node-*linux* | xargs -I{} mv {} node + ls | grep nwjs-*linux* | xargs -I{} mv {} nwjs + + mkdir tools + for file in *.js *.sh; do + mv $file tools; + done } _log() { @@ -68,7 +77,7 @@ _log() { build() { # prepare node _log "prepare node v${_node_version}" - export PATH="$srcdir/node-v${_node_version}-linux-x64/bin:$PATH" + export PATH="$srcdir/node/bin:$PATH" # prepare nw-gyp _log "prepare nw-gyp" @@ -80,14 +89,14 @@ build() { cp "$(which node)" "${srcdir}/node.${_node_version}" # run fix scripts - export NW_PACKAGE_DIR="${srcdir}/wechat_devtools/code/package.nw" + export NW_PACKAGE_DIR="${srcdir}/package.nw" export NW_VERSION=$_nwjs_ver export srcdir=$srcdir export NO_WINE=true - for script in fix-package-name-node fix-cli.sh fix-other.sh fix-menu.sh fix-core.sh rebuild-modules.sh; do + for script in fix-package-name.js fix-cli.sh fix-other.sh fix-menu.sh fix-core.sh rebuild-node-modules.sh; do _log "run ${script}" - "${srcdir}/${script}" + "${srcdir}/tools/${script}" done # cleanup @@ -98,8 +107,8 @@ package() { mkdir -p "${pkgdir}${_install_dir}" cd "${pkgdir}${_install_dir}" - cp -r "${srcdir}/nwjs-sdk-v${_nwjs_ver}-linux-x64/"* ./ - cp -r "${srcdir}/wechat_devtools/code/package.nw" ./package.nw + cp -r "${srcdir}/nwjs/"* ./ + cp -r "${srcdir}/package.nw" ./package.nw find ./package.nw -type d | xargs -I {} chmod -R a+rx {} cp ${srcdir}/node.${_node_version} node diff --git a/fix-cli.sh b/fix-cli.sh index 9386cb7632b2..f58f524413d0 100755 --- a/fix-cli.sh +++ b/fix-cli.sh @@ -1,6 +1,8 @@ #! /bin/bash set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +NW_PACKAGE_DIR="$root_dir/package.nw" if [ -z "$NW_PACKAGE_DIR" ]; then echo -e "\e[1;31m\$NW_PACKAGE_DIR is empty\e[0m" >&2 diff --git a/fix-core.sh b/fix-core.sh index a34f09139588..024ca855f8ef 100755 --- a/fix-core.sh +++ b/fix-core.sh @@ -1,11 +1,13 @@ #!/bin/bash -echo "Fix Core" - -package_dir="$srcdir/wechat_devtools/code/package.nw" -tmp_dir=$(mktemp -d) -unpack_script="$srcdir/wxvpkg_unpack" -pack_script="$srcdir/wxvpkg_pack" +root_dir=$(cd `dirname $0`/.. && pwd -P) +package_dir="$root_dir/package.nw" +tmp_dir="$root_dir/tmp/core" +mkdir -p $tmp_dir +unpack_script="$root_dir/tools/wxvpkg_unpack.js" +pack_script="$root_dir/tools/wxvpkg_pack.js" + +echo "Fix Core" # unpack 文件 到 路径 node "$unpack_script" "$package_dir/core.wxvpkg" "$tmp_dir/core.wxvpkg" diff --git a/fix-menu.sh b/fix-menu.sh index 71ad0880f576..9adcfdd92214 100755 --- a/fix-menu.sh +++ b/fix-menu.sh @@ -3,57 +3,126 @@ set -e -if [ -z "$NW_PACKAGE_DIR" ]; then - echo -e "\e[1;31m\$NW_PACKAGE_DIR is empty\e[0m" >&2 - exit 1 -fi +root_dir=$(cd `dirname $0`/.. && pwd -P) +NW_PACKAGE_DIR="$root_dir/package.nw" cd "$NW_PACKAGE_DIR" -target_file=js/core/index.js +target_file=js/unpack/hackrequire/index.js if [ ! -f "$target_file" ]; then echo -e "\e[1;31m$target_file is not exist\e[0m" >&2 exit 1 fi - -if [ "$(wc -l < "$target_file")" -gt 0 ]; then +# 判断匹配函数,匹配函数不为0,则包含给定字符 +if [ `grep -c "patch wechat devtools begin" $target_file` -ne '0' ];then echo -e "\e[1;31m$target_file seems to have been modified\e[0m" >&2 exit 1 fi tmp_file=$(mktemp) cat > "$tmp_file" <<EOF -const oldMenuAppend = nw.Menu.prototype.append -const oldMenuInsert = nw.Menu.prototype.insert -function isSeparator(menu_item) { - return menu_item && menu_item.type === 'separator' -} -nw.Menu.prototype.append = function (menu_item) { - const items = this.items - const len = this.items.length - if (~items.indexOf(menu_item)) return - if (len === 0 && isSeparator(menu_item)) { - return menu_item._destroy() - } - if (!isSeparator(menu_item) || !isSeparator(items[len - 1])) { - oldMenuAppend.call(this, menu_item) - } else { - return menu_item._destroy() - } -} -nw.Menu.prototype.insert = function (menu_item, i) { - const items = this.items - const len = this.items.length - if (~items.indexOf(menu_item)) return - if (len === 0 && isSeparator(menu_item)) { - return menu_item._destroy() - } - if (!isSeparator(menu_item) || (!isSeparator(items[i]) && !isSeparator(items[i - 1]))) { - oldMenuInsert.call(this, menu_item) - } else { - return menu_item._destroy() - } -} +/* patch wechat devtools begin */ +/* nw-menu.js */ +(() => { + try { + if (typeof nw === "undefined") { + return; + } + + let log = function (content) { + process.stderr.write(content + "\n"); + }; + + let originMenuItem = nw.MenuItem; + nw.MenuItem = function MenuItem(options) { + + options = Object.assign({}, options); + + delete options.shortcutName; + delete options.shouldEnabled; + + if (options.label && (typeof options.label === "string")) { + + if (options.label.indexOf("[") !== -1) { + let rest = options.label.split("[").slice(1).join("[").trim(); + if (rest[rest.length - 1] === "]") { + rest = rest.slice(0, -1).split("+").map((x) => { + if (!x) { return "+" } + switch (x) { + case "↓": { return "Down"; } + case "↑": { return "Up"; } + case "PAGE↓": { return "PageDown"; } + case "PAGE↑": { return "PageUp"; } + case "←": { return "Left"; } + case "→": { return "Right"; } + default: { return x; } + } + }); + if (rest.length > 1) { + options.key = rest[rest.length - 1]; + options.modifiers = rest.slice(0, -1).join("+"); + } else { + options.key = rest[0]; + } + } + options.label = options.label.split("[")[0]; + } + + if (options.label.indexOf("(&") !== -1) { + options.label = options.label.split("(&")[0]; + } + options.label = options.label.replace("&", "").trim(); + + switch (options.label) { + case "Go to Declaration": { options.label = "转到声明"; break; } + case "Go to References": { options.label = "转到引用"; break; } + case "Find All References": { options.label = "查找所有引用"; break; } + case "Find All Implementations": { options.label = "查找所有实现"; break; } + } + + } + + return new originMenuItem(options); + + }; + + let originAppend = nw.Menu.prototype.append; + nw.Menu.prototype.append = function (item) { + + if (item.parentMenu) { + item.parentMenu.remove(item); + } + item.parentMenu = this; + + if ((this.items.length > 0) && + (this.items[this.items.length - 1].type === "separator") && + (item.type === "separator")) { + originInsert.call(this, item, this.items.length); + return; + } + + if ((this.items.length === 0) && (item.type === "separator")) { + originInsert.call(this, item, this.items.length); + return; + } + + return originAppend.call(this, item); + }; + + let originInsert = nw.Menu.prototype.insert; + nw.Menu.prototype.insert = function (item, index) { + if (item.parentMenu) { + item.parentMenu.remove(item); + } + item.parentMenu = this; + return originInsert.call(this, item, index); + }; + } catch (error) { + process.stderr.write(error.message); + process.stderr.write(error.stack); + } +})(); +/* patch wechat devtools end */ EOF cat "$target_file" >> "$tmp_file" diff --git a/fix-other.sh b/fix-other.sh index c179ca689d51..30b8d722ec16 100755 --- a/fix-other.sh +++ b/fix-other.sh @@ -1,7 +1,9 @@ #!/bin/bash - -package_dir="$NW_PACKAGE_DIR" -tmp_dir=$(mktemp -d) +set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +srcdir=$root_dir +tmp_dir="$root_dir/tmp" +package_dir="$root_dir/package.nw" # 修复: webview manager # 此bug导致以下功能异常: @@ -13,7 +15,7 @@ sed -i 's#module.exports = createWebviewManager;#module.exports = createWebviewM # 修复:可视化用的wcc,wcsc echo "fix: wcc,wcsc" if [[ ! -d "$tmp_dir/node_modules" ]];then - mkdir "$tmp_dir/node_modules" + mkdir -p "$tmp_dir/node_modules" fi cd $tmp_dir && npm install miniprogram-compiler # wcc wcsc diff --git a/fix-package-name-node b/fix-package-name.js index a37f59efb41d..e71c681eb21b 100755..100644 --- a/fix-package-name-node +++ b/fix-package-name.js @@ -11,12 +11,11 @@ const parseFile = function (path) { content.name = "wechat_devtools"; // 开启调试,更新参数 - content['chromium-args'] = content['chromium-args'].replace('--ignore-gpu-blacklist', '--ignore-gpu-blocklist') + ' --mixed-context' + content['chromium-args'] = content['chromium-args'].replace('--disable-devtools', '--mixed-context').replace('--ignore-gpu-blacklist', '--ignore-gpu-blocklist') content.window.height = content.window.width = 1000 - fs.writeFileSync(path, JSON.stringify(content, null, 4)); + fs.writeFileSync(path, JSON.stringify(content)); }; -const pkgDir = process.env['NW_PACKAGE_DIR'] -parseFile(`${pkgDir}/package.json`); -parseFile(`${pkgDir}/package-lock.json`); +parseFile(path.resolve(__dirname, "../package.nw/package.json")); +parseFile(path.resolve(__dirname, "../package.nw/package-lock.json")); diff --git a/rebuild-modules.sh b/rebuild-node-modules.sh index e58bca78edd6..b205c26935c8 100755..100644 --- a/rebuild-modules.sh +++ b/rebuild-node-modules.sh @@ -1,35 +1,31 @@ -#! /bin/bash +#!/bin/bash +# 参数: +# 1 ---- NW版本 set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +package_dir="$root_dir/package.nw" +export PATH="$root_dir/node/bin:$PATH" -if [ -z "$NW_PACKAGE_DIR" ]; then - echo -e "\e[1;31m\$NW_PACKAGE_DIR is empty\e[0m" >&2 - exit 1 +if [ ! -z $1 ];then + NW_VERSION=$1 fi - -if [ -z "$NW_VERSION" ]; then - echo -e "\e[1;31m\$NW_VERSION is empty\e[0m" >&2 - exit 1 +if [ -z $NW_VERSION ]; then + echo "NW 版本未指定!" + exit 1 fi -TEMP_DIR=$(mktemp -d) -trap "{ rm -rf $TEMP_DIR; }" EXIT - -# prepare python2 -# fix https://github.com/nwjs/nw-gyp/issues/122 -ln -sf "$(which python2)" "$TEMP_DIR/python" -export PATH=$TEMP_DIR:$PATH - -node_modules="$NW_PACKAGE_DIR/node_modules" -dry_run="n" -package_dir="$NW_PACKAGE_DIR" - -if [ ! -d "$node_modules" ]; then - echo -e "\e[1;31m$node_modules is not exist\e[0m" >&2 - exit 1 +PY_VERSION=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'` +if [ $PY_VERSION != 2 ]; then + hash python2 2>/dev/null || { echo >&2 "I require python2 but it's not installed. Aborting."; exit 1; } + ln -s "$( which python2 )" "$root_dir/node/bin/python" fi -# 以下原封复制 +hash nw-gyp 2>/dev/null || { + echo "=======请安装nw-gyp=======" + exit 1 +} + # 代理处理 echo "尝试取消所有代理" unset http_proxy diff --git a/wxvpkg_pack b/wxvpkg_pack.js index 6918c5269eaa..6918c5269eaa 100644 --- a/wxvpkg_pack +++ b/wxvpkg_pack.js diff --git a/wxvpkg_unpack b/wxvpkg_unpack.js index 14c46a56186f..14c46a56186f 100644 --- a/wxvpkg_unpack +++ b/wxvpkg_unpack.js |