mirror of
https://github.com/contentful/skills.git
synced 2026-09-14 20:17:03 +08:00
304df8742d
skill-kit build overwrites package.json with a minimal {name, version},
losing the scoped name, description, license, and files fields. The
release pipeline now runs fix-skill-packagejson.mjs after build to
restore repo conventions and sync the version from root package.json.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
/**
|
|
* Post-build fix for skill-kit skills.
|
|
*
|
|
* skill-kit build overwrites package.json with a minimal {name, version}.
|
|
* This script restores the fields that the repo convention requires:
|
|
* scoped name, description, license, and files array.
|
|
*
|
|
* Run after `pnpm run build` in the release pipeline.
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, readdirSync, existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const rootPkg = JSON.parse(readFileSync('package.json', 'utf-8'));
|
|
const repoVersion = rootPkg.version;
|
|
|
|
const skillsDir = 'skills';
|
|
const dirs = readdirSync(skillsDir, { withFileTypes: true })
|
|
.filter((d) => d.isDirectory())
|
|
.map((d) => d.name);
|
|
|
|
for (const dir of dirs) {
|
|
const pkgPath = join(skillsDir, dir, 'package.json');
|
|
if (!existsSync(pkgPath)) continue;
|
|
|
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
const isSkillKit = existsSync(join(skillsDir, dir, 'bin'));
|
|
|
|
pkg.version = repoVersion;
|
|
|
|
if (!pkg.name.startsWith('@contentful/skill-')) {
|
|
pkg.name = `@contentful/skill-${dir}`;
|
|
}
|
|
|
|
if (!pkg.license) pkg.license = 'MIT';
|
|
|
|
if (isSkillKit && !pkg.files) {
|
|
pkg.files = ['SKILL.md', 'scripts/**', 'bin/**', 'references/**'];
|
|
} else if (!pkg.files) {
|
|
pkg.files = ['SKILL.md', 'references/**'];
|
|
}
|
|
|
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
}
|
|
|
|
console.log(`Fixed ${dirs.length} skill package.json files (version ${repoVersion})`);
|