mirror of
https://github.com/jnMetaCode/superpowers-zh.git
synced 2026-09-03 07:23:56 +08:00
之前 .claude-plugin/plugin.json 和 .cursor-plugin/plugin.json 的 version 字段一直停在 1.1.8,落后于 npm 1.1.9 / 1.2.0 / 1.2.1——每次发版都要手改。 - 新增 scripts/sync-plugin-version.js:用正则替换 version 字段一行, 保留两个 manifest 的原排版(数组单行/多行、缩进等),无 diff 噪音 - 在 package.json 挂 npm version 钩子:bump 后自动同步并 git add 到 version commit 里,从此不会再漏 - 把当前两个 manifest 从 1.1.8 一次性修到 1.2.1
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// 把 package.json 的 version 同步到 plugin manifest
|
|
// 由 npm version 钩子触发,跑在 version commit 创建之前
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
import { resolve, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
|
|
const targets = [
|
|
'.claude-plugin/plugin.json',
|
|
'.cursor-plugin/plugin.json',
|
|
];
|
|
|
|
let touched = 0;
|
|
for (const rel of targets) {
|
|
const path = resolve(root, rel);
|
|
const text = readFileSync(path, 'utf8');
|
|
const json = JSON.parse(text);
|
|
if (json.version === pkg.version) continue;
|
|
// 只替换顶层 version 字段一行,保留原文件其他字段的格式(数组单行/多行、缩进等)
|
|
const updated = text.replace(/("version":\s*")[^"]+(")/, `$1${pkg.version}$2`);
|
|
if (updated === text) {
|
|
throw new Error(`未能在 ${rel} 中定位 version 字段`);
|
|
}
|
|
writeFileSync(path, updated, 'utf8');
|
|
console.log(` ${rel}: ${json.version} -> ${pkg.version}`);
|
|
touched++;
|
|
}
|
|
if (touched === 0) console.log(` plugin manifests already at ${pkg.version}`);
|