| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env node
- // Copyright (c) 未来飞马
- //
- // This Source Code Form is subject to the terms of the Mozilla Public
- // License, v. 2.0. If a copy of the MPL was not distributed with this
- // file, You can obtain one at https://mozilla.org/MPL/2.0/.
- // skill-heterarchy 安装器 — 把技能文件铺到目标技能目录。
- //
- // 用法:
- // node bin/install.js [目标目录]
- // 默认目标:$SKILLS_DIR || /opt/data/skills/skill-heterarchy
- import { cp, mkdir, rm } from 'node:fs/promises';
- import { existsSync } from 'node:fs';
- import { dirname, resolve, join } from 'node:path';
- import { fileURLToPath } from 'node:url';
- import { VERSION, SKILL_NAME } from '../lib/index.mjs';
- const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
- const dest = resolve(process.argv[2] || process.env.SKILLS_DIR || `/opt/data/skills/${SKILL_NAME}`);
- // 需要安装的条目(与 package.json files 对齐;LESSONS.md 保留现场,不覆盖)
- const ENTRIES = ['SKILL.md', 'README.md', 'LICENSE', 'CHANGELOG.md', 'package.json', 'skill-package-manifest.json', 'lib', 'bin', 'scripts'];
- if (!existsSync(join(pkgRoot, 'SKILL.md'))) {
- console.error(`✗ 找不到源文件:${join(pkgRoot, 'SKILL.md')}`);
- process.exit(1);
- }
- await mkdir(dest, { recursive: true });
- for (const entry of ENTRIES) {
- const src = join(pkgRoot, entry);
- if (!existsSync(src)) continue;
- const dst = join(dest, entry);
- await rm(dst, { recursive: true, force: true }); // 覆盖旧版本,避免残留
- await cp(src, dst, { recursive: true });
- }
- // LESSONS.md 若已存在则保留(教训是现场记录,重新安装不应清空)
- let kept = '';
- try {
- const src = join(pkgRoot, 'LESSONS.md');
- const dst = join(dest, 'LESSONS.md');
- if (existsSync(dst)) kept = '(LESSONS.md 已保留,未覆盖)';
- else if (existsSync(src)) await cp(src, dst);
- } catch { /* 非致命 */ }
- console.log(`${SKILL_NAME} v${VERSION} 已安装 → ${dest}${kept}`);
|