@aymanbagabas/drift 0.0.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/drift.js +15 -0
- package/install.js +51 -0
- package/package.json +40 -0
package/bin/drift.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher: exec the native drift binary that install.js placed in vendor/,
|
|
3
|
+
// passing through args and the terminal so the TUI works normally.
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const binName = process.platform === "win32" ? "drift.exe" : "drift";
|
|
8
|
+
const bin = path.join(__dirname, "..", "vendor", binName);
|
|
9
|
+
|
|
10
|
+
const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
11
|
+
if (res.error) {
|
|
12
|
+
console.error(`drift: ${res.error.message}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
process.exit(res.status ?? 0);
|
package/install.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Postinstall: download the prebuilt drift binary for this platform from the
|
|
2
|
+
// matching GitHub release and unpack it into vendor/. The archive names mirror
|
|
3
|
+
// the GoReleaser `archives.name_template` (drift_<version>_<os>_<arch>.<ext>).
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { execFileSync } = require("child_process");
|
|
8
|
+
|
|
9
|
+
const OWNER = "aymanbagabas";
|
|
10
|
+
const REPO = "drift";
|
|
11
|
+
const { version } = require("./package.json");
|
|
12
|
+
|
|
13
|
+
const PLATFORM = { darwin: "darwin", linux: "linux", win32: "windows" }[process.platform];
|
|
14
|
+
const ARCH = { x64: "amd64", arm64: "arm64" }[process.arch];
|
|
15
|
+
|
|
16
|
+
if (!PLATFORM || !ARCH) {
|
|
17
|
+
console.error(`drift: unsupported platform ${process.platform}/${process.arch}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ext = PLATFORM === "windows" ? "zip" : "tar.gz";
|
|
22
|
+
const asset = `${REPO}_${version}_${PLATFORM}_${ARCH}.${ext}`;
|
|
23
|
+
const url = `https://github.com/${OWNER}/${REPO}/releases/download/v${version}/${asset}`;
|
|
24
|
+
const binName = PLATFORM === "windows" ? "drift.exe" : "drift";
|
|
25
|
+
const vendor = path.join(__dirname, "vendor");
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
fs.mkdirSync(vendor, { recursive: true });
|
|
29
|
+
const archivePath = path.join(os.tmpdir(), asset);
|
|
30
|
+
|
|
31
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
throw new Error(`download failed (${res.status}) for ${url}`);
|
|
34
|
+
}
|
|
35
|
+
fs.writeFileSync(archivePath, Buffer.from(await res.arrayBuffer()));
|
|
36
|
+
|
|
37
|
+
// bsdtar (macOS, Linux, Windows 10+) extracts both .tar.gz and .zip.
|
|
38
|
+
execFileSync("tar", ["-xf", archivePath, "-C", vendor, binName], { stdio: "inherit" });
|
|
39
|
+
fs.unlinkSync(archivePath);
|
|
40
|
+
|
|
41
|
+
const binPath = path.join(vendor, binName);
|
|
42
|
+
if (!fs.existsSync(binPath)) {
|
|
43
|
+
throw new Error(`binary ${binName} not found in ${asset}`);
|
|
44
|
+
}
|
|
45
|
+
if (PLATFORM !== "windows") fs.chmodSync(binPath, 0o755);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main().catch((err) => {
|
|
49
|
+
console.error(`drift: failed to install binary: ${err.message}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aymanbagabas/drift",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "A standalone git diff pager for the terminal.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"drift": "bin/drift.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/drift.js",
|
|
13
|
+
"install.js"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"os": [
|
|
19
|
+
"darwin",
|
|
20
|
+
"linux",
|
|
21
|
+
"win32"
|
|
22
|
+
],
|
|
23
|
+
"cpu": [
|
|
24
|
+
"x64",
|
|
25
|
+
"arm64"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"git",
|
|
29
|
+
"diff",
|
|
30
|
+
"pager",
|
|
31
|
+
"tui",
|
|
32
|
+
"terminal"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/aymanbagabas/drift.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/aymanbagabas/drift#readme",
|
|
39
|
+
"license": "MIT"
|
|
40
|
+
}
|