Smail/deploy/bundle-plugins.mjs
smail d7837de561
Some checks are pending
Security Checks / security (push) Waiting to run
保存模拟部署迁移与最新构建校验阶段成果
2026-09-08 18:33:21 +08:00

24 lines
1.0 KiB
JavaScript

import { cp, lstat, mkdir, readdir, rename } from 'node:fs/promises'
import path from 'node:path'
import { buildPlan, root } from './build-plugins.mjs'
const plan = buildPlan({ target: process.argv[2] })
const destination = path.join(root, 'backend/cmd/smail/bundled')
for (const item of plan) {
const info = await lstat(item.output)
if (!info.isFile() || info.isSymbolicLink()) throw new Error('待嵌入插件不是普通文件')
}
try {
await readdir(destination)
const history = path.join(root, 'out/build-history', `plugins-${Date.now()}`)
await mkdir(path.dirname(history), { recursive: true })
const info = await lstat(destination)
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('嵌入目录无效')
await rename(destination, history)
} catch (error) {
if (error.code !== 'ENOENT') throw error
}
await mkdir(destination, { recursive: true })
for (const item of plan) await cp(item.output, path.join(destination, path.basename(item.output)), { force: false })
console.log('三个插件已准备嵌入主程序。')