#obsidian ![](https://www.youtube.com/embed/kQCc7HYOfpY?si=3_LcTmYjFWafYe8l) ## From My Template - ✅ husky - ✅ bun - ✅ bun workflow - ✅ extended obsidian typescript api 1. git clone [HananoshikaYomaru/obsidian-sample-plugin (github.com)](https://github.com/HananoshikaYomaru/obsidian-sample-plugin) to your github repo and in your `/plugins` directory 3. run `bun install` 4. change the name of the folder 5. change the manifest 6. change the `package.json` 7. change the readme 8. remove comments and change your plugin name in the code 9. update your plugin logic 10. continue on [[#Test it Locally]] ## From Scratch (obsidian Official Plugin template) ### Clone the Sample Plugin [obsidianmd/obsidian-sample-plugin (github.com)](https://github.com/obsidianmd/obsidian-sample-plugin) 1. change the name of the folder 2. change the manifest 3. change the `package.json` 4. change the readme 5. remove comments and change your plugin name in the code ### Change to Bun follow this: [Install TypeScript declarations for Bun | Bun Examples](https://bun.sh/guides/runtime/typescript) `bun-fix.d.ts` ```html /// <reference lib="dom" /> /// <reference lib="dom.iterable" /> ``` `tsconfig.json` ```json { "compilerOptions": { "baseUrl": ".", "inlineSourceMap": true, "inlineSources": true, "module": "ESNext", "target": "ES6", "allowJs": true, "noImplicitAny": true, "moduleResolution": "node", "importHelpers": true, "isolatedModules": true, "strictNullChecks": true, "allowSyntheticDefaultImports": true, "noUncheckedIndexedAccess": true, "skipLibCheck": true, "lib": ["DOM", "ES5", "ES6", "ES7", "ESNext"], "types": ["bun-types"], "paths": { "@/*": ["./src/*"] } }, "include": ["**/*.ts"], "exclude": ["node_modules"] } ``` update the `package.json` > `scripts` to ```json "dev": "bun esbuild.config.mjs", "build": "bun esbuild.config.mjs production", "version": "bun version-bump.mjs && git add manifest.json versions.json", ``` ### Move Files to Src Folder ### Add the Extended Types [Fevol/obsidian-typings: Typescript typings for undocumented parts of the Obsidian API (github.com)](https://github.com/Fevol/obsidian-typings) ### Install Husky ```bash npm install husky -D ``` ```bash npm pkg set scripts.prepare="husky install" npm run prepare ``` ```bash npx husky add .husky/pre-push "npm test" git add .husky/pre-push ``` change the `package.json` > `scripts` to ```json "build": "bun esbuild.config.mjs production", ``` ### Test it Locally Open your vault setting > community plugin, you should see your plugin. ### Github Release Workflow create a file `.github/workflow/release.yml` in your project. Copy and paste the following ```yml fold name: Release Obsidian plugin on: push: tags: - "*" jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: oven-sh/setup-bun@v1 with: bun-version: latest - name: Build plugin run: | bun install bun run build - name: Create release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | tag="${GITHUB_REF#refs/tags/}" gh release create "$tag" \ --title="$tag" \ --draft \ main.js manifest.json styles.css ``` ### Release > [!warning] You need to enable github action workflow permission! > Setting > Actions > General > Workflow Permission > change to "read and write permission" ```bash # update the version number in package.json bun version git add . git commit -m <message> git tag -a <version> -m <version> git push origin <version> git push # after the release workflow done, update the release doc on github ``` ### Testing Using BRAT > [!info] read more > [TfTHacker/obsidian42-brat: BRAT - Beta Reviewer's Auto-update Tool for Obsidian. Part of the Obsidian42 family of plugins. (github.com)](https://github.com/TfTHacker/obsidian42-brat) BRAT allow you to test plugin that haven't released officially on obsidia marketplace just by using a github repo link. ### Submit a PR to Obsidian Releases > [!info] read more > [Submit your plugin - Developer Documentation (obsidian.md)](https://docs.obsidian.md/Plugins/Releasing/Submit+your+plugin) you need to create a PR on [Pull requests · obsidianmd/obsidian-releases (github.com)](https://github.com/obsidianmd/obsidian-releases/pulls), everyone is doing this. ![](https://res.cloudinary.com/yomaru/image/upload/v1697050340/obsidian/z06mp0up14glqidybtlo.png) After you submit your PR, wait for approval 🎉 ## Best practice 1. use a development vault 2. use real notes to test 3. remove other plugin, isolate your plugin to test 4. write auto test cases for functions and manual test cases for features