Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MapleLeaf2007 authored Nov 20, 2024
0 parents commit 75a7829
Show file tree
Hide file tree
Showing 21 changed files with 737 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release and Publish # 发布和发布的工作流程名称
on:
push:
branches:
- main # 仅当推送到 main 分支时触发
permissions:
contents: write # 设置内容的权限为写
pull-requests: write # 设置拉取请求的权限为写
jobs:
release-please:
# 设置工作流程运行环境为 Ubuntu
runs-on: ubuntu-latest
steps:
# 使用 release-please-action@v3 动作
- uses: google-github-actions/release-please-action@v3
id: release
with:
# 设置发布类型为 Node.js
release-type: node
# 设置包名
package-name: karin-plugin-template-ts
# 设置发起PR的默认分支
default-branch: main
# 检出代码
- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}
# 设置 Node.js 环境
- uses: actions/setup-node@v4
with:
# 设置 Node.js 版本
node-version: 20
# 设置 npm 注册表 URL
registry-url: "https://registry.npmjs.org"
if: ${{ steps.release.outputs.release_created }}
# 添加node-karin并安装依赖
- run: npm install --save-dev node-karin && npm install
if: ${{ steps.release.outputs.release_created }}
# 编译
- run: npm run build
if: ${{ steps.release.outputs.release_created }}
# 安装jq工具 删除开发依赖
- run: sudo apt-get install jq && jq 'del(.devDependencies)' package.json > package.json.tmp && mv package.json.tmp package.json
if: ${{ steps.release.outputs.release_created }}
# 发布带npm
- run: npm run pub
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 包管理器文件
.npmrc
yarn.lock
pnpm-lock.yaml
package-lock.json

# 包管理器日志
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# 编辑器配置
.idea/
.vscode/

# 临时文件
/logs/
/temp/

# 配置
/lib

# 依赖
node_modules/
config/config/pm2.yaml
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Changelog

## [1.0.2](https://github.com/KarinJS/karin-plugin-template/compare/v1.0.1...v1.0.2) (2024-07-20)


### Bug Fixes

