Skip to content

Commit 34676fa

Browse files
committed
chore: switch template to @napgram/sdk
1 parent bf5c7d6 commit 34676fa

5 files changed

Lines changed: 55 additions & 12 deletions

File tree

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ NapGram 原生插件模板仓库(可作为 GitHub **Template repository** 使
1313

1414
## 快速开始
1515

16+
### 0) 使用模板创建仓库
17+
18+
1. 打开本仓库,点击 **Use this template** 创建新仓库
19+
2. 克隆新仓库到本地
20+
3. 修改 `napgram-plugin.json`(id/name/description/permissions)
21+
4. 修改 `package.json`(name/version/description)
22+
1623
### 1) 安装依赖
1724

1825
```bash
@@ -24,9 +31,9 @@ pnpm install
2431
编辑 `src/index.ts`,实现你的插件逻辑:
2532

2633
```typescript
27-
import type { NapGramPlugin } from '@naplink/napgram-plugin-types';
34+
import { definePlugin } from '@napgram/sdk';
2835

29-
const plugin: NapGramPlugin = {
36+
const plugin = definePlugin({
3037
id: 'my-plugin',
3138
name: 'My Plugin',
3239
version: '1.0.0',
@@ -36,12 +43,12 @@ const plugin: NapGramPlugin = {
3643
if (event.message.text === 'ping') await event.reply('pong');
3744
});
3845
}
39-
};
46+
});
4047

4148
export default plugin;
4249
```
4350

44-
> 注:模板内包含 `src/types/@naplink/napgram-plugin-types/index.d.ts` 的最小类型声明,便于直接开发与通过 CI;构建产物不会包含该依赖
51+
> 注:模板内包含 `src/types/@napgram/sdk/index.d.ts` 的最小类型声明,便于离线开发与通过 CI;构建产物不会包含该声明。模板默认依赖 `@napgram/sdk`,如已安装可按需移除此兜底类型
4552
4653
### 3) 构建
4754

@@ -177,13 +184,17 @@ napgram-plugin-template/
177184

178185
### 自动化发布(推荐)
179186

180-
tag 后 Release workflow 会自动:
187+
推送 tag 后 Release workflow 会自动:
181188
1. 打包产物并生成 `marketplace-index-snippet.json`
182-
2. 若配置了 `MARKETPLACE_PR_TOKEN`,自动向 marketplace 提交 PR(你负责合并
189+
2. 若配置了 `MARKETPLACE_PR_TOKEN`,自动向 **NapGram/marketplace** 提交 PR(请关注 `https://github.com/NapGram/marketplace/pulls`
183190

184191
需要在**实际插件仓库**配置以下 Secrets:
185192
- `NPM_TOKEN`:npm automation token(用于 publish)
186-
- `MARKETPLACE_PR_TOKEN`:GitHub PAT(公开仓库用 `public_repo` 即可)
193+
- `MARKETPLACE_PR_TOKEN`:GitHub PAT(需要 **repo** + **workflow** 权限)
194+
195+
`MARKETPLACE_PR_TOKEN` 权限建议(fine-grained):
196+
- Repository access:选择你的插件仓库
197+
- Permissions:Contents(read/write)、Pull requests(read/write)、Workflows(read/write)
187198

188199
可选配置:
189200
- `MARKETPLACE_DIST_HOST`:自定义资源下载域名,未设置时默认使用 GitHub Release 下载链接

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"pack:tgz": "pnpm build && node scripts/pack.mjs tgz",
1515
"marketplace:snippet": "node scripts/marketplace-snippet.mjs"
1616
},
17-
"dependencies": {},
17+
"dependencies": {
18+
"@napgram/sdk": "^0.1.0"
19+
},
1820
"devDependencies": {
1921
"@types/node": "^25.0.3",
2022
"typescript": "^5.9.3"

pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { NapGramPlugin } from '@naplink/napgram-plugin-types';
1+
import { definePlugin } from '@napgram/sdk';
22

33
/**
44
* Ping Pong 插件
55
*
66
* 原生 NapGram 插件示例:收到 "ping" 回复 "pong"
77
*/
8-
const plugin: NapGramPlugin = {
8+
const plugin = definePlugin({
99
// 插件元信息
1010
id: 'ping-pong',
1111
name: 'Ping Pong Plugin (Template)',
@@ -40,7 +40,7 @@ const plugin: NapGramPlugin = {
4040
ctx.logger.info('Ping Pong plugin unloaded');
4141
});
4242
},
43-
};
43+
});
4444

4545
// 导出插件(默认导出)
4646
export default plugin;

src/types/@naplink/napgram-plugin-types/index.d.ts renamed to src/types/@napgram/sdk/index.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module '@naplink/napgram-plugin-types' {
1+
declare module '@napgram/sdk' {
22
export interface NapGramPlugin {
33
id: string;
44
name: string;
@@ -44,6 +44,12 @@ declare module '@naplink/napgram-plugin-types' {
4444
unsubscribe(): void;
4545
}
4646

47+
export type PluginWithConfig<TConfig = unknown> = Omit<NapGramPlugin, 'install'> & {
48+
install(ctx: PluginContext, config?: TConfig): void | Promise<void>;
49+
};
50+
51+
export function definePlugin<TConfig = unknown, T extends PluginWithConfig<TConfig> = PluginWithConfig<TConfig>>(plugin: T): T;
52+
4753
export interface MessageEvent {
4854
eventId: string;
4955
instanceId: number;

0 commit comments

Comments
 (0)