@rudderjs/cli 0.0.6
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/LICENSE +21 -0
- package/README.md +156 -0
- package/dist/commands/make/agent.d.ts +4 -0
- package/dist/commands/make/agent.d.ts.map +1 -0
- package/dist/commands/make/agent.js +41 -0
- package/dist/commands/make/agent.js.map +1 -0
- package/dist/commands/make/command.d.ts +4 -0
- package/dist/commands/make/command.d.ts.map +1 -0
- package/dist/commands/make/command.js +46 -0
- package/dist/commands/make/command.js.map +1 -0
- package/dist/commands/make/controller.d.ts +5 -0
- package/dist/commands/make/controller.d.ts.map +1 -0
- package/dist/commands/make/controller.js +46 -0
- package/dist/commands/make/controller.js.map +1 -0
- package/dist/commands/make/event.d.ts +4 -0
- package/dist/commands/make/event.d.ts.map +1 -0
- package/dist/commands/make/event.js +32 -0
- package/dist/commands/make/event.js.map +1 -0
- package/dist/commands/make/job.d.ts +4 -0
- package/dist/commands/make/job.d.ts.map +1 -0
- package/dist/commands/make/job.js +41 -0
- package/dist/commands/make/job.js.map +1 -0
- package/dist/commands/make/listener.d.ts +4 -0
- package/dist/commands/make/listener.d.ts.map +1 -0
- package/dist/commands/make/listener.js +34 -0
- package/dist/commands/make/listener.js.map +1 -0
- package/dist/commands/make/mail.d.ts +4 -0
- package/dist/commands/make/mail.d.ts.map +1 -0
- package/dist/commands/make/mail.js +41 -0
- package/dist/commands/make/mail.js.map +1 -0
- package/dist/commands/make/mcp-prompt.d.ts +4 -0
- package/dist/commands/make/mcp-prompt.d.ts.map +1 -0
- package/dist/commands/make/mcp-prompt.js +45 -0
- package/dist/commands/make/mcp-prompt.js.map +1 -0
- package/dist/commands/make/mcp-resource.d.ts +4 -0
- package/dist/commands/make/mcp-resource.d.ts.map +1 -0
- package/dist/commands/make/mcp-resource.js +44 -0
- package/dist/commands/make/mcp-resource.js.map +1 -0
- package/dist/commands/make/mcp-server.d.ts +4 -0
- package/dist/commands/make/mcp-server.d.ts.map +1 -0
- package/dist/commands/make/mcp-server.js +46 -0
- package/dist/commands/make/mcp-server.js.map +1 -0
- package/dist/commands/make/mcp-tool.d.ts +4 -0
- package/dist/commands/make/mcp-tool.d.ts.map +1 -0
- package/dist/commands/make/mcp-tool.js +43 -0
- package/dist/commands/make/mcp-tool.js.map +1 -0
- package/dist/commands/make/middleware.d.ts +4 -0
- package/dist/commands/make/middleware.d.ts.map +1 -0
- package/dist/commands/make/middleware.js +40 -0
- package/dist/commands/make/middleware.js.map +1 -0
- package/dist/commands/make/model.d.ts +5 -0
- package/dist/commands/make/model.d.ts.map +1 -0
- package/dist/commands/make/model.js +43 -0
- package/dist/commands/make/model.js.map +1 -0
- package/dist/commands/make/provider.d.ts +4 -0
- package/dist/commands/make/provider.d.ts.map +1 -0
- package/dist/commands/make/provider.js +39 -0
- package/dist/commands/make/provider.js.map +1 -0
- package/dist/commands/make/request.d.ts +4 -0
- package/dist/commands/make/request.d.ts.map +1 -0
- package/dist/commands/make/request.js +40 -0
- package/dist/commands/make/request.js.map +1 -0
- package/dist/commands/make.d.ts +3 -0
- package/dist/commands/make.d.ts.map +1 -0
- package/dist/commands/make.js +33 -0
- package/dist/commands/make.js.map +1 -0
- package/dist/commands/migrate.d.ts +11 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +152 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/module/make.d.ts +9 -0
- package/dist/commands/module/make.d.ts.map +1 -0
- package/dist/commands/module/make.js +190 -0
- package/dist/commands/module/make.js.map +1 -0
- package/dist/commands/module/publish.d.ts +14 -0
- package/dist/commands/module/publish.d.ts.map +1 -0
- package/dist/commands/module/publish.js +117 -0
- package/dist/commands/module/publish.js.map +1 -0
- package/dist/commands/module.d.ts +3 -0
- package/dist/commands/module.d.ts.map +1 -0
- package/dist/commands/module.js +7 -0
- package/dist/commands/module.js.map +1 -0
- package/dist/commands/vendor-publish.d.ts +5 -0
- package/dist/commands/vendor-publish.d.ts.map +1 -0
- package/dist/commands/vendor-publish.js +190 -0
- package/dist/commands/vendor-publish.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +253 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suleiman Shahbari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @rudderjs/cli
|
|
2
|
+
|
|
3
|
+
RudderJS CLI — code generators, module scaffolding, and rudder command dispatch.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
The CLI is automatically included when you scaffold a project with `create-rudderjs-app`. For manual setup:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D @rudderjs/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add to `package.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"scripts": {
|
|
18
|
+
"rudder": "node node_modules/@rudderjs/cli/dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm rudder --help # List all commands
|
|
27
|
+
pnpm rudder make:controller User # Generate a controller
|
|
28
|
+
pnpm rudder db:seed # Run a user-defined command
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Must be run from a directory containing `bootstrap/app.ts`**. The CLI boots the RudderJS application before dispatching commands — all service providers, DI bindings, and database connections are available.
|
|
32
|
+
|
|
33
|
+
## How It Works
|
|
34
|
+
|
|
35
|
+
1. The CLI locates `bootstrap/app.ts` by walking up from the current directory
|
|
36
|
+
2. It calls `rudderjs.boot()` — boots all service providers
|
|
37
|
+
3. Route loaders for `commands` are executed (registers commands from `routes/console.ts`)
|
|
38
|
+
4. The CLI dispatches the matching command with parsed arguments and options
|
|
39
|
+
|
|
40
|
+
## Built-in Commands
|
|
41
|
+
|
|
42
|
+
### `make:*` Generators
|
|
43
|
+
|
|
44
|
+
| Command | Output | Description |
|
|
45
|
+
|---------|--------|-------------|
|
|
46
|
+
| `make:controller <Name>` | `app/Http/Controllers/<Name>Controller.ts` | Decorator-based controller |
|
|
47
|
+
| `make:model <Name>` | `app/Models/<Name>.ts` | ORM Model |
|
|
48
|
+
| `make:job <Name>` | `app/Jobs/<Name>.ts` | Queue Job |
|
|
49
|
+
| `make:middleware <Name>` | `app/Http/Middleware/<Name>Middleware.ts` | Middleware class |
|
|
50
|
+
| `make:request <Name>` | `app/Http/Requests/<Name>Request.ts` | FormRequest class |
|
|
51
|
+
| `make:provider <Name>` | `app/Providers/<Name>ServiceProvider.ts` | ServiceProvider |
|
|
52
|
+
| `make:command <Name>` | `app/Commands/<Name>.ts` | Rudder command class |
|
|
53
|
+
| `make:event <Name>` | `app/Events/<Name>.ts` | Event class |
|
|
54
|
+
| `make:listener <Name>` | `app/Listeners/<Name>.ts` | Event listener class |
|
|
55
|
+
| `make:mail <Name>` | `app/Mail/<Name>.ts` | Mailable class |
|
|
56
|
+
| `make:module <Name>` | `app/Modules/<Name>/` | Full module scaffold |
|
|
57
|
+
|
|
58
|
+
All `make:*` commands support `--force` to overwrite existing files.
|
|
59
|
+
|
|
60
|
+
### `module:*` Commands
|
|
61
|
+
|
|
62
|
+
| Command | Description |
|
|
63
|
+
|---------|-------------|
|
|
64
|
+
| `module:publish [module]` | Merge `*.prisma` shards from `app/Modules/` into `prisma/schema.prisma` |
|
|
65
|
+
|
|
66
|
+
`module:publish` options:
|
|
67
|
+
- `--generate` — run `prisma generate` after merging
|
|
68
|
+
- `--migrate` — run `prisma migrate dev` after merging
|
|
69
|
+
- `--name <name>` — migration name when using `--migrate` (default: `auto`)
|
|
70
|
+
|
|
71
|
+
### `vendor:publish`
|
|
72
|
+
|
|
73
|
+
Copies publishable assets (pages, config, migrations) declared by service providers into your application.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm rudder vendor:publish # publish all available assets
|
|
77
|
+
pnpm rudder vendor:publish --list # list available assets without copying
|
|
78
|
+
pnpm rudder vendor:publish --tag=panels-pages # publish by tag
|
|
79
|
+
pnpm rudder vendor:publish --provider=PanelServiceProvider # publish by provider
|
|
80
|
+
pnpm rudder vendor:publish --tag=panels-pages --force # overwrite existing files
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Assets are declared by packages in their service provider's `boot()` method via `this.publishes()`. See `@rudderjs/core` for the `ServiceProvider` API.
|
|
84
|
+
|
|
85
|
+
### Database Commands
|
|
86
|
+
|
|
87
|
+
Laravel-style migration commands that delegate to the appropriate ORM tool. The CLI auto-detects which ORM is installed by checking `package.json` for `@rudderjs/orm-prisma` or `@rudderjs/orm-drizzle`.
|
|
88
|
+
|
|
89
|
+
| Command | Description | Prisma | Drizzle |
|
|
90
|
+
|---|---|---|---|
|
|
91
|
+
| `rudder migrate` | Run pending migrations | `prisma migrate dev` (dev) / `prisma migrate deploy` (prod) | `drizzle-kit migrate` |
|
|
92
|
+
| `rudder migrate:fresh` | Drop all + re-migrate | `prisma migrate reset --force` | `drizzle-kit migrate --force` |
|
|
93
|
+
| `rudder migrate:status` | Show migration status | `prisma migrate status` | `drizzle-kit check` |
|
|
94
|
+
| `rudder make:migration <name>` | Create new migration | `prisma migrate dev --create-only --name <name>` | `drizzle-kit generate --name <name>` |
|
|
95
|
+
| `rudder db:push` | Push schema directly (no migration file) | `prisma db push` | `drizzle-kit push` |
|
|
96
|
+
| `rudder db:generate` | Regenerate DB client | `prisma generate` | No-op (Drizzle schemas are TypeScript) |
|
|
97
|
+
|
|
98
|
+
### `route:list`
|
|
99
|
+
|
|
100
|
+
Lists all registered API routes (from `@rudderjs/router`) and Vike filesystem page routes.
|
|
101
|
+
|
|
102
|
+
## `make:module` Scaffold
|
|
103
|
+
|
|
104
|
+
The `make:module Blog` command creates:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
app/Modules/Blog/
|
|
108
|
+
├── BlogSchema.ts # Zod input/output schemas and types
|
|
109
|
+
├── BlogService.ts # @Injectable() service with CRUD stubs
|
|
110
|
+
├── BlogServiceProvider.ts # ServiceProvider — registers DI + REST routes
|
|
111
|
+
├── Blog.test.ts # Basic schema validation tests
|
|
112
|
+
└── Blog.prisma # Prisma model shard
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
It also auto-registers `BlogServiceProvider` in `bootstrap/providers.ts`.
|
|
116
|
+
|
|
117
|
+
After scaffolding, run `pnpm rudder module:publish --generate` to merge the Prisma shard and regenerate the client.
|
|
118
|
+
|
|
119
|
+
## User-Defined Commands
|
|
120
|
+
|
|
121
|
+
Commands defined in `routes/console.ts` are auto-registered:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { rudder } from '@rudderjs/core'
|
|
125
|
+
|
|
126
|
+
rudder.command('db:seed', async () => {
|
|
127
|
+
await User.create({ name: 'Alice', email: 'alice@example.com' })
|
|
128
|
+
}).description('Seed the database')
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Class-based commands:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { Command, rudder } from '@rudderjs/core'
|
|
135
|
+
|
|
136
|
+
class SeedCommand extends Command {
|
|
137
|
+
readonly signature = 'db:seed {--count=10}'
|
|
138
|
+
readonly description = 'Seed the database'
|
|
139
|
+
|
|
140
|
+
async handle() {
|
|
141
|
+
const count = Number(this.option('count') ?? 10)
|
|
142
|
+
this.info(`Seeding ${count} records...`)
|
|
143
|
+
// ...
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
rudder.register(SeedCommand)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Notes
|
|
151
|
+
|
|
152
|
+
- The CLI must be run from (or below) a directory containing `bootstrap/app.ts`
|
|
153
|
+
- All `make:*` generators use `--force` to overwrite existing files
|
|
154
|
+
- `make:controller` appends `Controller` suffix if missing; `make:middleware` appends `Middleware`; `make:request` appends `Request`; `make:provider` appends `ServiceProvider`
|
|
155
|
+
- `module:publish` uses `// <rudderjs:modules:start>` / `// <rudderjs:modules:end>` markers to replace previously merged content
|
|
156
|
+
- Built with [Commander.js](https://github.com/tj/commander.js) and [@clack/prompts](https://github.com/bombshell-dev/clack)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/commands/make/agent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqBhD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `import { Agent } from '@rudderjs/ai'
|
|
7
|
+
import type { HasTools, AnyTool } from '@rudderjs/ai'
|
|
8
|
+
|
|
9
|
+
export class ${className} extends Agent implements HasTools {
|
|
10
|
+
instructions(): string {
|
|
11
|
+
return 'You are a helpful assistant.'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// model(): string | undefined { return 'anthropic/claude-sonnet-4-5' }
|
|
15
|
+
|
|
16
|
+
tools(): AnyTool[] {
|
|
17
|
+
return []
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
export function makeAgent(program) {
|
|
23
|
+
program
|
|
24
|
+
.command('make:agent <name>')
|
|
25
|
+
.description('Create a new AI agent class')
|
|
26
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
27
|
+
.action(async (name, opts) => {
|
|
28
|
+
const className = name.endsWith('Agent') ? name : `${name}Agent`;
|
|
29
|
+
const relPath = `app/Agents/${className}.ts`;
|
|
30
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
31
|
+
if (existsSync(outPath) && !opts.force) {
|
|
32
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
33
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
37
|
+
await writeFile(outPath, stub(className));
|
|
38
|
+
console.log(chalk.green(' ✔ Agent created:'), chalk.cyan(relPath));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AC;QAED,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAClD,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QAEzC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/make/command.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBzC;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkBrD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { log } from '@clack/prompts';
|
|
5
|
+
export function stub(name) {
|
|
6
|
+
// Convert PascalCase to kebab:case for default signature, e.g. SendEmails → send:emails
|
|
7
|
+
const kebab = name
|
|
8
|
+
.replace(/([A-Z])/g, (m, l, i) => (i === 0 ? l : `-${l}`))
|
|
9
|
+
.toLowerCase();
|
|
10
|
+
return `import { Command } from '@rudderjs/rudder'
|
|
11
|
+
|
|
12
|
+
export class ${name} extends Command {
|
|
13
|
+
readonly signature = '${kebab} {--force : Force the operation}'
|
|
14
|
+
readonly description = 'Description of ${name}'
|
|
15
|
+
|
|
16
|
+
async handle(): Promise<void> {
|
|
17
|
+
this.info('Running ${name}...')
|
|
18
|
+
|
|
19
|
+
const force = this.option('force')
|
|
20
|
+
if (force) this.comment(' Force flag is set')
|
|
21
|
+
|
|
22
|
+
// TODO: implement
|
|
23
|
+
|
|
24
|
+
this.info('Done.')
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
export function makeCommandCmd(program) {
|
|
30
|
+
program
|
|
31
|
+
.command('make:command <name>')
|
|
32
|
+
.description('Create a new rudder command class')
|
|
33
|
+
.option('-f, --force', 'Overwrite existing file')
|
|
34
|
+
.action(async (name, opts) => {
|
|
35
|
+
const filePath = resolve(process.cwd(), `app/Commands/${name}.ts`);
|
|
36
|
+
if (existsSync(filePath) && !opts.force) {
|
|
37
|
+
log.error(`File already exists: app/Commands/${name}.ts\nUse --force to overwrite.`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
await mkdir(resolve(process.cwd(), 'app/Commands'), { recursive: true });
|
|
41
|
+
await writeFile(filePath, stub(name));
|
|
42
|
+
log.success(`Created app/Commands/${name}.ts`);
|
|
43
|
+
log.info(`Register it in routes/console.ts:\n rudder.register(${name})`);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/commands/make/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEpC,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,wFAAwF;IACxF,MAAM,KAAK,GAAG,IAAI;SACf,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACzD,WAAW,EAAE,CAAA;IAEhB,OAAO;;eAEM,IAAI;4BACS,KAAK;2CACU,IAAI;;;yBAGtB,IAAI;;;;;;;;;;CAU5B,CAAA;AACD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO;SACJ,OAAO,CAAC,qBAAqB,CAAC;SAC9B,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,aAAa,EAAE,yBAAyB,CAAC;SAChD,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,IAAyB,EAAE,EAAE;QACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,IAAI,KAAK,CAAC,CAAA;QAElE,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACxC,GAAG,CAAC,KAAK,CAAC,qCAAqC,IAAI,gCAAgC,CAAC,CAAA;YACpF,OAAM;QACR,CAAC;QAED,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACxE,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrC,GAAG,CAAC,OAAO,CAAC,wBAAwB,IAAI,KAAK,CAAC,CAAA;QAC9C,GAAG,CAAC,IAAI,CAAC,wDAAwD,IAAI,GAAG,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
export declare function stub(className: string, prefix: string): string;
|
|
3
|
+
export declare function derivePrefix(className: string): string;
|
|
4
|
+
export declare function makeController(program: Command): void;
|
|
5
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/commands/make/controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAY9D;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsBrD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className, prefix) {
|
|
6
|
+
return `import { Controller, Get } from '@rudderjs/router'
|
|
7
|
+
import type { Context } from '@rudderjs/core'
|
|
8
|
+
|
|
9
|
+
@Controller('${prefix}')
|
|
10
|
+
export class ${className} {
|
|
11
|
+
@Get('/')
|
|
12
|
+
async index(_ctx: Context) {
|
|
13
|
+
return []
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
export function derivePrefix(className) {
|
|
19
|
+
const base = className.replace(/Controller$/, '');
|
|
20
|
+
// PascalCase → kebab-case, then pluralise
|
|
21
|
+
const kebab = base
|
|
22
|
+
.replace(/([A-Z])/g, (m, l, i) => (i === 0 ? l : `-${l}`))
|
|
23
|
+
.toLowerCase();
|
|
24
|
+
return `/${kebab}s`;
|
|
25
|
+
}
|
|
26
|
+
export function makeController(program) {
|
|
27
|
+
program
|
|
28
|
+
.command('make:controller <name>')
|
|
29
|
+
.description('Create a new controller class')
|
|
30
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
31
|
+
.action(async (name, opts) => {
|
|
32
|
+
const className = name.endsWith('Controller') ? name : `${name}Controller`;
|
|
33
|
+
const prefix = derivePrefix(className);
|
|
34
|
+
const relPath = `app/Http/Controllers/${className}.ts`;
|
|
35
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
36
|
+
if (existsSync(outPath) && !opts.force) {
|
|
37
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
38
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
42
|
+
await writeFile(outPath, stub(className, prefix));
|
|
43
|
+
console.log(chalk.green(' ✔ Controller created:'), chalk.cyan(relPath));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/commands/make/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,IAAI,CAAC,SAAiB,EAAE,MAAc;IACpD,OAAO;;;eAGM,MAAM;eACN,SAAS;;;;;;CAMvB,CAAA;AACD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;IACjD,0CAA0C;IAC1C,MAAM,KAAK,GAAG,IAAI;SACf,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CA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CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/commands/make/event.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAO9C;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqBhD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `export class ${className} {
|
|
7
|
+
constructor(
|
|
8
|
+
// public readonly userId: string,
|
|
9
|
+
) {}
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
export function makeEvent(program) {
|
|
14
|
+
program
|
|
15
|
+
.command('make:event <name>')
|
|
16
|
+
.description('Create a new event class')
|
|
17
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
18
|
+
.action(async (name, opts) => {
|
|
19
|
+
const className = name;
|
|
20
|
+
const relPath = `app/Events/${className}.ts`;
|
|
21
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
22
|
+
if (existsSync(outPath) && !opts.force) {
|
|
23
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
24
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
28
|
+
await writeFile(outPath, stub(className));
|
|
29
|
+
console.log(chalk.green(' ✔ Event created:'), chalk.cyan(relPath));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
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C,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../../../src/commands/make/job.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqB9C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `import { Job } from '@rudderjs/queue'
|
|
7
|
+
|
|
8
|
+
export class ${className} extends Job {
|
|
9
|
+
static queue = 'default'
|
|
10
|
+
static retries = 3
|
|
11
|
+
|
|
12
|
+
constructor(/* inject payload here */) {
|
|
13
|
+
super()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async handle(): Promise<void> {
|
|
17
|
+
// TODO: implement job logic
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
export function makeJob(program) {
|
|
23
|
+
program
|
|
24
|
+
.command('make:job <name>')
|
|
25
|
+
.description('Create a new queue job class')
|
|
26
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
27
|
+
.action(async (name, opts) => {
|
|
28
|
+
const className = name;
|
|
29
|
+
const relPath = `app/Jobs/${className}.ts`;
|
|
30
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
31
|
+
if (existsSync(outPath) && !opts.force) {
|
|
32
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
33
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
37
|
+
await writeFile(outPath, stub(className));
|
|
38
|
+
console.log(chalk.green(' ✔ Job created:'), chalk.cyan(relPath));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.js","sourceRoot":"","sources":["../../../src/commands/make/job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,IAAI,CAAC,SAAiB;IACpC,OAAO;;eAEM,SAAS;;;;;;;;;;;;CAYvB,CAAA;AACD,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,OAAgB;IACtC,OAAO;SACJ,OAAO,CAAC,iBAAiB,CAAC;SAC1B,WAAW,CAAC,8BAA8B,CAAC;SAC3C,MAAM,CAAC,aAAa,EAAE,kCAAkC,CAAC;SACzD,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,IAAyB,EAAE,EAAE;QACxD,MAAM,SAAS,GAAG,IAAI,CAAA;QACtB,MAAM,OAAO,GAAK,YAAY,SAAS,KAAK,CAAA;QAC5C,MAAM,OAAO,GAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAA;QAEjD,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC,CAAA;YAC1D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC,CAAA;YACzD,OAAM;QACR,CAAC;QAED,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAClD,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QAEzC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACnE,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/commands/make/listener.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS9C;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqBnD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `import type { Listener } from '@rudderjs/core'
|
|
7
|
+
|
|
8
|
+
export class ${className} implements Listener {
|
|
9
|
+
async handle(event: unknown): Promise<void> {
|
|
10
|
+
// TODO: implement listener logic
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
}
|
|
15
|
+
export function makeListener(program) {
|
|
16
|
+
program
|
|
17
|
+
.command('make:listener <name>')
|
|
18
|
+
.description('Create a new event listener class')
|
|
19
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
20
|
+
.action(async (name, opts) => {
|
|
21
|
+
const className = name;
|
|
22
|
+
const relPath = `app/Listeners/${className}.ts`;
|
|
23
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
24
|
+
if (existsSync(outPath) && !opts.force) {
|
|
25
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
26
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
30
|
+
await writeFile(outPath, stub(className));
|
|
31
|
+
console.log(chalk.green(' ✔ Listener created:'), chalk.cyan(relPath));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/commands/make/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,IAAI,CAAC,SAAiB;IACpC,OAAO;;eAEM,SAAS;;;;;CAKvB,CAAA;AACD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO;SACJ,OAAO,CAAC,sBAAsB,CAAC;SAC/B,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,aAAa,EAAE,kCAAkC,CAAC;SACzD,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,IAAyB,EAAE,EAAE;QACxD,MAAM,SAAS,GAAG,IAAI,CAAA;QACtB,MAAM,OAAO,GAAK,iBAAiB,SAAS,KAAK,CAAA;QACjD,MAAM,OAAO,GAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAA;QAEjD,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC,CAAA;YAC1D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC,CAAA;YACzD,OAAM;QACR,CAAC;QAED,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAClD,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QAEzC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,uBAAuB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mail.d.ts","sourceRoot":"","sources":["../../../src/commands/make/mail.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB9C;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqB/C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `import { Mailable } from '@rudderjs/mail'
|
|
7
|
+
|
|
8
|
+
export class ${className} extends Mailable {
|
|
9
|
+
constructor(/* inject data here */) {
|
|
10
|
+
super()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
build(): this {
|
|
14
|
+
return this
|
|
15
|
+
.subject('Your subject here')
|
|
16
|
+
.html('<p>Your HTML content here</p>')
|
|
17
|
+
.text('Your plain text content here')
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
export function makeMail(program) {
|
|
23
|
+
program
|
|
24
|
+
.command('make:mail <name>')
|
|
25
|
+
.description('Create a new mailable class')
|
|
26
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
27
|
+
.action(async (name, opts) => {
|
|
28
|
+
const className = name;
|
|
29
|
+
const relPath = `app/Mail/${className}.ts`;
|
|
30
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
31
|
+
if (existsSync(outPath) && !opts.force) {
|
|
32
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
33
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
37
|
+
await writeFile(outPath, stub(className));
|
|
38
|
+
console.log(chalk.green(' ✔ Mailable created:'), chalk.cyan(relPath));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=mail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mail.js","sourceRoot":"","sources":["../../../src/commands/make/mail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,IAAI,CAAC,SAAiB;IACpC,OAAO;;eAEM,SAAS;;;;;;;;;;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AAE,MAAM,GAAG,MAAM,CAoB9C;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqBpD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
export function stub(className) {
|
|
6
|
+
return `import { McpPrompt, Description } from '@rudderjs/mcp'
|
|
7
|
+
import type { McpPromptMessage } from '@rudderjs/mcp'
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
|
|
10
|
+
@Description('Describe what this prompt does.')
|
|
11
|
+
export class ${className} extends McpPrompt {
|
|
12
|
+
arguments() {
|
|
13
|
+
return z.object({
|
|
14
|
+
// Define your prompt arguments here
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async handle(args: Record<string, unknown>): Promise<McpPromptMessage[]> {
|
|
19
|
+
return [
|
|
20
|
+
{ role: 'user', content: 'Summarize the following data...' },
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
export function makeMcpPrompt(program) {
|
|
27
|
+
program
|
|
28
|
+
.command('make:mcp-prompt <name>')
|
|
29
|
+
.description('Create a new MCP prompt class')
|
|
30
|
+
.option('-f, --force', 'Overwrite if file already exists')
|
|
31
|
+
.action(async (name, opts) => {
|
|
32
|
+
const className = name.endsWith('Prompt') ? name : `${name}Prompt`;
|
|
33
|
+
const relPath = `app/Mcp/Prompts/${className}.ts`;
|
|
34
|
+
const outPath = resolve(process.cwd(), relPath);
|
|
35
|
+
if (existsSync(outPath) && !opts.force) {
|
|
36
|
+
console.error(chalk.red(` ✗ Already exists: ${relPath}`));
|
|
37
|
+
console.error(chalk.dim(' Use --force to overwrite.'));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
41
|
+
await writeFile(outPath, stub(className));
|
|
42
|
+
console.log(chalk.green(' ✔ MCP prompt created:'), chalk.cyan(relPath));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=mcp-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-prompt.js","sourceRoot":"","sources":["../../../src/commands/make/mcp-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,IAAI,CAAC,SAAiB;IACpC,OAAO;;;;;eAKM,SAAS;;;;;;;;;;;;;CAavB,CAAA;AACD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO;SACJ,OAAO,CAAC,wBAAwB,CAAC;SACjC,WAAW,CAAC,+BAA+B,CAAC;SAC5C,MAAM,CAAC,aAAa,EAAE,kCAAkC,CAAC;SACzD,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,IAAyB,EAAE,EAAE;QACxD,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,QAAQ,CAAA;QAClE,MAAM,OAAO,GAAK,mBAAmB,SAAS,KAAK,CAAA;QACnD,MAAM,OAAO,GAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAA;QAEjD,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,uBA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