@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.
@@ -0,0 +1,520 @@
1
+ # Usage Examples
2
+
3
+ Complete guide with real-world examples for using `spek-cli` CLI tool.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Run directly with npx (no installation needed)
9
+ npx spek-cli
10
+
11
+ # Or install globally
12
+ npm install -g spek-cli
13
+ ```
14
+
15
+ ## Basic Usage
16
+
17
+ ### First Time Setup
18
+
19
+ When you run the CLI for the first time, you'll be prompted to configure your Directus connection:
20
+
21
+ ```bash
22
+ $ npx spek-cli
23
+
24
+ 📦 spek-cli
25
+
26
+ 🔧 Configuration not found. Let's set it up!
27
+
28
+ ? Enter your Directus instance URL: https://my-company.directus.app
29
+ ? Enter your Directus access token: ********************************
30
+
31
+ ✓ Configuration saved to /Users/username/.spek-cli/config.json
32
+
33
+ ? Enter the file ID to download: abc123-def456-ghi789
34
+
35
+ 📥 Downloading file: abc123-def456-ghi789...
36
+ ✓ Download complete
37
+ 🔍 Validating ZIP file...
38
+ ✓ ZIP file is valid
39
+ 📦 Extracting files...
40
+ ✓ Files extracted successfully
41
+
42
+ ✓ Success! Files extracted to current directory
43
+ ```
44
+
45
+ ### Direct Download (With File ID)
46
+
47
+ Once configured, you can download files directly:
48
+
49
+ ```bash
50
+ # Using -d flag
51
+ npx spek-cli -d abc123-def456-ghi789
52
+
53
+ # Using --download flag
54
+ npx spek-cli --download abc123-def456-ghi789
55
+ ```
56
+
57
+ **Output:**
58
+ ```
59
+ 📦 spek-cli
60
+
61
+ 📥 Downloading file: abc123-def456-ghi789...
62
+ ✓ Download complete
63
+ 🔍 Validating ZIP file...
64
+ ✓ ZIP file is valid
65
+ 📦 Extracting files...
66
+ ✓ Files extracted successfully
67
+
68
+ ✓ Success! Files extracted to current directory
69
+ ```
70
+
71
+ ### Interactive Mode
72
+
73
+ Run without arguments to be prompted for the file ID:
74
+
75
+ ```bash
76
+ $ npx spek-cli
77
+
78
+ 📦 spek-cli
79
+
80
+ ? Enter the file ID to download: abc123-def456-ghi789
81
+
82
+ 📥 Downloading file: abc123-def456-ghi789...
83
+ ✓ Download complete
84
+ 🔍 Validating ZIP file...
85
+ ✓ ZIP file is valid
86
+ 📦 Extracting files...
87
+ ✓ Files extracted successfully
88
+
89
+ ✓ Success! Files extracted to current directory
90
+ ```
91
+
92
+ ## Real-World Workflows
93
+
94
+ ### Workflow 1: Designer → Developer Handoff
95
+
96
+ **Scenario:** Designer exports specs from Figma, developer downloads them.
97
+
98
+ **Designer (in Figma Plugin):**
99
+ 1. Open SpeX plugin in Figma
100
+ 2. Go to "Vault Export" tab
101
+ 3. Click "Export to Vault"
102
+ 4. Copy the file ID from success dialog
103
+ 5. Share file ID with developer (via Slack, email, etc.)
104
+
105
+ **Developer:**
106
+ ```bash
107
+ # Create project directory
108
+ mkdir my-design-specs
109
+ cd my-design-specs
110
+
111
+ # Download specs
112
+ npx spek-cli -d abc123-def456-ghi789
113
+
114
+ # Files are now in current directory
115
+ ls
116
+ # Output: README.md manifest.json components/ icons/ images/
117
+ ```
118
+
119
+ ### Workflow 2: CI/CD Pipeline
120
+
121
+ **Scenario:** Automatically download latest specs in CI pipeline.
122
+
123
+ **GitHub Actions Example:**
124
+ ```yaml
125
+ name: Download Design Specs
126
+
127
+ on:
128
+ workflow_dispatch:
129
+ inputs:
130
+ file_id:
131
+ description: 'Directus file ID'
132
+ required: true
133
+
134
+ jobs:
135
+ download-specs:
136
+ runs-on: ubuntu-latest
137
+ steps:
138
+ - name: Checkout code
139
+ uses: actions/checkout@v3
140
+
141
+ - name: Setup Node.js
142
+ uses: actions/setup-node@v3
143
+ with:
144
+ node-version: '20'
145
+
146
+ - name: Setup spek-cli config
147
+ run: |
148
+ mkdir -p ~/.spek-cli
149
+ echo '{
150
+ "directusUrl": "${{ secrets.DIRECTUS_URL }}",
151
+ "accessToken": "${{ secrets.DIRECTUS_TOKEN }}",
152
+ "createdAt": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"
153
+ }' > ~/.spek-cli/config.json
154
+
155
+ - name: Download specs
156
+ run: npx spek-cli -d ${{ github.event.inputs.file_id }}
157
+
158
+ - name: Commit specs
159
+ run: |
160
+ git config user.name "GitHub Actions"
161
+ git config user.email "actions@github.com"
162
+ git add .
163
+ git commit -m "Update design specs"
164
+ git push
165
+ ```
166
+
167
+ ### Workflow 3: Multiple Projects
168
+
169
+ **Scenario:** Working with multiple Directus instances.
170
+
171
+ **Setup:**
172
+ ```bash
173
+ # Project A
174
+ cd ~/projects/project-a
175
+ npx spek-cli -d file-id-a
176
+
177
+ # Project B (different Directus instance)
178
+ cd ~/projects/project-b
179
+ # Need to reconfigure for different instance
180
+ rm ~/.spek-cli/config.json
181
+ npx spek-cli -d file-id-b
182
+ ```
183
+
184
+ **Better Approach (Future Enhancement):**
185
+ ```bash
186
+ # Use environment variables (future feature)
187
+ DIRECTUS_URL=https://project-a.directus.app \
188
+ DIRECTUS_TOKEN=token-a \
189
+ npx spek-cli -d file-id-a
190
+ ```
191
+
192
+ ### Workflow 4: Overwriting Existing Specs
193
+
194
+ **Scenario:** Update specs with newer version.
195
+
196
+ ```bash
197
+ $ cd my-design-specs
198
+ $ npx spek-cli -d new-file-id
199
+
200
+ 📦 spek-cli
201
+
202
+ 📥 Downloading file: new-file-id...
203
+ ✓ Download complete
204
+ 🔍 Validating ZIP file...
205
+ ✓ ZIP file is valid
206
+
207
+ ⚠️ Warning: Some files already exist in the current directory
208
+ ? Files already exist in current directory. Overwrite? (y/N) › y
209
+
210
+ 📦 Extracting files...
211
+ ✓ Files extracted successfully
212
+
213
+ ✓ Success! Files extracted to current directory
214
+ ```
215
+
216
+ ## Common Scenarios
217
+
218
+ ### Scenario: Getting File ID from Plugin
219
+
220
+ 1. In Figma, open SpeX plugin
221
+ 2. Navigate to "Vault Export" tab
222
+ 3. Click "Export to Vault"
223
+ 4. Success dialog shows:
224
+ ```
225
+ ✓ Export Successful!
226
+
227
+ File ID: abc123-def456-ghi789
228
+
229
+ Download Link: https://your-instance.directus.app/assets/abc123-def456-ghi789?download
230
+
231
+ [Copy File ID] [Copy Download Link]
232
+ ```
233
+ 5. Click "Copy File ID"
234
+ 6. Use in CLI: `npx spek-cli -d abc123-def456-ghi789`
235
+
236
+ ### Scenario: Organizing Downloaded Specs
237
+
238
+ ```bash
239
+ # Create organized directory structure
240
+ mkdir -p ~/design-specs/project-name/v1.0
241
+ cd ~/design-specs/project-name/v1.0
242
+
243
+ # Download specs
244
+ npx spek-cli -d abc123-def456-ghi789
245
+
246
+ # Result:
247
+ # ~/design-specs/
248
+ # └── project-name/
249
+ # └── v1.0/
250
+ # ├── README.md
251
+ # ├── manifest.json
252
+ # ├── components/
253
+ # ├── icons/
254
+ # └── images/
255
+ ```
256
+
257
+ ### Scenario: Checking What Will Be Downloaded
258
+
259
+ ```bash
260
+ # Download to temporary directory first
261
+ mkdir /tmp/specs-preview
262
+ cd /tmp/specs-preview
263
+ npx spek-cli -d abc123-def456-ghi789
264
+
265
+ # Review contents
266
+ ls -la
267
+
268
+ # If satisfied, download to actual location
269
+ cd ~/my-project
270
+ npx spek-cli -d abc123-def456-ghi789
271
+
272
+ # Cleanup preview
273
+ rm -rf /tmp/specs-preview
274
+ ```
275
+
276
+ ### Scenario: Handling Errors
277
+
278
+ **Invalid File ID:**
279
+ ```bash
280
+ $ npx spek-cli -d invalid-id
281
+
282
+ 📦 spek-cli
283
+
284
+ 📥 Downloading file: invalid-id...
285
+
286
+ ❌ Error: File not found: invalid-id
287
+ ```
288
+
289
+ **Authentication Failed:**
290
+ ```bash
291
+ $ npx spek-cli -d abc123-def456-ghi789
292
+
293
+ 📦 spek-cli
294
+
295
+ 📥 Downloading file: abc123-def456-ghi789...
296
+
297
+ ❌ Error: Authentication failed. Please check your access token.
298
+
299
+ # Fix: Update config
300
+ $ rm ~/.spek-cli/config.json
301
+ $ npx spek-cli -d abc123-def456-ghi789
302
+ # Will prompt for new credentials
303
+ ```
304
+
305
+ **Network Error:**
306
+ ```bash
307
+ $ npx spek-cli -d abc123-def456-ghi789
308
+
309
+ 📦 spek-cli
310
+
311
+ 📥 Downloading file: abc123-def456-ghi789...
312
+
313
+ ❌ Error: Failed to download file: Network request failed
314
+ ```
315
+
316
+ ## Command Reference
317
+
318
+ ### Download Commands
319
+
320
+ ```bash
321
+ # Interactive mode (prompts for file ID)
322
+ npx spek-cli
323
+
324
+ # Direct download with short flag
325
+ npx spek-cli -d <file-id>
326
+
327
+ # Direct download with long flag
328
+ npx spek-cli --download <file-id>
329
+ ```
330
+
331
+ ### Help Commands
332
+
333
+ ```bash
334
+ # Show help
335
+ npx spek-cli --help
336
+ npx spek-cli -h
337
+
338
+ # Show version
339
+ npx spek-cli --version
340
+ npx spek-cli -v
341
+ ```
342
+
343
+ ### Configuration Management
344
+
345
+ ```bash
346
+ # View current config
347
+ cat ~/.spek-cli/config.json
348
+
349
+ # Reset config (will prompt for new setup)
350
+ rm ~/.spek-cli/config.json
351
+ npx spek-cli
352
+
353
+ # Backup config
354
+ cp ~/.spek-cli/config.json ~/.spek-cli/config.backup.json
355
+
356
+ # Restore config
357
+ cp ~/.spek-cli/config.backup.json ~/.spek-cli/config.json
358
+ ```
359
+
360
+ ## Tips & Best Practices
361
+
362
+ ### 1. Organize by Version
363
+
364
+ ```bash
365
+ # Create version-specific directories
366
+ mkdir -p specs/v1.0 specs/v1.1 specs/v2.0
367
+
368
+ # Download each version
369
+ cd specs/v1.0 && npx spek-cli -d file-id-v1.0
370
+ cd ../v1.1 && npx spek-cli -d file-id-v1.1
371
+ cd ../v2.0 && npx spek-cli -d file-id-v2.0
372
+ ```
373
+
374
+ ### 2. Use with Git
375
+
376
+ ```bash
377
+ # Add specs directory to git
378
+ cd my-project
379
+ mkdir design-specs
380
+ cd design-specs
381
+ npx spek-cli -d abc123-def456-ghi789
382
+
383
+ # Commit to version control
384
+ git add .
385
+ git commit -m "Add design specs v1.0"
386
+ ```
387
+
388
+ ### 3. Automate with Scripts
389
+
390
+ **download-specs.sh:**
391
+ ```bash
392
+ #!/bin/bash
393
+
394
+ FILE_ID=$1
395
+
396
+ if [ -z "$FILE_ID" ]; then
397
+ echo "Usage: ./download-specs.sh <file-id>"
398
+ exit 1
399
+ fi
400
+
401
+ # Create timestamped directory
402
+ TIMESTAMP=$(date +%Y%m%d_%H%M%S)
403
+ SPEC_DIR="specs_${TIMESTAMP}"
404
+
405
+ mkdir -p "$SPEC_DIR"
406
+ cd "$SPEC_DIR"
407
+
408
+ # Download specs
409
+ npx spek-cli -d "$FILE_ID"
410
+
411
+ echo "Specs downloaded to: $SPEC_DIR"
412
+ ```
413
+
414
+ **Usage:**
415
+ ```bash
416
+ chmod +x download-specs.sh
417
+ ./download-specs.sh abc123-def456-ghi789
418
+ ```
419
+
420
+ ### 4. Team Configuration
421
+
422
+ **Share config template (without token):**
423
+
424
+ **config.template.json:**
425
+ ```json
426
+ {
427
+ "directusUrl": "https://your-company.directus.app",
428
+ "accessToken": "YOUR_TOKEN_HERE",
429
+ "createdAt": "2026-02-13T00:00:00.000Z"
430
+ }
431
+ ```
432
+
433
+ **Setup instructions for team:**
434
+ ```bash
435
+ # Copy template
436
+ cp config.template.json ~/.spek-cli/config.json
437
+
438
+ # Edit with your personal token
439
+ nano ~/.spek-cli/config.json
440
+ ```
441
+
442
+ ## Troubleshooting
443
+
444
+ ### Problem: "Command not found"
445
+
446
+ **Solution:**
447
+ ```bash
448
+ # Use npx instead of global install
449
+ npx spek-cli -d <file-id>
450
+
451
+ # Or install globally
452
+ npm install -g spek-cli
453
+ ```
454
+
455
+ ### Problem: "Permission denied"
456
+
457
+ **Solution:**
458
+ ```bash
459
+ # Check directory permissions
460
+ ls -la
461
+
462
+ # Ensure you have write access
463
+ chmod u+w .
464
+
465
+ # Or run in a directory you own
466
+ cd ~/my-project
467
+ npx spek-cli -d <file-id>
468
+ ```
469
+
470
+ ### Problem: "Config file corrupted"
471
+
472
+ **Solution:**
473
+ ```bash
474
+ # Delete and recreate
475
+ rm ~/.spek-cli/config.json
476
+ npx spek-cli
477
+ # Follow setup prompts
478
+ ```
479
+
480
+ ### Problem: "Download hangs"
481
+
482
+ **Solution:**
483
+ ```bash
484
+ # Check network connection
485
+ ping your-directus-instance.com
486
+
487
+ # Check Directus instance is accessible
488
+ curl https://your-directus-instance.com
489
+
490
+ # Try again with timeout (future feature)
491
+ # For now, Ctrl+C and retry
492
+ ```
493
+
494
+ ## Getting Help
495
+
496
+ ```bash
497
+ # Show help
498
+ npx spek-cli --help
499
+
500
+ # Check version
501
+ npx spek-cli --version
502
+
503
+ # View config location
504
+ echo ~/.spek-cli/config.json
505
+ ```
506
+
507
+ ## Next Steps
508
+
509
+ After downloading specs:
510
+
511
+ 1. **Review README.md:** Contains overview and structure
512
+ 2. **Check manifest.json:** Lists all components and assets
513
+ 3. **Explore components/:** Component specifications
514
+ 4. **Review icons/:** Icon assets and metadata
515
+ 5. **Check images/:** Image assets
516
+
517
+ For more information, see:
518
+ - [Architecture Documentation](./ARCHITECTURE.md)
519
+ - [Testing Guide](./TESTING.md)
520
+ - [Main README](../README.md)