@cj-ways/orgclone 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.
Files changed (3) hide show
  1. package/bin/orgclone +20 -0
  2. package/install.js +81 -0
  3. package/package.json +20 -0
package/bin/orgclone ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Shim that locates and runs the orgclone binary.
4
+ */
5
+
6
+ const { spawnSync } = require("child_process");
7
+ const path = require("path");
8
+ const fs = require("fs");
9
+
10
+ const isWin = process.platform === "win32";
11
+ const binName = isWin ? "orgclone.exe" : "orgclone";
12
+ const binPath = path.join(__dirname, binName);
13
+
14
+ if (!fs.existsSync(binPath)) {
15
+ console.error("orgclone binary not found. Try reinstalling: npm install -g orgclone");
16
+ process.exit(1);
17
+ }
18
+
19
+ const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
20
+ process.exit(result.status ?? 1);
package/install.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall script: downloads the correct orgclone binary from GitHub Releases.
4
+ */
5
+
6
+ const https = require("https");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const { execSync } = require("child_process");
10
+ const zlib = require("zlib");
11
+
12
+ const REPO = "cj-ways/orgclone";
13
+ const VERSION = require("./package.json").version;
14
+ const BIN_DIR = path.join(__dirname, "bin");
15
+ const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "orgclone.exe" : "orgclone");
16
+
17
+ function getPlatformTarget() {
18
+ const platform = process.platform;
19
+ const arch = process.arch;
20
+
21
+ const platformMap = { win32: "windows", darwin: "darwin", linux: "linux" };
22
+ const archMap = { x64: "amd64", arm64: "arm64" };
23
+
24
+ const p = platformMap[platform];
25
+ const a = archMap[arch];
26
+
27
+ if (!p || !a) throw new Error(`Unsupported platform: ${platform}/${arch}`);
28
+
29
+ const ext = platform === "win32" ? ".exe" : "";
30
+ return `orgclone_${p}_${a}${ext}`;
31
+ }
32
+
33
+ function download(url, dest) {
34
+ return new Promise((resolve, reject) => {
35
+ const follow = (u) => {
36
+ https.get(u, { headers: { "User-Agent": "orgclone-installer" } }, (res) => {
37
+ if (res.statusCode === 301 || res.statusCode === 302) {
38
+ follow(res.headers.location);
39
+ return;
40
+ }
41
+ if (res.statusCode !== 200) {
42
+ reject(new Error(`HTTP ${res.statusCode} for ${u}`));
43
+ return;
44
+ }
45
+ const file = fs.createWriteStream(dest);
46
+ res.pipe(file);
47
+ file.on("finish", () => file.close(resolve));
48
+ file.on("error", reject);
49
+ }).on("error", reject);
50
+ };
51
+ follow(url);
52
+ });
53
+ }
54
+
55
+ async function main() {
56
+ if (fs.existsSync(BIN_PATH)) {
57
+ console.log("orgclone binary already installed.");
58
+ return;
59
+ }
60
+
61
+ fs.mkdirSync(BIN_DIR, { recursive: true });
62
+
63
+ const target = getPlatformTarget();
64
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${target}`;
65
+
66
+ console.log(`Downloading orgclone ${VERSION} for ${process.platform}/${process.arch}...`);
67
+
68
+ try {
69
+ await download(url, BIN_PATH);
70
+ if (process.platform !== "win32") {
71
+ fs.chmodSync(BIN_PATH, 0o755);
72
+ }
73
+ console.log("orgclone installed successfully.");
74
+ } catch (err) {
75
+ console.error(`Failed to download binary: ${err.message}`);
76
+ console.error(`You can manually download from: https://github.com/${REPO}/releases`);
77
+ process.exit(1);
78
+ }
79
+ }
80
+
81
+ main();
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@cj-ways/orgclone",
3
+ "version": "0.1.0",
4
+ "description": "Clone entire GitHub orgs or GitLab groups with one command",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/cj-ways/orgclone.git"
9
+ },
10
+ "scripts": {
11
+ "postinstall": "node install.js"
12
+ },
13
+ "bin": {
14
+ "orgclone": "bin/orgclone"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "install.js"
19
+ ]
20
+ }