gitmorph 0.2.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/gm +15 -0
  2. package/package.json +35 -0
  3. package/postinstall.js +72 -0
package/bin/gm ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ BINARY_PATH="$(dirname "$0")/gm-binary"
5
+
6
+ if [ ! -f "$BINARY_PATH" ]; then
7
+ echo "Error: gm binary not installed. Try reinstalling:" >&2
8
+ echo " npm install -g @morphllm/gitmorph" >&2
9
+ echo "" >&2
10
+ echo "Or install directly:" >&2
11
+ echo " curl -fsSL https://gitmorph.com/cli/install.sh | sh" >&2
12
+ exit 1
13
+ fi
14
+
15
+ exec "$BINARY_PATH" "$@"
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "gitmorph",
3
+ "version": "0.2.0",
4
+ "description": "GitMorph CLI — work with gitmorph.com from the command line",
5
+ "bin": {
6
+ "gm": "bin/gm"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "postinstall.js"
11
+ ],
12
+ "scripts": {
13
+ "postinstall": "node postinstall.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://gitmorph.com/bhaktateas/cli"
18
+ },
19
+ "homepage": "https://gitmorph.com",
20
+ "keywords": [
21
+ "gitmorph",
22
+ "cli",
23
+ "git",
24
+ "devtools"
25
+ ],
26
+ "license": "MIT",
27
+ "os": [
28
+ "darwin",
29
+ "linux"
30
+ ],
31
+ "cpu": [
32
+ "x64",
33
+ "arm64"
34
+ ]
35
+ }
package/postinstall.js ADDED
@@ -0,0 +1,72 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const https = require("https");
4
+
5
+ const VERSION = require("./package.json").version;
6
+ const HOST = "gitmorph.com";
7
+ const REPO = "tejas/cli";
8
+ const BIN_DIR = path.join(__dirname, "bin");
9
+ const BINARY_PATH = path.join(BIN_DIR, "gm-binary");
10
+
11
+ const PLATFORM_MAP = {
12
+ "darwin-arm64": "gm-darwin-arm64",
13
+ "darwin-x64": "gm-darwin-amd64",
14
+ "linux-x64": "gm-linux-amd64",
15
+ "linux-arm64": "gm-linux-arm64",
16
+ };
17
+
18
+ function fetch(url) {
19
+ return new Promise((resolve, reject) => {
20
+ https.get(url, (res) => {
21
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
22
+ return fetch(res.headers.location).then(resolve, reject);
23
+ }
24
+ if (res.statusCode !== 200) {
25
+ return reject(new Error(`HTTP ${res.statusCode} from ${url}`));
26
+ }
27
+ const chunks = [];
28
+ res.on("data", (chunk) => chunks.push(chunk));
29
+ res.on("end", () => resolve(Buffer.concat(chunks)));
30
+ res.on("error", reject);
31
+ }).on("error", reject);
32
+ });
33
+ }
34
+
35
+ async function main() {
36
+ const key = `${process.platform}-${process.arch}`;
37
+ const filename = PLATFORM_MAP[key];
38
+
39
+ if (!filename) {
40
+ console.error(`Unsupported platform: ${key}`);
41
+ console.error("Install directly: curl -fsSL https://gitmorph.com/cli/install.sh | sh");
42
+ process.exit(0);
43
+ }
44
+
45
+ console.log(`Downloading gm v${VERSION} for ${key}...`);
46
+
47
+ try {
48
+ // Fetch release metadata from Gitea API
49
+ const releaseUrl = `https://${HOST}/api/v1/repos/${REPO}/releases/tags/v${VERSION}`;
50
+ const releaseData = JSON.parse((await fetch(releaseUrl)).toString());
51
+ const asset = (releaseData.assets || []).find((a) => a.name === filename);
52
+
53
+ if (!asset) {
54
+ throw new Error(`No binary found for ${filename} in release v${VERSION}`);
55
+ }
56
+
57
+ // Download binary via browser_download_url
58
+ const downloadUrl = asset.browser_download_url || `https://${HOST}/attachments/${asset.uuid}`;
59
+ const data = await fetch(downloadUrl);
60
+
61
+ fs.mkdirSync(BIN_DIR, { recursive: true });
62
+ fs.writeFileSync(BINARY_PATH, data);
63
+ fs.chmodSync(BINARY_PATH, 0o755);
64
+ console.log("gm installed successfully.");
65
+ } catch (err) {
66
+ console.error(`Failed to download gm binary: ${err.message}`);
67
+ console.error("Install directly: curl -fsSL https://gitmorph.com/cli/install.sh | sh");
68
+ process.exit(0);
69
+ }
70
+ }
71
+
72
+ main();