Skip to content

Commit ee66c24

Browse files
committed
refactor: merge manifest.json into plugin.json
- Remove standalone metadata file generation from build.ts - Update release.yml template: write download_url directly into plugin.json instead of pushing a separate manifest.json to main branch - Add download_url field to scaffold template plugin.json
1 parent 22fc6d2 commit ee66c24

3 files changed

Lines changed: 13 additions & 35 deletions

File tree

packages/create-songloft-plugin/templates/base/.github/workflows/release.yml

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,19 @@ jobs:
8585
- name: Commit version bump on current branch
8686
run: |
8787
VERSION="${{ steps.version.outputs.version }}"
88+
DOWNLOAD_URL="${{ steps.create_release.outputs.download_url }}"
89+
node -e "
90+
const fs = require('fs');
91+
const p = JSON.parse(fs.readFileSync('plugin.json', 'utf-8'));
92+
p.version = '${VERSION}';
93+
p.download_url = '${DOWNLOAD_URL}';
94+
fs.writeFileSync('plugin.json', JSON.stringify(p, null, 2) + '\n');
95+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
96+
pkg.version = '${VERSION}';
97+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
98+
"
8899
git config user.name "github-actions[bot]"
89100
git config user.email "github-actions[bot]@users.noreply.github.com"
90101
git add plugin.json package.json
91102
git diff --staged --quiet || git commit -m "chore(release): bump to v${VERSION}"
92103
git push
93-
94-
- name: Push manifest.json to main branch (updateUrl target)
95-
env:
96-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97-
run: |
98-
VERSION="${{ steps.version.outputs.version }}"
99-
DOWNLOAD_URL="${{ steps.create_release.outputs.download_url }}"
100-
101-
# plugin.json 的 updateUrl 指向 main 分支的 manifest.json,
102-
# 所以无论 workflow 从哪个 branch 跑,manifest.json 必须落到 main。
103-
CONTENT=$(jq -nc --arg v "$VERSION" --arg u "$DOWNLOAD_URL" \
104-
'{version: $v, download_url: $u}')
105-
ENCODED=$(printf '%s' "$CONTENT" | base64 -w 0)
106-
107-
EXISTING_SHA=$(gh api "repos/${GITHUB_REPOSITORY}/contents/manifest.json?ref=main" --jq '.sha' 2>/dev/null || echo "")
108-
109-
if [ -n "$EXISTING_SHA" ]; then
110-
jq -cn --arg msg "chore(release): manifest v${VERSION}" \
111-
--arg content "$ENCODED" --arg sha "$EXISTING_SHA" \
112-
'{message: $msg, content: $content, sha: $sha, branch: "main"}' | \
113-
gh api "repos/${GITHUB_REPOSITORY}/contents/manifest.json" --method PUT --input -
114-
else
115-
jq -cn --arg msg "chore(release): manifest v${VERSION}" \
116-
--arg content "$ENCODED" \
117-
'{message: $msg, content: $content, branch: "main"}' | \
118-
gh api "repos/${GITHUB_REPOSITORY}/contents/manifest.json" --method PUT --input -
119-
fi

packages/create-songloft-plugin/templates/base/plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"minHostVersion": "1.3.0",
1212
"permissions": {{permissions}},
1313
"updateUrl": "",
14+
"download_url": "",
1415
"entryHash": "",
1516
"zipHash": ""
1617
}

packages/plugin-builder/src/build.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,7 @@ export async function buildPlugin(opts: BuildOptions): Promise<BuildResult> {
196196
const zipPath = join(outDir, `${manifest.entryPath}.jsplugin.zip`);
197197
writeFileSync(zipPath, zipBuffer);
198198

199-
// [8] 生成远程元数据文件
200-
const metaPath = join(outDir, `${manifest.entryPath}.json`);
201-
writeFileSync(metaPath, JSON.stringify({
202-
version: manifest.version,
203-
download_url: `https://github.com/songloft-org/plugins/releases/download/jsplugin-${manifest.entryPath}-${manifest.version}/${manifest.entryPath}.jsplugin.zip`,
204-
}, null, 2));
205-
206-
// [9] 输出报告
199+
// [8] 输出报告
207200
const mainJsGzip = Buffer.byteLength(mainJsContent);
208201
console.log(`\n✅ Build successful!`);
209202
console.log(` 📦 ${zipPath} (${(zipBuffer.length / 1024).toFixed(1)} KB)`);

0 commit comments

Comments
 (0)