refactor: 整理文件,便于维护

This commit is contained in:
msojocs 2022-02-27 20:15:14 +08:00
parent 41938a29a0
commit e9c717dd5d
20 changed files with 171 additions and 251 deletions

View File

@ -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"

View File

@ -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执行错误

View File

@ -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

View File

@ -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);
};

View File

@ -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
$root_dir/tools/fix-core.sh
$root_dir/tools/fix-other.sh

0
tools/appimage.sh Normal file → Executable file
View File

4
tools/build-release.sh Normal file → Executable file
View File

@ -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"

View File

@ -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);

15
tools/fix-cli.sh Executable file
View File

@ -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

View File

@ -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"

130
tools/fix-menu.sh Executable file
View File

@ -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" <<EOF
/* 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"
cat "$tmp_file" > "$target_file"
rm "$tmp_file"

View File

@ -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

View File

@ -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) {

View File

@ -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");

View File

@ -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);

View File

@ -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 || {

View File

@ -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();
});

View File

@ -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