Skip to content

Commit d3d11ef

Browse files
committed
chore: migrate from esbuild to Bun
- Replace esbuild with Bun as the build tool - Add bunfig.toml for Bun configuration - Update build process with new build.mjs script - Modernize GitHub Actions workflow for releases - Simplify release asset management - Remove package-lock.json in favor of bun.lock - Update documentation and contribution guides - Add local workflow testing instructions
1 parent 64143ad commit d3d11ef

File tree

10 files changed

+391
-2285
lines changed

10 files changed

+391
-2285
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,22 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
11-
- uses: actions/setup-node@v4
11+
- uses: oven-sh/setup-bun@v1
1212
with:
13-
node-version: "22"
13+
bun-version: latest
1414

1515
- run: |
16-
npm install
17-
npm run build
16+
bun install
17+
bun run build
1818
19-
- name: Package
20-
run: |
21-
mkdir dist
22-
cp main.js manifest.json README.md dist/
23-
zip -r release.zip dist/
24-
25-
- uses: actions/create-release@v1
26-
id: create_release
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
- name: Create Release and Upload Assets
20+
uses: softprops/action-gh-release@v1
2921
with:
30-
tag_name: ${{ github.ref }}
31-
release_name: ${{ github.ref }}
32-
33-
- uses: actions/upload-release-asset@v1
22+
name: ${{ github.ref }}
23+
files: |
24+
main.js
25+
manifest.json
26+
styles.css
27+
fail_on_unmatched_files: true
3428
env:
3529
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
with:
37-
upload_url: ${{ steps.create_release.outputs.upload_url }}
38-
asset_path: ./release.zip
39-
asset_name: release-${{ github.ref_name }}.zip
40-
asset_content_type: application/zip
41-
42-
- uses: actions/upload-release-asset@v1
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45-
with:
46-
upload_url: ${{ steps.create_release.outputs.upload_url }}
47-
asset_path: ./main.js
48-
asset_name: main.js
49-
asset_content_type: text/javascript
50-
51-
- uses: actions/upload-release-asset@v1
52-
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
with:
55-
upload_url: ${{ steps.create_release.outputs.upload_url }}
56-
asset_path: ./manifest.json
57-
asset_name: manifest.json
58-
asset_content_type: application/json

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Build artifacts
2-
main.js
2+
**/*.js
33
main.js.map
44

55
# Dependencies
66
node_modules/
77

8+
# Bun
9+
.bun/
10+
# bun.lock - We want to track the lock file
11+
812
# Test vault - plugins
913
test-vault/.obsidian/plugins/*
1014
!test-vault/.obsidian/plugins/journals/.hotreload

CONTRIBUTING.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@
99

1010
## Development
1111

12+
This project uses Bun as the build tool:
13+
1214
1. Clone this repository `gh repo clone philoserf/obsidian-vault-changelog`.
13-
2. Install dependencies with `npm install`.
14-
3. Build the project with `npm run build`.
15+
2. Install Bun: [https://bun.sh/docs/installation](https://bun.sh/docs/installation)
16+
3. Install dependencies: `bun install`
17+
4. Format: `bun run format`
18+
5. Lint: `bun run lint`
19+
6. Development build with auto-refresh: `bun run dev`
20+
7. Production build: `bun run build`
1521

1622
### Using the test-vault
1723

1824
The project includes a test-vault for development:
1925

2026
1. Open the test-vault in Obsidian (`File > Open another vault > Open folder as vault` and select the `test-vault` directory)
21-
2. Build the plugin with hot-reload: `npm run dev`
27+
2. Build the plugin with hot-reload: `bun run dev`
2228
3. Changes will automatically be applied to the plugin in the test-vault
2329

2430
### Manual installation
@@ -27,3 +33,14 @@ Alternatively, you can manually install the plugin in your own vault:
2733

2834
1. Copy `manifest.json` and `main.js` into your **Obsidian plugins folder** (`.obsidian/plugins/obsidian-vault-changelog`).
2935
2. Reload Obsidian and enable the plugin.
36+
37+
## Test release
38+
39+
```shell
40+
act \
41+
--container-architecture linux/amd64 \
42+
-W .github/workflows/release.yml \
43+
-P ubuntu-latest=catthehacker/ubuntu:act-latest \
44+
--pull=false \
45+
-e <(echo '{"ref": "refs/tags/v1.0.0", "ref_name": "v1.0.0"}')
46+
```

build.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { join } from "path";
2+
import { build, file, write } from "bun";
3+
import { mkdir } from "node:fs/promises";
4+
5+
const production = process.argv[2] === "production";
6+
7+
// Setup output paths
8+
const outDir = production
9+
? "."
10+
: "test-vault/.obsidian/plugins/obsidian-vault-changelog";
11+
12+
// Ensure the directory exists
13+
await mkdir(outDir, { recursive: true });
14+
15+
// Copy manifest.json and styles.css to output directory in dev mode
16+
if (!production) {
17+
await write(
18+
join(outDir, "manifest.json"),
19+
await file("manifest.json").text(),
20+
);
21+
await write(join(outDir, "styles.css"), await file("styles.css").text());
22+
}
23+
24+
const buildOptions = {
25+
entrypoints: ["./src/main.ts"],
26+
outdir: outDir,
27+
outfile: join(outDir, "main.js"),
28+
format: "cjs",
29+
external: ["obsidian"],
30+
target: "browser",
31+
minify: production,
32+
sourcemap: production ? "none" : "external",
33+
};
34+
35+
async function runBuild() {
36+
const result = await build(buildOptions);
37+
38+
if (!result.success) {
39+
console.error("Build failed:", result.logs);
40+
process.exit(1);
41+
}
42+
43+
if (production) {
44+
console.log("Production build completed");
45+
process.exit(0);
46+
} else {
47+
console.log("Development build completed. Watching for changes...");
48+
49+
// Use Node's fs.watch for file changes
50+
const { watch } = await import("node:fs");
51+
watch("./src", { recursive: true }, async (eventType, filename) => {
52+
console.log(`File ${filename} changed, rebuilding...`);
53+
await build(buildOptions);
54+
});
55+
}
56+
}
57+
58+
runBuild();

0 commit comments

Comments
 (0)