* 测试 ([123f121](https://github.com/KarinJS/karin-plugin-template/commit/123f12135ae1b1842984dd5eaa2349eeacd482f0))
* 测试3 ([7b65f69](https://github.com/KarinJS/karin-plugin-template/commit/7b65f69567e5fc313246746b18aea9d23ca67662))

## [1.0.1](https://github.com/KarinJS/karin-plugin-template/compare/v1.0.0...v1.0.1) (2024-07-20)


### Bug Fixes

* 测试2 ([b6a0b8d](https://github.com/KarinJS/karin-plugin-template/commit/b6a0b8d0f9175916ed6fbb3c034b4ee30f168c07))

## 1.0.0 (2024-07-20)


### Features

* 添加更多示例插件 ([a850ac5](https://github.com/KarinJS/karin-plugin-template/commit/a850ac5fb1a03e8134f0fb2e517464e8117d5565))


### Bug Fixes

* 测试 ([94b2995](https://github.com/KarinJS/karin-plugin-template/commit/94b29953a99d75e31e548e031598eeaf8c17fa96))
* 跟随上游 ([61d3bdf](https://github.com/KarinJS/karin-plugin-template/commit/61d3bdfc29801edaed046f35c771e68abe5540b7))
* 路径构建 ([b17f344](https://github.com/KarinJS/karin-plugin-template/commit/b17f344db0cf6f3dfa29f6d0f903825b9c769e9f))
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# karin的ts插件开发模板

## 前言

ts插件的开发较为繁琐,但请不要着急,容我娓娓道来~

- `TypeScript` 开发编写 -> 编译为`js` -> 发布 `npm` 包 -> 用户安装

## 克隆模板仓库

> 需要注意 请先安装`karin`~
打开[模板仓库](https://github.com/KarinJS/karin-plugin-template-ts)

点击`Use this template``使用此模板`按钮,创建自己的仓库。
![202404121412587](https://cdn.jsdelivr.net/gh/Zyy955/imgs/img/202404121412587.png)

填写仓库名称,描述,选择是否公开。
![202404121414580](https://cdn.jsdelivr.net/gh/Zyy955/imgs/img/202404121414580.png)

```bash
# 请改成你自己的仓库
git clone https://github.com/karinjs/karin-plugin-template-ts.git ./plugins/karin-plugin-template-ts
```

## 安装开发依赖

```bash
pnpm install
```

## 开始你的开发

> 目前无法直接执行`ts`插件包,需要手动编译后跑`js`
```bash
# 编译
npm run build
# or
pnpm build
```

## 配置基本秘钥

> 需要1个基本的`npm`秘钥
1. 前往[npmjs](https://www.npmjs.com/)注册账号
2. 注册完成点击`右上角头像` -> `Access Tokens` -> `Granular Access Token` -> `Classic Token`
3. 填写`token``name`,选择`Automation`,如下图
![npm](./resources//image/npm.png)
4. 随后点击`Generate Token`即可
5. 打开[Github](https://github.com),请自行登录账号。
6. 打开你刚才`Fork`的仓库,点击`Settings(设置)` -> `Secrets and variables(机密和变量)` -> `actions(操作)`
7. 选择`Repository secrets(仓库机密)`,点击`New repository secret(新建仓库机密)`
8. `Name *(名称 *)` 输入 `NPM_TOKEN``Secret *(机密 *)` 输入你刚才得到的`npm`秘钥,随后保存即可。
9. 允许`github-actions`发起`pr`,打开仓库主页,点击`Settings(设置)` -> `Actions(操作)` -> 勾选`Allow GitHub Actions to create and approve pull requests(允许 GitHub Actions 创建和批准拉取请求)` -> `Save(保存)`

这里的步骤很长,请仔细认真一步步来,`npm`的秘钥,获取一次之后,多个仓库都可以重复使用,建议`npm`账户打开`2FA`

## 设置npm包名称

> [!IMPORTANT]
> 对于包名,请自行查看`npm`上是否已经冲突,`npm`的包名必须是唯一的。
你需要更改以下这些选项:

- `package.json`:
- `name`: 改成npm包名,请注意使用`全部小写`
- `author`: 改成你的名字,需要英文哦
- `description`: 改成插件描述
- `homepage`: `npm`显示的主页
- `bugs.url`: 反馈bug
- `repository`: 指定项目的代码存储库地址
- `.github/workflows/release-please.yml`:
- 修改其中的`package-name`,注意,这里需要和上面`package.json`的一致。

> 对于更多选项,请自行查看注释。
## 推送

> [!IMPORTANT]
> 编写好代码之后,正常`git pull`,随后等待几秒钟,合并`pr`即可。
利用`Gihub`提供的`actions`来编译,推送`npm`

## 安装发布的包

```bash
# 在karin根目录执行
pnpm add package.name -w
```
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key: value
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import neostandard from 'neostandard'

const data = neostandard({
ignores: ['node_modules', 'temp', 'logs', 'data'],
globals: ['logger', 'NodeJS'],
ts: true,
})

/** 关闭驼峰命名 */
data.forEach((val, index) => {
if (val?.rules?.['camelcase']) data[index].rules['camelcase'] = ['off']
})

export default data
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "karin-plugin-template-ts",
"version": "0.0.1",
"author": "Lain",
"type": "module",
"description": "karin plugin template",
"homepage": "https://github.com/KarinJS/karin-plugin-template-ts",
"bugs": {
"url": "https://github.com/KarinJS/karin-plugin-template-ts/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/KarinJS/karin-plugin-template-ts.git"
},
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
"pub": "npm publish --access public"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/lodash": "^4.17.7",
"@types/node": "^20.14.11",
"@types/node-schedule": "^2.1.7",
"@types/ws": "^8.5.11",
"eslint": "^9.7.0",
"neostandard": "^0.11.1",
"tsc-alias": "^1.8.10",
"typescript": "^5.5.3"
},
"karin": {
"apps": [
"lib/apps"
],
"outDir": "lib",
"rootDir": "src"
},
"files": [
"/lib/**/*.js",
"/lib/**/*.d.ts",
"/config/*.yaml",
"resources",
"LICENSE",
"package.json",
"README.md"
],
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
Binary file added resources/image/npm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/image/启程宣发.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions resources/template/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>

<head>
<style>
body {
width: 1067px;
height: 600px;
margin: 0;
padding: 0;
background-size: cover;
}
</style>
</head>

<body>
<!-- 本地图片 -->
<img src="{{@file}}" alt="启程宣发">
</body>

</html>
6 changes: 6 additions & 0 deletions src/apps/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { karin } from 'node-karin'

export const hello = karin.command(/^#$/, async (e) => {
await e.reply('hello', { at: false, recallMsg: 0, reply: true })
return true
})
27 changes: 27 additions & 0 deletions src/apps/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { karin, handler } from 'node-karin'

export const test = karin.handler('test.image', async (args: any, reject: (msg?: string) => void) => {
/** 取消注释告知karin继续使用下一个处理器 */
// reject('继续循环下一个handler')
return 'Handler处理完成'
})

export const testHandler = karin.command(/^#?handler$/, async (e) => {
const msg = '测试handler'
/** 对于传参,开发者传自行需要的参数即可,无任何参数强制需求... */
const res = await handler.call('test.image', { e, msg })
await e.reply(res)
return true
}, {
/** 插件优先级 */
priority: 9999,

/** 插件触发是否打印触发日志 */
log: true,

/** 插件名称 */
name: '测试handler',

/** 谁可以触发这个插件 'all' | 'master' | 'admin' | 'group.owner' | 'group.admin' */
permission: 'all',
})
Loading

0 comments on commit 75a7829

Please sign in to comment.