switch to submodule
This commit is contained in:
parent
18255ce4cd
commit
572e484498
7 changed files with 7 additions and 100 deletions
|
|
@ -1,59 +0,0 @@
|
|||
import { execSync } from "node:child_process";
|
||||
import { createWriteStream, mkdirSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { join, resolve } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { t, extract as tarExtract } from "tar";
|
||||
|
||||
const extractDir = resolve("deps");
|
||||
const fileName = "milsko.tar.gz";
|
||||
const source =
|
||||
"https://forgejo.nishi.boats/api/v1/repos/pyrite-dev/milsko/tags";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { upstream } = require("../package.json");
|
||||
|
||||
export async function download() {
|
||||
console.log("[Mw] Fetching Milsko release tags from", source);
|
||||
|
||||
const response = await fetch(source);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
"Failed to fetch the Milsko repository tags, try running npm run install or npm run update again (" +
|
||||
response.status +
|
||||
")"
|
||||
);
|
||||
}
|
||||
|
||||
const tags = await response.json();
|
||||
const match = tags.find((k) => k.name == upstream);
|
||||
|
||||
if (!match) {
|
||||
throw new Error(
|
||||
"Could not find a tag that matches the upstream version " + upstream
|
||||
);
|
||||
}
|
||||
|
||||
const tarUrl = match["tarball_url"];
|
||||
console.log("[Mw] Fetching tarball from " + tarUrl);
|
||||
|
||||
const tarball = await fetch(tarUrl);
|
||||
|
||||
const filePath = join(extractDir, fileName);
|
||||
mkdirSync(extractDir, { recursive: true }); // mkdir -p
|
||||
|
||||
const tarStream = Readable.fromWeb(tarball.body);
|
||||
const fileStream = createWriteStream(filePath);
|
||||
|
||||
await pipeline(tarStream, fileStream);
|
||||
await tarExtract({
|
||||
file: filePath,
|
||||
cwd: extractDir
|
||||
});
|
||||
|
||||
console.log("[Mw] Milsko library successfully installed!");
|
||||
}
|
||||
|
||||
if (import.meta.main)
|
||||
download();
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import { execSync } from "node:child_process"
|
||||
import { createRequire } from "node:module";
|
||||
import { download } from "./download";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const forceBuild = process.env["npm_config_build_from_source"] == "true";
|
||||
|
||||
function hasPrebuilt() {
|
||||
let prebuilt = false;
|
||||
|
||||
try {
|
||||
require("node-gyp-build")("..");
|
||||
prebuilt = true;
|
||||
} catch (error) {
|
||||
prebuilt = false;
|
||||
}
|
||||
|
||||
return prebuilt;
|
||||
}
|
||||
|
||||
async function install() {
|
||||
console.log("[Mw] Downloading Milsko library...");
|
||||
await download();
|
||||
|
||||
console.log("[Mw] Building from source...");
|
||||
execSync("npx node-gyp rebuild", { stdio: "inherit" });
|
||||
}
|
||||
|
||||
if (forceBuild || !hasPrebuilt()) {
|
||||
install();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue