mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-22 00:00:04 +08:00
update: node support
This commit is contained in:
parent
12631c5bce
commit
ff17cf39cf
20
tools/fix-cli-node
Normal file
20
tools/fix-cli-node
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
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);
|
23
tools/fix-package-name-node
Normal file
23
tools/fix-package-name-node
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
const parseFile = function (path) {
|
||||||
|
|
||||||
|
if (!fs.existsSync(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
|
|
||||||
|
content.name = "wechat_devtools";
|
||||||
|
// 开启调试,更新参数
|
||||||
|
content['chromium-args'] = content['chromium-args'].replace('--disable-devtools', '').replace('--ignore-gpu-blacklist', '--ignore-gpu-blocklist')
|
||||||
|
|
||||||
|
fs.writeFileSync(path, JSON.stringify(content, null, 4));
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
parseFile(path.resolve(__dirname, "../package.nw/package.json"));
|
||||||
|
parseFile(path.resolve(__dirname, "../package.nw/package-lock.json"));
|
23
tools/fix-selection-copy-node
Normal file
23
tools/fix-selection-copy-node
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require("path");
|
||||||
|
const os = require("os");
|
||||||
|
const fs = require("fs");
|
||||||
|
const { spawn, execSync } = require("child_process");
|
||||||
|
|
||||||
|
console.info("Patching editor selection copy configs");
|
||||||
|
|
||||||
|
let configPath = os.homedir() + "/.config/wechat_devtools/Default/Editor/User/settings.json";
|
||||||
|
let config = undefined;
|
||||||
|
if (fs.existsSync(configPath)) {
|
||||||
|
// console.info(configPath)
|
||||||
|
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
||||||
|
} else {
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
config["editor.selectionClipboard"] = false;
|
||||||
|
|
||||||
|
// nodejs只支持一级一级目录创建,效率低
|
||||||
|
execSync(`mkdir -p ${path.dirname(configPath)}`)
|
||||||
|
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
|
43
tools/install-desktop-icon-node
Normal file
43
tools/install-desktop-icon-node
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const os = require("os");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
const { info } = require("console");
|
||||||
|
|
||||||
|
for (let size of ["64", "128", "256", "512"]) {
|
||||||
|
let iconPath =
|
||||||
|
os.homedir() +
|
||||||
|
`/.local/share/icons/hicolor/${size}x${size}/wechat-devtools.png`;
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(iconPath));
|
||||||
|
} catch (error) {}
|
||||||
|
info(`Writing icon file ${iconPath}`);
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve(__dirname, "../res/icons", `wechat-devtools${size}.png`),
|
||||||
|
iconPath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let svgPath =
|
||||||
|
os.homedir() + "/.local/share/icons/hicolor/scalable/wechat-devtools.svg";
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(svgPath));
|
||||||
|
} catch (error) {}
|
||||||
|
info(`Writing icon file ${svgPath}`);
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve(__dirname, "../res/icons/wechat-devtools.svg"),
|
||||||
|
svgPath
|
||||||
|
);
|
||||||
|
|
||||||
|
let desktopCode = fs
|
||||||
|
.readFileSync(path.resolve(__dirname, "../res/template.desktop"), "utf8")
|
||||||
|
.replace("dir", path.resolve(__dirname, ".."));
|
||||||
|
|
||||||
|
desktopPath =
|
||||||
|
os.homedir() + "/.local/share/applications/wechat-devtools.desktop";
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.dirname(desktopPath));
|
||||||
|
} catch (error) {}
|
||||||
|
info(`Writing desktop file ${desktopPath}`);
|
||||||
|
fs.writeFileSync(desktopPath, desktopCode);
|
36
tools/patch-wechat-devtools-node
Normal file
36
tools/patch-wechat-devtools-node
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#!/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);
|
@ -18,7 +18,7 @@
|
|||||||
this.next(); return;
|
this.next(); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@.task.execute(@path(__dirname, "update-nwjs"), [], false, this.test);
|
@.task.execute(@path(__dirname, "update-nwjs-node"), [], false, this.test);
|
||||||
|
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
|
||||||
|
87
tools/setup-wechat-devtools-node
Normal file
87
tools/setup-wechat-devtools-node
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
const init_node = function () {
|
||||||
|
console.info("Initializing node");
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, "../node"))) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateNode = spawn(
|
||||||
|
path.resolve(__dirname, "update-node-node"),
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
updateNode.on("close", (code) => {
|
||||||
|
console.log(`Update Node code: ${code}`);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const init_nwjs = function () {
|
||||||
|
console.info("Initializing nwjs");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateNwjs = spawn(
|
||||||
|
path.resolve(__dirname, "update-nwjs-node"),
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
updateNwjs.on("close", (code) => {
|
||||||
|
console.log(`Update Nwjs result code: ${code}`);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const init_wechat = function () {
|
||||||
|
console.info("Initializing wechat-devtools package");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, "../package.nw"))) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateWechat = spawn(
|
||||||
|
path.resolve(__dirname, "update-wechat-devtools-node"),
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
updateWechat.on("close", (code) => {
|
||||||
|
console.log(
|
||||||
|
`Initializing wechat-devtools package result code:${code}`
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const start = async () => {
|
||||||
|
try {
|
||||||
|
await init_node();
|
||||||
|
await init_nwjs();
|
||||||
|
await init_wechat();
|
||||||
|
|
||||||
|
console.log(`Succeeded setting up wechat-devtools`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("异常", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
start();
|
14
tools/test
Normal file
14
tools/test
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) {
|
||||||
|
if (!fs.existsSync(path.resolve(__dirname, "../nwjs/package.nw"))) {
|
||||||
|
// 链接
|
||||||
|
fs.symlinkSync(
|
||||||
|
path.resolve(__dirname, "../package.nw"),
|
||||||
|
path.resolve(__dirname, "../nwjs/package.nw")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
109
tools/update-node-node
Normal file
109
tools/update-node-node
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
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 download = function () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.resolve(__dirname, "../cache"));
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
let url = nodeConfig.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
info(`Downloading ${url}`);
|
||||||
|
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) => {
|
||||||
|
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"))) {
|
||||||
|
fs.linkSync(
|
||||||
|
"../node/bin/node",
|
||||||
|
path.resolve(__dirname, "../nwjs/node")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node.exe"))) {
|
||||||
|
fs.linkSync(
|
||||||
|
"node",
|
||||||
|
path.resolve(__dirname, "../nwjs/node.exe")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const start = async () => {
|
||||||
|
try {
|
||||||
|
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);
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
start();
|
@ -4,6 +4,7 @@ const path = require('path')
|
|||||||
const net = require('net')
|
const net = require('net')
|
||||||
const { spawn, execSync } = require('child_process');
|
const { spawn, execSync } = require('child_process');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
const { exit } = require('process');
|
||||||
|
|
||||||
const download = (nwjs) => {
|
const download = (nwjs) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -92,7 +93,7 @@ const upgrade = function (extractPath) {
|
|||||||
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node"));
|
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node"));
|
||||||
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node.exe"));
|
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node.exe"));
|
||||||
}
|
}
|
||||||
if (!fs.existsSync(path.resolve(__dirname, "../package.nw"))) {
|
if (fs.existsSync(path.resolve(__dirname, "../package.nw"))) {
|
||||||
fs.linkSync(path.resolve(__dirname, "../package.nw"), path.resolve(__dirname, "../nwjs/package.nw"));
|
fs.linkSync(path.resolve(__dirname, "../package.nw"), path.resolve(__dirname, "../nwjs/package.nw"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,11 +109,12 @@ const init = async () => {
|
|||||||
const result = await upgrade(extractPath)
|
const result = await upgrade(extractPath)
|
||||||
|
|
||||||
console.info(`Succeeded upgrading nwjs to version ${nwjs.version}`);
|
console.info(`Succeeded upgrading nwjs to version ${nwjs.version}`);
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
|
|
||||||
if (error) {
|
if (err) {
|
||||||
console.error('error--->', error);
|
console.error('error--->', err);
|
||||||
}
|
}
|
||||||
|
exit(-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init()
|
init()
|
288
tools/update-wechat-devtools-node
Normal file
288
tools/update-wechat-devtools-node
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const { execSync, exec, spawn } = require("child_process");
|
||||||
|
const https = require("https");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { info } = require("console");
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
const urls = {
|
||||||
|
stable: "https://developers.weixin.qq.com/miniprogram/dev/devtools/stable.html",
|
||||||
|
rc: "https://developers.weixin.qq.com/miniprogram/dev/devtools/rc.html",
|
||||||
|
nightly:
|
||||||
|
"https://developers.weixin.qq.com/miniprogram/dev/devtools/nightly.html",
|
||||||
|
};
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
let branch = args[0];
|
||||||
|
let ver = args[1];
|
||||||
|
if (!branch || !urls[branch]) {
|
||||||
|
branch = "stable";
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = urls[branch];
|
||||||
|
// "https://servicewechat.com/wxa-dev-logic/download_redirect?type=x64&from=mpwiki";
|
||||||
|
// const url = "https://servicewechat.com/wxa-dev-logic/download_redirect?type=x64&from=mpwiki&version_type=1";
|
||||||
|
// https://servicewechat.com/wxa-dev-logic/download_redirect?type=x64&from=mpwiki&download_version=1022001191&version_type=1
|
||||||
|
// https://servicewechat.com/wxa-dev-logic/download_redirect?type=x64&from=mpwiki&download_version=1021911180&version_type=1
|
||||||
|
// https://dldir1.qq.com/WechatWebDev/nightly/p-7aa88fbb60d64e4a96fac38999591e31/wechat_devtools_1.02.2001202_x64.exe
|
||||||
|
|
||||||
|
let version = undefined;
|
||||||
|
|
||||||
|
const packageDir = "code/package.nw";
|
||||||
|
|
||||||
|
const fetching = function () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path(__dirname, "../cache"));
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
info(`Fetching wechat-dev-tool info: ${url}`);
|
||||||
|
|
||||||
|
if (ver) {
|
||||||
|
version = ver;
|
||||||
|
resolve(
|
||||||
|
`https://servicewechat.com/wxa-dev-logic/download_redirect?type=x64&from=mpwiki&download_version=${ver}&version_type=1`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
https
|
||||||
|
.get(url, (res) => {
|
||||||
|
let result = "";
|
||||||
|
res.on("data", (data) => {
|
||||||
|
result += data;
|
||||||
|
});
|
||||||
|
res.on("end", () => {
|
||||||
|
let links = {};
|
||||||
|
result
|
||||||
|
.toString("utf8")
|
||||||
|
.split('<div class="page-inner"')[1]
|
||||||
|
.split('<a href="')
|
||||||
|
.slice(1)
|
||||||
|
.map((a) => {
|
||||||
|
return a.split("</a>")[0];
|
||||||
|
})
|
||||||
|
.filter((link) => link[0] != "#")
|
||||||
|
.forEach((link) => {
|
||||||
|
let content = link
|
||||||
|
.split(">")
|
||||||
|
.slice(1)
|
||||||
|
.join(">")
|
||||||
|
.replace(/<([^>]*)>/g, "")
|
||||||
|
.replace(/\s+/g, "-")
|
||||||
|
.toLowerCase();
|
||||||
|
if (
|
||||||
|
content === "windows-64" ||
|
||||||
|
content === "windows-32" ||
|
||||||
|
content === "macos"
|
||||||
|
) {
|
||||||
|
if (!links[content]) {
|
||||||
|
links[content] = [];
|
||||||
|
}
|
||||||
|
let url = link.split('"')[0];
|
||||||
|
links[content].push(url);
|
||||||
|
info(`Found ${content} link: ${url}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!links["windows-64"][0]) {
|
||||||
|
console.error("No windows-64 dist found");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
resolve(links["windows-64"][0]);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", reject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const download = function (url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
info(`Downloading ${url}`);
|
||||||
|
|
||||||
|
version = url.match(/version=(\d+)&/)[1];
|
||||||
|
let mainVer = version.substring(0, version.length - 9);
|
||||||
|
let subVer = version.substring(version.length - 9, version.length - 7);
|
||||||
|
let time = version.substring(version.length - 7);
|
||||||
|
version = [mainVer, subVer, time].join(".");
|
||||||
|
|
||||||
|
let localPath = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
util.format("../cache/wechat_devtools_%s_x64.exe", version)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (fs.existsSync(localPath)) {
|
||||||
|
resolve(localPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// wget -c url -O out
|
||||||
|
const ls = spawn("wget", ["-c", url, "-O", `${localPath}.tmp`], {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
ls.on("close", (code) => {
|
||||||
|
fs.renameSync(`${localPath}.tmp`, localPath);
|
||||||
|
resolve(localPath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const extract = function (localPath) {
|
||||||
|
// 解压
|
||||||
|
info(`Extracting ${localPath}`);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let extractPath = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
`../tmp/${path.basename(localPath)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
execSync(`rm -rf ${extractPath}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(extractPath);
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
const ext = spawn(
|
||||||
|
"7z",
|
||||||
|
["x", localPath, `-o${extractPath}`, packageDir],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
ext.on("close", (code) => {
|
||||||
|
info(`解压完毕:${code}`);
|
||||||
|
resolve(extractPath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const upgrade = function (extractPath) {
|
||||||
|
info(`Upgrading ${path.basename(extractPath)}`);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// 删除原文件
|
||||||
|
execSync(`rm -rf ${path.resolve(__dirname, "../package.nw")}`);
|
||||||
|
|
||||||
|
// 替换
|
||||||
|
fs.renameSync(
|
||||||
|
path.resolve(extractPath, packageDir),
|
||||||
|
path.resolve(__dirname, "../package.nw")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 删除临时
|
||||||
|
execSync(`rm -rf ${extractPath}`);
|
||||||
|
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) {
|
||||||
|
if (!fs.existsSync(path.resolve(__dirname, "../nwjs/package.nw"))) {
|
||||||
|
// 链接
|
||||||
|
fs.symlinkSync(
|
||||||
|
path.resolve(__dirname, "../package.nw"),
|
||||||
|
path.resolve(__dirname, "../nwjs/package.nw")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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"), [], {
|
||||||
|
stdio: "inherit",
|
||||||
|
}).on("close", (code) => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const patch_wechat_devtools_editor_selection_autocopy = function () {
|
||||||
|
info("Patching wechat-devtools editor selection autocopy");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
spawn(path.resolve(__dirname, "fix-selection-copy-node"), [], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
}).on("close", (code) => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const patch_wechat_devtools_CLI = function () {
|
||||||
|
info("Patching wechat-devtools CLI supports");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
spawn(path.resolve(__dirname, "fix-cli-node"), [], { stdio: "inherit" }).on(
|
||||||
|
"close",
|
||||||
|
(code) => {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
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"), [], {
|
||||||
|
stdio: "inherit",
|
||||||
|
}).on("close", (code) => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const patch_wechat_devtools = function () {
|
||||||
|
info("Patching wechat-devtools");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const exec = spawn(
|
||||||
|
path.resolve(__dirname, "patch-wechat-devtools-node"),
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
exec.on("close", (code) => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const patch_wcc_wcsc = function () {
|
||||||
|
info("Patching wcc and wcsc");
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve(__dirname, "../wine/wcc"),
|
||||||
|
path.resolve(__dirname, "../package.nw/js/vendor/wcc")
|
||||||
|
);
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.resolve(__dirname, "../wine/wcsc"),
|
||||||
|
path.resolve(__dirname, "../package.nw/js/vendor/wcsc")
|
||||||
|
);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const start = async () => {
|
||||||
|
try {
|
||||||
|
const url = await fetching();
|
||||||
|
const localPath = await download(url);
|
||||||
|
const extractPath = await extract(localPath);
|
||||||
|
await upgrade(extractPath);
|
||||||
|
await patch_wechat_devtools_package_name();
|
||||||
|
await patch_wechat_devtools_editor_selection_autocopy();
|
||||||
|
await patch_wechat_devtools_CLI();
|
||||||
|
await rebuild_wechat_devtools_node_modules();
|
||||||
|
await patch_wechat_devtools();
|
||||||
|
await patch_wcc_wcsc();
|
||||||
|
console.log(
|
||||||
|
`Succeeded upgrading wechat-devtools to version ${version}`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("异常", error);
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
start();
|
Loading…
x
Reference in New Issue
Block a user