diff --git a/bin/wechat-devtools b/bin/wechat-devtools index acfeaa2..2c417c1 100755 --- a/bin/wechat-devtools +++ b/bin/wechat-devtools @@ -1,27 +1,19 @@ #!/bin/bash -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 )" +root_dir=$(cd `dirname $0`/.. && pwd -P) -cd $DIR/.. - -export WECHAT_DEVTOOLS_DIR="$DIR/../nwjs" +export WECHAT_DEVTOOLS_DIR="$root_dir/nwjs" export APPDATA="$( echo ~ )/.config/wechat_devtools" -export PATH="$DIR/../wine:$DIR/../node/bin:$DIR/../nwjs:$PATH" +export PATH="$root_dir/wine:$root_dir/node/bin:$root_dir/nwjs:$PATH" # LANG=zh_CN.UTF-8 exec "$DIR"/../nwjs/nw --load-extension="$DIR"/../nwjs/package.nw/js/ideplugin "$@" -EXTENSION1="--load-extension=$DIR/../nwjs/package.nw/js/ideplugin" +EXTENSION1="--load-extension=$root_dir/nwjs/package.nw/js/ideplugin" EXTENSION2="--load-extension=$( echo ~ )/.config/wechat_devtools/WeappPlugin" # 调试器AppData与Storage可用 -INSPECTOR1="--custom-devtools-frontend=file://$DIR/../nwjs/package.nw/js/ideplugin/inspector" # 要加file://指明为本地文件路径 +INSPECTOR1="--custom-devtools-frontend=file://$root_dir/package.nw/js/ideplugin/inspector" # 要加file://指明为本地文件路径 INSPECTOR2="--custom-devtools-frontend=file://$( echo ~ )/.config/wechat_devtools/WeappPlugin/inspector/" USERDATADIR="$( echo ~ )/.config/wechat_devtools" # "$@"参数 LANG=zh_CN.UTF-8 -exec "$DIR"/../nwjs/nw $DIR/../package.nw $EXTENSION2 $INSPECTOR1 "$@" \ No newline at end of file +exec "$root_dir/nwjs/nw" $root_dir/package.nw $EXTENSION1 $INSPECTOR1 "$@" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0138de6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3" +services: + web: + image: node:16.13.1 + volumes: + - .:/workspace + entrypoint: /workspace/docker/entrypoint \ No newline at end of file diff --git a/docker/entrypoint b/docker/entrypoint new file mode 100644 index 0000000..764e817 --- /dev/null +++ b/docker/entrypoint @@ -0,0 +1,64 @@ +#!/bin/bash + +set -e # 命令出错就退出 +trap 'catchError $LINENO $BASH_COMMAND' SIGHUP SIGINT SIGQUIT EXIT # 捕获错误情况 + +catchError() { + exit_code=$? + if [ $exit_code -ne 0 ]; then + fail "\033[31mcommand: $2\n at $0:$1\n at $STEP\033[0m" + fi + exit $exit_code +} + +success() { + echo -e "\033[42;37m 成功 \033[0m $1" +} + +fail() { + echo -e "\033[41;37m 失败 \033[0m $1" +} + +echo "start" +python --version +node --version + +echo "\ + deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free\ + # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free + deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free\ + # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free + deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free\ + # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free + deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free\ + # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free + "> /etc/apt/sources.list + +apt-get clean; # 清空缓存 +apt-get update; # 更新 +apt-get install -y libx11-dev libxkbfile-dev + +hash node-gyp 2>/dev/null || { + echo >&2 "I require node-gyp but it's not installed. Installing."; + npm install -g node-gyp +} +node-gyp list + + +# test +# cd / +# mkdir -p test +# rm -rf test.a +# exec /workspace/tools/rebuild-node-modules + +# exit 0; +# end test + +cd /workspace +hash 7z 2>/dev/null || { + echo >&2 "I require 7z but it's not installed. Installing."; + apt-get update + apt-get install p7zip-full -y +} +export https_proxy="http://192.168.249.236:7890" +exec ./tools/setup-wechat-devtools-bash diff --git a/readme.md b/readme.md index 6d9557c..a70515d 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,26 @@ Docker容器启动方法 如需要映射外部目录,请自行修改Docker启动命令 -# 构筑方法1(推荐,支持断点续传) +# 构筑方法0(推荐,支持断点续传) + +1. 请先在Linux环境中自行安装`wine`和`wine-binfmt`; +2. 请安装`docker` `docker-compose` +3. 克隆本项目: +``` +git clone https://github.com/jiyeme/wechat-devtools.git +``` +4. 在本地项目目录中执行如下的语句,构筑开发者工具: +``` +docker-compose up +``` +5. 在本地项目目录中执行如下的语句,可以安装应用图标(非必须): +``` +./tools/install-desktop-icon-node +``` + +之后即可通过点击应用图标启动微信开发者工具,也可以运行`bin/wechat-devtools`通过命令行启动 + +# 构筑方法1(支持断点续传) 1. 请先在Linux环境中自行安装`wine`和`wine-binfmt`; 2. 请安装nodejs,并配置到PATH环境变量中; diff --git a/test/linkDir b/test/linkDir new file mode 100644 index 0000000..0e32a45 --- /dev/null +++ b/test/linkDir @@ -0,0 +1,9 @@ +#!/usr/bin/env node +const path = require("path") +const fs = require("fs") + +fs.symlinkSync( + path.resolve(__dirname, "../package.nw"), + path.resolve(__dirname, "../nwjs/package.nw") + +) \ No newline at end of file diff --git a/tools/rebuild-node-modules b/tools/rebuild-node-modules index cd2ed29..34a05e3 100755 --- a/tools/rebuild-node-modules +++ b/tools/rebuild-node-modules @@ -54,11 +54,12 @@ rm -fr "${package_dir}/node_modules_tmp/node_modules/spdlog-node" (cp -fr "${package_dir}/node_modules_tmp/node_modules/oniguruma" "${package_dir}/node_modules_tmp/node_modules/oniguruma-node") (cp -fr "${package_dir}/node_modules_tmp/node_modules/spdlog" "${package_dir}/node_modules_tmp/node_modules/spdlog-node") -(cd "${package_dir}/node_modules_tmp/node_modules" && find -name *.node | xargs -I{} cp -r {} ${package_dir}/node_modules/{}) +(cd "${package_dir}/node_modules_tmp/node_modules" && find -name "*.node" | xargs -I{} cp -r {} ${package_dir}/node_modules/{}) mkdir -p "${package_dir}/node_modules/vscode-ripgrep/bin" cp -fr "${package_dir}/node_modules_tmp/node_modules/vscode-ripgrep/bin/rg" "${package_dir}/node_modules/vscode-ripgrep/bin/rg" -rm -fr "${package_dir}/node_modules_tmp" +rm -rf "${package_dir}/node_modules_tmp" + # 移除旧配置 -rm -fr ~/.config/wechat_devtools +# rm -fr ~/.config/wechat_devtools diff --git a/tools/setup-wechat-devtools-bash b/tools/setup-wechat-devtools-bash index 1893962..d5298e0 100644 --- a/tools/setup-wechat-devtools-bash +++ b/tools/setup-wechat-devtools-bash @@ -1,17 +1,38 @@ #!/bin/bash +set -e # 命令出错就退出 +trap 'catchError $LINENO $BASH_COMMAND' SIGHUP SIGINT SIGQUIT EXIT # 捕获错误情况 + +catchError() { + exit_code=$? + if [ $exit_code -ne 0 ]; then + fail "\033[31mcommand: $2\n at $0:$1\n at $STEP\033[0m" + fi + exit $exit_code +} + +success() { + echo -e "\033[42;37m 成功 \033[0m $1" +} + +fail() { + echo -e "\033[41;37m 失败 \033[0m $1" +} + + root_dir=$(cd `dirname $0`/.. && pwd -P) echo "==========Initializing node==========" if [ -f "$root_dir/node/bin/node" ]; then - echo "node安装完毕" + success "node安装完毕" else - exec "$root_dir/tools/update-node-node" + node "$root_dir/tools/update-node-node" + success "node ok" fi if [ ! -f "$root_dir/node/bin/node" ]; then - echo "Node安装失败" + fail "Node安装失败" exit fi @@ -20,14 +41,14 @@ export PATH="$root_dir/node/bin":$PATH echo "==========Initializing nwjs==========" if [ -f "$root_dir/nwjs/nw" ]; then - echo "nwjs安装完毕" + success "nwjs安装完毕" else - exec "$root_dir/tools/update-nwjs-node" + node "$root_dir/tools/update-nwjs-node" fi echo "==========Initializing wechat-devtools package==========" if [ -f "$root_dir/package.nw/package.json" ]; then - echo "微信开发者工具安装完毕" + success "微信开发者工具安装完毕" else - exec "$root_dir/tools/update-wechat-devtools-node" + node "$root_dir/tools/update-wechat-devtools-node" fi \ No newline at end of file diff --git a/tools/update-wechat-devtools-node b/tools/update-wechat-devtools-node index 8b95ea2..954be3f 100644 --- a/tools/update-wechat-devtools-node +++ b/tools/update-wechat-devtools-node @@ -6,6 +6,7 @@ const fs = require("fs"); const path = require("path"); const { info } = require("console"); const util = require("util"); +const {exit} = require("process") const urls = { stable: "https://developers.weixin.qq.com/miniprogram/dev/devtools/stable.html", @@ -155,6 +156,9 @@ const extract = function (localPath) { stdio: "inherit", } ); + ext.on("error", code=>{ + reject(code) + }) ext.on("close", (code) => { info(`解压完毕:${code}`); resolve(extractPath); @@ -179,7 +183,9 @@ const upgrade = function (extractPath) { execSync(`rm -rf ${extractPath}`); if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) { - if (!fs.existsSync(path.resolve(__dirname, "../nwjs/package.nw"))) { + if (!fs.statSync(__dirname, "../nwjs/package.nw").isSymbolicLink()) { + execSync(`rm -rf ${path.resolve(__dirname, "../nwjs/package.nw")}`) + console.log(`创建链接 ${path.resolve(__dirname, "../package.nw")}--->${path.resolve(__dirname, "../nwjs/package.nw")}`) // 链接 fs.symlinkSync( path.resolve(__dirname, "../package.nw"), @@ -229,14 +235,18 @@ const rebuild_wechat_devtools_node_modules = function () { info("Rebuilding wechat-devtools node modules"); return new Promise((resolve, reject) => { - spawn(path.resolve(__dirname, "rebuild-node-modules"), [], { + const e = spawn(path.resolve(__dirname, "rebuild-node-modules"), [], { stdio: "inherit", - }).on("close", (code) => { + }) + e.on("error", code=>{ + reject(code) + }) + e.on("close", (code) => { console.info(`Rebuilding wechat-devtools node modules Result Code: ${code}`) if(0 === code) resolve(); else{ - reject() + reject(code) } }); });