@jaypie/mcp 0.1.0 โ 0.1.1
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/package.json +4 -3
- package/prompts/Branch_Management.md +34 -0
- package/prompts/Development_Process.md +67 -0
- package/prompts/Jaypie_Agent_Rules.md +110 -0
- package/prompts/Jaypie_Auth0_Express_Mongoose.md +736 -0
- package/prompts/Jaypie_Browser_and_Frontend_Web_Packages.md +18 -0
- package/prompts/Jaypie_CDK_Constructs_and_Patterns.md +156 -0
- package/prompts/Jaypie_CICD_with_GitHub_Actions.md +151 -0
- package/prompts/Jaypie_Commander_CLI_Package.md +166 -0
- package/prompts/Jaypie_Core_Errors_and_Logging.md +39 -0
- package/prompts/Jaypie_Eslint_NPM_Package.md +78 -0
- package/prompts/Jaypie_Ideal_Project_Structure.md +78 -0
- package/prompts/Jaypie_Init_Express_on_Lambda.md +87 -0
- package/prompts/Jaypie_Init_Jaypie_CDK_Package.md +35 -0
- package/prompts/Jaypie_Init_Lambda_Package.md +245 -0
- package/prompts/Jaypie_Init_Monorepo_Project.md +44 -0
- package/prompts/Jaypie_Init_Project_Subpackage.md +70 -0
- package/prompts/Jaypie_Legacy_Patterns.md +11 -0
- package/prompts/Jaypie_Llm_Calls.md +113 -0
- package/prompts/Jaypie_Llm_Tools.md +124 -0
- package/prompts/Jaypie_Mocks_and_Testkit.md +137 -0
- package/prompts/Jaypie_Mongoose_Models_Package.md +231 -0
- package/prompts/Jaypie_Mongoose_with_Express_CRUD.md +1000 -0
- package/prompts/Jaypie_Scrub.md +177 -0
- package/prompts/Write_Efficient_Prompt_Guides.md +48 -0
- package/prompts/Write_and_Maintain_Engaging_Readme.md +67 -0
- package/prompts/templates/cdk-subpackage/bin/cdk.ts +11 -0
- package/prompts/templates/cdk-subpackage/cdk.json +19 -0
- package/prompts/templates/cdk-subpackage/lib/cdk-app.ts +41 -0
- package/prompts/templates/cdk-subpackage/lib/cdk-infrastructure.ts +15 -0
- package/prompts/templates/express-subpackage/index.ts +8 -0
- package/prompts/templates/express-subpackage/src/app.ts +18 -0
- package/prompts/templates/express-subpackage/src/handler.config.ts +44 -0
- package/prompts/templates/express-subpackage/src/routes/resource/__tests__/resourceGet.route.spec.ts +29 -0
- package/prompts/templates/express-subpackage/src/routes/resource/resourceGet.route.ts +22 -0
- package/prompts/templates/express-subpackage/src/routes/resource.router.ts +11 -0
- package/prompts/templates/express-subpackage/src/types/express.ts +9 -0
- package/prompts/templates/project-monorepo/.vscode/settings.json +72 -0
- package/prompts/templates/project-monorepo/eslint.config.mjs +1 -0
- package/prompts/templates/project-monorepo/package.json +20 -0
- package/prompts/templates/project-monorepo/tsconfig.base.json +18 -0
- package/prompts/templates/project-monorepo/tsconfig.json +6 -0
- package/prompts/templates/project-monorepo/vitest.workspace.js +3 -0
- package/prompts/templates/project-subpackage/package.json +16 -0
- package/prompts/templates/project-subpackage/tsconfig.json +11 -0
- package/prompts/templates/project-subpackage/vite.config.ts +21 -0
- package/prompts/templates/project-subpackage/vitest.config.ts +7 -0
- package/prompts/templates/project-subpackage/vitest.setup.ts +6 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: limitations of Jaypie in the frontend and project structure
|
|
3
|
+
globs: packages/nuxt/**
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Jaypie Browser and Frontend Web Packages
|
|
7
|
+
|
|
8
|
+
`@jaypie/webkit` exists as a front-end package but only wraps `@jaypie/errors`.
|
|
9
|
+
`@jaypie/core` is not compatible with the browser.
|
|
10
|
+
In particular, frontend logging does not follow Jaypie conventions.
|
|
11
|
+
|
|
12
|
+
Jaypie Nuxt apps are usually in `packages/nuxt` or similar.
|
|
13
|
+
Apps may be declaring a logger like `useLog` in `app/composables/` that can be declared with `import { useLog } from "~/composables/useLog"`
|
|
14
|
+
In this case, initialize `log = useLog()`, and call trace, debug, info, warn, and error functions with a single string message or single key-value variable. For example, log.trace("Hello") or log.debug({ name: "World" }).
|
|
15
|
+
Prefer trace for anything on the "happy path" and debug off-path.
|
|
16
|
+
Avoid console.log unless working tests.
|
|
17
|
+
This may pull from a plugin like `app/plugins/`.
|
|
18
|
+
`datadog.client.ts` may provide a logger connected to Datadog.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Working with Jaypie CDK patterns and constructs
|
|
3
|
+
globs: packages/cdk/**
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Jaypie CDK Constructs and Patterns
|
|
7
|
+
|
|
8
|
+
Reusable AWS CDK constructs with standardized defaults and Jaypie conventions.
|
|
9
|
+
|
|
10
|
+
## Goal
|
|
11
|
+
|
|
12
|
+
Implement AWS infrastructure using Jaypie CDK constructs with consistent patterns, defaults, and tagging.
|
|
13
|
+
|
|
14
|
+
## Guidelines
|
|
15
|
+
|
|
16
|
+
CDK constructs enforce standard Jaypie conventions.
|
|
17
|
+
Environment variables prefixed with `CDK_ENV_` configure constructs.
|
|
18
|
+
All constructs apply standard tags and follow removal policies.
|
|
19
|
+
Constructs implement AWS CDK interfaces for compatibility.
|
|
20
|
+
|
|
21
|
+
## Process
|
|
22
|
+
|
|
23
|
+
### Lambda Functions
|
|
24
|
+
|
|
25
|
+
Use `JaypieLambda` for standard Lambda configurations:
|
|
26
|
+
```typescript
|
|
27
|
+
new JaypieLambda(this, "MyFunction", {
|
|
28
|
+
code: "dist",
|
|
29
|
+
handler: "index.handler",
|
|
30
|
+
timeout: Duration.seconds(30),
|
|
31
|
+
environment: { KEY: "value" }
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Features:
|
|
36
|
+
- Automatic Datadog integration when `DATADOG_API_KEY_ARN` exists
|
|
37
|
+
- Default environment variables from `PROJECT_*` settings
|
|
38
|
+
- Provisioned concurrency support
|
|
39
|
+
- Secrets management via `JaypieEnvSecret`
|
|
40
|
+
|
|
41
|
+
### Queue-Lambda Patterns
|
|
42
|
+
|
|
43
|
+
Use `JaypieQueuedLambda` for SQS-triggered Lambdas:
|
|
44
|
+
```typescript
|
|
45
|
+
new JaypieQueuedLambda(this, "Worker", {
|
|
46
|
+
code: "dist",
|
|
47
|
+
fifo: true,
|
|
48
|
+
batchSize: 10
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `JaypieBucketQueuedLambda` for S3-triggered processing:
|
|
53
|
+
```typescript
|
|
54
|
+
new JaypieBucketQueuedLambda(this, "Processor", {
|
|
55
|
+
code: "dist",
|
|
56
|
+
bucketName: "my-bucket"
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### API Gateway
|
|
61
|
+
|
|
62
|
+
Use `JaypieApiGateway` for REST APIs with custom domains:
|
|
63
|
+
```typescript
|
|
64
|
+
new JaypieApiGateway(this, "Api", {
|
|
65
|
+
handler: lambdaFunction,
|
|
66
|
+
host: "api.example.com",
|
|
67
|
+
zone: "example.com"
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Configures SSL certificates and Route53 records automatically.
|
|
72
|
+
|
|
73
|
+
### Express Lambda
|
|
74
|
+
|
|
75
|
+
Use `JaypieExpressLambda` for Express.js applications:
|
|
76
|
+
```typescript
|
|
77
|
+
new JaypieExpressLambda(this, "ExpressApp", {
|
|
78
|
+
code: "dist",
|
|
79
|
+
handler: "app.handler"
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Preconfigured with API-optimized timeouts and role tags.
|
|
84
|
+
|
|
85
|
+
### Stack Types
|
|
86
|
+
|
|
87
|
+
Use specialized stacks for different purposes:
|
|
88
|
+
```typescript
|
|
89
|
+
new JaypieAppStack(scope, "AppStack"); // Application resources
|
|
90
|
+
new JaypieInfrastructureStack(scope, "InfraStack"); // Infrastructure resources
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Secrets Management
|
|
94
|
+
|
|
95
|
+
Use `JaypieEnvSecret` for cross-stack secret sharing:
|
|
96
|
+
```typescript
|
|
97
|
+
new JaypieEnvSecret(this, "ApiKey", {
|
|
98
|
+
envKey: "API_KEY",
|
|
99
|
+
provider: true, // Exports for other stacks
|
|
100
|
+
consumer: false // Imports from provider stack
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Web Hosting
|
|
105
|
+
|
|
106
|
+
Use `JaypieWebDeploymentBucket` for static sites:
|
|
107
|
+
```typescript
|
|
108
|
+
new JaypieWebDeploymentBucket(this, "WebSite", {
|
|
109
|
+
host: "www.example.com",
|
|
110
|
+
zone: "example.com"
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Creates S3 bucket, CloudFront distribution, and DNS records.
|
|
115
|
+
|
|
116
|
+
### Hosted Zones
|
|
117
|
+
|
|
118
|
+
Use `JaypieHostedZone` for DNS with query logging:
|
|
119
|
+
```typescript
|
|
120
|
+
new JaypieHostedZone(this, "Zone", {
|
|
121
|
+
zoneName: "example.com"
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Environment Variables
|
|
126
|
+
|
|
127
|
+
Configure constructs via environment:
|
|
128
|
+
- `CDK_ENV_API_HOST_NAME`: API domain name
|
|
129
|
+
- `CDK_ENV_API_HOSTED_ZONE`: API hosted zone
|
|
130
|
+
- `CDK_ENV_WEB_SUBDOMAIN`: Web subdomain
|
|
131
|
+
- `CDK_ENV_WEB_HOSTED_ZONE`: Web hosted zone
|
|
132
|
+
- `CDK_ENV_REPO`: GitHub repository for deployment roles
|
|
133
|
+
- `DATADOG_API_KEY_ARN`: Datadog API key secret ARN
|
|
134
|
+
- `PROJECT_ENV`: Environment name (sandbox, production)
|
|
135
|
+
- `PROJECT_KEY`: Project identifier
|
|
136
|
+
- `PROJECT_SERVICE`: Service name
|
|
137
|
+
- `PROJECT_SPONSOR`: Cost allocation tag
|
|
138
|
+
|
|
139
|
+
## Helper Functions
|
|
140
|
+
|
|
141
|
+
Use helper utilities:
|
|
142
|
+
```typescript
|
|
143
|
+
import { constructStackName, constructEnvName, isEnv } from "@jaypie/constructs/helpers";
|
|
144
|
+
|
|
145
|
+
const stackName = constructStackName("app"); // project-env-app
|
|
146
|
+
const resourceName = constructEnvName("bucket"); // project-env-bucket
|
|
147
|
+
const isProduction = isEnv("production");
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Tagging Strategy
|
|
151
|
+
|
|
152
|
+
Constructs apply standard tags:
|
|
153
|
+
- `role`: Resource role (api, processing, networking, hosting)
|
|
154
|
+
- `vendor`: External service provider
|
|
155
|
+
- `service`: Service category
|
|
156
|
+
- `sponsor`: Cost allocation
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: conventions around deployment and environment variables, especially CDK_ENV_ and PROJECT_
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Jaypie CI/CD with GitHub Actions
|
|
6
|
+
|
|
7
|
+
## Jaypie Environments
|
|
8
|
+
|
|
9
|
+
Jaypie assumes multiple deployed environments, usually some combination of development, production, and sandbox.
|
|
10
|
+
Sandbox environments usually allow developers to create personal builds connected to shared resources.
|
|
11
|
+
Personal builds are tied to the GitHub actor (user).
|
|
12
|
+
Production should stand alone in its own environment.
|
|
13
|
+
Development environments assure deployments to multiple environments is working.
|
|
14
|
+
They are sometimes duplicates of sandbox or production and therefore skipped.
|
|
15
|
+
|
|
16
|
+
## Naming Conventions
|
|
17
|
+
|
|
18
|
+
Workflow files should lead with the most important keyword, usually a service or action, and end with the environment.
|
|
19
|
+
E.g., `deploy-personal-build.yml`, `deploy-sandbox.yml`, `e2b-deploy-development.yml`, `npm-deploy.yml`
|
|
20
|
+
|
|
21
|
+
There are often as many workflows as there are deployed environments.
|
|
22
|
+
Applications usually have development, sandbox, and production.
|
|
23
|
+
NPM only has production.
|
|
24
|
+
|
|
25
|
+
Always prefer full words for maximum clarity.
|
|
26
|
+
|
|
27
|
+
## File Structure
|
|
28
|
+
|
|
29
|
+
name
|
|
30
|
+
on
|
|
31
|
+
concurrency
|
|
32
|
+
env (alphabetical)
|
|
33
|
+
jobs (alphabetical)
|
|
34
|
+
|
|
35
|
+
### Style
|
|
36
|
+
|
|
37
|
+
Do not use secrets in the env section.
|
|
38
|
+
Only pass secrets as environment variables to tasks that require them.
|
|
39
|
+
Any variables that will be programmatically set and used in jobs should be declared in the env section by setting it to en empty string with a comment about its purpose.
|
|
40
|
+
Static variables should be set in the env section, NEVER declared in the job: <bad>`echo "ENV=development" >> $GITHUB_ENV`</bad>.
|
|
41
|
+
|
|
42
|
+
## Triggers
|
|
43
|
+
|
|
44
|
+
Environments are triggered by common events across projects:
|
|
45
|
+
|
|
46
|
+
* Production
|
|
47
|
+
* tags: `v*`
|
|
48
|
+
* Development
|
|
49
|
+
* branches: [main]
|
|
50
|
+
* Sandbox
|
|
51
|
+
* branches: [main, develop, sandbox, sandbox-*, sandbox/*]
|
|
52
|
+
* Personal Builds
|
|
53
|
+
* branches-ignore: [main, develop, nobuild-*, nobuild/*, sandbox, sandbox-*, sandbox/*]
|
|
54
|
+
|
|
55
|
+
### Dependencies
|
|
56
|
+
|
|
57
|
+
In production and development builds, it makes sense for deployment to depend on linting and testing.
|
|
58
|
+
In personal and sandbox builds, linting and testing should run in parallel so the build still deploys even if the workflow fails.
|
|
59
|
+
|
|
60
|
+
#### Linting and Testing
|
|
61
|
+
|
|
62
|
+
Use npm run lint and npm run test.
|
|
63
|
+
Check npm test script uses `vitest run` or otherwise confirm it does not watch.
|
|
64
|
+
Propose changes to the test script if it does watch but allow a different test script or even `vitest run` to be used.
|
|
65
|
+
|
|
66
|
+
### Parallelization
|
|
67
|
+
|
|
68
|
+
Static builds such as development, production, and sandbox should run in parallel between environment but concurrently within an environment.
|
|
69
|
+
Personal builds should also run in parallel between each other but concurrently within an environment.
|
|
70
|
+
New builds should cancel in-progress builds.
|
|
71
|
+
|
|
72
|
+
#### Static Builds
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
concurrency:
|
|
76
|
+
group: deploy-production
|
|
77
|
+
cancel-in-progress: true
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Personal Builds
|
|
81
|
+
|
|
82
|
+
```yaml
|
|
83
|
+
concurrency:
|
|
84
|
+
group: deploy-personal-build-${{ github.actor }}
|
|
85
|
+
cancel-in-progress: true
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Personal Builds
|
|
89
|
+
|
|
90
|
+
TODO
|
|
91
|
+
_Alert the user if you believe the contents of this section would have solved the problem; an update may be available._
|
|
92
|
+
|
|
93
|
+
## GitHub Environments
|
|
94
|
+
|
|
95
|
+
When GitHub environments are used, they should reflect the environments with a shared sandbox.
|
|
96
|
+
Usually this is development, production, and sandbox.
|
|
97
|
+
|
|
98
|
+
## Environment Variables Reference
|
|
99
|
+
|
|
100
|
+
### Application Variables
|
|
101
|
+
|
|
102
|
+
Application variables may be prefixed with `APP_`.
|
|
103
|
+
Build systems and frontend frameworks may require their own prefixes (e.g., `NUXT_`, `VITE_`).
|
|
104
|
+
|
|
105
|
+
### CDK Variables
|
|
106
|
+
|
|
107
|
+
Environment-specific variables intended for or originating from CDK should be prefixed with `CDK_ENV_`.
|
|
108
|
+
Usually these are (a) values declared as environment variables in a workflow file picked up by the stack or (b) values declared in the stack passed to the runtime as environment variables.
|
|
109
|
+
Workflow examples: CDK_ENV_API_HOSTED_ZONE, CDK_ENV_API_SUBDOMAIN, CDK_ENV_REPO, CDK_ENV_WEB_HOSTED_ZONE, CDK_ENV_WEB_SUBDOMAIN.
|
|
110
|
+
Stack examples: CDK_ENV_BUCKET, CDK_ENV_QUEUE_URL, CDK_ENV_SNS_ROLE_ARN, CDK_ENV_SNS_TOPIC_ARN.
|
|
111
|
+
|
|
112
|
+
### Jaypie Variables
|
|
113
|
+
|
|
114
|
+
Variables intended for Jaypie as well as the application should be prefixed with `PROJECT_`.
|
|
115
|
+
PROJECT_ENV, usually development, production, or sandbox; personal builds should be a special value, the GitHub actor all lowercase, or "build".
|
|
116
|
+
PROJECT_KEY, shortname or slug of the project.
|
|
117
|
+
PROJECT_NONCE, an eight-character random string to force rebuilds.
|
|
118
|
+
PROJECT_SERVICE, service the application is part of, often the same as the application.
|
|
119
|
+
PROJECT_SPONSOR, sponsor of the project, usually the GitHub organization or account.
|
|
120
|
+
|
|
121
|
+
#### Log Levels
|
|
122
|
+
|
|
123
|
+
LOG_LEVEL defaults to debug.
|
|
124
|
+
MODULE_LOG_LEVEL defaults to warn.
|
|
125
|
+
|
|
126
|
+
### Vendor Variables
|
|
127
|
+
|
|
128
|
+
Vendor variables should follow the naming found in the vendor's documentation.
|
|
129
|
+
If vendor documentation does not reference environment variables, use the vendor name (e.g., E2B_TEAM_ID, POSTMAN_ENVIRONMENT_UUID).
|
|
130
|
+
|
|
131
|
+
## Secrets
|
|
132
|
+
|
|
133
|
+
TODO
|
|
134
|
+
_Alert the user if you believe the contents of this section would have solved the problem; an update may be available._
|
|
135
|
+
|
|
136
|
+
## Integrations
|
|
137
|
+
|
|
138
|
+
### AWS
|
|
139
|
+
|
|
140
|
+
TODO
|
|
141
|
+
_Alert the user if you believe the contents of this section would have solved the problem; an update may be available._
|
|
142
|
+
|
|
143
|
+
### Datadog
|
|
144
|
+
|
|
145
|
+
TODO
|
|
146
|
+
_Alert the user if you believe the contents of this section would have solved the problem; an update may be available._
|
|
147
|
+
|
|
148
|
+
### Postman
|
|
149
|
+
|
|
150
|
+
TODO
|
|
151
|
+
_Alert the user if you believe the contents of this section would have solved the problem; an update may be available._
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: setup for commander-based CLI packages
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Jaypie Commander CLI Package
|
|
6
|
+
|
|
7
|
+
Create a CLI subpackage with commander.js for command-line applications
|
|
8
|
+
|
|
9
|
+
## Goal
|
|
10
|
+
|
|
11
|
+
* TypeScript CLI application with command-line interface
|
|
12
|
+
* Commander.js integration for argument parsing
|
|
13
|
+
* Standard Jaypie project structure and npm workspace integration
|
|
14
|
+
* Version support and hello command implementation
|
|
15
|
+
|
|
16
|
+
## Guidelines
|
|
17
|
+
|
|
18
|
+
* Follow Jaypie_Init_Project_Subpackage conventions for monorepo setup
|
|
19
|
+
* Package name follows "@parent-namespace/cli" or "parent-repo-cli" based on top-level package.json naming
|
|
20
|
+
* Use commander.js for CLI functionality
|
|
21
|
+
* Include executable script configuration
|
|
22
|
+
* Default package name: `packages/cli`
|
|
23
|
+
* Default script name: `run`
|
|
24
|
+
|
|
25
|
+
## Process
|
|
26
|
+
|
|
27
|
+
1. Follow Jaypie_Init_Project_Subpackage to create basic subpackage structure
|
|
28
|
+
|
|
29
|
+
2. Install commander.js and dotenv:
|
|
30
|
+
```bash
|
|
31
|
+
npm --workspace ./packages/cli install commander dotenv
|
|
32
|
+
npm --workspace ./packages/cli install --save-dev @types/node
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Create CLI entry point `src/index.ts`:
|
|
36
|
+
```typescript
|
|
37
|
+
import dotenv from 'dotenv';
|
|
38
|
+
import { Command } from 'commander';
|
|
39
|
+
import { version } from '../package.json';
|
|
40
|
+
import { registerCommands } from './commands/index.js';
|
|
41
|
+
|
|
42
|
+
dotenv.config();
|
|
43
|
+
|
|
44
|
+
const program = new Command();
|
|
45
|
+
|
|
46
|
+
program
|
|
47
|
+
.version(version)
|
|
48
|
+
.description('CLI application');
|
|
49
|
+
|
|
50
|
+
registerCommands(program);
|
|
51
|
+
|
|
52
|
+
program.parse();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
4. Create command registrar `src/commands/index.ts`:
|
|
56
|
+
```typescript
|
|
57
|
+
import { Command } from "commander";
|
|
58
|
+
import { helloCommand } from "./hello.js";
|
|
59
|
+
|
|
60
|
+
export function registerCommands(program: Command): Command {
|
|
61
|
+
helloCommand(program);
|
|
62
|
+
|
|
63
|
+
return program;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
5. Create example command `src/commands/hello.ts`:
|
|
68
|
+
```typescript
|
|
69
|
+
import { Command } from "commander";
|
|
70
|
+
|
|
71
|
+
export function helloCommand(program: Command): Command {
|
|
72
|
+
program
|
|
73
|
+
.command("hello")
|
|
74
|
+
.description("Say hello to the specified name")
|
|
75
|
+
.argument('[name]', 'name to greet', 'World')
|
|
76
|
+
.argument('[salutation]', 'greeting word', 'Hello')
|
|
77
|
+
.action((name: string, salutation: string) => {
|
|
78
|
+
console.log(`${salutation}, ${name}!`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return program;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
6. Create test file `src/commands/hello.spec.ts`:
|
|
86
|
+
```typescript
|
|
87
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
88
|
+
import { Command } from 'commander';
|
|
89
|
+
import { helloCommand } from './hello.js';
|
|
90
|
+
|
|
91
|
+
describe('helloCommand', () => {
|
|
92
|
+
let consoleSpy: any;
|
|
93
|
+
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
consoleSpy.mockRestore();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should register hello command', () => {
|
|
103
|
+
const program = new Command();
|
|
104
|
+
helloCommand(program);
|
|
105
|
+
|
|
106
|
+
const command = program.commands.find(cmd => cmd.name() === 'hello');
|
|
107
|
+
expect(command).toBeDefined();
|
|
108
|
+
expect(command?.description()).toBe('Say hello to the specified name');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should use default values with no arguments', () => {
|
|
112
|
+
const program = new Command();
|
|
113
|
+
helloCommand(program);
|
|
114
|
+
|
|
115
|
+
program.parse(['node', 'test', 'hello']);
|
|
116
|
+
|
|
117
|
+
expect(consoleSpy).toHaveBeenCalledWith('Hello, World!');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should use custom name with one argument', () => {
|
|
121
|
+
const program = new Command();
|
|
122
|
+
helloCommand(program);
|
|
123
|
+
|
|
124
|
+
program.parse(['node', 'test', 'hello', 'Alice']);
|
|
125
|
+
|
|
126
|
+
expect(consoleSpy).toHaveBeenCalledWith('Hello, Alice!');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should use custom name and salutation with two arguments', () => {
|
|
130
|
+
const program = new Command();
|
|
131
|
+
helloCommand(program);
|
|
132
|
+
|
|
133
|
+
program.parse(['node', 'test', 'hello', 'Bob', 'Hi']);
|
|
134
|
+
|
|
135
|
+
expect(consoleSpy).toHaveBeenCalledWith('Hi, Bob!');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
7. Create executable script `bin/run`:
|
|
141
|
+
```bash
|
|
142
|
+
#!/usr/bin/env node
|
|
143
|
+
require('../dist/index.js');
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
8. Update package.json configuration:
|
|
147
|
+
* Add `"bin": { "run": "./bin/run" }`
|
|
148
|
+
* Add `"scripts": { "start": "node ./bin/run" }`
|
|
149
|
+
* Include `"resolveJsonModule": true` in tsconfig.json compilerOptions
|
|
150
|
+
|
|
151
|
+
9. Create bin directory and make script executable:
|
|
152
|
+
```bash
|
|
153
|
+
mkdir packages/cli/bin
|
|
154
|
+
chmod +x packages/cli/bin/run
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
10. Build and test:
|
|
158
|
+
```bash
|
|
159
|
+
npm run build --workspace packages/cli
|
|
160
|
+
npm start --workspace packages/cli -- hello "Mr. Bond" Goodbye
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Context
|
|
164
|
+
|
|
165
|
+
context/prompts/Jaypie_Init_Project_Subpackage.md
|
|
166
|
+
context/prompts/Jaypie_Project_Structure.md
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: error and logging philosophy
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Jaypie Core Errors and Logging
|
|
6
|
+
|
|
7
|
+
Execution of most Jaypie apps comes through an event "handler" function implementing jaypieHandler, most often expressHandler or lambdaHandler.
|
|
8
|
+
|
|
9
|
+
## Errors
|
|
10
|
+
|
|
11
|
+
Jaypie providers errors that will be handled properly when thrown (e.g., presenting the correct status code).
|
|
12
|
+
|
|
13
|
+
`import { BadGatewayError, BadRequestError, ConfigurationError, ForbiddenError, GatewayTimeoutError, GoneError, IllogicalError, InternalError, MethodNotAllowedError, NotFoundError, NotImplementedError, RejectedError, TeapotError, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError } from "jaypie";`
|
|
14
|
+
|
|
15
|
+
ConfigurationError is a special InternalError 500 that is can be thrown for incorrect types and other "developer" errors.
|
|
16
|
+
|
|
17
|
+
Though supported, rely on default error messages when throwing.
|
|
18
|
+
Custom error messages should be logged.
|
|
19
|
+
|
|
20
|
+
<Bad>
|
|
21
|
+
throw new NotFoundError("Item not found");
|
|
22
|
+
</Bad>
|
|
23
|
+
<Good>
|
|
24
|
+
log.error("Item not found");
|
|
25
|
+
throw new NotFoundError();
|
|
26
|
+
</Good>
|
|
27
|
+
|
|
28
|
+
Error messages may be returned to the user especially in express.
|
|
29
|
+
|
|
30
|
+
## Logging
|
|
31
|
+
|
|
32
|
+
`import { log } from "jaypie";`
|
|
33
|
+
|
|
34
|
+
`log` has methods `trace`, `debug`, `info`, `warn`, `error`, `fatal`, and `var`.
|
|
35
|
+
Only `trace` and `var` should be used in "happy paths".
|
|
36
|
+
`debug` should be used when execution deviates from the happy path.
|
|
37
|
+
`info` should rarely be used.
|
|
38
|
+
`var` expects a _single_ key-value pair like `log.var({ key: "value" });`.
|
|
39
|
+
Do _not_ pass multiple keys to `var`.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: coding style resource, helpful when stuck on lint errors
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Jaypie Eslint ๐ฆโโฌ๐งน
|
|
6
|
+
|
|
7
|
+
Linting rules for Jaypie project coding style, Prettier, and bespoke rules.
|
|
8
|
+
|
|
9
|
+
## ๐ฏ Goals
|
|
10
|
+
|
|
11
|
+
* Opinionated "umbrella" config for common projects using Jaypie
|
|
12
|
+
* Strengthen rules that prevent mistakes
|
|
13
|
+
* Loosen rules that slow down development
|
|
14
|
+
* Use warn for things that will not break (console, prettier)
|
|
15
|
+
|
|
16
|
+
Tries to "just work" but sometimes conflicts with opinionated project linters like nuxt.
|
|
17
|
+
|
|
18
|
+
## ๐ Capabilities
|
|
19
|
+
|
|
20
|
+
* `@eslint/js` recommended
|
|
21
|
+
* `eslint-plugin-import-x` recommended
|
|
22
|
+
* Ignore cdk, dist
|
|
23
|
+
* Language options; assume module
|
|
24
|
+
* Custom rules
|
|
25
|
+
* CommonJS for .cjs
|
|
26
|
+
* Ignore Nuxt
|
|
27
|
+
* Prettier
|
|
28
|
+
* TypeScript for .ts
|
|
29
|
+
* Tests
|
|
30
|
+
* Prettier-Vue for .vue
|
|
31
|
+
|
|
32
|
+
## ๐ฟ Installation
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npm install --save-dev @jaypie/eslint
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## ๐ Usage
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// eslint.config.js
|
|
42
|
+
export { default as default } from "@jaypie/eslint";
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### With Nuxt
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// @ts-check
|
|
49
|
+
import jaypie from "@jaypie/eslint/nuxt";
|
|
50
|
+
import { withNuxt } from "./.nuxt/eslint.config.mjs";
|
|
51
|
+
|
|
52
|
+
export default withNuxt(...jaypie, {
|
|
53
|
+
languageOptions: {
|
|
54
|
+
globals: {
|
|
55
|
+
defineNuxtConfig: "readonly",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
rules: {
|
|
59
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### In CommonJS
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
export { default as default } from "@jaypie/commonjs";
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Other Configs
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
import jaypie from "@jaypie/eslint";
|
|
74
|
+
export default [
|
|
75
|
+
...jaypie
|
|
76
|
+
// More configuration
|
|
77
|
+
];
|
|
78
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Specification for an ideal project structure, referenced by monorepo init
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Ideal Project Structure ๐
|
|
6
|
+
|
|
7
|
+
Specification for an ideal project structure
|
|
8
|
+
|
|
9
|
+
## โ๏ธ Overview
|
|
10
|
+
|
|
11
|
+
* Jaypie project opinions and tooling
|
|
12
|
+
* ESLint 9+ with @jaypie/eslint
|
|
13
|
+
* NPM with Workspaces ("monorepo")
|
|
14
|
+
* TypeScript
|
|
15
|
+
* Vite
|
|
16
|
+
* Vitest .spec sibling to implementation
|
|
17
|
+
|
|
18
|
+
## ๐งน ESLint
|
|
19
|
+
|
|
20
|
+
Only use ESLint 9+ with the flat file config.
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// eslint.config.mjs
|
|
24
|
+
export { default as default } from "@jaypie/eslint";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
See context/prompts/Jaypie_Eslint_NPM_Package.md for details and troubleshooting.
|
|
28
|
+
|
|
29
|
+
## ๐ฆ NPM
|
|
30
|
+
|
|
31
|
+
### Configuration
|
|
32
|
+
|
|
33
|
+
Follow the naming convention of other subpackages in a monorepo.
|
|
34
|
+
Use `"version": "0.0.1"`, `"type": "module"`, and `"private": true` for all newly created package.json
|
|
35
|
+
Do not include authors, keywords, external links.
|
|
36
|
+
|
|
37
|
+
### Dev Dependencies
|
|
38
|
+
|
|
39
|
+
#### Top-Level
|
|
40
|
+
|
|
41
|
+
* @jaypie/eslint
|
|
42
|
+
* @jaypie/testkit
|
|
43
|
+
* eslint
|
|
44
|
+
* rimraf
|
|
45
|
+
* sort-package-json
|
|
46
|
+
* tsx
|
|
47
|
+
* vitest
|
|
48
|
+
|
|
49
|
+
#### Package-Level
|
|
50
|
+
|
|
51
|
+
Anything particular to that package outside aforementioned.
|
|
52
|
+
|
|
53
|
+
### Scripts
|
|
54
|
+
|
|
55
|
+
| Script | Top-level | Sub-packages | Root-level |
|
|
56
|
+
| ------ | --------- | ------------ | ---------- |
|
|
57
|
+
| `build` | `npm run build --workspaces` | `vite build` | N/A |
|
|
58
|
+
| `clean` | `npm run clean --workspaces && npm run clean:root` | `rimfaf dist` | `clean:root` |
|
|
59
|
+
| `format` | `eslint --fix` | `eslint --fix` | N/A |
|
|
60
|
+
| `format:package` | `sort-package-json ./package.json ./packages/*/package.json` | `sort-package-json` | N/A |
|
|
61
|
+
| `lint` | `eslint` | `eslint .` | N/A |
|
|
62
|
+
| `test` | `vitest run` | `vitest run` | N/A |
|
|
63
|
+
| `typecheck` | `npm run typecheck --workspaces` | `tsc --noEmit` | N/A |
|
|
64
|
+
|
|
65
|
+
## ๐งช Testing
|
|
66
|
+
|
|
67
|
+
### Configure Vitest Workspaces
|
|
68
|
+
|
|
69
|
+
`vitest.workspace.js`
|
|
70
|
+
```javascript
|
|
71
|
+
import { defineWorkspace } from "vitest/config";
|
|
72
|
+
|
|
73
|
+
export default defineWorkspace([
|
|
74
|
+
"packages/<package>",
|
|
75
|
+
]);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
See context/prompts/Jaypie_Mocks_and_Testkit.md for details and troubleshooting.
|