opencode-worktree 0.1.3
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/opencode-worktree +89 -0
- package/package.json +38 -0
- package/postinstall.mjs +69 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const updateNotifier = require('update-notifier');
|
|
8
|
+
|
|
9
|
+
const pkg = require('../package.json');
|
|
10
|
+
|
|
11
|
+
updateNotifier({ pkg }).notify({ isGlobal: true });
|
|
12
|
+
|
|
13
|
+
const detectPlatformAndArch = () => {
|
|
14
|
+
let platform;
|
|
15
|
+
switch (os.platform()) {
|
|
16
|
+
case 'darwin':
|
|
17
|
+
platform = 'darwin';
|
|
18
|
+
break;
|
|
19
|
+
case 'linux':
|
|
20
|
+
platform = 'linux';
|
|
21
|
+
break;
|
|
22
|
+
case 'win32':
|
|
23
|
+
platform = 'windows';
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
platform = os.platform();
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let arch;
|
|
31
|
+
switch (os.arch()) {
|
|
32
|
+
case 'x64':
|
|
33
|
+
arch = 'x64';
|
|
34
|
+
break;
|
|
35
|
+
case 'arm64':
|
|
36
|
+
arch = 'arm64';
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
arch = os.arch();
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { platform, arch };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const resolveBinaryPath = () => {
|
|
47
|
+
const { platform, arch } = detectPlatformAndArch();
|
|
48
|
+
const packageName = `${pkg.name}-${platform}-${arch}`;
|
|
49
|
+
const binaryName = platform === 'windows' ? 'opencode-worktree.exe' : 'opencode-worktree';
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
53
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
54
|
+
const binaryPath = path.join(packageDir, 'bin', binaryName);
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(binaryPath)) {
|
|
57
|
+
throw new Error(`Binary not found at ${binaryPath}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return binaryPath;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
63
|
+
throw new Error(`Could not find ${packageName}: ${message}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const run = () => {
|
|
68
|
+
try {
|
|
69
|
+
const binaryPath = resolveBinaryPath();
|
|
70
|
+
const args = process.argv.slice(2);
|
|
71
|
+
const child = spawn(binaryPath, args, { stdio: 'inherit' });
|
|
72
|
+
|
|
73
|
+
child.on('exit', (code) => {
|
|
74
|
+
process.exit(code ?? 0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
child.on('error', (error) => {
|
|
78
|
+
console.error('Failed to start opencode-worktree binary.');
|
|
79
|
+
console.error(error);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Failed to locate opencode-worktree binary.');
|
|
84
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
run();
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-worktree",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "TUI for managing git worktrees with opencode integration.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "arturosdg",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/arturosdg/opencode-worktree.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/arturosdg/opencode-worktree/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/arturosdg/opencode-worktree#readme",
|
|
15
|
+
"bin": {
|
|
16
|
+
"opencode-worktree": "./bin/opencode-worktree"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"postinstall": "node ./postinstall.mjs"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"update-notifier": "^7.3.1"
|
|
23
|
+
},
|
|
24
|
+
"optionalDependencies": {
|
|
25
|
+
"opencode-worktree-darwin-arm64": "0.1.3",
|
|
26
|
+
"opencode-worktree-darwin-x64": "0.1.3",
|
|
27
|
+
"opencode-worktree-linux-x64": "0.1.3",
|
|
28
|
+
"opencode-worktree-linux-arm64": "0.1.3",
|
|
29
|
+
"opencode-worktree-windows-x64": "0.1.3"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"bin",
|
|
33
|
+
"postinstall.mjs"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
const detectPlatformAndArch = () => {
|
|
13
|
+
let platform;
|
|
14
|
+
switch (os.platform()) {
|
|
15
|
+
case "darwin":
|
|
16
|
+
platform = "darwin";
|
|
17
|
+
break;
|
|
18
|
+
case "linux":
|
|
19
|
+
platform = "linux";
|
|
20
|
+
break;
|
|
21
|
+
case "win32":
|
|
22
|
+
platform = "windows";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
platform = os.platform();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let arch;
|
|
30
|
+
switch (os.arch()) {
|
|
31
|
+
case "x64":
|
|
32
|
+
arch = "x64";
|
|
33
|
+
break;
|
|
34
|
+
case "arm64":
|
|
35
|
+
arch = "arm64";
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
arch = os.arch();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { platform, arch };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const verifyBinary = () => {
|
|
46
|
+
const { platform, arch } = detectPlatformAndArch();
|
|
47
|
+
const packageName = `opencode-worktree-${platform}-${arch}`;
|
|
48
|
+
const binaryName =
|
|
49
|
+
platform === "windows" ? "opencode-worktree.exe" : "opencode-worktree";
|
|
50
|
+
|
|
51
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
52
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
53
|
+
const binaryPath = path.join(packageDir, "bin", binaryName);
|
|
54
|
+
|
|
55
|
+
if (!fs.existsSync(binaryPath)) {
|
|
56
|
+
throw new Error(`Binary not found at ${binaryPath}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return binaryPath;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const binaryPath = verifyBinary();
|
|
64
|
+
console.log(`opencode-worktree binary verified at: ${binaryPath}`);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("Failed to setup opencode-worktree binary.");
|
|
67
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|