Skip to content

Commit

Permalink
feat: add zip script for packaging plugin releases
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksteamdev committed Dec 30, 2024
1 parent f222a91 commit cd7b81e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ jobs:

- name: Run Release Script
run: bun run release

- name: Zip Release Artifacts
run: bun run zip

- name: Upload Release Artifacts
uses: ncipollo/release-action@v1
with:
allowUpdates: true
omitBody: true
omitName: true
artifacts: "packages/obsidian-plugin/main.js,packages/obsidian-plugin/manifest.json,packages/obsidian-plugin/styles.css,packages/mcp-server/dist/*"
artifacts: "packages/obsidian-plugin/releases/obsidian-plugin-*.zip,packages/obsidian-plugin/main.js,packages/obsidian-plugin/manifest.json,packages/obsidian-plugin/styles.css,packages/mcp-server/dist/*"
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages/*"
],
"scripts": {
"release": "bun --filter '*' release"
"release": "bun --filter '*' release",
"zip": "bun --filter '*' zip"
},
"devDependencies": {
"npm-run-all": "^4.1.5"
Expand Down
1 change: 1 addition & 0 deletions packages/obsidian-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_modules
# They should be uploaded to GitHub releases instead.
main.js
bin
releases/

# Exclude sourcemaps
*.map
Expand Down
6 changes: 5 additions & 1 deletion packages/obsidian-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
"dev": "bun --watch run bun.config.ts --watch",
"link": "bun scripts/link.ts",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"release": "run-s build"
"release": "run-s build zip",
"zip": "bun scripts/zip.ts"
},
"dependencies": {
"@types/fs-extra": "^11.0.4",
"arktype": "^2.0.0-rc.30",
"express": "^4.21.2",
"fs-extra": "^11.2.0",
"obsidian-local-rest-api": "^2.5.4",
"radash": "^12.1.0",
"rxjs": "^7.8.1",
Expand All @@ -32,6 +35,7 @@
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"archiver": "^7.0.1",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "^5.7.2"
Expand Down
28 changes: 28 additions & 0 deletions packages/obsidian-plugin/scripts/zip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { create } from "archiver";
import { createWriteStream } from "fs";
import fs from "fs-extra";
import { join, resolve } from "path";
import { version } from "../package.json" with { type: "json" };

async function zipPlugin() {
const pluginDir = resolve(import.meta.dir, "..");

const releaseDir = join(pluginDir, "releases");
fs.ensureDirSync(releaseDir);

const zipFilePath = join(releaseDir, `obsidian-plugin-${version}.zip`);
const output = createWriteStream(zipFilePath);

const archive = create("zip", { zlib: { level: 9 } });
archive.pipe(output);

// Add the required files
archive.file(join(pluginDir, "main.js"), { name: "main.js" });
archive.file(join(pluginDir, "manifest.json"), { name: "manifest.json" });
archive.file(join(pluginDir, "styles.css"), { name: "styles.css" });

await archive.finalize();
console.log("Plugin files zipped successfully!");
}

zipPlugin().catch(console.error);

0 comments on commit cd7b81e

Please sign in to comment.