Skip to content

Commit a292843

Browse files
committed
init
0 parents  commit a292843

26 files changed

+1756
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.d.ts]
15+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.cjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
extends: [
3+
'plugin:vue/vue3-essential',
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
'@vue/eslint-config-typescript',
7+
'@vue/eslint-config-prettier/skip-formatting',
8+
"turbo",
9+
"prettier",
10+
],
11+
12+
parser: "@typescript-eslint/parser",
13+
14+
overrides: [
15+
],
16+
17+
plugins: ["@typescript-eslint", "prettier"],
18+
19+
rules: {
20+
// Note: you must disable the base rule as it can report incorrect errors
21+
semi: "off",
22+
quotes: "off",
23+
"no-undef": "off",
24+
"@typescript-eslint/no-var-requires": "off",
25+
"@typescript-eslint/no-this-alias": "off",
26+
"@typescript-eslint/no-non-null-assertion": "off",
27+
"@typescript-eslint/no-unused-vars": "off",
28+
"@typescript-eslint/no-explicit-any": "off",
29+
"turbo/no-undeclared-env-vars": "off",
30+
"prettier/prettier": "error",
31+
},
32+
}

.github/workflows/release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Create Release on Tag Push
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# Checkout
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
# Install Node.js
17+
- name: Install Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 18
21+
registry-url: "https://registry.npmjs.org"
22+
23+
# Install pnpm
24+
- name: Install pnpm
25+
uses: pnpm/action-setup@v2
26+
id: pnpm-install
27+
with:
28+
version: 8
29+
run_install: false
30+
31+
# Get pnpm store directory
32+
- name: Get pnpm store directory
33+
id: pnpm-cache
34+
shell: bash
35+
run: |
36+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
37+
38+
# Setup pnpm cache
39+
- name: Setup pnpm cache
40+
uses: actions/cache@v3
41+
with:
42+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
43+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44+
restore-keys: |
45+
${{ runner.os }}-pnpm-store-
46+
47+
# Install dependencies
48+
- name: Install dependencies
49+
run: pnpm install
50+
51+
# Build for production, 这一步会生成一个 package.zip
52+
- name: Build for production
53+
run: pnpm build
54+
55+
- name: Release
56+
uses: ncipollo/release-action@v1
57+
with:
58+
allowUpdates: true
59+
artifactErrorsFailBuild: true
60+
artifacts: "package.zip"
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
prerelease: true

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea
2+
.vscode
3+
.DS_Store
4+
pnpm-lock.yaml
5+
package.zip
6+
node_modules
7+
dev
8+
dist
9+
build
10+
tmp

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 SiYuan 思源笔记
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
2+
# SiYuan plugin sample with vite
3+
4+
[中文版](./README_zh_CN.md)
5+
6+
> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.2.8](https://github.com/siyuan-note/plugin-sample/tree/v0.2.8)
7+
8+
9+
10+
1. Using vite for packaging
11+
2. Use symbolic linking instead of putting the project into the plugins directory program development
12+
3. Provides a github action template to automatically generate package.zip and upload to new release
13+
14+
15+
## Get started
16+
17+
1. Make a copy of this repo as a template with the `Use this template` button, please note that the repo name must be the same as the plugin name, the default branch must be `main`
18+
19+
2. Clone your repo to a local development folder at any place
20+
- Notice: we **don't recommand** you to place the folder under your `{workspace}/data/plugins/` folder.
21+
22+
3. Install NodeJS and pnpm, then run pnpm i in the command line under your repo folder
23+
4. **Auto create development symbolic links**
24+
- Make sure that SiYuan is running
25+
- Run `pnpm run make-link`, the script will detect all the siyuan workspace, please select the targe workspace and the script will automatically create the symbolic link under the `{workspace}/data/plugins/` folder
26+
```bash
27+
>>> pnpm run make-link
28+
> [email protected] make-link H:\SrcCode\开源项目\plugin-sample-vite
29+
> node --no-warnings ./scripts/make_dev_link.js
30+
31+
"targetDir" is empty, try to get SiYuan directory automatically....
32+
Got 2 SiYuan workspaces
33+
[0] H:\Media\SiYuan
34+
[1] H:\临时文件夹\SiYuanDevSpace
35+
Please select a workspace[0-1]: 0
36+
Got target directory: H:\Media\SiYuan/data/plugins
37+
Done! Created symlink H:\Media\SiYuan/data/plugins/plugin-sample-vite-svelte
38+
```
39+
4. **Manually create development symbolic links**
40+
- Open `./scripts/make_dev_link.js` file, set `targetDir` to your SiYuan plugin directory `<siyuan workspace>/data/plugins`
41+
- Run `pnpm run make-link`, succeed if following message is shown:
42+
```bash
43+
>>> pnpm run make-link
44+
> [email protected] make-link H:\SrcCode\plugin-sample-vite-svelte
45+
> node ./scripts/make_dev_link.js
46+
47+
Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
48+
```
49+
5. **Create development symbolic links by using environment variable**
50+
- You can set environment variable `SIYUAN_PLUGIN_DIR` as `/data/plugins`
51+
6. Execute pnpm run dev for real-time compilation
52+
7. Open SiYuan marketplace and enable plugin in downloaded tab
53+
54+
> Notice: as the `make-link` script rely on the `fetch` function, please **ensure that at least version v18 of nodejs is installed** if you want to use make-link script.
55+
56+
## I18n
57+
58+
In terms of internationalization, our main consideration is to support multiple languages. Specifically, we need to
59+
complete the following tasks:
60+
61+
* Meta information about the plugin itself, such as plugin description and readme
62+
* `description` and `readme` fields in plugin.json, and the corresponding README*.md file
63+
* Text used in the plugin, such as button text and tooltips
64+
* src/i18n/*.json language configuration files
65+
* Use `this.i18.key` to get the text in the code
66+
67+
It is recommended that the plugin supports at least English and Simplified Chinese, so that more people can use it more
68+
conveniently.
69+
70+
## plugin.json
71+
72+
```json
73+
{
74+
"name": "plugin-sample-vite-svelte",
75+
"author": "frostime",
76+
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
77+
"version": "0.1.3",
78+
"minAppVersion": "2.8.8",
79+
"backends": ["windows", "linux", "darwin"],
80+
"frontends": ["desktop"],
81+
"displayName": {
82+
"en_US": "Plugin sample with vite and svelte",
83+
"zh_CN": "插件样例 vite + svelte 版"
84+
},
85+
"description": {
86+
"en_US": "SiYuan plugin sample with vite and svelte",
87+
"zh_CN": "使用 vite 和 svelte 开发的思源插件样例"
88+
},
89+
"readme": {
90+
"en_US": "README_en_US.md",
91+
"zh_CN": "README.md"
92+
},
93+
"funding": {
94+
"openCollective": "",
95+
"patreon": "",
96+
"github": "",
97+
"custom": [
98+
"https://ld246.com/sponsor"
99+
]
100+
},
101+
"keywords": [
102+
"sample", "示例"
103+
]
104+
}
105+
```
106+
107+
* `name`: Plugin name, must be the same as the repo name, and must be unique globally (no duplicate plugin names in the
108+
marketplace)
109+
* `author`: Plugin author name
110+
* `url`: Plugin repo URL
111+
* `version`: Plugin version number, it is recommended to follow the [semver](https://semver.org/) specification
112+
* `minAppVersion`: Minimum version number of SiYuan required to use this plugin
113+
* `backends`: Backend environment required by the plugin, optional values are `windows`, `linux`, `darwin`, `docker`, `android`, `ios` and `all`
114+
* `windows`: Windows desktop
115+
* `linux`: Linux desktop
116+
* `darwin`: macOS desktop
117+
* `docker`: Docker
118+
* `android`: Android APP
119+
* `ios`: iOS APP
120+
* `all`: All environments
121+
* `frontends`: Frontend environment required by the plugin, optional values are `desktop`, `desktop-window`, `mobile`, `browser-desktop`, `browser-mobile` and `all`
122+
* `desktop`: Desktop
123+
* `desktop-window`: Desktop window converted from tab
124+
* `mobile`: Mobile APP
125+
* `browser-desktop`: Desktop browser
126+
* `browser-mobile`: Mobile browser
127+
* `all`: All environments
128+
* `displayName`: Template display name, mainly used for display in the marketplace list, supports multiple languages
129+
* `default`: Default language, must exist
130+
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
131+
* `description`: Plugin description, mainly used for display in the marketplace list, supports multiple languages
132+
* `default`: Default language, must exist
133+
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
134+
* `readme`: readme file name, mainly used to display in the marketplace details page, supports multiple languages
135+
* `default`: Default language, must exist
136+
* `zh_CN`, `en_US` and other languages: optional, it is recommended to provide at least Chinese and English
137+
* `funding`: Plugin sponsorship information
138+
* `openCollective`: Open Collective name
139+
* `patreon`: Patreon name
140+
* `github`: GitHub login name
141+
* `custom`: Custom sponsorship link list
142+
* `keywords`: Search keyword list, used for marketplace search function
143+
144+
## Package
145+
146+
No matter which method is used to compile and package, we finally need to generate a package.zip, which contains at
147+
least the following files:
148+
149+
* i18n/*
150+
* icon.png (160*160)
151+
* index.css
152+
* index.js
153+
* plugin.json
154+
* preview.png (1024*768)
155+
* README*.md
156+
157+
## List on the marketplace
158+
159+
* `pnpm run build` to generate package.zip
160+
* Create a new GitHub release using your new version number as the "Tag version". See here for an
161+
example: https://github.com/siyuan-note/plugin-sample/releases
162+
* Upload the file package.zip as binary attachments
163+
* Publish the release
164+
165+
If it is the first release, please create a pull request to
166+
the [Community Bazaar](https://github.com/siyuan-note/bazaar) repository and modify the plugins.json file in it. This
167+
file is the index of all community plugin repositories, the format is:
168+
169+
```json
170+
{
171+
"repos": [
172+
"username/reponame"
173+
]
174+
}
175+
```
176+
177+
After the PR is merged, the bazaar will automatically update the index and deploy through GitHub Actions. When releasing
178+
a new version of the plugin in the future, you only need to follow the above steps to create a new release, and you
179+
don't need to PR the community bazaar repo.
180+
181+
Under normal circumstances, the community bazaar repo will automatically update the index and deploy every hour,
182+
and you can check the deployment status at https://github.com/siyuan-note/bazaar/actions.
183+
184+
## Use Github Action
185+
186+
The github action is included in this sample, you can use it to publish your new realse to marketplace automatically:
187+
188+
1. In your repo setting page `https://github.com/OWNER/REPO/settings/actions`, down to **Workflow Permissions** and open the configuration like this:
189+
190+
![](asset/action.png)
191+
192+
2. Push a tag in the format `v*` and github will automatically create a new release with new bulit package.zip
193+
194+
3. By default, it will only publish a pre-release, if you don't think this is necessary, change the settings in release.yml
195+
196+
```yaml
197+
- name: Release
198+
uses: ncipollo/release-action@v1
199+
with.
200+
allowUpdates: true
201+
artifactErrorsFailBuild: true
202+
artifacts: 'package.zip'
203+
token: ${{ secrets.GITHUB_TOKEN }}
204+
prerelease: true # change this to false
205+
```
206+
207+
208+
## How to remove svelte dependencies
209+
210+
> Pure vite without svelte: https://github.com/frostime/plugin-sample-vite
211+
212+
This plugin is packaged in vite and provides a dependency on the svelte framework. However, in practice some developers may not want to use svelte and only want to use the vite package.
213+
214+
In fact you can use this template without using svelte without any modifications at all. The compilation-related parts of the svelte compilation are loaded into the vite workflow as plugins, so even if you don't have svelte in your project, it won't matter much.
215+
216+
If you insist on removing all svelte dependencies so that they do not pollute your workspace, you can perform the following steps. 1.
217+
218+
1. delete the
219+
```json
220+
{
221+
"@sveltejs/vite-plugin-svelte": "^2.0.3",
222+
"@tsconfig/svelte": "^4.0.1",
223+
"svelte": "^3.57.0"
224+
}
225+
```
226+
2. delete the `svelte.config.js` file
227+
3. delete the following line from the `vite.config.js` file
228+
- Line 6: `import { svelte } from "@sveltejs/vite-plugin-svelte"`
229+
- Line 20: `svelte(),`
230+
4. delete line 37 of `tsconfig.json` from `"svelte"` 5.
231+
5. re-run `pnpm i`

0 commit comments

Comments
 (0)