@mockmaster/cli 1.0.7 → 1.0.8
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 +202 -202
- package/package.json +4 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Michael Baker
|
|
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
CHANGED
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
# @mockmaster/cli
|
|
2
|
-
|
|
3
|
-
> File system operations and OpenAPI scenario generation for mock-master
|
|
4
|
-
|
|
5
|
-
Part of the [mock-master](https://github.com/PxPerfectMike/MockMaster) monorepo.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @mockmaster/cli
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Features
|
|
14
|
-
|
|
15
|
-
- **File System Operations** - Save and load scenarios to/from disk
|
|
16
|
-
- **OpenAPI Integration** - Generate scenarios from OpenAPI specifications
|
|
17
|
-
- **Scenario Management** - List, read, write, and delete scenarios
|
|
18
|
-
- **Type Safe** - Full TypeScript support
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
### Generate Scenarios from OpenAPI
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
import { generateScenariosFromSpec } from '@mockmaster/cli'
|
|
26
|
-
import { parseYaml } from '@mockmaster/openapi'
|
|
27
|
-
|
|
28
|
-
// Parse your OpenAPI spec
|
|
29
|
-
const spec = parseYaml(`
|
|
30
|
-
openapi: 3.0.0
|
|
31
|
-
info:
|
|
32
|
-
title: User API
|
|
33
|
-
version: 1.0.0
|
|
34
|
-
paths:
|
|
35
|
-
/users:
|
|
36
|
-
get:
|
|
37
|
-
responses:
|
|
38
|
-
'200':
|
|
39
|
-
content:
|
|
40
|
-
application/json:
|
|
41
|
-
schema:
|
|
42
|
-
type: array
|
|
43
|
-
items:
|
|
44
|
-
type: object
|
|
45
|
-
properties:
|
|
46
|
-
id: { type: integer }
|
|
47
|
-
name: { type: string }
|
|
48
|
-
email: { type: string, format: email }
|
|
49
|
-
`)
|
|
50
|
-
|
|
51
|
-
// Generate scenarios with realistic mock data
|
|
52
|
-
const scenarios = generateScenariosFromSpec(spec, 'user-api')
|
|
53
|
-
|
|
54
|
-
console.log(scenarios[0])
|
|
55
|
-
// Scenario with recordings for each endpoint
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Save Scenarios to Disk
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { writeScenario } from '@mockmaster/cli'
|
|
62
|
-
|
|
63
|
-
// Save scenario to ./scenarios/user-api.json
|
|
64
|
-
await writeScenario('./scenarios', scenario)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Load Scenarios from Disk
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import { readScenario } from '@mockmaster/cli'
|
|
71
|
-
|
|
72
|
-
// Load scenario from disk
|
|
73
|
-
const scenario = await readScenario('./scenarios', 'user-api')
|
|
74
|
-
|
|
75
|
-
if (scenario) {
|
|
76
|
-
console.log('Loaded:', scenario.name)
|
|
77
|
-
console.log('Recordings:', scenario.recordings.length)
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### List All Scenarios
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { listScenarios } from '@mockmaster/cli'
|
|
85
|
-
|
|
86
|
-
// List all scenarios in directory
|
|
87
|
-
const allScenarios = await listScenarios('./scenarios')
|
|
88
|
-
|
|
89
|
-
allScenarios.forEach((s) => {
|
|
90
|
-
console.log(`${s.name}: ${s.recordings.length} recordings`)
|
|
91
|
-
})
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Delete a Scenario
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
import { deleteScenario } from '@mockmaster/cli'
|
|
98
|
-
|
|
99
|
-
// Delete scenario file
|
|
100
|
-
await deleteScenario('./scenarios', 'user-api')
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## API
|
|
104
|
-
|
|
105
|
-
### Generation
|
|
106
|
-
|
|
107
|
-
- `generateScenariosFromSpec(spec: OpenAPISpec, scenarioName: string): Scenario[]` - Generate scenarios from OpenAPI spec with realistic mock data
|
|
108
|
-
|
|
109
|
-
### File Operations
|
|
110
|
-
|
|
111
|
-
- `writeScenario(directory: string, scenario: Scenario): Promise<void>` - Write scenario to disk as JSON
|
|
112
|
-
- `readScenario(directory: string, name: string): Promise<Scenario | null>` - Read scenario from disk
|
|
113
|
-
- `listScenarios(directory: string): Promise<Scenario[]>` - List all scenarios in directory
|
|
114
|
-
- `deleteScenario(directory: string, name: string): Promise<void>` - Delete scenario file
|
|
115
|
-
|
|
116
|
-
## Complete Workflow Example
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { parseYaml } from '@mockmaster/openapi'
|
|
120
|
-
import { generateScenariosFromSpec, writeScenario, readScenario } from '@mockmaster/cli'
|
|
121
|
-
import { createReplayHandler } from '@mockmaster/msw-adapter'
|
|
122
|
-
|
|
123
|
-
// 1. Parse OpenAPI spec
|
|
124
|
-
const spec = parseYaml(openApiYaml)
|
|
125
|
-
|
|
126
|
-
// 2. Generate scenarios with mock data
|
|
127
|
-
const scenarios = generateScenariosFromSpec(spec, 'my-api')
|
|
128
|
-
|
|
129
|
-
// 3. Save to disk
|
|
130
|
-
await writeScenario('./scenarios', scenarios[0])
|
|
131
|
-
|
|
132
|
-
// 4. Later, load from disk
|
|
133
|
-
const loaded = await readScenario('./scenarios', 'my-api')
|
|
134
|
-
|
|
135
|
-
// 5. Create replay handler
|
|
136
|
-
if (loaded) {
|
|
137
|
-
const handler = createReplayHandler(loaded)
|
|
138
|
-
|
|
139
|
-
// 6. Use in tests
|
|
140
|
-
const response = handler({ method: 'GET', path: '/users' })
|
|
141
|
-
console.log(response.body)
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## File Format
|
|
146
|
-
|
|
147
|
-
Scenarios are saved as JSON files:
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
./scenarios/
|
|
151
|
-
├── user-api.json
|
|
152
|
-
├── payment-api.json
|
|
153
|
-
└── notification-api.json
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
Each file contains:
|
|
157
|
-
```json
|
|
158
|
-
{
|
|
159
|
-
"name": "user-api",
|
|
160
|
-
"description": "Generated from User API (1.0.0)",
|
|
161
|
-
"recordings": [
|
|
162
|
-
{
|
|
163
|
-
"request": {
|
|
164
|
-
"method": "GET",
|
|
165
|
-
"url": "https://api.example.com/users",
|
|
166
|
-
"path": "/users",
|
|
167
|
-
"timestamp": 1234567890
|
|
168
|
-
},
|
|
169
|
-
"response": {
|
|
170
|
-
"status": 200,
|
|
171
|
-
"body": [...],
|
|
172
|
-
"headers": {...},
|
|
173
|
-
"timestamp": 1234567890
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
],
|
|
177
|
-
"createdAt": 1234567890,
|
|
178
|
-
"updatedAt": 1234567890
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Use Cases
|
|
183
|
-
|
|
184
|
-
- **Version Control** - Commit scenarios as JSON files
|
|
185
|
-
- **Test Fixtures** - Store test data as scenarios
|
|
186
|
-
- **CI/CD** - Use scenarios in automated tests
|
|
187
|
-
- **Team Sharing** - Share API responses across team
|
|
188
|
-
|
|
189
|
-
## Related Packages
|
|
190
|
-
|
|
191
|
-
- `@mockmaster/openapi` - OpenAPI parsing and generation
|
|
192
|
-
- `@mockmaster/msw-adapter` - Record & replay functionality
|
|
193
|
-
- `@mockmaster/data` - Factory system for generating test data
|
|
194
|
-
|
|
195
|
-
## Links
|
|
196
|
-
|
|
197
|
-
- [Main Documentation](https://github.com/PxPerfectMike/MockMaster)
|
|
198
|
-
- [npm Organization](https://www.npmjs.com/org/mockmaster)
|
|
199
|
-
|
|
200
|
-
## License
|
|
201
|
-
|
|
202
|
-
MIT
|
|
1
|
+
# @mockmaster/cli
|
|
2
|
+
|
|
3
|
+
> File system operations and OpenAPI scenario generation for mock-master
|
|
4
|
+
|
|
5
|
+
Part of the [mock-master](https://github.com/PxPerfectMike/MockMaster) monorepo.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mockmaster/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **File System Operations** - Save and load scenarios to/from disk
|
|
16
|
+
- **OpenAPI Integration** - Generate scenarios from OpenAPI specifications
|
|
17
|
+
- **Scenario Management** - List, read, write, and delete scenarios
|
|
18
|
+
- **Type Safe** - Full TypeScript support
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Generate Scenarios from OpenAPI
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { generateScenariosFromSpec } from '@mockmaster/cli'
|
|
26
|
+
import { parseYaml } from '@mockmaster/openapi'
|
|
27
|
+
|
|
28
|
+
// Parse your OpenAPI spec
|
|
29
|
+
const spec = parseYaml(`
|
|
30
|
+
openapi: 3.0.0
|
|
31
|
+
info:
|
|
32
|
+
title: User API
|
|
33
|
+
version: 1.0.0
|
|
34
|
+
paths:
|
|
35
|
+
/users:
|
|
36
|
+
get:
|
|
37
|
+
responses:
|
|
38
|
+
'200':
|
|
39
|
+
content:
|
|
40
|
+
application/json:
|
|
41
|
+
schema:
|
|
42
|
+
type: array
|
|
43
|
+
items:
|
|
44
|
+
type: object
|
|
45
|
+
properties:
|
|
46
|
+
id: { type: integer }
|
|
47
|
+
name: { type: string }
|
|
48
|
+
email: { type: string, format: email }
|
|
49
|
+
`)
|
|
50
|
+
|
|
51
|
+
// Generate scenarios with realistic mock data
|
|
52
|
+
const scenarios = generateScenariosFromSpec(spec, 'user-api')
|
|
53
|
+
|
|
54
|
+
console.log(scenarios[0])
|
|
55
|
+
// Scenario with recordings for each endpoint
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Save Scenarios to Disk
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { writeScenario } from '@mockmaster/cli'
|
|
62
|
+
|
|
63
|
+
// Save scenario to ./scenarios/user-api.json
|
|
64
|
+
await writeScenario('./scenarios', scenario)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Load Scenarios from Disk
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { readScenario } from '@mockmaster/cli'
|
|
71
|
+
|
|
72
|
+
// Load scenario from disk
|
|
73
|
+
const scenario = await readScenario('./scenarios', 'user-api')
|
|
74
|
+
|
|
75
|
+
if (scenario) {
|
|
76
|
+
console.log('Loaded:', scenario.name)
|
|
77
|
+
console.log('Recordings:', scenario.recordings.length)
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### List All Scenarios
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { listScenarios } from '@mockmaster/cli'
|
|
85
|
+
|
|
86
|
+
// List all scenarios in directory
|
|
87
|
+
const allScenarios = await listScenarios('./scenarios')
|
|
88
|
+
|
|
89
|
+
allScenarios.forEach((s) => {
|
|
90
|
+
console.log(`${s.name}: ${s.recordings.length} recordings`)
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Delete a Scenario
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { deleteScenario } from '@mockmaster/cli'
|
|
98
|
+
|
|
99
|
+
// Delete scenario file
|
|
100
|
+
await deleteScenario('./scenarios', 'user-api')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## API
|
|
104
|
+
|
|
105
|
+
### Generation
|
|
106
|
+
|
|
107
|
+
- `generateScenariosFromSpec(spec: OpenAPISpec, scenarioName: string): Scenario[]` - Generate scenarios from OpenAPI spec with realistic mock data
|
|
108
|
+
|
|
109
|
+
### File Operations
|
|
110
|
+
|
|
111
|
+
- `writeScenario(directory: string, scenario: Scenario): Promise<void>` - Write scenario to disk as JSON
|
|
112
|
+
- `readScenario(directory: string, name: string): Promise<Scenario | null>` - Read scenario from disk
|
|
113
|
+
- `listScenarios(directory: string): Promise<Scenario[]>` - List all scenarios in directory
|
|
114
|
+
- `deleteScenario(directory: string, name: string): Promise<void>` - Delete scenario file
|
|
115
|
+
|
|
116
|
+
## Complete Workflow Example
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { parseYaml } from '@mockmaster/openapi'
|
|
120
|
+
import { generateScenariosFromSpec, writeScenario, readScenario } from '@mockmaster/cli'
|
|
121
|
+
import { createReplayHandler } from '@mockmaster/msw-adapter'
|
|
122
|
+
|
|
123
|
+
// 1. Parse OpenAPI spec
|
|
124
|
+
const spec = parseYaml(openApiYaml)
|
|
125
|
+
|
|
126
|
+
// 2. Generate scenarios with mock data
|
|
127
|
+
const scenarios = generateScenariosFromSpec(spec, 'my-api')
|
|
128
|
+
|
|
129
|
+
// 3. Save to disk
|
|
130
|
+
await writeScenario('./scenarios', scenarios[0])
|
|
131
|
+
|
|
132
|
+
// 4. Later, load from disk
|
|
133
|
+
const loaded = await readScenario('./scenarios', 'my-api')
|
|
134
|
+
|
|
135
|
+
// 5. Create replay handler
|
|
136
|
+
if (loaded) {
|
|
137
|
+
const handler = createReplayHandler(loaded)
|
|
138
|
+
|
|
139
|
+
// 6. Use in tests
|
|
140
|
+
const response = handler({ method: 'GET', path: '/users' })
|
|
141
|
+
console.log(response.body)
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## File Format
|
|
146
|
+
|
|
147
|
+
Scenarios are saved as JSON files:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
./scenarios/
|
|
151
|
+
├── user-api.json
|
|
152
|
+
├── payment-api.json
|
|
153
|
+
└── notification-api.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Each file contains:
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"name": "user-api",
|
|
160
|
+
"description": "Generated from User API (1.0.0)",
|
|
161
|
+
"recordings": [
|
|
162
|
+
{
|
|
163
|
+
"request": {
|
|
164
|
+
"method": "GET",
|
|
165
|
+
"url": "https://api.example.com/users",
|
|
166
|
+
"path": "/users",
|
|
167
|
+
"timestamp": 1234567890
|
|
168
|
+
},
|
|
169
|
+
"response": {
|
|
170
|
+
"status": 200,
|
|
171
|
+
"body": [...],
|
|
172
|
+
"headers": {...},
|
|
173
|
+
"timestamp": 1234567890
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"createdAt": 1234567890,
|
|
178
|
+
"updatedAt": 1234567890
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Use Cases
|
|
183
|
+
|
|
184
|
+
- **Version Control** - Commit scenarios as JSON files
|
|
185
|
+
- **Test Fixtures** - Store test data as scenarios
|
|
186
|
+
- **CI/CD** - Use scenarios in automated tests
|
|
187
|
+
- **Team Sharing** - Share API responses across team
|
|
188
|
+
|
|
189
|
+
## Related Packages
|
|
190
|
+
|
|
191
|
+
- `@mockmaster/openapi` - OpenAPI parsing and generation
|
|
192
|
+
- `@mockmaster/msw-adapter` - Record & replay functionality
|
|
193
|
+
- `@mockmaster/data` - Factory system for generating test data
|
|
194
|
+
|
|
195
|
+
## Links
|
|
196
|
+
|
|
197
|
+
- [Main Documentation](https://github.com/PxPerfectMike/MockMaster)
|
|
198
|
+
- [npm Organization](https://www.npmjs.com/org/mockmaster)
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mockmaster/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "CLI tool for mock-master",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mock-master": "./dist/index.js"
|
|
@@ -17,18 +17,13 @@
|
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"commander": "^11.1.0",
|
|
21
|
-
"chalk": "^5.3.0",
|
|
22
|
-
"inquirer": "^9.2.12",
|
|
23
|
-
"ora": "^8.0.1",
|
|
24
20
|
"fs-extra": "^11.2.0",
|
|
25
|
-
"@mockmaster/
|
|
26
|
-
"@mockmaster/
|
|
27
|
-
"@mockmaster/
|
|
21
|
+
"@mockmaster/openapi": "1.0.5",
|
|
22
|
+
"@mockmaster/msw-adapter": "1.0.6",
|
|
23
|
+
"@mockmaster/core": "1.0.5"
|
|
28
24
|
},
|
|
29
25
|
"devDependencies": {
|
|
30
26
|
"@types/node": "^20.11.0",
|
|
31
|
-
"@types/inquirer": "^9.0.7",
|
|
32
27
|
"@types/fs-extra": "^11.0.4",
|
|
33
28
|
"@vitest/coverage-v8": "^1.2.0",
|
|
34
29
|
"typescript": "^5.3.3",
|