Files
dsh-markmag/scripts/install.mjs
T
发条 ff8017bbbb 初始版本 0.1.0:四道菜团队中台 DSH 插件
模型通道:接管官方 API Key 通道指向弹匣网关(GLM-5.3 / GLM-5.3-Flash)
登录:浏览器取一次性接入码 → 换成员专属 key → 写入 DSH 凭据
工具面:MCP 暴露查汇总/查任务/查项目/建任务/完成/改期/whoami
面板:侧边栏入口,个人看板 + 角色可见范围 + 行内操作
离职吊销:成员停用即吊销名下全部 TDB key

发布配置:scope 包名、私有 registry 锁定、prepack 自动构建、prepublishOnly 检查
2026-11-07 19:19:20 +08:00

92 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 把 @sidaocai/dsh-markmag 装进桌面版 DSH 的 profile。
*
* 为什么手工做:桌面版 profile 由 Electron 拥有,npm 的 dsh CLI 管不了它,
* 所以直接按它认的结构摆文件 —— 包进 node_modules + 名字进 bundles。
*
* 幂等:跑几次结果一样。改任何文件前先备份。会顺手清掉旧包名(dsh-markmag)的残留。
*/
import fs from "node:fs"
import { homedir } from "node:os"
import { join, dirname } from "node:path"
import { fileURLToPath } from "node:url"
const HOME = homedir()
const PLUGIN = "@sidaocai/dsh-markmag"
const LEGACY = "dsh-markmag"
const PROFILE = join(HOME, ".dsh/profiles/desktop")
const PKG = join(PROFILE, "package.json")
const PATCH = join(PROFILE, "cordis.patch.yml")
const DEST = join(PROFILE, "node_modules", PLUGIN)
const STAMP = "20261107-plugin"
const SRC = join(dirname(fileURLToPath(import.meta.url)), "..")
const log = (k, v) => console.log(k.padEnd(16), v)
const die = (m) => { console.error("✗ " + m); process.exit(1) }
if (!fs.existsSync(PKG)) die("没找到桌面版 profile:" + PKG)
// 1. 备份
for (const f of [PKG, PATCH]) {
if (!fs.existsSync(f)) continue
const bak = f + ".bak-" + STAMP
if (!fs.existsSync(bak)) fs.copyFileSync(f, bak)
}
log("backup:", fs.existsSync(PKG + ".bak-" + STAMP) ? "ok" : "FAIL")
// 2. 清旧包名残留
const legacyDir = join(PROFILE, "node_modules", LEGACY)
if (fs.existsSync(legacyDir)) {
fs.rmSync(legacyDir, { recursive: true, force: true })
log("legacy:", "已移除 node_modules/" + LEGACY)
}
// 3. 摆包
fs.rmSync(DEST, { recursive: true, force: true })
fs.mkdirSync(DEST, { recursive: true })
for (const item of ["package.json", "cordis.patch.yml", "src", "dist", "README.md", "LICENSE", "CHANGELOG.md"]) {
const from = join(SRC, item)
if (fs.existsSync(from)) fs.cpSync(from, join(DEST, item), { recursive: true })
}
log("plugin:", fs.existsSync(join(DEST, "src/host.js")) ? "installed" : "FAIL")
// 4. 登记进 profile
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"))
pkg.dsh ??= {}
pkg.dsh.profile ??= {}
pkg.dsh.profile.bundles = (pkg.dsh.profile.bundles || []).filter((b) => b !== LEGACY)
if (!pkg.dsh.profile.bundles.includes(PLUGIN)) pkg.dsh.profile.bundles.push(PLUGIN)
pkg.dependencies ??= {}
delete pkg.dependencies[LEGACY]
pkg.dependencies[PLUGIN] = "file:" + SRC
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2) + "\n")
log("bundles:", PLUGIN)
// 5. 摘掉历史手工段
let patch = fs.existsSync(PATCH) ? fs.readFileSync(PATCH, "utf8") : ""
const MARK = "# 四道菜团队模型通道"
const at = patch.indexOf(MARK)
if (at >= 0) {
patch = patch.slice(0, at).trimEnd() + "\n"
fs.writeFileSync(PATCH, patch)
log("manual block:", "removed")
} else log("manual block:", "none")
// 6. 自检
const bundlePatch = fs.readFileSync(join(DEST, "cordis.patch.yml"), "utf8")
const checks = {
bundleListed: JSON.parse(fs.readFileSync(PKG, "utf8")).dsh.profile.bundles.includes(PLUGIN),
hostExists: fs.existsSync(join(DEST, "src/host.js")),
clientExists: fs.existsSync(join(DEST, "dist/client.js")),
patchHasGateway: bundlePatch.includes("brain.sidaocai.cn/tdb-api/claude-code/default"),
patchHasGlm: bundlePatch.includes("glm-5.3-flash"),
hostInserted: bundlePatch.includes("@sidaocai/dsh-markmag"),
noLegacy: !fs.readdirSync(join(PROFILE, "node_modules")).includes(LEGACY),
}
log("SELF_CHECK", JSON.stringify(checks))
if (!Object.values(checks).every(Boolean)) {
console.log("\n✗ 自检没过,用备份回滚:" + PKG + ".bak-" + STAMP)
process.exit(1)
}
console.log("\n重启桌面版 DSH 生效。")