@gpc-cli/plugin-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @gpc-cli/plugin-sdk
|
|
2
|
+
|
|
3
|
+
Plugin interface and SDK for extending GPC with custom commands, lifecycle hooks, and integrations.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gpc-cli/plugin-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Create a Plugin
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { definePlugin } from "@gpc-cli/plugin-sdk";
|
|
15
|
+
import type { GpcPlugin } from "@gpc-cli/plugin-sdk";
|
|
16
|
+
|
|
17
|
+
export const myPlugin: GpcPlugin = definePlugin({
|
|
18
|
+
name: "gpc-plugin-slack",
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
|
|
21
|
+
hooks: {
|
|
22
|
+
afterCommand({ command, result }) {
|
|
23
|
+
// Notify Slack after every command
|
|
24
|
+
if (result.success) {
|
|
25
|
+
postToSlack(`${command} completed successfully`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
onError({ error }) {
|
|
30
|
+
postToSlack(`GPC error: ${error.message}`);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
registerCommands(registry) {
|
|
34
|
+
registry.addCommand({
|
|
35
|
+
name: "slack:notify",
|
|
36
|
+
description: "Send a Slack notification",
|
|
37
|
+
options: [
|
|
38
|
+
{ flags: "--channel <channel>", description: "Slack channel" },
|
|
39
|
+
],
|
|
40
|
+
action: async (opts) => {
|
|
41
|
+
await postToSlack(opts.channel, "Manual notification from GPC");
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Lifecycle Hooks
|
|
50
|
+
|
|
51
|
+
| Hook | When | Use Case |
|
|
52
|
+
|------|------|----------|
|
|
53
|
+
| `beforeCommand` | Before any CLI command | Logging, validation, feature flags |
|
|
54
|
+
| `afterCommand` | After command completes | Notifications, metrics, summaries |
|
|
55
|
+
| `onError` | When a command fails | Error reporting, alerting |
|
|
56
|
+
| `beforeRequest` | Before each API call | Request logging, headers |
|
|
57
|
+
| `afterResponse` | After each API response | Response logging, metrics |
|
|
58
|
+
| `registerCommands` | Plugin initialization | Add custom commands to the CLI |
|
|
59
|
+
|
|
60
|
+
## Permissions
|
|
61
|
+
|
|
62
|
+
Plugins declare required permissions in their manifest:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const plugin: GpcPlugin = {
|
|
66
|
+
name: "my-plugin",
|
|
67
|
+
version: "1.0.0",
|
|
68
|
+
manifest: {
|
|
69
|
+
permissions: ["api:read", "hooks:afterCommand"],
|
|
70
|
+
},
|
|
71
|
+
hooks: { ... },
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Permission | Grants |
|
|
76
|
+
|-----------|--------|
|
|
77
|
+
| `read:config` | Read GPC configuration |
|
|
78
|
+
| `write:config` | Modify GPC configuration |
|
|
79
|
+
| `read:auth` | Access auth credentials |
|
|
80
|
+
| `api:read` | Read-only API access |
|
|
81
|
+
| `api:write` | Write API access |
|
|
82
|
+
| `commands:register` | Register custom commands |
|
|
83
|
+
| `hooks:*` | Subscribe to specific hooks |
|
|
84
|
+
|
|
85
|
+
Third-party plugins require user approval before loading:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
gpc plugins approve gpc-plugin-slack
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Scaffold a Plugin
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
gpc plugins init my-plugin
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Generates a complete plugin project with TypeScript config, tests, and example hooks.
|
|
98
|
+
|
|
99
|
+
## Part of the GPC Monorepo
|
|
100
|
+
|
|
101
|
+
See the [Plugin Development Guide](https://yasserstudio.github.io/gpc/advanced/plugins) for full documentation.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|