mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-22 00:00:04 +08:00
100 lines
2.6 KiB
Plaintext
Executable File
100 lines
2.6 KiB
Plaintext
Executable File
#!/usr/bin/env mew_js
|
|
|
|
const nwjs = require("../conf/nwjs.json");
|
|
|
|
@.async(function () {
|
|
|
|
@.fs.makeDirs(@path(__dirname, "../cache"));
|
|
|
|
let client = @.net.httpClient();
|
|
|
|
let url = @.format(nwjs.url, { "version": nwjs.version });
|
|
|
|
let localPath = @path(__dirname, "../cache", url.split("?")[0].split("/").slice(-1)[0]);
|
|
|
|
if (@.fs.exists(localPath)) {
|
|
@info(`Cache available ${@.fs.filename(localPath)}`);
|
|
this.next(localPath);
|
|
return;
|
|
}
|
|
|
|
let lastSize = 0;
|
|
let lastProgress = 0;
|
|
let lastTime = Date.now();
|
|
|
|
@info(`Downloading ${url}`);
|
|
client.download(url, localPath, {
|
|
"resumeBroken": true,
|
|
"redirects": Object.create(null),
|
|
"onSuccess": () => {
|
|
this.next(localPath);
|
|
},
|
|
"onProgress": (size, total) => {
|
|
let progress = size / total * 100;
|
|
let now = Date.now();
|
|
if ((progress - lastProgress > 10) ||
|
|
(now - lastTime > 1000)) {
|
|
let speed = (size - lastSize) / (now - lastTime) * 1000 / 1024;
|
|
lastSize = size;
|
|
lastTime = now;
|
|
lastProgress = progress;
|
|
@info(`Downloaded ${@.fs.filename(localPath)}: ${progress.toFixed(2)}%, speed ${speed.toFixed(2)} KiB/s`);
|
|
}
|
|
},
|
|
"onError": this.reject
|
|
});
|
|
|
|
}).then(function (localPath) {
|
|
|
|
@info(`Extracting ${localPath}`);
|
|
|
|
let extractPath = @path(__dirname, `../tmp/${@.fs.basename(localPath)}`);
|
|
|
|
@.fs.deleteFile.sync(extractPath);
|
|
|
|
@.fs.makeDirs(extractPath);
|
|
|
|
@.task.execute("tar", ["xf", localPath], extractPath, (error) => {
|
|
|
|
if (error) {
|
|
this.reject(error); return;
|
|
}
|
|
|
|
this.next(extractPath);
|
|
|
|
});
|
|
|
|
}).then(function (extractPath) {
|
|
|
|
@info(`Upgrading ${@.fs.filename(extractPath)}`);
|
|
|
|
@.fs.deleteFile.sync(@path(__dirname, "../nwjs"));
|
|
|
|
@.fs.moveFile.sync(@path(extractPath, @.fs.listFiles(extractPath)[0].name),
|
|
@path(__dirname, "../nwjs"))
|
|
|
|
@.fs.deleteFile.sync(extractPath);
|
|
|
|
if (@.fs.exists(@path(__dirname, "../node/bin/node"))) {
|
|
@.fs.linkFile("../node/bin/node", @path(__dirname, "../nwjs/node"));
|
|
@.fs.linkFile("node", @path(__dirname, "../nwjs/node.exe"));
|
|
}
|
|
if (!@.fs.exists(@path(__dirname, "../package.nw"))) {
|
|
@.fs.linkFile("../package.nw", @path(__dirname, "../nwjs/package.nw"));
|
|
}
|
|
|
|
this.next();
|
|
|
|
}).finished((error) => {
|
|
|
|
if (error) {
|
|
@error(error);
|
|
process.exit(1);
|
|
}
|
|
|
|
@celebr(`Succeeded upgrading nwjs to version ${nwjs.version}`);
|
|
|
|
process.exit(0);
|
|
|
|
});
|