bincode-dev 0.0.23 → 0.0.25
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/README.md +1 -1
- package/package.json +5 -5
- package/scripts/fix-binaries.js +27 -27
- package/scripts/postinstall.js +46 -46
- package/scripts/prepack.js +90 -90
- package/scripts/prepare-platform-packages.js +148 -148
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# bincode-dev
|
|
1
|
+
# bincode-dev
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bincode-dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
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.25",
|
|
10
|
+
"bincode-dev-darwin-x64": "0.0.25",
|
|
11
|
+
"bincode-dev-linux-x64": "0.0.25",
|
|
12
|
+
"bincode-dev-windows-x64": "0.0.25"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "bun script/build.ts",
|
package/scripts/fix-binaries.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
|
|
5
|
-
const platformMap = {
|
|
6
|
-
darwin: ['darwin-arm64', 'darwin-x64'],
|
|
7
|
-
linux: ['linux-x64'],
|
|
8
|
-
win32: ['windows-x64']
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const distDir = path.join(__dirname, '..', 'dist');
|
|
12
|
-
|
|
13
|
-
const currentPlatform = os.platform();
|
|
14
|
-
const archs = platformMap[currentPlatform] || [];
|
|
15
|
-
|
|
16
|
-
archs.forEach(arch => {
|
|
17
|
-
const binPath = path.join(distDir, `opencode-${arch}`, 'bin', currentPlatform === 'win32' ? 'bincode.exe' : 'bincode');
|
|
18
|
-
if (fs.existsSync(binPath)) {
|
|
19
|
-
try {
|
|
20
|
-
fs.chmodSync(binPath, 0o755);
|
|
21
|
-
console.log(`Set executable: ${binPath}`);
|
|
22
|
-
} catch (e) {
|
|
23
|
-
console.warn(`Failed to chmod ${binPath}:`, e.message);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
const platformMap = {
|
|
6
|
+
darwin: ['darwin-arm64', 'darwin-x64'],
|
|
7
|
+
linux: ['linux-x64'],
|
|
8
|
+
win32: ['windows-x64']
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const distDir = path.join(__dirname, '..', 'dist');
|
|
12
|
+
|
|
13
|
+
const currentPlatform = os.platform();
|
|
14
|
+
const archs = platformMap[currentPlatform] || [];
|
|
15
|
+
|
|
16
|
+
archs.forEach(arch => {
|
|
17
|
+
const binPath = path.join(distDir, `opencode-${arch}`, 'bin', currentPlatform === 'win32' ? 'bincode.exe' : 'bincode');
|
|
18
|
+
if (fs.existsSync(binPath)) {
|
|
19
|
+
try {
|
|
20
|
+
fs.chmodSync(binPath, 0o755);
|
|
21
|
+
console.log(`Set executable: ${binPath}`);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.warn(`Failed to chmod ${binPath}:`, e.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Self-heal install: ensure the correct platform binary package exists.
|
|
3
|
-
*
|
|
4
|
-
* Some npm setups (especially global installs) may skip optionalDependencies.
|
|
5
|
-
* We still want `npm i(-g) bincode-dev` to work without manual platform installs.
|
|
6
|
-
*/
|
|
7
|
-
const childProcess = require("child_process")
|
|
8
|
-
const fs = require("fs")
|
|
9
|
-
const path = require("path")
|
|
10
|
-
const os = require("os")
|
|
11
|
-
|
|
12
|
-
const root = path.join(__dirname, "..")
|
|
13
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"))
|
|
14
|
-
const version = pkg.version
|
|
15
|
-
|
|
16
|
-
const platform = os.platform()
|
|
17
|
-
const arch = os.arch()
|
|
18
|
-
|
|
19
|
-
const targetPkgMap = {
|
|
20
|
-
"darwin:arm64": "bincode-dev-darwin-arm64",
|
|
21
|
-
"darwin:x64": "bincode-dev-darwin-x64",
|
|
22
|
-
"linux:x64": "bincode-dev-linux-x64",
|
|
23
|
-
"win32:x64": "bincode-dev-windows-x64",
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const targetPkg = targetPkgMap[`${platform}:${arch}`]
|
|
27
|
-
if (!targetPkg || !version) process.exit(0)
|
|
28
|
-
|
|
29
|
-
function isInstalled() {
|
|
30
|
-
try {
|
|
31
|
-
require.resolve(`${targetPkg}/package.json`, { paths: [root] })
|
|
32
|
-
return true
|
|
33
|
-
} catch {
|
|
34
|
-
return false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isInstalled()) process.exit(0)
|
|
39
|
-
|
|
40
|
-
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
|
|
41
|
-
const args = ["install", "--no-save", "--no-audit", "--no-fund", `${targetPkg}@${version}`]
|
|
42
|
-
|
|
43
|
-
// Install into bincode-dev's own node_modules so `require.resolve()` works reliably.
|
|
44
|
-
childProcess.spawnSync(npmCmd, args, { cwd: root, stdio: "inherit", env: process.env })
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Self-heal install: ensure the correct platform binary package exists.
|
|
3
|
+
*
|
|
4
|
+
* Some npm setups (especially global installs) may skip optionalDependencies.
|
|
5
|
+
* We still want `npm i(-g) bincode-dev` to work without manual platform installs.
|
|
6
|
+
*/
|
|
7
|
+
const childProcess = require("child_process")
|
|
8
|
+
const fs = require("fs")
|
|
9
|
+
const path = require("path")
|
|
10
|
+
const os = require("os")
|
|
11
|
+
|
|
12
|
+
const root = path.join(__dirname, "..")
|
|
13
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"))
|
|
14
|
+
const version = pkg.version
|
|
15
|
+
|
|
16
|
+
const platform = os.platform()
|
|
17
|
+
const arch = os.arch()
|
|
18
|
+
|
|
19
|
+
const targetPkgMap = {
|
|
20
|
+
"darwin:arm64": "bincode-dev-darwin-arm64",
|
|
21
|
+
"darwin:x64": "bincode-dev-darwin-x64",
|
|
22
|
+
"linux:x64": "bincode-dev-linux-x64",
|
|
23
|
+
"win32:x64": "bincode-dev-windows-x64",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const targetPkg = targetPkgMap[`${platform}:${arch}`]
|
|
27
|
+
if (!targetPkg || !version) process.exit(0)
|
|
28
|
+
|
|
29
|
+
function isInstalled() {
|
|
30
|
+
try {
|
|
31
|
+
require.resolve(`${targetPkg}/package.json`, { paths: [root] })
|
|
32
|
+
return true
|
|
33
|
+
} catch {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isInstalled()) process.exit(0)
|
|
39
|
+
|
|
40
|
+
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
|
|
41
|
+
const args = ["install", "--no-save", "--no-audit", "--no-fund", `${targetPkg}@${version}`]
|
|
42
|
+
|
|
43
|
+
// Install into bincode-dev's own node_modules so `require.resolve()` works reliably.
|
|
44
|
+
childProcess.spawnSync(npmCmd, args, { cwd: root, stdio: "inherit", env: process.env })
|
|
45
|
+
|
|
46
|
+
|
package/scripts/prepack.js
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* prepack cleanup to keep the published npm tarball small.
|
|
3
|
-
*
|
|
4
|
-
* Runs automatically on `npm pack` and `npm publish`.
|
|
5
|
-
*
|
|
6
|
-
* What it does:
|
|
7
|
-
* - Removes accidental nested package output at `dist/bincode-dev` (it includes a full copy of the web console).
|
|
8
|
-
* - Removes non-target platform binary variants (baseline/musl/extra arches).
|
|
9
|
-
* - Removes sourcemaps from `app/dist` to reduce file count/size.
|
|
10
|
-
*/
|
|
11
|
-
const fs = require("fs")
|
|
12
|
-
const path = require("path")
|
|
13
|
-
|
|
14
|
-
const root = path.join(__dirname, "..")
|
|
15
|
-
const appDistDir = path.join(root, "app", "dist")
|
|
16
|
-
|
|
17
|
-
function syncOptionalDependencyVersions() {
|
|
18
|
-
const pkgPath = path.join(root, "package.json")
|
|
19
|
-
let pkg
|
|
20
|
-
try {
|
|
21
|
-
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
22
|
-
} catch {
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const version = pkg.version
|
|
27
|
-
if (!version) return
|
|
28
|
-
|
|
29
|
-
const opt = pkg.optionalDependencies
|
|
30
|
-
if (!opt) return
|
|
31
|
-
|
|
32
|
-
// Keep these pinned exactly to the wrapper version to avoid mismatches.
|
|
33
|
-
const keys = [
|
|
34
|
-
"bincode-dev-darwin-arm64",
|
|
35
|
-
"bincode-dev-darwin-x64",
|
|
36
|
-
"bincode-dev-linux-x64",
|
|
37
|
-
"bincode-dev-windows-x64",
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
let changed = false
|
|
41
|
-
for (const k of keys) {
|
|
42
|
-
if (opt[k] !== version) {
|
|
43
|
-
opt[k] = version
|
|
44
|
-
changed = true
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (changed) {
|
|
49
|
-
pkg.optionalDependencies = opt
|
|
50
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n")
|
|
51
|
-
console.log(`[prepack] synced optionalDependencies versions to ${version}`)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function rmrf(targetPath) {
|
|
56
|
-
try {
|
|
57
|
-
fs.rmSync(targetPath, { recursive: true, force: true })
|
|
58
|
-
} catch {
|
|
59
|
-
// ignore
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function walkFiles(dir, visitor) {
|
|
64
|
-
let entries
|
|
65
|
-
try {
|
|
66
|
-
entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
67
|
-
} catch {
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (const e of entries) {
|
|
72
|
-
const p = path.join(dir, e.name)
|
|
73
|
-
if (e.isDirectory()) walkFiles(p, visitor)
|
|
74
|
-
else if (e.isFile()) visitor(p)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function removeSourcemaps() {
|
|
79
|
-
// app/dist/**/*.map
|
|
80
|
-
walkFiles(appDistDir, (p) => {
|
|
81
|
-
if (p.endsWith(".map")) rmrf(p)
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
syncOptionalDependencyVersions()
|
|
86
|
-
removeSourcemaps()
|
|
87
|
-
|
|
88
|
-
console.log("[prepack] removed sourcemaps")
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
/**
|
|
2
|
+
* prepack cleanup to keep the published npm tarball small.
|
|
3
|
+
*
|
|
4
|
+
* Runs automatically on `npm pack` and `npm publish`.
|
|
5
|
+
*
|
|
6
|
+
* What it does:
|
|
7
|
+
* - Removes accidental nested package output at `dist/bincode-dev` (it includes a full copy of the web console).
|
|
8
|
+
* - Removes non-target platform binary variants (baseline/musl/extra arches).
|
|
9
|
+
* - Removes sourcemaps from `app/dist` to reduce file count/size.
|
|
10
|
+
*/
|
|
11
|
+
const fs = require("fs")
|
|
12
|
+
const path = require("path")
|
|
13
|
+
|
|
14
|
+
const root = path.join(__dirname, "..")
|
|
15
|
+
const appDistDir = path.join(root, "app", "dist")
|
|
16
|
+
|
|
17
|
+
function syncOptionalDependencyVersions() {
|
|
18
|
+
const pkgPath = path.join(root, "package.json")
|
|
19
|
+
let pkg
|
|
20
|
+
try {
|
|
21
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
22
|
+
} catch {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const version = pkg.version
|
|
27
|
+
if (!version) return
|
|
28
|
+
|
|
29
|
+
const opt = pkg.optionalDependencies
|
|
30
|
+
if (!opt) return
|
|
31
|
+
|
|
32
|
+
// Keep these pinned exactly to the wrapper version to avoid mismatches.
|
|
33
|
+
const keys = [
|
|
34
|
+
"bincode-dev-darwin-arm64",
|
|
35
|
+
"bincode-dev-darwin-x64",
|
|
36
|
+
"bincode-dev-linux-x64",
|
|
37
|
+
"bincode-dev-windows-x64",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
let changed = false
|
|
41
|
+
for (const k of keys) {
|
|
42
|
+
if (opt[k] !== version) {
|
|
43
|
+
opt[k] = version
|
|
44
|
+
changed = true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (changed) {
|
|
49
|
+
pkg.optionalDependencies = opt
|
|
50
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n")
|
|
51
|
+
console.log(`[prepack] synced optionalDependencies versions to ${version}`)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function rmrf(targetPath) {
|
|
56
|
+
try {
|
|
57
|
+
fs.rmSync(targetPath, { recursive: true, force: true })
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function walkFiles(dir, visitor) {
|
|
64
|
+
let entries
|
|
65
|
+
try {
|
|
66
|
+
entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
67
|
+
} catch {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const e of entries) {
|
|
72
|
+
const p = path.join(dir, e.name)
|
|
73
|
+
if (e.isDirectory()) walkFiles(p, visitor)
|
|
74
|
+
else if (e.isFile()) visitor(p)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function removeSourcemaps() {
|
|
79
|
+
// app/dist/**/*.map
|
|
80
|
+
walkFiles(appDistDir, (p) => {
|
|
81
|
+
if (p.endsWith(".map")) rmrf(p)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
syncOptionalDependencyVersions()
|
|
86
|
+
removeSourcemaps()
|
|
87
|
+
|
|
88
|
+
console.log("[prepack] removed sourcemaps")
|
|
89
|
+
|
|
90
|
+
|
|
@@ -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
|
+
|