mirror of
https://github.com/openclaw/clawhub.git
synced 2026-08-14 08:52:21 +00:00
* refactor: rename internal clawdhub package path * fix: update workflow paths after clawhub dir rename * fix: preserve old tag npm release compatibility --------- Co-authored-by: Onur <onur@solmaz.io>
50 lines
1.4 KiB
TypeScript
Executable File
50 lines
1.4 KiB
TypeScript
Executable File
#!/usr/bin/env bun
|
|
import { existsSync } from 'node:fs'
|
|
import { stat } from 'node:fs/promises'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const packageRootPath = fileURLToPath(new URL('./packages/clawhub/', import.meta.url))
|
|
const distCliUrl = new URL('./packages/clawhub/dist/cli.js', import.meta.url)
|
|
const distCliPath = fileURLToPath(distCliUrl)
|
|
const srcRootPath = fileURLToPath(new URL('./packages/clawhub/src/', import.meta.url))
|
|
|
|
const shouldBuild = await (async () => {
|
|
if (!existsSync(distCliPath)) return true
|
|
try {
|
|
const dist = await stat(distCliPath)
|
|
const latestSrcMtime = await getLatestMtime(srcRootPath)
|
|
return latestSrcMtime > dist.mtimeMs
|
|
} catch {
|
|
return true
|
|
}
|
|
})()
|
|
|
|
if (shouldBuild) {
|
|
const proc = Bun.spawn(['bun', 'run', 'build'], {
|
|
cwd: packageRootPath,
|
|
stdin: 'inherit',
|
|
stdout: 'inherit',
|
|
stderr: 'inherit',
|
|
})
|
|
const code = await proc.exited
|
|
if (code !== 0) process.exit(code)
|
|
}
|
|
|
|
await import(distCliUrl.href)
|
|
|
|
async function getLatestMtime(root: string) {
|
|
let latest = 0
|
|
const glob = new Bun.Glob('**/*.ts')
|
|
for await (const rel of glob.scan({ cwd: root, onlyFiles: true })) {
|
|
if (rel.endsWith('.test.ts')) continue
|
|
const path = `${root}${root.endsWith('/') ? '' : '/'}${rel}`
|
|
try {
|
|
const entry = await stat(path)
|
|
latest = Math.max(latest, entry.mtimeMs)
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|
|
return latest
|
|
}
|