mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
feat(sdk): prepare v2 packages for publishing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
/* TODO: Migrate this script to the new in-process @opencode-ai/sdk.
|
||||
import path from "path"
|
||||
import { pathToFileURL } from "bun"
|
||||
import { createOpencode } from "@opencode-ai/sdk"
|
||||
@@ -77,3 +78,4 @@ Examples:
|
||||
}
|
||||
|
||||
void main()
|
||||
*/
|
||||
|
||||
@@ -50,6 +50,9 @@ await $`bun ./packages/ai/script/publish.ts`
|
||||
console.log("\n=== util ===\n")
|
||||
await $`bun ./packages/util/script/publish.ts`
|
||||
|
||||
console.log("\n=== shell scan ===\n")
|
||||
await $`bun ./packages/shell-scan/script/publish.ts`
|
||||
|
||||
console.log("\n=== protocol ===\n")
|
||||
await $`bun ./packages/protocol/script/publish.ts`
|
||||
|
||||
@@ -65,6 +68,15 @@ await $`bun ./packages/plugin/script/publish.ts`
|
||||
console.log("\n=== core ===\n")
|
||||
await $`bun ./packages/core/script/publish.ts`
|
||||
|
||||
console.log("\n=== simulation ===\n")
|
||||
await $`bun ./packages/simulation/script/publish.ts`
|
||||
|
||||
console.log("\n=== server ===\n")
|
||||
await $`bun ./packages/server/script/publish.ts`
|
||||
|
||||
console.log("\n=== sdk ===\n")
|
||||
await $`bun ./packages/sdk/script/publish.ts`
|
||||
|
||||
console.log("\n=== ui ===\n")
|
||||
await $`bun ./packages/ui/script/publish.ts`
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
|
||||
const packages = ["@opencode-ai/simulation", "@opencode-ai/server"]
|
||||
const publish = Bun.argv.includes("--publish")
|
||||
|
||||
if (!publish) {
|
||||
console.log("Package names to reserve:")
|
||||
for (const name of packages) console.log(`- ${name}`)
|
||||
console.log("\nRun `bun run reserve-packages --publish` to log in and publish reservation placeholders.")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (run(["npm", "whoami"]) !== 0) {
|
||||
if (run(["npm", "login"]) !== 0) throw new Error("npm login failed")
|
||||
if (run(["npm", "whoami"]) !== 0) throw new Error("npm authentication failed")
|
||||
}
|
||||
|
||||
const directory = await mkdtemp(path.join(tmpdir(), "opencode-package-reservations-"))
|
||||
try {
|
||||
for (const name of packages) {
|
||||
const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}`)
|
||||
if (response.ok) {
|
||||
console.log(`Skipping ${name}: already exists on npm`)
|
||||
continue
|
||||
}
|
||||
if (response.status !== 404) throw new Error(`Failed to check ${name}: npm returned ${response.status}`)
|
||||
|
||||
const target = path.join(directory, name.slice("@opencode-ai/".length))
|
||||
await mkdir(target, { recursive: true })
|
||||
await Bun.write(
|
||||
path.join(target, "package.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name,
|
||||
version: "0.0.0-reserved",
|
||||
description: "Reserved for OpenCode",
|
||||
license: "MIT",
|
||||
repository: {
|
||||
type: "git",
|
||||
url: "git+https://github.com/anomalyco/opencode.git",
|
||||
},
|
||||
publishConfig: {
|
||||
access: "public",
|
||||
tag: "reserved",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
)
|
||||
await Bun.write(path.join(target, "README.md"), `# ${name}\n\nReserved for OpenCode.\n`)
|
||||
|
||||
console.log(`Reserving ${name}`)
|
||||
if (run(["npm", "publish", "--access", "public", "--tag", "reserved"], target) !== 0) {
|
||||
throw new Error(`Failed to reserve ${name}`)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
function run(command: string[], cwd?: string) {
|
||||
return Bun.spawnSync(command, {
|
||||
cwd,
|
||||
stdin: "inherit",
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
}).exitCode
|
||||
}
|
||||
Reference in New Issue
Block a user