chore: dev support macos
This commit is contained in:
parent
ac6abd81c9
commit
240f4dcfb1
@ -29,6 +29,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^1.0.0-beta.10",
|
"@tauri-apps/cli": "^1.0.0-beta.10",
|
||||||
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
"@types/react-dom": "^17.0.0",
|
"@types/react-dom": "^17.0.0",
|
||||||
"@vitejs/plugin-react": "^1.1.1",
|
"@vitejs/plugin-react": "^1.1.1",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
|
import zlib from "zlib";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import AdmZip from "adm-zip";
|
import AdmZip from "adm-zip";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
@ -16,15 +17,17 @@ const CLASH_LATEST_DATE = "2021.12.07";
|
|||||||
function resolveClash() {
|
function resolveClash() {
|
||||||
const { platform, arch } = process;
|
const { platform, arch } = process;
|
||||||
|
|
||||||
let name = "";
|
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
if (platform === "win32" && arch === "x64") {
|
const map = {
|
||||||
name = `clash-windows-386`;
|
"win32-x64": "clash-windows-386",
|
||||||
}
|
"darwin-x64": "clash-darwin-amd64",
|
||||||
|
"darwin-arm64": "clash-darwin-arm64",
|
||||||
|
};
|
||||||
|
|
||||||
|
const name = map[`${platform}-${arch}`];
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
throw new Error("todo");
|
throw new Error(`unsupport platform "${platform}-${arch}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isWin = platform === "win32";
|
const isWin = platform === "win32";
|
||||||
@ -60,14 +63,28 @@ async function resolveSidecar() {
|
|||||||
if (!(await fs.pathExists(tempZip))) await downloadFile(binInfo.url, tempZip);
|
if (!(await fs.pathExists(tempZip))) await downloadFile(binInfo.url, tempZip);
|
||||||
|
|
||||||
// Todo: support gz
|
// Todo: support gz
|
||||||
const zip = new AdmZip(tempZip);
|
if (binInfo.zip === "zip") {
|
||||||
zip.getEntries().forEach((entry) => {
|
const zip = new AdmZip(tempZip);
|
||||||
console.log("[INFO]: entry name", entry.entryName);
|
zip.getEntries().forEach((entry) => {
|
||||||
});
|
console.log("[INFO]: entry name", entry.entryName);
|
||||||
zip.extractAllTo(tempDir, true);
|
});
|
||||||
|
zip.extractAllTo(tempDir, true);
|
||||||
// save as sidecar
|
// save as sidecar
|
||||||
await fs.rename(tempExe, sidecarPath);
|
await fs.rename(tempExe, sidecarPath);
|
||||||
|
console.log(`[INFO]: unzip finished`);
|
||||||
|
} else {
|
||||||
|
// gz
|
||||||
|
const readStream = fs.createReadStream(tempZip);
|
||||||
|
const writeStream = fs.createWriteStream(sidecarPath);
|
||||||
|
readStream
|
||||||
|
.pipe(zlib.createGunzip())
|
||||||
|
.pipe(writeStream)
|
||||||
|
.on("finish", () => {
|
||||||
|
console.log(`[INFO]: gunzip finished`);
|
||||||
|
execSync(`chmod 755 ${sidecarPath}`);
|
||||||
|
console.log(`[INFO]: chmod binary finished`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// delete temp dir
|
// delete temp dir
|
||||||
await fs.remove(tempDir);
|
await fs.remove(tempDir);
|
||||||
@ -97,6 +114,8 @@ async function downloadFile(url, path) {
|
|||||||
});
|
});
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
await fs.writeFile(path, new Uint8Array(buffer));
|
await fs.writeFile(path, new Uint8Array(buffer));
|
||||||
|
|
||||||
|
console.log(`[INFO]: download finished "${url}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// main
|
/// main
|
||||||
|
@ -559,6 +559,13 @@
|
|||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
"@types/responselike" "*"
|
"@types/responselike" "*"
|
||||||
|
|
||||||
|
"@types/fs-extra@^9.0.13":
|
||||||
|
version "9.0.13"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
|
||||||
|
integrity sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/http-cache-semantics@*":
|
"@types/http-cache-semantics@*":
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
|
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user