#!/usr/bin/env node // Adapted from ego lite (MIT): plugins/scripts/sync-skills.mjs import { execFileSync } from 'node:child_process'; import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = fileURLToPath(new URL('..', import.meta.url)); const canonical = '.claude/skills/browserclaw/SKILL.md'; const copies = ['.agents/skills/browserclaw/SKILL.md', 'plugins/browserclaw/skills/browserclaw/SKILL.md']; const versioned = [ ['plugins/browserclaw/plugin.json', (json) => json], ['plugins/browserclaw/.claude-plugin/plugin.json', (json) => json], ['.claude-plugin/marketplace.json', (json) => json.plugins[0]], ['.cursor-plugin/marketplace.json', (json) => json.plugins[0]], ]; const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')); for (const copy of copies) { mkdirSync(dirname(join(root, copy)), { recursive: true }); copyFileSync(join(root, canonical), join(root, copy)); console.log(`Synced ${canonical} -> ${copy}`); } for (const [file, owner] of versioned) { const path = join(root, file); const text = readFileSync(path, 'utf8'); const fields = text.match(/"version": "[^"]*"/g) ?? []; if (fields.length !== 1 || typeof owner(JSON.parse(text)).version !== 'string') throw new Error(`${file} must have exactly one "version" field, at the expected path`); writeFileSync(path, text.replace(/"version": "[^"]*"/, `"version": "${version}"`)); console.log(`Set ${file} version to ${version}`); } if ( process.argv.includes('--stage') && !['', 'false'].includes(process.env.npm_config_git_tag_version ?? 'true') && existsSync(join(root, '.git')) ) { execFileSync('git', ['add', '--', ...copies, ...versioned.map(([file]) => file)], { cwd: root, stdio: 'inherit' }); }