Skip to content

Commit 90df2ff

Browse files
committed
feat(openclaw): package skill in build
1 parent f76bcca commit 90df2ff

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

scripts/copy-docs.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { copyFile } from 'fs/promises'
1+
import { copyFile, cp } from 'fs/promises'
22
import path from 'path'
33
import { existsSync } from 'fs'
44

@@ -14,6 +14,16 @@ async function copyDocs() {
1414
} else {
1515
console.warn(`⚠ README.md not found at ${readmeSrc} - skipping copy`)
1616
}
17+
18+
// Copy openclaw-skill/ to dist
19+
const openclawSrc = path.join(process.cwd(), 'openclaw-skill')
20+
const openclawDest = path.join(distDir, 'openclaw-skill')
21+
if (existsSync(openclawSrc)) {
22+
await cp(openclawSrc, openclawDest, { recursive: true })
23+
console.log(`✓ openclaw-skill/ copied to ${openclawDest}`)
24+
} else {
25+
console.warn(`⚠ openclaw-skill/ not found at ${openclawSrc} - skipping copy`)
26+
}
1727
}
1828

1929
copyDocs().catch(console.error)

src/commands/openclaw.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path'
22
import os from 'os'
3+
import { fileURLToPath } from 'url'
34
import fs from 'fs-extra'
45
import { getLogger } from '../utils/logger-context.js'
56
import { TelemetryService } from '../lib/TelemetryService.js'
@@ -27,11 +28,9 @@ export class OpenclawCommand {
2728
const workspace = options.workspace ?? 'workspace'
2829
const force = options.force ?? false
2930

30-
// 1. Resolve and verify openclaw-skill/ exists in the project
31-
const skillSourceDir = path.join(this.projectRoot, 'openclaw-skill')
32-
if (!(await fs.pathExists(skillSourceDir))) {
33-
throw new Error(`openclaw-skill/ directory not found in ${this.projectRoot}`)
34-
}
31+
// 1. Resolve and verify openclaw-skill/ exists
32+
const skillSourceDir = await this.resolveSkillDir()
33+
logger.debug(`Resolved openclaw-skill directory: ${skillSourceDir}`)
3534

3635
// 2. Check ~/.openclaw exists
3736
const openclawHome = path.join(os.homedir(), '.openclaw')
@@ -77,6 +76,37 @@ export class OpenclawCommand {
7776
}
7877
}
7978

79+
/**
80+
* Resolve the openclaw-skill directory.
81+
* 1. Check relative to the package install location (dist/openclaw-skill/ for npm installs)
82+
* 2. Fall back to projectRoot/openclaw-skill/ (for local dev / repo clones)
83+
* 3. Throw if neither exists
84+
*/
85+
private async resolveSkillDir(): Promise<string> {
86+
// 1. Relative to the installed package (works for npm installs)
87+
const __filename = fileURLToPath(import.meta.url)
88+
const __dirname = path.dirname(__filename)
89+
// In dist: dist/commands/openclaw.js -> walk up to dist/, then openclaw-skill/
90+
let packageDir = __dirname
91+
while (packageDir !== path.dirname(packageDir)) {
92+
const candidate = path.join(packageDir, 'openclaw-skill')
93+
if (await fs.pathExists(candidate)) {
94+
return candidate
95+
}
96+
packageDir = path.dirname(packageDir)
97+
}
98+
99+
// 2. Relative to projectRoot (for local dev / repo clones)
100+
const devCandidate = path.join(this.projectRoot, 'openclaw-skill')
101+
if (await fs.pathExists(devCandidate)) {
102+
return devCandidate
103+
}
104+
105+
throw new Error(
106+
`openclaw-skill/ directory not found. Searched from package location (${__dirname}) and project root (${this.projectRoot}).`
107+
)
108+
}
109+
80110
/**
81111
* Handle an existing file/symlink at the target path.
82112
* Returns true if already correctly linked (no action needed).

0 commit comments

Comments
 (0)