From a6033761252c484387fff9f51529c999cc432882 Mon Sep 17 00:00:00 2001 From: msojocs Date: Wed, 16 Mar 2022 16:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B1=E5=8C=96=E5=AF=B9=E5=AE=BF=E4=B8=BB?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=9A=84=E8=A6=81=E6=B1=82=EF=BC=9B=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B5=9E=E8=B5=8F=E6=94=AF=E6=8C=81=E5=90=8D?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/node.json | 6 -- conf/node_info | 6 ++ docs/FAQ.MD | 2 +- readme.md | 8 +-- test/core-test | 0 test/env | 2 +- tools/setup-wechat-devtools-bash | 2 +- tools/update-node-node | 120 ------------------------------- tools/update-node.sh | 63 ++++++++++++++++ 9 files changed, 76 insertions(+), 133 deletions(-) delete mode 100644 conf/node.json create mode 100644 conf/node_info mode change 100644 => 100755 test/core-test mode change 100644 => 100755 test/env delete mode 100755 tools/update-node-node create mode 100755 tools/update-node.sh diff --git a/conf/node.json b/conf/node.json deleted file mode 100644 index 9bb0256..0000000 --- a/conf/node.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "此处版本应与nwjs使用的node版本一致", - "version": "16.1.0", - "url": "https://npm.taobao.org/mirrors/node/v${version}/node-v${version}-linux-x64.tar.gz", - "url-global": "https://nodejs.org/download/release/v${version}/node-v${version}-linux-x64.tar.gz" -} \ No newline at end of file diff --git a/conf/node_info b/conf/node_info new file mode 100644 index 0000000..a970451 --- /dev/null +++ b/conf/node_info @@ -0,0 +1,6 @@ +# 此处版本应与nwjs使用的node版本一致 +if [ -z $NODE_VERSION ];then + NODE_VERSION=16.1.0 +fi +NODE_URL_CN=https://npm.taobao.org/mirrors/node/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz +NODE_URL_GLOBAL=https://nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz diff --git a/docs/FAQ.MD b/docs/FAQ.MD index 5faf078..836d046 100644 --- a/docs/FAQ.MD +++ b/docs/FAQ.MD @@ -15,7 +15,7 @@ 3. 为什么自己构筑或更新后的运行时编辑器和调试器是一片空白? - 检查一下`conf/node.json`和`conf/nwjs.json`里面定义的版本是否与最新微信官方开发者工具的一致。如果有修改版本号的情况,则在更新完这两个JSON文件后,执行`tools/update-node`和`tools/update-nwjs`命令。然后删除`package.nw`目录重新执行`tools/setup-wechat-devtools`命令(感谢ReggieCai31的issue和解决方案) + 检查一下`conf/node_info`和`conf/nwjs.json`里面定义的版本是否与最新微信官方开发者工具的一致。如果有修改版本号的情况,则在更新完这两个JSON文件后,执行`tools/update-node`和`tools/update-nwjs`命令。然后删除`package.nw`目录重新执行`tools/setup-wechat-devtools`命令(感谢ReggieCai31的issue和解决方案) 4. 为什么自己构筑的运行时加载项目时会卡住? diff --git a/readme.md b/readme.md index 9a5e5c2..1e9801b 100644 --- a/readme.md +++ b/readme.md @@ -95,8 +95,7 @@ docker-compose up 1. 如果构建`wine`版本,请先在Linux环境中自行安装`wine` `wine-binfmt`; 2. 安装编译`nodegit`所需的依赖:`python2.7 python3.6及以上 libkrb5-dev gcc openssl libssh2-1-dev g++ make pkg-config` -3. 请安装nodejs,并配置到PATH环境变量中,版本不限; -4. 克隆本项目: +3. 克隆本项目: ``` git clone https://github.com/msojocs/wechat-devtools-linux.git ``` @@ -147,5 +146,6 @@ git clone https://github.com/msojocs/wechat-devtools-linux.git ![赞赏码](https://user-images.githubusercontent.com/20937135/154661198-93854dc1-c8ba-4c97-a7ab-9f8de26c0226.png) -# 感谢支持 - 1. *喆 \ No newline at end of file +# 感谢赞赏支持 + 1. *喆 + 2. @shaoxp \ No newline at end of file diff --git a/test/core-test b/test/core-test old mode 100644 new mode 100755 diff --git a/test/env b/test/env old mode 100644 new mode 100755 index 49b6b64..6f0e172 --- a/test/env +++ b/test/env @@ -1,2 +1,2 @@ #!/usr/bin/env node -console.log(process.env['action']==='true') \ No newline at end of file +console.log(process.version) \ No newline at end of file diff --git a/tools/setup-wechat-devtools-bash b/tools/setup-wechat-devtools-bash index a1aaec4..9822af9 100755 --- a/tools/setup-wechat-devtools-bash +++ b/tools/setup-wechat-devtools-bash @@ -27,7 +27,7 @@ echo "==========Initializing node==========" if [ -f "$root_dir/node/bin/node" ]; then success "node安装完毕" else - node "$root_dir/tools/update-node-node" + "$root_dir/tools/update-node.sh" success "node ok" fi diff --git a/tools/update-node-node b/tools/update-node-node deleted file mode 100755 index bf4025a..0000000 --- a/tools/update-node-node +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env node -const path = require("path"); -const fs = require("fs"); -const { execSync, spawn } = require("child_process"); - -const nodeConfig = require("../conf/node.json"); -const { exit } = require("process"); - -const download = function () { - return new Promise((resolve, reject) => { - try { - fs.mkdirSync(path.resolve(__dirname, "../cache")); - } catch (error) { - console.error(error) - } - - let url = process.env['ACTION_MODE'] === 'true'?nodeConfig["url-global"]:nodeConfig.url - url = url.replace("${version}", nodeConfig.version) - .replace("${version}", nodeConfig.version); - - let localPath = path.resolve( - __dirname, - "../cache", - url.split("?")[0].split("/").slice(-1)[0] - ); - - if (fs.existsSync(localPath)) { - console.info(`Cache available ${path.basename(localPath)}`); - resolve(localPath); - return; - } - - console.info(`Downloading ${url} ---> ${localPath}`); - spawn("wget", ["-c", url, "-O", `${localPath}.tmp`], { - stdio: "inherit", - }).on("close", (code) => { - fs.renameSync(`${localPath}.tmp`, localPath); - resolve(localPath); - }); - }); -}; -const extract = function (localPath) { - console.info(`Extracting ${localPath}`); - - return new Promise((resolve, reject) => { - try { - fs.mkdirSync(path.resolve(__dirname, "../tmp")); - } catch (error) {} - let extractPath = path.resolve( - __dirname, - `../tmp/${path.basename(localPath)}` - ); - - execSync(`rm -rf ${extractPath}`); - - fs.mkdirSync(extractPath); - - spawn("tar", ["xf", localPath, '-C', extractPath], { stdio: "inherit" }).on( - "close", - (code) => { - console.log(`Extracting result code: ${code}`) - resolve(extractPath); - } - ); - }); -}; -const upgrade = function (extractPath) { - console.info(`Upgrading ${path.basename(extractPath)}`); - - return new Promise((resolve, reject) => { - execSync(`rm -rf ${path.resolve(__dirname, "../node")}`); - - fs.renameSync( - path.resolve(extractPath, fs.readdirSync(extractPath)[0]), - path.resolve(__dirname, "../node") - ); - - execSync(`rm -rf ${extractPath}`); - - if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) { - if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node"))) { - execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -sr ../node/bin/node node`) - } - if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node.exe"))) { - execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -s node node.exe`) - } - } - - resolve(); - }); -}; - -const start = async () => { - try { - const args = process.argv.slice(2); - if(args[0])nodeConfig.version=args[0] - const nodePath = path.resolve(__dirname, "../node/bin/node") - if(fs.existsSync(nodePath)){ - const version = execSync(`${path.resolve(__dirname, "../node/bin/node")} --version`).toString().replace('\n', '') - if(version === `v${nodeConfig.version}`){ - console.log(`Node版本:${version} 已经安装,忽略`) - exit(0) - }else{ - console.log(`已安装Node版本:${version},将要安装v${nodeConfig.version}`) - } - } - const localPath = await download(); - const extractPath = await extract(localPath); - await upgrade(extractPath); - - console.log( - `Succeeded upgrading nodeConfig to version ${nodeConfig.version}` - ); - } catch (error) { - console.error("异常", error); - exit(-1) - } -}; - -start(); diff --git a/tools/update-node.sh b/tools/update-node.sh new file mode 100755 index 0000000..8271616 --- /dev/null +++ b/tools/update-node.sh @@ -0,0 +1,63 @@ +#!/bin/bash +set -e + +root_dir=$(cd `dirname $0`/.. && pwd -P) + +# 获取配置 +NODE_VERSION=$1 +source "$root_dir/conf/node_info" +echo "NODE_VERSION:$NODE_VERSION" +echo "NODE_URL_CN:$NODE_URL_CN" +echo "NODE_URL_GLOBAL:$NODE_URL_GLOBAL" + +# 检测安装 +if [ -f $root_dir/node/bin/node ];then + # 存在,检测已有版本是否与要安装的版本一致 + version=$($root_dir/node/bin/node --version) + if [ $version == "v$NODE_VERSION" ];then + echo "已安装NODE版本: v$NODE_VERSION" + exit 0 + fi + # 不一致,装 +fi + +# ########未安装或已有版本与目标版本不一致######## + +# 下载 +cache_dir="$root_dir/cache" +mkdir -p $cache_dir +if [ "$ACTION_MODE" == "true" ];then + echo "ACTION_MODE true" + url=$NODE_URL_GLOBAL +else + echo "ACTION_MODE false" + url=$NODE_URL_CN +fi +parse=(${url//\// }) +localPath="$cache_dir/${parse[-1]}" +if [ ! -f $localPath ];then + # 不存在,下载 + wget -c $url -O${localPath}.tmp + mv ${localPath}.tmp ${localPath} +fi + +# 解压(下载完成或已存在) +tmp_dir="$root_dir/tmp" +mkdir -p $tmp_dir +extractPath="$tmp_dir/${parse[-1]}" +rm -rf $extractPath +mkdir -p $extractPath +tar xf $localPath -C $extractPath + +# 升级 +rm -rf "$root_dir/node" +ls $extractPath | xargs -I {} mv $extractPath/{} "$root_dir/node" +rm -rf $extractPath +if [ -d "$root_dir/nwjs" ];then + cd "$root_dir/nwjs" + rm -rf node node.exe + ln -s ../node/bin/node node + ln -s node node.exe +fi + +echo "Succeeded upgrading node to version ${NODE_VERSION}" \ No newline at end of file