diff --git a/docker-compose.yml b/docker-compose.yml index 2bc7496..94d65e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: environment: - ACTION=${ACTION_MODE:-false} # - https_proxy=${https_proxy:-} - - NO_WINE=${NO_WINE:-false} + - NO_WINE=${NO_WINE:-true} - LOCAL_USER_ID=${UID:-1000} entrypoint: /workspace/docker/docker-entrypoint userns_mode: "host" \ No newline at end of file diff --git a/docs/FAQ.MD b/docs/FAQ.MD index 1b34cf3..5faf078 100644 --- a/docs/FAQ.MD +++ b/docs/FAQ.MD @@ -19,7 +19,7 @@ 4. 为什么自己构筑的运行时加载项目时会卡住? - 检查一下在`package.nw/node_modules`目录下的node文件,是否依旧是Windows版本的dll,而非linux需要的so。如果依旧是Windows下的dll的话,可以考虑执行`tools/rebuild-node-modules`命令重新编译。如果已经是linux的so文件的话,则同问题3解决方法 + 检查一下在`package.nw/node_modules`目录下的node文件,是否依旧是Windows版本的dll,而非linux需要的so。如果依旧是Windows下的dll的话,可以考虑执行`tools/rebuild-node-modules.sh`命令重新编译。如果已经是linux的so文件的话,则同问题3解决方法 5. 为什么自己构筑或更新后的在加载项目后,IDE界面会显示错误崩溃? @@ -35,7 +35,7 @@ 8. 直接下载下来的发布包,在加载项目后,为什么右侧的编辑界面是空白? - 根据相关的情况分析,可以打开在微信开发者工具菜单里的调试支持。查看里面的日志报错,目前大部分情况是您的系统里libstdc++版本与预编译的版本不一致。可以考虑采用docker版本,或者执行`tools/rebuild-node-modules`命令重新编译系统支持的原生模块。 + 根据相关的情况分析,可以打开在微信开发者工具菜单里的调试支持。查看里面的日志报错,目前大部分情况是您的系统里libstdc++版本与预编译的版本不一致。可以考虑采用docker版本,或者执行`tools/rebuild-node-modules.sh`命令重新编译系统支持的原生模块。 9. 自己构筑时,为什么会报告python执行错误? diff --git a/old/compact/Dockerfile b/old/compact/Dockerfile deleted file mode 100644 index cb9d4b4..0000000 --- a/old/compact/Dockerfile +++ /dev/null @@ -1,61 +0,0 @@ -FROM debian:stretch -LABEL maintainer="minun (minun@mewmew.cn)" - -ENV LANG=C.UTF-8 - -# update repo sources -RUN set -ex; \ - cp /etc/apt/sources.list /etc/apt/sources.list.bak; \ - echo "deb http://mirrors.aliyun.com/debian/ stretch main" > /etc/apt/sources.list; \ - echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main" >> /etc/apt/sources.list; \ - rm -rf /var/cache/apt/archives/lock \ - apt-get clean; \ - apt-get update --fix-missing; - -RUN DEBIAN_FRONTEND=noninteractive \ - apt-get install -y --no-install-recommends \ - apt-utils \ - build-essential \ - ca-certificates \ - git \ - libx11-dev \ - libxkbfile-dev \ - pkg-config \ - python \ - p7zip-full - -ADD runtime-mewjs.tar.gz /opt/mewjs -COPY node-v12.6.0-linux-x64.tar.gz /opt/wechat/cache/node-v12.6.0-linux-x64.tar.gz -COPY nwjs-sdk-v0.39.3-linux-x64.tar.gz /opt/wechat/cache/nwjs-sdk-v0.39.3-linux-x64.tar.gz -COPY wechat_devtools_1.03.2009140_x64.exe /opt/wechat/cache/wechat_devtools_1.03.2009140_x64.exe -COPY build /opt/wechat/cache/build - -RUN chmod +x /opt/mewjs/bin/hako \ - /opt/mewjs/bin/mew \ - /opt/mewjs/bin/chan \ - /opt/mewjs/bin/mew_* \ - /opt/mewjs/bin/npm \ - /opt/mewjs/bin/npx - -RUN set -ex; \ - useradd -m builder -s /bin/bash; \ - mkdir -p /opt/local/proj; \ - cd /opt/local/proj; \ - git clone https://github.com/dragonation/wechat-devtools.git; \ - mkdir -p /opt/local/proj/wechat-devtools/cache; \ - cd wechat-devtools; \ - cp -fr /opt/wechat/cache/* cache/; \ - cp -f /opt/wechat/cache/build build; \ - chmod -R 777 . - -ENV PATH=/opt/mewjs/bin:/usr/local/bin:/usr/bin:/bin - -WORKDIR /opt/local/proj/wechat-devtools - -# docker build -t wechat-devtools-compact-builder . -# docker run -ti --rm -v `pwd`:/opt/wechat/output wechat-devtools-compact-builder /bin/bash --login -i - -# su builder -# export PATH=/opt/mewjs/bin:$PATH -# ./build -# cp wechat-devtools-compact.tar.gz /opt/wechat/output/wechat-devtools-1.03.2009140-compact.tar.gz diff --git a/patch/nw-menu.js b/patch/nw-menu.js deleted file mode 100644 index 52ff3b0..0000000 --- a/patch/nw-menu.js +++ /dev/null @@ -1,92 +0,0 @@ -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); -}; diff --git a/test/reduce-wine b/test/reduce-wine index 99de2a7..9d2ef87 100644 --- a/test/reduce-wine +++ b/test/reduce-wine @@ -2,5 +2,5 @@ export NO_WINE=true root_dir=$(cd `dirname $0`/.. && pwd -P) -$root_dir/tools/fix-core -$root_dir/tools/fix-other \ No newline at end of file +$root_dir/tools/fix-core.sh +$root_dir/tools/fix-other.sh \ No newline at end of file diff --git a/tools/appimage.sh b/tools/appimage.sh old mode 100644 new mode 100755 diff --git a/tools/build-release.sh b/tools/build-release.sh old mode 100644 new mode 100755 index 2a853a6..3aa500c --- a/tools/build-release.sh +++ b/tools/build-release.sh @@ -47,8 +47,8 @@ for type in wine no_wine; do if [[ $type == 'no_wine' ]];then notice "no wine handle" export NO_WINE=true - bash "$root_dir/tools/fix-core" - bash "$root_dir/tools/fix-other" + bash "$root_dir/tools/fix-core.sh" + bash "$root_dir/tools/fix-other.sh" fi mkdir -p "$build_dir/$FULL_NAME" diff --git a/tools/fix-cli-node b/tools/fix-cli-node deleted file mode 100755 index a770348..0000000 --- a/tools/fix-cli-node +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env node -const path = require("path"); -const fs = require("fs"); - -console.info("Patching CLI command"); - -const rootDir = path.dirname(__dirname); - -let cli = fs.readFileSync(path.resolve(rootDir, "package.nw/js/common/cli/index.js"), "utf8"); - -cli = cli.replace(/USERPROFILE/g, "HOME"); -cli = cli.replace(/AppData\/Local\/\$\{global\.userDirName\}\/User Data/g, - ".config/${global.userDirName}"); -cli = cli.replace(/`\.\/\$\{global.appname\}\.exe`/g, - "require(\"path\").join(__dirname, \"../../../../bin/wechat-devtools\")"); -cli = cli.replace(/"\.\.\/\.\.\/\.\.\/\.\.\/resources_win\/nw\/x64\/nw.exe"/g, - "\"../../../../nwjs/nw\""); - -fs.writeFileSync(path.resolve(rootDir, "package.nw/js/common/cli/index.js"), cli); \ No newline at end of file diff --git a/tools/fix-cli.sh b/tools/fix-cli.sh new file mode 100755 index 0000000..f58f524 --- /dev/null +++ b/tools/fix-cli.sh @@ -0,0 +1,15 @@ +#! /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 + exit 1 +fi + +cd "$NW_PACKAGE_DIR" + +sed -i 's#AppData/Local/\${global.userDirName}/User Data/Default#.config/\${global.userDirName}/Default#g' js/common/cli/index.js +sed -i 's#USERPROFILE#HOME#g' js/common/cli/index.js diff --git a/tools/fix-core b/tools/fix-core.sh similarity index 96% rename from tools/fix-core rename to tools/fix-core.sh index 4ae2754..024ca85 100755 --- a/tools/fix-core +++ b/tools/fix-core.sh @@ -1,13 +1,13 @@ #!/bin/bash -echo "Fix Core" root_dir=$(cd `dirname $0`/.. && pwd -P) package_dir="$root_dir/package.nw" tmp_dir="$root_dir/tmp/core" -unpack_script="$root_dir/tools/wxvpkg/unpack" -pack_script="$root_dir/tools/wxvpkg/pack" 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/tools/fix-menu.sh b/tools/fix-menu.sh new file mode 100755 index 0000000..9adcfdd --- /dev/null +++ b/tools/fix-menu.sh @@ -0,0 +1,130 @@ +#! /bin/bash +# Author: https://github.com/cytle/wechat_web_devtools/issues/293#issuecomment-604623774 + +set -e + +root_dir=$(cd `dirname $0`/.. && pwd -P) +NW_PACKAGE_DIR="$root_dir/package.nw" + +cd "$NW_PACKAGE_DIR" +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 +# 判断匹配函数,匹配函数不为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" < { + 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" + +cat "$tmp_file" > "$target_file" +rm "$tmp_file" diff --git a/tools/fix-other b/tools/fix-other.sh similarity index 98% rename from tools/fix-other rename to tools/fix-other.sh index c454a2e..30b8d72 100755 --- a/tools/fix-other +++ b/tools/fix-other.sh @@ -15,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/tools/fix-package-name-node b/tools/fix-package-name.js old mode 100755 new mode 100644 similarity index 94% rename from tools/fix-package-name-node rename to tools/fix-package-name.js index f0f7a93..e71c681 --- a/tools/fix-package-name-node +++ b/tools/fix-package-name.js @@ -1,7 +1,6 @@ #!/usr/bin/env node const path = require("path"); const fs = require("fs"); -const { spawn } = require("child_process"); const parseFile = function (path) { diff --git a/tools/fix-selection-copy-node b/tools/fix-selection-copy-node index dfeea81..95db925 100755 --- a/tools/fix-selection-copy-node +++ b/tools/fix-selection-copy-node @@ -2,7 +2,7 @@ const path = require("path"); const os = require("os"); const fs = require("fs"); -const { spawn, execSync } = require("child_process"); +const { execSync } = require("child_process"); console.info("Patching editor selection copy configs"); diff --git a/tools/patch-wechat-devtools-node b/tools/patch-wechat-devtools-node deleted file mode 100755 index cd2711a..0000000 --- a/tools/patch-wechat-devtools-node +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env node -const path = require("path"); -const fs = require("fs"); -const { spawn } = require("child_process"); - -let code = fs.readFileSync(path.resolve(__dirname, "../package.nw/js/unpack/hackrequire/index.js"), {encoding:"utf8"}); - -let signatureBegin = "/* patch wechat devtools begin */\n"; -let signatureEnd = "/* patch wechat devtools end */\n"; - -let index = code.indexOf(signatureBegin); - -let patch = fs.readdirSync(path.resolve(__dirname, "../patch")).map((file) => { - console.log(file) - if ((file !== ".") && (file.endsWith(".js"))) { - return (`/* ${file} */\n` + - "(() => {\n\n" + - " try {\n\n" + - fs.readFileSync(path.resolve(__dirname, "../patch", file), {encoding:"utf8"}).trim().split("\n").map((line) => { - return " " + line; - }).join("\n") + "\n\n" + - " } catch (error) {\n" + - " process.stderr.write(error.message);\n" + - " process.stderr.write(error.stack);\n" + - " }\n\n" + - "})();"); - } - return ""; -}).join("\n").trim() + "\n"; - -if (code.indexOf(signatureBegin) !== -1) { - code = code.split(signatureEnd).slice(1).join(signatureEnd); -} - -fs.writeFileSync(path.resolve(__dirname, "../package.nw/js/unpack/hackrequire/index.js"), - signatureBegin + patch + signatureEnd + code); diff --git a/tools/rebuild-node-modules b/tools/rebuild-node-modules.sh similarity index 89% rename from tools/rebuild-node-modules rename to tools/rebuild-node-modules.sh index ee497d6..b205c26 100755 --- a/tools/rebuild-node-modules +++ b/tools/rebuild-node-modules.sh @@ -3,17 +3,13 @@ # 1 ---- NW版本 set -e -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" -package_dir="$DIR/../package.nw" -export PATH="$DIR/../node/bin:$PATH" +root_dir=$(cd `dirname $0`/.. && pwd -P) +package_dir="$root_dir/package.nw" +export PATH="$root_dir/node/bin:$PATH" -NW_VERSION=$1 +if [ ! -z $1 ];then + NW_VERSION=$1 +fi if [ -z $NW_VERSION ]; then echo "NW 版本未指定!" exit 1 @@ -22,7 +18,7 @@ fi 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 )" "$DIR/../node/bin/python" + ln -s "$( which python2 )" "$root_dir/node/bin/python" fi hash nw-gyp 2>/dev/null || { diff --git a/tools/update-wechat-devtools-node b/tools/update-wechat-devtools-node index 595bd27..19b12bd 100755 --- a/tools/update-wechat-devtools-node +++ b/tools/update-wechat-devtools-node @@ -208,7 +208,7 @@ const patch_wechat_devtools_package_name = function () { info("Patching wechat-devtools package name"); return new Promise((resolve, reject) => { - spawn(path.resolve(__dirname, "fix-package-name-node"), [], { + spawn(path.resolve(__dirname, "fix-package-name.js"), [], { stdio: "inherit", }).on("close", (code) => { resolve(); @@ -230,7 +230,7 @@ const patch_wechat_devtools_CLI = function () { info("Patching wechat-devtools CLI supports"); return new Promise((resolve, reject) => { - spawn(path.resolve(__dirname, "fix-cli-node"), [], { + spawn(path.resolve(__dirname, "fix-cli.sh"), [], { stdio: "inherit", }).on("close", (code) => { resolve(); @@ -241,7 +241,7 @@ const patch_wechat_devtools_core = function () { info("Patching wechat-devtools core.wxvpkg"); return new Promise((resolve, reject) => { - spawn(path.resolve(__dirname, "fix-core"), [], { + spawn(path.resolve(__dirname, "fix-core.sh"), [], { stdio: "inherit", }).on("close", (code) => { resolve(); @@ -253,7 +253,7 @@ const rebuild_wechat_devtools_node_modules = function () { return new Promise((resolve, reject) => { const nwConfig = require(path.resolve(__dirname, "../conf/nwjs.json")) - const e = spawn(path.resolve(__dirname, "rebuild-node-modules"), [nwConfig.version], { + const e = spawn(path.resolve(__dirname, "rebuild-node-modules.sh"), [nwConfig.version], { stdio: "inherit", }) e.on("error", code=>{ @@ -274,7 +274,7 @@ const patch_wechat_devtools = function () { return new Promise((resolve, reject) => { const exec = spawn( - path.resolve(__dirname, "patch-wechat-devtools-node"), + path.resolve(__dirname, "fix-menu.sh"), [], { stdio: "inherit", @@ -289,7 +289,7 @@ const patch_other = function () { info("Patching Other"); return new Promise((resolve, reject) => { - execSync(path.resolve(__dirname, "fix-other")) + execSync(path.resolve(__dirname, "fix-other.sh")) resolve(); }); diff --git a/tools/wechat-devtools-env.sh b/tools/wechat-devtools-env.sh deleted file mode 100755 index 1008137..0000000 --- a/tools/wechat-devtools-env.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" - -export PATH=$DIR/../node/bin:$PATH -export PATH=$DIR/../nwjs:$PATH diff --git a/tools/wxvpkg/pack b/tools/wxvpkg_pack.js similarity index 100% rename from tools/wxvpkg/pack rename to tools/wxvpkg_pack.js diff --git a/tools/wxvpkg/unpack b/tools/wxvpkg_unpack.js similarity index 100% rename from tools/wxvpkg/unpack rename to tools/wxvpkg_unpack.js