init
This commit is contained in:
commit
0ea7bf7769
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.js text eol=lf
|
||||||
|
*.json text eol=lf
|
||||||
|
*.ts text eol=lf
|
||||||
|
*.code-snippets text eol=lf
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
release/
|
||||||
|
yarn.lock
|
||||||
|
pnpm-lock.yaml
|
||||||
|
cache/
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 cool-team-official
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
84
README.md
Normal file
84
README.md
Normal file
@ -0,0 +1,84 @@
|
|||||||
|

|
||||||
|
|
||||||
|
## 官网
|
||||||
|
|
||||||
|
[https://cool-js.com](https://cool-js.com)
|
||||||
|
|
||||||
|
[插件开发文档](https://cool-js.com/admin/node/core/plugin.html#使用插件)
|
||||||
|
|
||||||
|
## 视频教程
|
||||||
|
|
||||||
|
[1、插件开发](https://www.bilibili.com/video/BV1aa4y187jh/)
|
||||||
|
|
||||||
|
[2、插件发布与使用](https://www.bilibili.com/video/BV1mw41157bx/)
|
||||||
|
|
||||||
|
## README 示例
|
||||||
|
|
||||||
|
下面时插件介绍的示例,你可以按照这样的规范写,当然不限于这种形式,你可以自由发挥,只要能表达清楚即可。
|
||||||
|
|
||||||
|
### 介绍
|
||||||
|
|
||||||
|
这是个示例插件, 写了一些简单的方法
|
||||||
|
|
||||||
|
### 标识
|
||||||
|
|
||||||
|
调用插件的时候需要用到标识,标识是唯一的,不能重复,建议使用英文,不要使用中文,对应插件 `plugin.json` 中的 `key` 字段
|
||||||
|
|
||||||
|
- 标识:test
|
||||||
|
|
||||||
|
### 配置
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"appId": "xxx的appId",
|
||||||
|
"appSecret": "xxx的appSecret"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方法
|
||||||
|
|
||||||
|
下面是插件提供的一些方法
|
||||||
|
|
||||||
|
- show
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/**
|
||||||
|
* 展示插件信息
|
||||||
|
* @param a 参数a
|
||||||
|
* @param b 参数b
|
||||||
|
* @returns 插件信息
|
||||||
|
*/
|
||||||
|
async show(a, b)
|
||||||
|
```
|
||||||
|
|
||||||
|
- demo
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/**
|
||||||
|
* 请求网络示例
|
||||||
|
* @returns 百度的请求结果
|
||||||
|
*/
|
||||||
|
async demo()
|
||||||
|
```
|
||||||
|
|
||||||
|
### 调用示例
|
||||||
|
|
||||||
|
```ts
|
||||||
|
@Inject()
|
||||||
|
pluginService: PluginService;
|
||||||
|
|
||||||
|
// 获取插件实例
|
||||||
|
const instance = await this.pluginService.getInstance('test');
|
||||||
|
|
||||||
|
// 调用show
|
||||||
|
await instance.show(1, 2);
|
||||||
|
|
||||||
|
// 调用demo
|
||||||
|
await instance.demo();
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### 更新日志
|
||||||
|
|
||||||
|
- v1.0.0 (2024-04-15)
|
||||||
|
- 初始版本
|
BIN
assets/logo.png
Normal file
BIN
assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
29
package.json
Normal file
29
package.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "cool-admin-midawy-plugin",
|
||||||
|
"version": "7.1.0",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "ts-node test/index.ts",
|
||||||
|
"test": "cool-plugin-cli --build & node dist/test/index.js",
|
||||||
|
"build": "cool-plugin-cli --build",
|
||||||
|
"release": "cool-plugin-cli --release"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"@cool-midway/plugin-cli": "^7.1.9",
|
||||||
|
"@types/node": "^20.11.30",
|
||||||
|
"axios": "^1.6.8",
|
||||||
|
"decompress": "^4.2.1",
|
||||||
|
"download": "^8.0.0",
|
||||||
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"md5": "^2.3.0",
|
||||||
|
"moment": "^2.30.1",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.4.3",
|
||||||
|
"uuid": "^9.0.1",
|
||||||
|
"ws": "^8.16.0"
|
||||||
|
}
|
||||||
|
}
|
16
plugin.json
Normal file
16
plugin.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "测试",
|
||||||
|
"key": "test",
|
||||||
|
"hook": "",
|
||||||
|
"singleton": false,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "插件描述",
|
||||||
|
"author": "作者",
|
||||||
|
"logo": "assets/logo.png",
|
||||||
|
"readme": "README.md",
|
||||||
|
"config": {
|
||||||
|
"appId": "@baseDir/1.md",
|
||||||
|
"appSecret": "xxxxx",
|
||||||
|
"filePath": "@baseDir/xxxxx"
|
||||||
|
}
|
||||||
|
}
|
66
src/index.ts
Normal file
66
src/index.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { BasePlugin } from "@cool-midway/plugin-cli";
|
||||||
|
import axios from "axios";
|
||||||
|
import fs from "fs";
|
||||||
|
import "./other";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
export class CoolPlugin extends BasePlugin {
|
||||||
|
/**
|
||||||
|
* 插件已就绪,注意:单例插件只会执行一次,非单例插件每次调用都会执行
|
||||||
|
*/
|
||||||
|
async ready() {
|
||||||
|
console.log("插件就绪");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 展示插件信息
|
||||||
|
* @param a 参数a
|
||||||
|
* @param b 参数b
|
||||||
|
* @returns 插件信息
|
||||||
|
*/
|
||||||
|
async show(a, b) {
|
||||||
|
console.log("传参", a, b);
|
||||||
|
return this.pluginInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用缓存,使用cool-admin的缓存,开发的时候只是模拟
|
||||||
|
*/
|
||||||
|
async useCache() {
|
||||||
|
await this.cache.set("a", "一个项目用COOL就够了");
|
||||||
|
const r = await this.cache.get("a");
|
||||||
|
console.log(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用其他插件
|
||||||
|
*/
|
||||||
|
async usePlugin() {
|
||||||
|
// 获得其他插件,开发的时候无法调试,只有安装到cool-admin中才能调试
|
||||||
|
const plugin = await this.pluginService.getInstance("xxx");
|
||||||
|
console.log(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求网络示例
|
||||||
|
*/
|
||||||
|
async demo() {
|
||||||
|
const res = await axios.get("https://www.baidu.com");
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取文件示例
|
||||||
|
*/
|
||||||
|
async readFile() {
|
||||||
|
// 如果是本地开发,filePath指向的是插件的根目录的文件
|
||||||
|
const { filePath } = this.pluginInfo.config;
|
||||||
|
const result = fs.readFileSync(filePath);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出插件实例, Plugin名称不可修改
|
||||||
|
export const Plugin = CoolPlugin;
|
1
src/other.ts
Normal file
1
src/other.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log('这是另外一个文件')
|
13
test/index.ts
Normal file
13
test/index.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { Plugin } from "../src/index";
|
||||||
|
import pluginInfo from "../plugin.json";
|
||||||
|
|
||||||
|
// 实例化插件
|
||||||
|
const instance = new Plugin();
|
||||||
|
// 初始化插件
|
||||||
|
instance.init(pluginInfo);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// 调用插件方法
|
||||||
|
const res = await instance.demo();
|
||||||
|
console.log(res);
|
||||||
|
})();
|
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2018",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"declaration": true,
|
||||||
|
"resolveJsonModule":true,
|
||||||
|
"pretty": true,
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["core", "src", "test"]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user