@khoaha/spek-cli 1.0.3
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/QUICKSTART.md +253 -0
- package/README.md +154 -0
- package/bin/cli.js +7 -0
- package/docs/ARCHITECTURE.md +286 -0
- package/docs/PUBLISH_QUICK_REFERENCE.md +135 -0
- package/docs/SVG_TO_VECTOR_DRAWABLE.md +186 -0
- package/docs/TESTING.md +429 -0
- package/docs/USAGE_EXAMPLES.md +520 -0
- package/docs/WINDOWS_DEVELOPMENT.md +487 -0
- package/docs/WORKFLOW.md +479 -0
- package/package.json +45 -0
- package/scripts/publish.ps1 +193 -0
- package/scripts/publish.sh +170 -0
- package/src/commands/svg-to-vd/handler.ts +131 -0
- package/src/config/manager.ts +58 -0
- package/src/directus/client.ts +101 -0
- package/src/download/handler.ts +116 -0
- package/src/index.ts +231 -0
- package/src/prompts/index.ts +76 -0
- package/src/types/index.ts +72 -0
- package/src/utils/file-utils.ts +69 -0
- package/src/utils/svg-converter.ts +196 -0
- package/tsconfig.json +20 -0
package/docs/TESTING.md
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# Testing Guide
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
1. **Directus Instance:** You need access to a Directus instance with the Vault Export feature
|
|
6
|
+
2. **Access Token:** Generate an access token from your Directus instance
|
|
7
|
+
3. **Test File:** Have a file ID from a Vault Export ready for testing
|
|
8
|
+
|
|
9
|
+
## Getting Test Data
|
|
10
|
+
|
|
11
|
+
### From Figma Plugin
|
|
12
|
+
|
|
13
|
+
1. Open the SpeX Figma plugin
|
|
14
|
+
2. Go to "Vault Export" tab
|
|
15
|
+
3. Configure your Directus connection
|
|
16
|
+
4. Export specs to vault
|
|
17
|
+
5. Copy the file ID from the success dialog
|
|
18
|
+
|
|
19
|
+
### File ID Format
|
|
20
|
+
|
|
21
|
+
File IDs are UUIDs, typically in this format:
|
|
22
|
+
```
|
|
23
|
+
abc123-def456-ghi789-jkl012
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Local Testing
|
|
27
|
+
|
|
28
|
+
### 1. Build the CLI Tool
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# From monorepo root
|
|
32
|
+
npm run cli:build
|
|
33
|
+
|
|
34
|
+
# Or from cli-tool directory
|
|
35
|
+
cd cli-tool
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 2. Test Locally (Without Publishing)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# From cli-tool directory
|
|
43
|
+
node dist/index.js --help
|
|
44
|
+
node dist/index.js -d <your-file-id>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3. Test with npx (Local Link)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# From cli-tool directory
|
|
51
|
+
npm link
|
|
52
|
+
|
|
53
|
+
# Now you can use it globally
|
|
54
|
+
spek-cli -d <your-file-id>
|
|
55
|
+
|
|
56
|
+
# Unlink when done
|
|
57
|
+
npm unlink -g spek-cli
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Test Scenarios
|
|
61
|
+
|
|
62
|
+
### Scenario 1: First Run (No Config)
|
|
63
|
+
|
|
64
|
+
**Expected Behavior:**
|
|
65
|
+
1. CLI prompts for Directus URL
|
|
66
|
+
2. CLI prompts for access token
|
|
67
|
+
3. Config is saved to `~/.spek-cli/config.json`
|
|
68
|
+
4. CLI prompts for file ID (if not provided)
|
|
69
|
+
5. Download and extraction proceeds
|
|
70
|
+
|
|
71
|
+
**Test Commands:**
|
|
72
|
+
```bash
|
|
73
|
+
# Interactive mode (prompts for everything)
|
|
74
|
+
spek-cli
|
|
75
|
+
|
|
76
|
+
# Direct mode (prompts for config only)
|
|
77
|
+
spek-cli -d <file-id>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Validation:**
|
|
81
|
+
- [ ] Config file created at `~/.spek-cli/config.json`
|
|
82
|
+
- [ ] Config contains correct URL and token
|
|
83
|
+
- [ ] Success message displayed
|
|
84
|
+
- [ ] Files extracted to current directory
|
|
85
|
+
|
|
86
|
+
### Scenario 2: Subsequent Runs (Config Exists)
|
|
87
|
+
|
|
88
|
+
**Expected Behavior:**
|
|
89
|
+
1. Config loaded from file
|
|
90
|
+
2. No prompts for URL/token
|
|
91
|
+
3. Prompts for file ID if not provided
|
|
92
|
+
4. Download and extraction proceeds
|
|
93
|
+
|
|
94
|
+
**Test Commands:**
|
|
95
|
+
```bash
|
|
96
|
+
# Interactive mode
|
|
97
|
+
spek-cli
|
|
98
|
+
|
|
99
|
+
# Direct mode
|
|
100
|
+
spek-cli -d <file-id>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Validation:**
|
|
104
|
+
- [ ] No config prompts shown
|
|
105
|
+
- [ ] Download proceeds immediately
|
|
106
|
+
- [ ] Files extracted successfully
|
|
107
|
+
|
|
108
|
+
### Scenario 3: Overwrite Existing Files
|
|
109
|
+
|
|
110
|
+
**Setup:**
|
|
111
|
+
```bash
|
|
112
|
+
# First download
|
|
113
|
+
spek-cli -d <file-id>
|
|
114
|
+
|
|
115
|
+
# Second download (same file)
|
|
116
|
+
spek-cli -d <file-id>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Expected Behavior:**
|
|
120
|
+
1. CLI detects existing files
|
|
121
|
+
2. Prompts: "Files already exist. Overwrite?"
|
|
122
|
+
3. If Yes → Overwrites files
|
|
123
|
+
4. If No → Cancels operation
|
|
124
|
+
|
|
125
|
+
**Validation:**
|
|
126
|
+
- [ ] Warning message shown
|
|
127
|
+
- [ ] Overwrite prompt appears
|
|
128
|
+
- [ ] Choosing "Yes" overwrites files
|
|
129
|
+
- [ ] Choosing "No" cancels without changes
|
|
130
|
+
|
|
131
|
+
### Scenario 4: Invalid Authentication
|
|
132
|
+
|
|
133
|
+
**Setup:**
|
|
134
|
+
```bash
|
|
135
|
+
# Edit config file with invalid token
|
|
136
|
+
# ~/.spek-cli/config.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Expected Behavior:**
|
|
140
|
+
1. Download attempt fails
|
|
141
|
+
2. Error message: "Authentication failed. Please check your access token."
|
|
142
|
+
3. Suggests checking config
|
|
143
|
+
|
|
144
|
+
**Test Commands:**
|
|
145
|
+
```bash
|
|
146
|
+
spek-cli -d <file-id>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Validation:**
|
|
150
|
+
- [ ] Clear error message
|
|
151
|
+
- [ ] No partial downloads
|
|
152
|
+
- [ ] Temp files cleaned up
|
|
153
|
+
|
|
154
|
+
### Scenario 5: File Not Found
|
|
155
|
+
|
|
156
|
+
**Test Commands:**
|
|
157
|
+
```bash
|
|
158
|
+
spek-cli -d invalid-file-id-12345
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Expected Behavior:**
|
|
162
|
+
1. Download attempt fails
|
|
163
|
+
2. Error message: "File not found: invalid-file-id-12345"
|
|
164
|
+
|
|
165
|
+
**Validation:**
|
|
166
|
+
- [ ] Clear error message
|
|
167
|
+
- [ ] No partial extraction
|
|
168
|
+
- [ ] Temp files cleaned up
|
|
169
|
+
|
|
170
|
+
### Scenario 6: Network Errors
|
|
171
|
+
|
|
172
|
+
**Setup:**
|
|
173
|
+
- Disconnect internet or use invalid Directus URL
|
|
174
|
+
|
|
175
|
+
**Expected Behavior:**
|
|
176
|
+
1. Connection fails
|
|
177
|
+
2. Error message with network details
|
|
178
|
+
|
|
179
|
+
**Validation:**
|
|
180
|
+
- [ ] Graceful error handling
|
|
181
|
+
- [ ] No hanging processes
|
|
182
|
+
- [ ] Temp files cleaned up
|
|
183
|
+
|
|
184
|
+
### Scenario 7: Corrupted ZIP File
|
|
185
|
+
|
|
186
|
+
**Note:** This is difficult to test without modifying the Directus server response.
|
|
187
|
+
|
|
188
|
+
**Expected Behavior:**
|
|
189
|
+
1. Download completes
|
|
190
|
+
2. ZIP validation fails
|
|
191
|
+
3. Error message: "Invalid or corrupted ZIP file"
|
|
192
|
+
|
|
193
|
+
**Validation:**
|
|
194
|
+
- [ ] No extraction attempted
|
|
195
|
+
- [ ] Temp files cleaned up
|
|
196
|
+
|
|
197
|
+
### Scenario 8: User Cancellation
|
|
198
|
+
|
|
199
|
+
**Test Commands:**
|
|
200
|
+
```bash
|
|
201
|
+
spek-cli
|
|
202
|
+
# Press Ctrl+C during any prompt
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Expected Behavior:**
|
|
206
|
+
1. Graceful exit
|
|
207
|
+
2. No partial operations
|
|
208
|
+
3. No temp files left behind
|
|
209
|
+
|
|
210
|
+
**Validation:**
|
|
211
|
+
- [ ] Clean exit
|
|
212
|
+
- [ ] No error messages
|
|
213
|
+
- [ ] No temp files
|
|
214
|
+
|
|
215
|
+
### Scenario 9: Help and Version
|
|
216
|
+
|
|
217
|
+
**Test Commands:**
|
|
218
|
+
```bash
|
|
219
|
+
spek-cli --help
|
|
220
|
+
spek-cli -h
|
|
221
|
+
spek-cli --version
|
|
222
|
+
spek-cli -v
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Expected Behavior:**
|
|
226
|
+
- Help shows usage, options, examples
|
|
227
|
+
- Version shows current version number
|
|
228
|
+
|
|
229
|
+
**Validation:**
|
|
230
|
+
- [ ] Help is clear and comprehensive
|
|
231
|
+
- [ ] Version matches package.json
|
|
232
|
+
|
|
233
|
+
### Scenario 10: Empty Directory vs. Non-Empty
|
|
234
|
+
|
|
235
|
+
**Test A: Empty Directory**
|
|
236
|
+
```bash
|
|
237
|
+
mkdir test-empty
|
|
238
|
+
cd test-empty
|
|
239
|
+
spek-cli -d <file-id>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Expected:** Direct extraction, no overwrite prompt
|
|
243
|
+
|
|
244
|
+
**Test B: Non-Empty Directory**
|
|
245
|
+
```bash
|
|
246
|
+
mkdir test-non-empty
|
|
247
|
+
cd test-non-empty
|
|
248
|
+
echo "test" > README.md
|
|
249
|
+
spek-cli -d <file-id>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Expected:** Overwrite prompt only if ZIP contains README.md
|
|
253
|
+
|
|
254
|
+
**Validation:**
|
|
255
|
+
- [ ] Empty dir: No prompt
|
|
256
|
+
- [ ] Non-empty dir with conflicts: Prompt shown
|
|
257
|
+
- [ ] Non-empty dir without conflicts: No prompt
|
|
258
|
+
|
|
259
|
+
## Manual Testing Checklist
|
|
260
|
+
|
|
261
|
+
### Setup Phase
|
|
262
|
+
- [ ] Build succeeds without errors
|
|
263
|
+
- [ ] TypeScript compilation clean
|
|
264
|
+
- [ ] All dependencies installed
|
|
265
|
+
|
|
266
|
+
### Configuration
|
|
267
|
+
- [ ] First run prompts for config
|
|
268
|
+
- [ ] Config saved correctly
|
|
269
|
+
- [ ] Config loaded on subsequent runs
|
|
270
|
+
- [ ] Invalid URL rejected during setup
|
|
271
|
+
- [ ] Empty token rejected during setup
|
|
272
|
+
|
|
273
|
+
### Download
|
|
274
|
+
- [ ] Valid file ID downloads successfully
|
|
275
|
+
- [ ] Invalid file ID shows error
|
|
276
|
+
- [ ] Network errors handled gracefully
|
|
277
|
+
- [ ] Authentication errors clear
|
|
278
|
+
|
|
279
|
+
### Extraction
|
|
280
|
+
- [ ] Files extracted to CWD
|
|
281
|
+
- [ ] Directory structure preserved
|
|
282
|
+
- [ ] Overwrite prompt works
|
|
283
|
+
- [ ] Cancellation works
|
|
284
|
+
- [ ] Temp files cleaned up
|
|
285
|
+
|
|
286
|
+
### User Experience
|
|
287
|
+
- [ ] Help message clear
|
|
288
|
+
- [ ] Version displayed correctly
|
|
289
|
+
- [ ] Error messages helpful
|
|
290
|
+
- [ ] Success messages clear
|
|
291
|
+
- [ ] Colors enhance readability
|
|
292
|
+
|
|
293
|
+
### Edge Cases
|
|
294
|
+
- [ ] Very large files (>100MB)
|
|
295
|
+
- [ ] Files with special characters
|
|
296
|
+
- [ ] Deeply nested directory structures
|
|
297
|
+
- [ ] Empty ZIP files
|
|
298
|
+
- [ ] ZIP with single file
|
|
299
|
+
- [ ] ZIP with many files (>1000)
|
|
300
|
+
|
|
301
|
+
## Automated Testing (Future)
|
|
302
|
+
|
|
303
|
+
### Unit Tests
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
// Example test structure
|
|
307
|
+
describe('Config Manager', () => {
|
|
308
|
+
it('should create config directory if not exists', () => {});
|
|
309
|
+
it('should save config with timestamp', () => {});
|
|
310
|
+
it('should load existing config', () => {});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe('Download Handler', () => {
|
|
314
|
+
it('should detect existing files', () => {});
|
|
315
|
+
it('should validate ZIP files', () => {});
|
|
316
|
+
it('should cleanup temp files on error', () => {});
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Integration Tests
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
describe('Full Download Flow', () => {
|
|
324
|
+
it('should download and extract valid file', async () => {});
|
|
325
|
+
it('should handle authentication errors', async () => {});
|
|
326
|
+
it('should handle file not found', async () => {});
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Performance Testing
|
|
331
|
+
|
|
332
|
+
### Metrics to Track
|
|
333
|
+
|
|
334
|
+
1. **Startup Time:** Time from command to first prompt
|
|
335
|
+
2. **Download Speed:** MB/s for various file sizes
|
|
336
|
+
3. **Extraction Time:** Time to extract various ZIP sizes
|
|
337
|
+
4. **Memory Usage:** Peak memory during download/extraction
|
|
338
|
+
|
|
339
|
+
### Test Files
|
|
340
|
+
|
|
341
|
+
- Small: <1MB
|
|
342
|
+
- Medium: 1-10MB
|
|
343
|
+
- Large: 10-100MB
|
|
344
|
+
- Very Large: >100MB
|
|
345
|
+
|
|
346
|
+
## Troubleshooting
|
|
347
|
+
|
|
348
|
+
### Build Fails
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
# Clean and rebuild
|
|
352
|
+
rm -rf dist node_modules
|
|
353
|
+
npm install
|
|
354
|
+
npm run build
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Config Issues
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# View config
|
|
361
|
+
cat ~/.spek-cli/config.json
|
|
362
|
+
|
|
363
|
+
# Delete config (forces re-setup)
|
|
364
|
+
rm ~/.spek-cli/config.json
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Temp Files Not Cleaned
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
# Check temp directory
|
|
371
|
+
ls /tmp/spek-cli-*
|
|
372
|
+
|
|
373
|
+
# Manual cleanup
|
|
374
|
+
rm /tmp/spek-cli-*
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Permission Errors
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
# Check config directory permissions
|
|
381
|
+
ls -la ~/.spek-cli
|
|
382
|
+
|
|
383
|
+
# Fix permissions
|
|
384
|
+
chmod 700 ~/.spek-cli
|
|
385
|
+
chmod 600 ~/.spek-cli/config.json
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Reporting Issues
|
|
389
|
+
|
|
390
|
+
When reporting issues, include:
|
|
391
|
+
|
|
392
|
+
1. **Command used:** Full command with arguments
|
|
393
|
+
2. **Error message:** Complete error output
|
|
394
|
+
3. **Environment:**
|
|
395
|
+
- OS and version
|
|
396
|
+
- Node.js version
|
|
397
|
+
- npm version
|
|
398
|
+
4. **Config:** Directus URL (redact token)
|
|
399
|
+
5. **File ID:** If applicable (redact if sensitive)
|
|
400
|
+
6. **Steps to reproduce:** Detailed steps
|
|
401
|
+
|
|
402
|
+
## Test Results Template
|
|
403
|
+
|
|
404
|
+
```markdown
|
|
405
|
+
## Test Results - [Date]
|
|
406
|
+
|
|
407
|
+
**Environment:**
|
|
408
|
+
- OS: Windows 10 / macOS 14 / Ubuntu 22.04
|
|
409
|
+
- Node.js: v20.11.0
|
|
410
|
+
- npm: v10.2.4
|
|
411
|
+
|
|
412
|
+
**Test Scenarios:**
|
|
413
|
+
- [ ] First run setup
|
|
414
|
+
- [ ] Subsequent runs
|
|
415
|
+
- [ ] Overwrite prompt
|
|
416
|
+
- [ ] Invalid auth
|
|
417
|
+
- [ ] File not found
|
|
418
|
+
- [ ] Network errors
|
|
419
|
+
- [ ] User cancellation
|
|
420
|
+
- [ ] Help/Version
|
|
421
|
+
- [ ] Empty directory
|
|
422
|
+
- [ ] Non-empty directory
|
|
423
|
+
|
|
424
|
+
**Issues Found:**
|
|
425
|
+
1. [Issue description]
|
|
426
|
+
2. [Issue description]
|
|
427
|
+
|
|
428
|
+
**Overall Status:** ✅ Pass / ❌ Fail
|
|
429
|
+
```
|