|
| 1 | +# AnyMenu Plugin Simple |
| 2 | + |
| 3 | +> 这是 [AnyMenu](https://github.com/any-menu/any-menu) 的插件开发模板 |
| 4 | +
|
| 5 | +## 编译 |
| 6 | + |
| 7 | +```bash |
| 8 | +$ npm install |
| 9 | +$ npm run build |
| 10 | +# 然后会将编译结果生成到 dist 目录下 |
| 11 | +``` |
| 12 | + |
| 13 | +## 使用 |
| 14 | + |
| 15 | +同普通的 AnyMenu 插件 |
| 16 | + |
| 17 | +将编译好的结果放置于 AnyMenu 的插件目录下,然后 AnyMenu 中刷新本地插件列表即可看到刚刚添加的新插件 |
| 18 | + |
| 19 | +将新插件开启后即可 (当前版本可能需要重启下插件/软件才可) |
| 20 | + |
| 21 | +## 从零生成此项目 (可选) |
| 22 | + |
| 23 | +可选阅读,仅推荐有需要自定义插件模板的查看 (如需要开发有 Vue/React 等依赖的插件模板) |
| 24 | + |
| 25 | +(1) git 环境 (可选) |
| 26 | + |
| 27 | +```bash |
| 28 | +$ git init |
| 29 | +# 并创建和修改 .gitignore |
| 30 | +``` |
| 31 | + |
| 32 | +(2) npm 环境 |
| 33 | + |
| 34 | +```bash |
| 35 | +$ npm init |
| 36 | +This utility will walk you through creating a package.json file. |
| 37 | +It only covers the most common items, and tries to guess sensible defaults. |
| 38 | + |
| 39 | +See `npm help init` for definitive documentation on these fields |
| 40 | +and exactly what they do. |
| 41 | + |
| 42 | +Use `npm install <pkg>` afterwards to install a package and |
| 43 | +save it as a dependency in the package.json file. |
| 44 | + |
| 45 | +Press ^C at any time to quit. |
| 46 | +package name: (anymenu-plugin-simple) |
| 47 | +version: (1.0.0) |
| 48 | +description: AnyMenu simple plugin example |
| 49 | +entry point: (index.js) |
| 50 | +test command: |
| 51 | +git repository: |
| 52 | +keywords: anymenu |
| 53 | +author: |
| 54 | +license: (ISC) MIT |
| 55 | +type: (commonjs) module |
| 56 | +About to write to H:\Git\Private\Group_AnyMenu\anymenu-plugin-simple\package.json: |
| 57 | + |
| 58 | +{ |
| 59 | + "name": "anymenu-plugin-simple", |
| 60 | + "version": "1.0.0", |
| 61 | + "description": "AnyMenu simple plugin example", |
| 62 | + "main": "index.js", |
| 63 | + "scripts": { |
| 64 | + "test": "echo \"Error: no test specified\" && exit 1" |
| 65 | + }, |
| 66 | + "keywords": [ |
| 67 | + "anymenu" |
| 68 | + ], |
| 69 | + "author": "", |
| 70 | + "license": "MIT", |
| 71 | + "type": "module" |
| 72 | +} |
| 73 | + |
| 74 | + |
| 75 | +Is this OK? (yes) |
| 76 | +``` |
| 77 | + |
| 78 | +(3) typescript 和 vite 环境 |
| 79 | + |
| 80 | +```bash |
| 81 | +# 可参考当前项目的 package.json |
| 82 | + |
| 83 | +$ npm install -D typescript vite |
| 84 | + |
| 85 | +# 替换 package.json 的 scripts (使用 vite 和 typescript) |
| 86 | +# 添加 tsconfig.json |
| 87 | +# 添加 vite.config.js |
| 88 | +``` |
| 89 | + |
| 90 | +(4) 程序文件 |
| 91 | + |
| 92 | +```bash |
| 93 | +# 然后是文件准备 |
| 94 | + |
| 95 | +# (1) typescript 类型 |
| 96 | +# 复制 any-menu/any-menu 项目的 src/Core/PluginInterface.ts 接口到 /types/any-menu.d.ts |
| 97 | +# 或复制该项目的 /types/any-menu.d.ts |
| 98 | +# 或等待后期这一步会转而使用 npm 类型依赖包来实现 |
| 99 | +# |
| 100 | +# 当然,如果你使用 js 来编写则不需要这一步,直接仿照官方的 js 示例插件来编写就可以了 |
| 101 | + |
| 102 | +# (2) 创建和编写 src/ 文件夹内的内容 (主要程序代码和样式文件) |
| 103 | +``` |
0 commit comments