Skip to content

Commit ad056c8

Browse files
authored
Initial commit
0 parents  commit ad056c8

22 files changed

+6627
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = tab
9+
indent_size = 4
10+
tab_width = 4

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
3+
main.js

.eslintrc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"env": { "node": true, "browser": true },
5+
"plugins": ["@typescript-eslint"],
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"airbnb-base",
11+
"prettier"
12+
],
13+
"parserOptions": {
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"no-unused-vars": "off",
18+
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
19+
"@typescript-eslint/ban-ts-comment": "off",
20+
"no-prototype-builtins": "off",
21+
"no-new": "off",
22+
"import/prefer-default-export": "off",
23+
"import/no-unresolved": "off",
24+
"import/extensions": "off",
25+
"consistent-return": "off",
26+
"no-console": "off"
27+
}
28+
}

.github/workflows/test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Install modules
11+
run: npm install
12+
- name: Run ESLint
13+
run: npx eslint .
14+
format:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Install modules
19+
run: npm install
20+
- name: Run Prettier
21+
run: npx prettier --check .
22+
build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Install modules
27+
run: npm install
28+
- name: Run build
29+
run: npm run build

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# vscode
2+
.vscode
3+
4+
# Intellij
5+
*.iml
6+
.idea
7+
8+
# npm
9+
node_modules
10+
11+
# Don't include the compiled main.js file in the repo.
12+
# They should be uploaded to GitHub releases instead.
13+
main.js
14+
15+
# Exclude sourcemaps
16+
*.map
17+
18+
# obsidian
19+
data.json
20+
21+
# Exclude macOS Finder (System Explorer) View States
22+
.DS_Store

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tag-version-prefix=""

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.husky/pre-commit
2+
.prettierignore

.prettierrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Obsidian Sample Plugin
2+
3+
This is a sample plugin for Obsidian (https://obsidian.md).
4+
5+
This project uses Typescript to provide type checking and documentation.
6+
The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains TSDoc comments describing what it does.
7+
8+
**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
9+
10+
This sample plugin demonstrates some of the basic functionality the plugin API can do.
11+
12+
- Changes the default font color to red using `styles.css`.
13+
- Adds a ribbon icon, which shows a Notice when clicked.
14+
- Adds a command "Open Sample Modal" which opens a Modal.
15+
- Adds a plugin setting tab to the settings page.
16+
- Registers a global click event and output 'click' to the console.
17+
- Registers a global interval which logs 'setInterval' to the console.
18+
19+
## First time developing plugins?
20+
21+
Quick starting guide for new plugin devs:
22+
23+
- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
24+
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
25+
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
26+
- Install NodeJS, then run `npm i` in the command line under your repo folder.
27+
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
28+
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
29+
- Reload Obsidian to load the new version of your plugin.
30+
- Enable plugin in settings window.
31+
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
32+
33+
## Releasing new releases
34+
35+
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
36+
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
37+
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
38+
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
39+
- Publish the release.
40+
41+
> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
42+
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
43+
44+
## Adding your plugin to the community plugin list
45+
46+
- Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md
47+
- Publish an initial version.
48+
- Make sure you have a `README.md` file in the root of your repo.
49+
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
50+
51+
## How to use
52+
53+
- Clone this repo.
54+
- `npm i` or `yarn` to install dependencies
55+
- `npm run dev` to start compilation in watch mode.
56+
57+
## Manually installing the plugin
58+
59+
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
60+
61+
## Improve code quality with eslint (optional)
62+
63+
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
64+
- To use eslint with this project, make sure to install eslint from terminal:
65+
- `npm install -g eslint`
66+
- To use eslint to analyze this project use this command:
67+
- `eslint main.ts`
68+
- eslint will then create a report with suggestions for code improvement by file and line number.
69+
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
70+
- `eslint .\src\`
71+
72+
## Funding URL
73+
74+
You can include funding URLs where people who use your plugin can financially support it.
75+
76+
The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:
77+
78+
```json
79+
{
80+
"fundingUrl": "https://buymeacoffee.com"
81+
}
82+
```
83+
84+
If you have multiple URLs, you can also do:
85+
86+
```json
87+
{
88+
"fundingUrl": {
89+
"Buy Me a Coffee": "https://buymeacoffee.com",
90+
"GitHub Sponsor": "https://github.com/sponsors",
91+
"Patreon": "https://www.patreon.com/"
92+
}
93+
}
94+
```
95+
96+
## API Documentation
97+
98+
See https://github.com/obsidianmd/obsidian-api

esbuild.config.mjs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import esbuild from "esbuild";
2+
import process from "process";
3+
import builtins from "builtin-modules";
4+
5+
const banner = `/*
6+
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
7+
if you want to view the source, please visit the github repository of this plugin
8+
*/
9+
`;
10+
11+
const prod = process.argv[2] === "production";
12+
13+
const context = await esbuild.context({
14+
banner: {
15+
js: banner,
16+
},
17+
entryPoints: ["src/main.ts"],
18+
bundle: true,
19+
external: [
20+
"obsidian",
21+
"electron",
22+
"@codemirror/autocomplete",
23+
"@codemirror/collab",
24+
"@codemirror/commands",
25+
"@codemirror/language",
26+
"@codemirror/lint",
27+
"@codemirror/search",
28+
"@codemirror/state",
29+
"@codemirror/view",
30+
"@lezer/common",
31+
"@lezer/highlight",
32+
"@lezer/lr",
33+
...builtins,
34+
],
35+
format: "cjs",
36+
target: "es2018",
37+
logLevel: "info",
38+
sourcemap: prod ? false : "inline",
39+
treeShaking: true,
40+
outfile: "main.js",
41+
});
42+
43+
if (prod) {
44+
await context.rebuild();
45+
process.exit(0);
46+
} else {
47+
await context.watch();
48+
}

manifest.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "obsidian-sample-plugin",
3+
"name": "Sample Plugin",
4+
"version": "1.0.0",
5+
"minAppVersion": "0.15.0",
6+
"description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.",
7+
"author": "Obsidian",
8+
"authorUrl": "https://obsidian.md",
9+
"fundingUrl": "https://obsidian.md/pricing",
10+
"isDesktopOnly": false
11+
}

0 commit comments

Comments
 (0)