diff --git a/docs/Features.MD b/docs/Features.MD index 3771182..e45e45f 100644 --- a/docs/Features.MD +++ b/docs/Features.MD @@ -22,7 +22,7 @@ - [x] 打开 - [x] 代码管理可点击 - - [ ] 终端打开(不通过) + - [x] 终端打开 ## 自动化测试 diff --git a/test/core-test b/test/core-test index 226608a..5f3d3ed 100644 --- a/test/core-test +++ b/test/core-test @@ -1,4 +1,12 @@ #!/bin/bash -node tools/wxvpkg/pack package.nw/core.wxvpkg.ext package.nw/core.wxvpkg -rm -rf /home/msojocs/.config/wechat_devtools/WeappCache -bin/wechat-devtools \ No newline at end of file +set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +a=$1 +if [ "$a" == '1' ];then + rm -rf "$root_dir/package.nw/core.wxvpkg.ext" + node tools/wxvpkg/unpack "$root_dir/package.nw/core.wxvpkg" "$root_dir/package.nw/core.wxvpkg.ext" +else + node tools/wxvpkg/pack package.nw/core.wxvpkg.ext package.nw/core.wxvpkg + rm -rf ~/.config/wechat_devtools/WeappCache + bin/wechat-devtools +fi \ No newline at end of file diff --git a/test/wxvpkg-test b/test/wxvpkg-test new file mode 100644 index 0000000..0bcb5a9 --- /dev/null +++ b/test/wxvpkg-test @@ -0,0 +1,15 @@ +#!/bin/bash +set -e +root_dir=$(cd `dirname $0`/.. && pwd -P) +tmp_dir="$root_dir/tmp" + +# unpack 文件 到 路径 +node "$root_dir/tools/wxvpkg/unpack" "$tmp_dir/core.wxvpkg" "$tmp_dir/core.wxvpkg.ext" + +# pack 路径 到 文件 +node "$root_dir/tools/wxvpkg/pack" "$tmp_dir/core.wxvpkg.ext" "$tmp_dir/core.wxvpkg.test" + +# unpack 文件 到 路径 +rm -rf "$tmp_dir/core.wxvpkg.ext1" +node "$root_dir/tools/wxvpkg/unpack" "$tmp_dir/core.wxvpkg.test" "$tmp_dir/core.wxvpkg.ext1" + diff --git a/tools/fix-cloudconsole b/tools/fix-core similarity index 58% rename from tools/fix-cloudconsole rename to tools/fix-core index 5ffab53..eee9d88 100755 --- a/tools/fix-cloudconsole +++ b/tools/fix-core @@ -1,29 +1,45 @@ #!/bin/bash -echo "Fix Cloud Console" +echo "Fix Core" root_dir=$(cd `dirname $0`/.. && pwd -P) package_dir="$root_dir/package.nw" -tmp_dir="$root_dir/tmp" +tmp_dir="$root_dir/tmp/core" +mkdir -p $tmp_dir # unpack 文件 到 路径 node "$root_dir/tools/wxvpkg/unpack" "$package_dir/core.wxvpkg" "$tmp_dir/core.wxvpkg" +# ____ _____ ____ _ _ ____ _____ ____ ___ ____ _____ +# | _ \| ____| _ \| | / \ / ___| ____| / ___/ _ \| _ \| ____| +# | |_) | _| | |_) | | / _ \| | | _| | | | | | | |_) | _| +# | _ <| |___| __/| |___ / ___ \ |___| |___ | |__| |_| | _ <| |___ +# |_| \_\_____|_| |_____/_/ \_\____|_____| \____\___/|_| \_\_____| +# # find open_find_result=$( grep -lr "this.props.onWindowOpenFail());" "$root_dir/tmp/core.wxvpkg" ) -token_find_result=$( grep -lr "constructor(){this._sessionToken=\"\",this._tokenMap={}}" "$tmp_dir/core.wxvpkg" ) echo "云开发控制台启动点: $open_find_result" -echo "WebSocket token存储对象位置: $token_find_result" - - # replace new_cb_handle="this.props.onWindowOpenFail());Object.keys(window).forEach(key=>{if(!e.window[key]){try{e.window[key]=window[key];}catch(e){console.error(e);}}});" sed -i "s/this.props.onWindowOpenFail());/$new_cb_handle/g" $open_find_result +token_find_result=$( grep -lr "constructor(){this._sessionToken=\"\",this._tokenMap={}}" "$tmp_dir/core.wxvpkg" ) +echo "WebSocket token存储对象位置: $token_find_result" new_constructor="constructor(){if(window.tokenData){/*有就直接用*/this._sessionToken=window.tokenData._sessionToken;this._tokenMap=window.tokenData._tokenMap;}else{/*没有就新建*/this._sessionToken=\"\",this._tokenMap={};window.tokenData=this;/*新建完要给中间人*/}}" sed -i "s#constructor(){this._sessionToken=\"\",this._tokenMap={}}#$new_constructor#g" "$token_find_result" +# open -a Terminal "`pwd`" --> gnome-terminal +find_result=$( grep -lr 'open -a Terminal "`pwd`"' "$tmp_dir/core.wxvpkg" ) +echo "Terminal启动位置: $find_result" +new_str="gnome-terminal" +sed -i "s#open -a Terminal \"\`pwd\`\"#$new_str#g" "$find_result" + # pack 路径 到 文件 node "$root_dir/tools/wxvpkg/pack" "$tmp_dir/core.wxvpkg" "$package_dir/core.wxvpkg" -rm -rf "$tmp_dir/core.wxvpkg" \ No newline at end of file +rm -rf "$tmp_dir/core.wxvpkg" + +if [ -d ~/.config/wechat_devtools/WeappCache ];then + echo "删除缓存" + rm -rf ~/.config/wechat_devtools/WeappCache +fi \ No newline at end of file diff --git a/tools/update-node-node b/tools/update-node-node index dd3267f..fdf5d48 100755 --- a/tools/update-node-node +++ b/tools/update-node-node @@ -2,7 +2,6 @@ const path = require("path"); const fs = require("fs"); const { execSync, spawn } = require("child_process"); -const util = require("util"); const nodeConfig = require("../conf/node.json"); const { exit } = require("process"); diff --git a/tools/update-wechat-devtools-node b/tools/update-wechat-devtools-node index be7b4ba..15f535c 100755 --- a/tools/update-wechat-devtools-node +++ b/tools/update-wechat-devtools-node @@ -232,10 +232,10 @@ const patch_wechat_devtools_CLI = function () { }); }; const patch_wechat_devtools_core = function () { - info("Patching wechat-devtools cloud console supports"); + info("Patching wechat-devtools core.wxvpkg"); return new Promise((resolve, reject) => { - spawn(path.resolve(__dirname, "fix-cloudconsole"), [], { + spawn(path.resolve(__dirname, "fix-core"), [], { stdio: "inherit", }).on("close", (code) => { resolve(); diff --git a/tools/wxvpkg/pack b/tools/wxvpkg/pack index 6918c52..f256dca 100644 --- a/tools/wxvpkg/pack +++ b/tools/wxvpkg/pack @@ -29,10 +29,13 @@ function writeInt32(number, start) { } let files = fs.readdirSync(dest) +// 文件数 let totalCount = files.length + let buf = Buffer.alloc(4) buf.writeInt32BE(totalCount, 0) writeSync(buf, 14) + let start = 18 // 12 + /name.length let dataOffset = start diff --git a/tools/wxvpkg/unpack b/tools/wxvpkg/unpack index 14c46a5..112645c 100644 --- a/tools/wxvpkg/unpack +++ b/tools/wxvpkg/unpack @@ -19,6 +19,7 @@ function readSync(start, length) { } const totalCount = readSync(14, 4).readInt32BE(0) +console.log('totalCount', totalCount) const map = {}; let n = 18; for (let i = 0; i < totalCount; i++) {