@codemieai/codemie-opencode 0.0.40

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/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Apache-2.0
2
+
3
+ See https://www.apache.org/licenses/LICENSE-2.0
package/bin/codemie ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("child_process")
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const os = require("os")
7
+
8
+ function run(target) {
9
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
+ stdio: "inherit",
11
+ })
12
+ if (result.error) {
13
+ console.error(result.error.message)
14
+ process.exit(1)
15
+ }
16
+ const code = typeof result.status === "number" ? result.status : 0
17
+ process.exit(code)
18
+ }
19
+
20
+ const envPath = process.env.CODEMIE_BIN_PATH || process.env.OPENCODE_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ const scriptPath = fs.realpathSync(__filename)
26
+ const scriptDir = path.dirname(scriptPath)
27
+
28
+ const platformMap = {
29
+ darwin: "darwin",
30
+ linux: "linux",
31
+ win32: "windows",
32
+ }
33
+ const archMap = {
34
+ x64: "x64",
35
+ arm64: "arm64",
36
+ arm: "arm",
37
+ }
38
+
39
+ let platform = platformMap[os.platform()]
40
+ if (!platform) {
41
+ platform = os.platform()
42
+ }
43
+ let arch = archMap[os.arch()]
44
+ if (!arch) {
45
+ arch = os.arch()
46
+ }
47
+ const base = "codemie-opencode-" + platform + "-" + arch
48
+ const binary = platform === "windows" ? "codemie.exe" : "codemie"
49
+
50
+ const scope = "@codemieai"
51
+
52
+ function findBinary(startDir) {
53
+ let current = startDir
54
+ for (;;) {
55
+ const modules = path.join(current, "node_modules")
56
+ if (fs.existsSync(modules)) {
57
+ // Check scoped location first: node_modules/@codemieai/codemie-{platform}-{arch}
58
+ const scopedDir = path.join(modules, scope, base)
59
+ const scopedCandidate = path.join(scopedDir, "bin", binary)
60
+ if (fs.existsSync(scopedCandidate)) {
61
+ return scopedCandidate
62
+ }
63
+ // Fallback: unscoped (for backward compat)
64
+ const entries = fs.readdirSync(modules)
65
+ for (const entry of entries) {
66
+ if (!entry.startsWith(base)) {
67
+ continue
68
+ }
69
+ const candidate = path.join(modules, entry, "bin", binary)
70
+ if (fs.existsSync(candidate)) {
71
+ return candidate
72
+ }
73
+ }
74
+ }
75
+ const parent = path.dirname(current)
76
+ if (parent === current) {
77
+ return
78
+ }
79
+ current = parent
80
+ }
81
+ }
82
+
83
+ const resolved = findBinary(scriptDir)
84
+ if (!resolved) {
85
+ console.error(
86
+ 'It seems that your package manager failed to install the right version of the codemie CLI for your platform. You can try manually installing the "' +
87
+ base +
88
+ '" package',
89
+ )
90
+ process.exit(1)
91
+ }
92
+
93
+ run(resolved)
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@codemieai/codemie-opencode",
3
+ "bin": {
4
+ "codemie": "./bin/codemie"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.40",
10
+ "license": "Apache-2.0",
11
+ "optionalDependencies": {
12
+ "@codemieai/codemie-opencode-darwin-x64-baseline": "0.0.40",
13
+ "@codemieai/codemie-opencode-darwin-x64": "0.0.40",
14
+ "@codemieai/codemie-opencode-windows-x64": "0.0.40",
15
+ "@codemieai/codemie-opencode-linux-x64-musl": "0.0.40",
16
+ "@codemieai/codemie-opencode-linux-x64-baseline-musl": "0.0.40",
17
+ "@codemieai/codemie-opencode-linux-arm64": "0.0.40",
18
+ "@codemieai/codemie-opencode-linux-x64-baseline": "0.0.40",
19
+ "@codemieai/codemie-opencode-linux-arm64-musl": "0.0.40",
20
+ "@codemieai/codemie-opencode-linux-x64": "0.0.40",
21
+ "@codemieai/codemie-opencode-darwin-arm64": "0.0.40",
22
+ "@codemieai/codemie-opencode-windows-x64-baseline": "0.0.40"
23
+ }
24
+ }
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
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
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function findBinary() {
51
+ const { platform, arch } = detectPlatformAndArch()
52
+ const packageName = `@codemieai/codemie-opencode-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "codemie.exe" : "codemie"
54
+
55
+ try {
56
+ // Use require.resolve to find the package
57
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
+ const packageDir = path.dirname(packageJsonPath)
59
+ const binaryPath = path.join(packageDir, "bin", binaryName)
60
+
61
+ if (!fs.existsSync(binaryPath)) {
62
+ throw new Error(`Binary not found at ${binaryPath}`)
63
+ }
64
+
65
+ return { binaryPath, binaryName }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
68
+ }
69
+ }
70
+
71
+ function prepareBinDirectory(binaryName) {
72
+ const binDir = path.join(__dirname, "bin")
73
+ const targetPath = path.join(binDir, binaryName)
74
+
75
+ // Ensure bin directory exists
76
+ if (!fs.existsSync(binDir)) {
77
+ fs.mkdirSync(binDir, { recursive: true })
78
+ }
79
+
80
+ // Remove existing binary/symlink if it exists
81
+ if (fs.existsSync(targetPath)) {
82
+ fs.unlinkSync(targetPath)
83
+ }
84
+
85
+ return { binDir, targetPath }
86
+ }
87
+
88
+ function symlinkBinary(sourcePath, binaryName) {
89
+ const { targetPath } = prepareBinDirectory(binaryName)
90
+
91
+ fs.symlinkSync(sourcePath, targetPath)
92
+ console.log(`codemie binary symlinked: ${targetPath} -> ${sourcePath}`)
93
+
94
+ // Verify the file exists after operation
95
+ if (!fs.existsSync(targetPath)) {
96
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ if (os.platform() === "win32") {
103
+ // On Windows, the .exe is already included in the package and bin field points to it
104
+ // No postinstall setup needed
105
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
+ return
107
+ }
108
+
109
+ // On non-Windows platforms, just verify the binary package exists
110
+ // Don't replace the wrapper script - it handles binary execution
111
+ const { binaryPath } = findBinary()
112
+ console.log(`Platform binary verified at: ${binaryPath}`)
113
+ console.log("Wrapper script will handle binary execution")
114
+ } catch (error) {
115
+ console.error("Failed to setup codemie binary:", error.message)
116
+ process.exit(1)
117
+ }
118
+ }
119
+
120
+ try {
121
+ main()
122
+ } catch (error) {
123
+ console.error("Postinstall script error:", error.message)
124
+ process.exit(0)
125
+ }