@harivilasp/mediautil 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mediautil.js +65 -0
- package/package.json +22 -0
package/bin/mediautil.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { spawnSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const version = "0.1.0";
|
|
9
|
+
const repo = process.env.MEDIAUTIL_REPO || "harivilasp/mediautil";
|
|
10
|
+
const binDir = path.join(__dirname, "..", "vendor");
|
|
11
|
+
const binPath = path.join(binDir, process.platform === "win32" ? "mediautil.exe" : "mediautil");
|
|
12
|
+
|
|
13
|
+
function target() {
|
|
14
|
+
const arch = os.arch() === "arm64" ? "aarch64" : "x86_64";
|
|
15
|
+
if (process.platform === "darwin") return `${arch}-apple-darwin`;
|
|
16
|
+
if (process.platform === "linux") return "x86_64-unknown-linux-gnu";
|
|
17
|
+
if (process.platform === "win32") return "x86_64-pc-windows-msvc";
|
|
18
|
+
throw new Error(`unsupported platform: ${process.platform}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function assetUrl() {
|
|
22
|
+
const t = target();
|
|
23
|
+
const suffix = process.platform === "win32" ? "zip" : "tar.gz";
|
|
24
|
+
return `https://github.com/${repo}/releases/download/v${version}/mediautil-${t}.${suffix}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function download(url, destination) {
|
|
28
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
29
|
+
const file = fs.createWriteStream(destination);
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
https.get(url, (response) => {
|
|
32
|
+
if (response.statusCode !== 200) {
|
|
33
|
+
reject(new Error(`download failed: ${response.statusCode} ${url}`));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
response.pipe(file);
|
|
37
|
+
file.on("finish", () => file.close(resolve));
|
|
38
|
+
}).on("error", reject);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function install() {
|
|
43
|
+
if (fs.existsSync(binPath)) return;
|
|
44
|
+
const archive = path.join(os.tmpdir(), path.basename(assetUrl()));
|
|
45
|
+
await download(assetUrl(), archive);
|
|
46
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
47
|
+
if (process.platform === "win32") {
|
|
48
|
+
spawnSync("powershell", ["-NoProfile", "-Command", `Expand-Archive -Force '${archive}' '${binDir}'`], { stdio: "inherit" });
|
|
49
|
+
} else {
|
|
50
|
+
spawnSync("tar", ["-xzf", archive, "-C", binDir], { stdio: "inherit" });
|
|
51
|
+
fs.chmodSync(binPath, 0o755);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
(async () => {
|
|
56
|
+
try {
|
|
57
|
+
await install();
|
|
58
|
+
if (process.argv.includes("--install-only")) return;
|
|
59
|
+
const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
60
|
+
process.exit(result.status ?? 1);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(error.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@harivilasp/mediautil",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local media utility shell for images, PDFs, OCR, QR codes, data URIs, and base64.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/harivilasp/mediautil.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"mediautil": "bin/mediautil.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"postinstall": "node bin/mediautil.js --install-only"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
}
|
|
22
|
+
}
|