bincode-dev 0.0.25 → 0.0.27
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/bincode +113 -113
- package/package.json +5 -5
- package/scripts/prepare-platform-packages.js +148 -148
package/bin/bincode
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
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 printWrapperVersionAndExit() {
|
|
9
|
-
try {
|
|
10
|
-
const pkgPath = path.join(__dirname, "..", "package.json")
|
|
11
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
12
|
-
if (pkg && pkg.version) {
|
|
13
|
-
process.stdout.write(String(pkg.version) + "\n")
|
|
14
|
-
process.exit(0)
|
|
15
|
-
}
|
|
16
|
-
} catch {
|
|
17
|
-
// ignore
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Ensure `bincode -v/--version/version` always reports the wrapper npm package version,
|
|
22
|
-
// not whatever is embedded inside the native binary (which can be confusing during publishing tests).
|
|
23
|
-
const rawArgs = process.argv.slice(2)
|
|
24
|
-
if (rawArgs.includes("-v") || rawArgs.includes("--version") || rawArgs[0] === "version") {
|
|
25
|
-
printWrapperVersionAndExit()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function run(target) {
|
|
29
|
-
const env = { ...process.env }
|
|
30
|
-
// Ensure this package variant uses its own config/data directories.
|
|
31
|
-
if (!env.BINCODE_APP_ID) env.BINCODE_APP_ID = "bincode-dev"
|
|
32
|
-
// Provide package-level defaults, but never override user-provided env vars.
|
|
33
|
-
// bincode -> staging (requested) -- mirror the same defaults for testing
|
|
34
|
-
if (!env.BINERIC_API_URL) env.BINERIC_API_URL = "https://stagingapi.bineric.com/api/v1/ai"
|
|
35
|
-
if (!env.BINERIC_FRONTEND_URL) env.BINERIC_FRONTEND_URL = "https://
|
|
36
|
-
|
|
37
|
-
// Best-effort: ensure executable bit on mac/linux.
|
|
38
|
-
try {
|
|
39
|
-
if (os.platform() !== "win32") fs.chmodSync(target, 0o755)
|
|
40
|
-
} catch {
|
|
41
|
-
// ignore
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
45
|
-
stdio: "inherit",
|
|
46
|
-
env,
|
|
47
|
-
})
|
|
48
|
-
if (result.error) {
|
|
49
|
-
console.error(result.error.message)
|
|
50
|
-
process.exit(1)
|
|
51
|
-
}
|
|
52
|
-
const code = typeof result.status === "number" ? result.status : 0
|
|
53
|
-
process.exit(code)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const platform = os.platform()
|
|
57
|
-
const arch = os.arch()
|
|
58
|
-
|
|
59
|
-
const targetPkgMap = {
|
|
60
|
-
"darwin:arm64": "bincode-dev-darwin-arm64",
|
|
61
|
-
"darwin:x64": "bincode-dev-darwin-x64",
|
|
62
|
-
"linux:x64": "bincode-dev-linux-x64",
|
|
63
|
-
"win32:x64": "bincode-dev-windows-x64",
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const key = `${platform}:${arch}`
|
|
67
|
-
const targetPkg = targetPkgMap[key]
|
|
68
|
-
const binaryName = platform === "win32" ? "bincode.exe" : "bincode"
|
|
69
|
-
|
|
70
|
-
if (!targetPkg) {
|
|
71
|
-
console.error(
|
|
72
|
-
[
|
|
73
|
-
`Unsupported platform/arch: ${platform}/${arch}`,
|
|
74
|
-
`No prebuilt bincode binary is published for this target.`,
|
|
75
|
-
].join("\n"),
|
|
76
|
-
)
|
|
77
|
-
process.exit(1)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let pkgRoot
|
|
81
|
-
try {
|
|
82
|
-
pkgRoot = path.dirname(require.resolve(`${targetPkg}/package.json`))
|
|
83
|
-
} catch {
|
|
84
|
-
console.error(
|
|
85
|
-
[
|
|
86
|
-
`Missing optional dependency: ${targetPkg}`,
|
|
87
|
-
``,
|
|
88
|
-
`This usually happens if you installed with --no-optional (or your package manager skipped optional deps).`,
|
|
89
|
-
`Also check that install scripts are not disabled (npm config ignore-scripts).`,
|
|
90
|
-
`Reinstall without skipping optional dependencies, e.g.:`,
|
|
91
|
-
` npm i bincode-dev`,
|
|
92
|
-
``,
|
|
93
|
-
`Or install the platform package directly:`,
|
|
94
|
-
` npm i ${targetPkg}`,
|
|
95
|
-
].join("\n"),
|
|
96
|
-
)
|
|
97
|
-
process.exit(1)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const candidate = path.join(pkgRoot, "bin", binaryName)
|
|
101
|
-
if (!fs.existsSync(candidate)) {
|
|
102
|
-
console.error(
|
|
103
|
-
[
|
|
104
|
-
`Could not find bincode binary inside ${targetPkg}.`,
|
|
105
|
-
`Expected at:`,
|
|
106
|
-
` ${candidate}`,
|
|
107
|
-
].join("\n"),
|
|
108
|
-
)
|
|
109
|
-
process.exit(1)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
run(candidate)
|
|
113
|
-
|
|
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 printWrapperVersionAndExit() {
|
|
9
|
+
try {
|
|
10
|
+
const pkgPath = path.join(__dirname, "..", "package.json")
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
12
|
+
if (pkg && pkg.version) {
|
|
13
|
+
process.stdout.write(String(pkg.version) + "\n")
|
|
14
|
+
process.exit(0)
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
// ignore
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Ensure `bincode -v/--version/version` always reports the wrapper npm package version,
|
|
22
|
+
// not whatever is embedded inside the native binary (which can be confusing during publishing tests).
|
|
23
|
+
const rawArgs = process.argv.slice(2)
|
|
24
|
+
if (rawArgs.includes("-v") || rawArgs.includes("--version") || rawArgs[0] === "version") {
|
|
25
|
+
printWrapperVersionAndExit()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function run(target) {
|
|
29
|
+
const env = { ...process.env }
|
|
30
|
+
// Ensure this package variant uses its own config/data directories.
|
|
31
|
+
if (!env.BINCODE_APP_ID) env.BINCODE_APP_ID = "bincode-dev"
|
|
32
|
+
// Provide package-level defaults, but never override user-provided env vars.
|
|
33
|
+
// bincode -> staging (requested) -- mirror the same defaults for testing
|
|
34
|
+
if (!env.BINERIC_API_URL) env.BINERIC_API_URL = "https://stagingapi.bineric.com/api/v1/bincode/ai"
|
|
35
|
+
if (!env.BINERIC_FRONTEND_URL) env.BINERIC_FRONTEND_URL = "https://staging.bineric.com"
|
|
36
|
+
|
|
37
|
+
// Best-effort: ensure executable bit on mac/linux.
|
|
38
|
+
try {
|
|
39
|
+
if (os.platform() !== "win32") fs.chmodSync(target, 0o755)
|
|
40
|
+
} catch {
|
|
41
|
+
// ignore
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
45
|
+
stdio: "inherit",
|
|
46
|
+
env,
|
|
47
|
+
})
|
|
48
|
+
if (result.error) {
|
|
49
|
+
console.error(result.error.message)
|
|
50
|
+
process.exit(1)
|
|
51
|
+
}
|
|
52
|
+
const code = typeof result.status === "number" ? result.status : 0
|
|
53
|
+
process.exit(code)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const platform = os.platform()
|
|
57
|
+
const arch = os.arch()
|
|
58
|
+
|
|
59
|
+
const targetPkgMap = {
|
|
60
|
+
"darwin:arm64": "bincode-dev-darwin-arm64",
|
|
61
|
+
"darwin:x64": "bincode-dev-darwin-x64",
|
|
62
|
+
"linux:x64": "bincode-dev-linux-x64",
|
|
63
|
+
"win32:x64": "bincode-dev-windows-x64",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const key = `${platform}:${arch}`
|
|
67
|
+
const targetPkg = targetPkgMap[key]
|
|
68
|
+
const binaryName = platform === "win32" ? "bincode.exe" : "bincode"
|
|
69
|
+
|
|
70
|
+
if (!targetPkg) {
|
|
71
|
+
console.error(
|
|
72
|
+
[
|
|
73
|
+
`Unsupported platform/arch: ${platform}/${arch}`,
|
|
74
|
+
`No prebuilt bincode binary is published for this target.`,
|
|
75
|
+
].join("\n"),
|
|
76
|
+
)
|
|
77
|
+
process.exit(1)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let pkgRoot
|
|
81
|
+
try {
|
|
82
|
+
pkgRoot = path.dirname(require.resolve(`${targetPkg}/package.json`))
|
|
83
|
+
} catch {
|
|
84
|
+
console.error(
|
|
85
|
+
[
|
|
86
|
+
`Missing optional dependency: ${targetPkg}`,
|
|
87
|
+
``,
|
|
88
|
+
`This usually happens if you installed with --no-optional (or your package manager skipped optional deps).`,
|
|
89
|
+
`Also check that install scripts are not disabled (npm config ignore-scripts).`,
|
|
90
|
+
`Reinstall without skipping optional dependencies, e.g.:`,
|
|
91
|
+
` npm i bincode-dev`,
|
|
92
|
+
``,
|
|
93
|
+
`Or install the platform package directly:`,
|
|
94
|
+
` npm i ${targetPkg}`,
|
|
95
|
+
].join("\n"),
|
|
96
|
+
)
|
|
97
|
+
process.exit(1)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const candidate = path.join(pkgRoot, "bin", binaryName)
|
|
101
|
+
if (!fs.existsSync(candidate)) {
|
|
102
|
+
console.error(
|
|
103
|
+
[
|
|
104
|
+
`Could not find bincode binary inside ${targetPkg}.`,
|
|
105
|
+
`Expected at:`,
|
|
106
|
+
` ${candidate}`,
|
|
107
|
+
].join("\n"),
|
|
108
|
+
)
|
|
109
|
+
process.exit(1)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
run(candidate)
|
|
113
|
+
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bincode-dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "Bincode: AI-powered development CLI (dev/test version, not affiliated with opencode)",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bincode": "./bin/bincode"
|
|
7
7
|
},
|
|
8
8
|
"optionalDependencies": {
|
|
9
|
-
"bincode-dev-darwin-arm64": "0.0.
|
|
10
|
-
"bincode-dev-darwin-x64": "0.0.
|
|
11
|
-
"bincode-dev-linux-x64": "0.0.
|
|
12
|
-
"bincode-dev-windows-x64": "0.0.
|
|
9
|
+
"bincode-dev-darwin-arm64": "0.0.27",
|
|
10
|
+
"bincode-dev-darwin-x64": "0.0.27",
|
|
11
|
+
"bincode-dev-linux-x64": "0.0.27",
|
|
12
|
+
"bincode-dev-windows-x64": "0.0.27"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "bun script/build.ts",
|
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates per-platform npm packages that contain the native bincode binary and app dist.
|
|
3
|
-
*
|
|
4
|
-
* Why:
|
|
5
|
-
* - Keeps the main `bincode-dev` package small.
|
|
6
|
-
* - Lets users run `npm i bincode-dev` on mac/linux/windows and get the right binary via optionalDependencies.
|
|
7
|
-
* - Includes app/dist so the web console works when installed via platform packages.
|
|
8
|
-
*
|
|
9
|
-
* Expected input:
|
|
10
|
-
* - `publish-bincode-dev/dist/opencode-<platform>-<arch>/bin/(bincode|bincode.exe)` exists (copied from packages/opencode/dist).
|
|
11
|
-
* - `publish-bincode-dev/app/dist` exists (copied from packages/app/dist).
|
|
12
|
-
*
|
|
13
|
-
* Output:
|
|
14
|
-
* - `publish-bincode-dev/platform-packages/<pkgName>/{package.json,README.md,bin/*,app/dist/*}`
|
|
15
|
-
*/
|
|
16
|
-
const fs = require("fs")
|
|
17
|
-
const path = require("path")
|
|
18
|
-
|
|
19
|
-
const root = path.join(__dirname, "..")
|
|
20
|
-
const mainPkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"))
|
|
21
|
-
const version = mainPkg.version
|
|
22
|
-
|
|
23
|
-
if (!version) {
|
|
24
|
-
console.error("[prepare-platform-packages] Missing version in publish-bincode-dev/package.json")
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function rmrf(p) {
|
|
29
|
-
fs.rmSync(p, { recursive: true, force: true })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function mkdirp(p) {
|
|
33
|
-
fs.mkdirSync(p, { recursive: true })
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function writeJson(p, obj) {
|
|
37
|
-
fs.writeFileSync(p, JSON.stringify(obj, null, 2) + "\n")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function copyRecursive(src, dest) {
|
|
41
|
-
mkdirp(path.dirname(dest))
|
|
42
|
-
const stat = fs.statSync(src)
|
|
43
|
-
if (stat.isDirectory()) {
|
|
44
|
-
mkdirp(dest)
|
|
45
|
-
const entries = fs.readdirSync(src)
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
copyRecursive(path.join(src, entry), path.join(dest, entry))
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
fs.copyFileSync(src, dest)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @type {Array<{pkg:string, opencodeDistDir:string, os:string, cpu:string, binName:string}>} */
|
|
55
|
-
const targets = [
|
|
56
|
-
{
|
|
57
|
-
pkg: "bincode-dev-darwin-arm64",
|
|
58
|
-
opencodeDistDir: "opencode-darwin-arm64",
|
|
59
|
-
os: "darwin",
|
|
60
|
-
cpu: "arm64",
|
|
61
|
-
binName: "bincode",
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
pkg: "bincode-dev-darwin-x64",
|
|
65
|
-
opencodeDistDir: "opencode-darwin-x64",
|
|
66
|
-
os: "darwin",
|
|
67
|
-
cpu: "x64",
|
|
68
|
-
binName: "bincode",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
pkg: "bincode-dev-linux-x64",
|
|
72
|
-
opencodeDistDir: "opencode-linux-x64",
|
|
73
|
-
os: "linux",
|
|
74
|
-
cpu: "x64",
|
|
75
|
-
binName: "bincode",
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
pkg: "bincode-dev-windows-x64",
|
|
79
|
-
opencodeDistDir: "opencode-windows-x64",
|
|
80
|
-
os: "win32",
|
|
81
|
-
cpu: "x64",
|
|
82
|
-
binName: "bincode.exe",
|
|
83
|
-
},
|
|
84
|
-
]
|
|
85
|
-
|
|
86
|
-
const distRoot = path.join(root, "dist")
|
|
87
|
-
const pkgsRoot = path.join(root, "platform-packages")
|
|
88
|
-
const appDistSource = path.join(root, "app", "dist")
|
|
89
|
-
|
|
90
|
-
mkdirp(pkgsRoot)
|
|
91
|
-
|
|
92
|
-
// Check if app/dist exists
|
|
93
|
-
if (!fs.existsSync(appDistSource)) {
|
|
94
|
-
console.error(`[prepare-platform-packages] Warning: app/dist not found at ${appDistSource}`)
|
|
95
|
-
console.error(`[prepare-platform-packages] Web console may not work in installed packages`)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
for (const t of targets) {
|
|
99
|
-
const sourceBin = path.join(distRoot, t.opencodeDistDir, "bin", t.binName)
|
|
100
|
-
if (!fs.existsSync(sourceBin)) {
|
|
101
|
-
console.error(`[prepare-platform-packages] Missing binary: ${sourceBin}`)
|
|
102
|
-
process.exit(1)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const outDir = path.join(pkgsRoot, t.pkg)
|
|
106
|
-
const outBinDir = path.join(outDir, "bin")
|
|
107
|
-
rmrf(outBinDir)
|
|
108
|
-
mkdirp(outBinDir)
|
|
109
|
-
|
|
110
|
-
const outBin = path.join(outBinDir, t.binName)
|
|
111
|
-
fs.copyFileSync(sourceBin, outBin)
|
|
112
|
-
|
|
113
|
-
// Ensure executable bit for mac/linux when packing from Windows/WSL.
|
|
114
|
-
if (t.os !== "win32") {
|
|
115
|
-
try {
|
|
116
|
-
fs.chmodSync(outBin, 0o755)
|
|
117
|
-
} catch {
|
|
118
|
-
// ignore
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Copy app/dist directory if it exists
|
|
123
|
-
const outAppDist = path.join(outDir, "app", "dist")
|
|
124
|
-
if (fs.existsSync(appDistSource)) {
|
|
125
|
-
rmrf(outAppDist)
|
|
126
|
-
copyRecursive(appDistSource, outAppDist)
|
|
127
|
-
console.log(`[prepare-platform-packages] Copied app/dist to ${t.pkg}`)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
writeJson(path.join(outDir, "package.json"), {
|
|
131
|
-
name: t.pkg,
|
|
132
|
-
version,
|
|
133
|
-
description: "Platform-specific bincode binary (internal dependency of bincode-dev).",
|
|
134
|
-
license: mainPkg.license || "MIT",
|
|
135
|
-
os: [t.os],
|
|
136
|
-
cpu: [t.cpu],
|
|
137
|
-
files: ["bin", "app/dist"],
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
fs.writeFileSync(
|
|
141
|
-
path.join(outDir, "README.md"),
|
|
142
|
-
`# ${t.pkg}\n\nPlatform-specific binary package for \`bincode-dev\`.\n\nDo not install directly unless you know what you're doing.\n`,
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
console.log(`[prepare-platform-packages] Prepared ${t.pkg}@${version}`)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates per-platform npm packages that contain the native bincode binary and app dist.
|
|
3
|
+
*
|
|
4
|
+
* Why:
|
|
5
|
+
* - Keeps the main `bincode-dev` package small.
|
|
6
|
+
* - Lets users run `npm i bincode-dev` on mac/linux/windows and get the right binary via optionalDependencies.
|
|
7
|
+
* - Includes app/dist so the web console works when installed via platform packages.
|
|
8
|
+
*
|
|
9
|
+
* Expected input:
|
|
10
|
+
* - `publish-bincode-dev/dist/opencode-<platform>-<arch>/bin/(bincode|bincode.exe)` exists (copied from packages/opencode/dist).
|
|
11
|
+
* - `publish-bincode-dev/app/dist` exists (copied from packages/app/dist).
|
|
12
|
+
*
|
|
13
|
+
* Output:
|
|
14
|
+
* - `publish-bincode-dev/platform-packages/<pkgName>/{package.json,README.md,bin/*,app/dist/*}`
|
|
15
|
+
*/
|
|
16
|
+
const fs = require("fs")
|
|
17
|
+
const path = require("path")
|
|
18
|
+
|
|
19
|
+
const root = path.join(__dirname, "..")
|
|
20
|
+
const mainPkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"))
|
|
21
|
+
const version = mainPkg.version
|
|
22
|
+
|
|
23
|
+
if (!version) {
|
|
24
|
+
console.error("[prepare-platform-packages] Missing version in publish-bincode-dev/package.json")
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function rmrf(p) {
|
|
29
|
+
fs.rmSync(p, { recursive: true, force: true })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function mkdirp(p) {
|
|
33
|
+
fs.mkdirSync(p, { recursive: true })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function writeJson(p, obj) {
|
|
37
|
+
fs.writeFileSync(p, JSON.stringify(obj, null, 2) + "\n")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function copyRecursive(src, dest) {
|
|
41
|
+
mkdirp(path.dirname(dest))
|
|
42
|
+
const stat = fs.statSync(src)
|
|
43
|
+
if (stat.isDirectory()) {
|
|
44
|
+
mkdirp(dest)
|
|
45
|
+
const entries = fs.readdirSync(src)
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
copyRecursive(path.join(src, entry), path.join(dest, entry))
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
fs.copyFileSync(src, dest)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @type {Array<{pkg:string, opencodeDistDir:string, os:string, cpu:string, binName:string}>} */
|
|
55
|
+
const targets = [
|
|
56
|
+
{
|
|
57
|
+
pkg: "bincode-dev-darwin-arm64",
|
|
58
|
+
opencodeDistDir: "opencode-darwin-arm64",
|
|
59
|
+
os: "darwin",
|
|
60
|
+
cpu: "arm64",
|
|
61
|
+
binName: "bincode",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
pkg: "bincode-dev-darwin-x64",
|
|
65
|
+
opencodeDistDir: "opencode-darwin-x64",
|
|
66
|
+
os: "darwin",
|
|
67
|
+
cpu: "x64",
|
|
68
|
+
binName: "bincode",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
pkg: "bincode-dev-linux-x64",
|
|
72
|
+
opencodeDistDir: "opencode-linux-x64",
|
|
73
|
+
os: "linux",
|
|
74
|
+
cpu: "x64",
|
|
75
|
+
binName: "bincode",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
pkg: "bincode-dev-windows-x64",
|
|
79
|
+
opencodeDistDir: "opencode-windows-x64",
|
|
80
|
+
os: "win32",
|
|
81
|
+
cpu: "x64",
|
|
82
|
+
binName: "bincode.exe",
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
const distRoot = path.join(root, "dist")
|
|
87
|
+
const pkgsRoot = path.join(root, "platform-packages")
|
|
88
|
+
const appDistSource = path.join(root, "app", "dist")
|
|
89
|
+
|
|
90
|
+
mkdirp(pkgsRoot)
|
|
91
|
+
|
|
92
|
+
// Check if app/dist exists
|
|
93
|
+
if (!fs.existsSync(appDistSource)) {
|
|
94
|
+
console.error(`[prepare-platform-packages] Warning: app/dist not found at ${appDistSource}`)
|
|
95
|
+
console.error(`[prepare-platform-packages] Web console may not work in installed packages`)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const t of targets) {
|
|
99
|
+
const sourceBin = path.join(distRoot, t.opencodeDistDir, "bin", t.binName)
|
|
100
|
+
if (!fs.existsSync(sourceBin)) {
|
|
101
|
+
console.error(`[prepare-platform-packages] Missing binary: ${sourceBin}`)
|
|
102
|
+
process.exit(1)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const outDir = path.join(pkgsRoot, t.pkg)
|
|
106
|
+
const outBinDir = path.join(outDir, "bin")
|
|
107
|
+
rmrf(outBinDir)
|
|
108
|
+
mkdirp(outBinDir)
|
|
109
|
+
|
|
110
|
+
const outBin = path.join(outBinDir, t.binName)
|
|
111
|
+
fs.copyFileSync(sourceBin, outBin)
|
|
112
|
+
|
|
113
|
+
// Ensure executable bit for mac/linux when packing from Windows/WSL.
|
|
114
|
+
if (t.os !== "win32") {
|
|
115
|
+
try {
|
|
116
|
+
fs.chmodSync(outBin, 0o755)
|
|
117
|
+
} catch {
|
|
118
|
+
// ignore
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Copy app/dist directory if it exists
|
|
123
|
+
const outAppDist = path.join(outDir, "app", "dist")
|
|
124
|
+
if (fs.existsSync(appDistSource)) {
|
|
125
|
+
rmrf(outAppDist)
|
|
126
|
+
copyRecursive(appDistSource, outAppDist)
|
|
127
|
+
console.log(`[prepare-platform-packages] Copied app/dist to ${t.pkg}`)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
writeJson(path.join(outDir, "package.json"), {
|
|
131
|
+
name: t.pkg,
|
|
132
|
+
version,
|
|
133
|
+
description: "Platform-specific bincode binary (internal dependency of bincode-dev).",
|
|
134
|
+
license: mainPkg.license || "MIT",
|
|
135
|
+
os: [t.os],
|
|
136
|
+
cpu: [t.cpu],
|
|
137
|
+
files: ["bin", "app/dist"],
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
fs.writeFileSync(
|
|
141
|
+
path.join(outDir, "README.md"),
|
|
142
|
+
`# ${t.pkg}\n\nPlatform-specific binary package for \`bincode-dev\`.\n\nDo not install directly unless you know what you're doing.\n`,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
console.log(`[prepare-platform-packages] Prepared ${t.pkg}@${version}`)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|