@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/QUICKSTART.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get started with `spek-cli` CLI tool in 5 minutes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js 18+ installed
|
|
8
|
+
- Access to a Directus instance with Vault Export
|
|
9
|
+
- A file ID from the Figma SpeX plugin
|
|
10
|
+
|
|
11
|
+
## Step 1: Get Your File ID
|
|
12
|
+
|
|
13
|
+
### From Figma Plugin
|
|
14
|
+
|
|
15
|
+
1. Open your Figma file
|
|
16
|
+
2. Launch the **SpeX** plugin
|
|
17
|
+
3. Navigate to **"Vault Export"** tab
|
|
18
|
+
4. Click **"Export to Vault"**
|
|
19
|
+
5. Wait for export to complete
|
|
20
|
+
6. Copy the **File ID** from the success dialog
|
|
21
|
+
|
|
22
|
+
**Example File ID:**
|
|
23
|
+
```
|
|
24
|
+
abc123-def456-ghi789-jkl012
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Step 2: Run the CLI Tool
|
|
28
|
+
|
|
29
|
+
Open your terminal and navigate to where you want the specs:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Create a directory for your specs
|
|
33
|
+
mkdir my-design-specs
|
|
34
|
+
cd my-design-specs
|
|
35
|
+
|
|
36
|
+
# Run the CLI tool
|
|
37
|
+
npx spek-cli -d abc123-def456-ghi789-jkl012
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Step 3: First-Time Setup
|
|
41
|
+
|
|
42
|
+
If this is your first time running the tool, you'll be prompted for configuration:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
📦 spek-cli
|
|
46
|
+
|
|
47
|
+
🔧 Configuration not found. Let's set it up!
|
|
48
|
+
|
|
49
|
+
? Enter your Directus instance URL: https://my-company.directus.app
|
|
50
|
+
? Enter your Directus access token: ********************************
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Getting Your Access Token
|
|
54
|
+
|
|
55
|
+
1. Log in to your Directus instance
|
|
56
|
+
2. Go to **User Settings** → **Access Tokens**
|
|
57
|
+
3. Click **"Create New Token"**
|
|
58
|
+
4. Give it a name (e.g., "CLI Tool")
|
|
59
|
+
5. Set permissions: **Read** access to **Files**
|
|
60
|
+
6. Copy the generated token
|
|
61
|
+
7. Paste it into the CLI prompt
|
|
62
|
+
|
|
63
|
+
## Step 4: Download Complete!
|
|
64
|
+
|
|
65
|
+
Once configured, the download will proceed automatically:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
✓ Configuration saved to ~/.spek-cli/config.json
|
|
69
|
+
|
|
70
|
+
📥 Downloading file: abc123-def456-ghi789-jkl012...
|
|
71
|
+
✓ Download complete
|
|
72
|
+
🔍 Validating ZIP file...
|
|
73
|
+
✓ ZIP file is valid
|
|
74
|
+
📦 Extracting files...
|
|
75
|
+
✓ Files extracted successfully
|
|
76
|
+
|
|
77
|
+
✓ Success! Files extracted to current directory
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Step 5: Explore Your Specs
|
|
81
|
+
|
|
82
|
+
Check what was downloaded:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
ls
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Typical Structure:**
|
|
89
|
+
```
|
|
90
|
+
my-design-specs/
|
|
91
|
+
├── README.md # Overview and usage guide
|
|
92
|
+
├── manifest.json # Component manifest
|
|
93
|
+
├── components/ # Component specifications
|
|
94
|
+
│ ├── Button.yaml
|
|
95
|
+
│ ├── Card.yaml
|
|
96
|
+
│ └── ...
|
|
97
|
+
├── icons/ # Icon assets
|
|
98
|
+
│ ├── icon-home.svg
|
|
99
|
+
│ ├── icon-user.svg
|
|
100
|
+
│ └── ...
|
|
101
|
+
└── images/ # Image assets
|
|
102
|
+
└── ...
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Next Steps
|
|
106
|
+
|
|
107
|
+
### Use with Cursor AI
|
|
108
|
+
|
|
109
|
+
1. Start the MCP server:
|
|
110
|
+
```bash
|
|
111
|
+
npx spex-mcp --mode local --port 8080
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. Open your project in Cursor
|
|
115
|
+
|
|
116
|
+
3. Ask Cursor to generate components:
|
|
117
|
+
```
|
|
118
|
+
"Generate a Button component based on the design specs"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Download More Specs
|
|
122
|
+
|
|
123
|
+
For subsequent downloads, just provide the file ID:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# No setup prompts - uses saved config
|
|
127
|
+
npx spek-cli -d new-file-id-xyz
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Interactive Mode
|
|
131
|
+
|
|
132
|
+
Run without arguments to be prompted for the file ID:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npx spek-cli
|
|
136
|
+
|
|
137
|
+
? Enter the file ID to download: abc123-def456-ghi789
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Common Commands
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Direct download
|
|
144
|
+
npx spek-cli -d <file-id>
|
|
145
|
+
|
|
146
|
+
# Interactive mode
|
|
147
|
+
npx spek-cli
|
|
148
|
+
|
|
149
|
+
# Show help
|
|
150
|
+
npx spek-cli --help
|
|
151
|
+
|
|
152
|
+
# Show version
|
|
153
|
+
npx spek-cli --version
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Troubleshooting
|
|
157
|
+
|
|
158
|
+
### "Authentication failed"
|
|
159
|
+
|
|
160
|
+
**Problem:** Your access token is invalid or expired.
|
|
161
|
+
|
|
162
|
+
**Solution:**
|
|
163
|
+
```bash
|
|
164
|
+
# Delete config and re-setup
|
|
165
|
+
rm ~/.spek-cli/config.json
|
|
166
|
+
npx spek-cli -d <file-id>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### "File not found"
|
|
170
|
+
|
|
171
|
+
**Problem:** The file ID doesn't exist or you don't have access.
|
|
172
|
+
|
|
173
|
+
**Solution:**
|
|
174
|
+
1. Verify the file ID is correct
|
|
175
|
+
2. Check the file exists in Directus
|
|
176
|
+
3. Ensure your token has read access
|
|
177
|
+
|
|
178
|
+
### "Files already exist"
|
|
179
|
+
|
|
180
|
+
**Problem:** You're downloading to a directory with existing files.
|
|
181
|
+
|
|
182
|
+
**Solution:**
|
|
183
|
+
The CLI will prompt you:
|
|
184
|
+
```
|
|
185
|
+
? Files already exist in current directory. Overwrite? (y/N)
|
|
186
|
+
```
|
|
187
|
+
- Choose **Yes** to overwrite
|
|
188
|
+
- Choose **No** to cancel
|
|
189
|
+
|
|
190
|
+
### Config Location
|
|
191
|
+
|
|
192
|
+
Your configuration is stored at:
|
|
193
|
+
- **Windows:** `C:\Users\<username>\.spek-cli\config.json`
|
|
194
|
+
- **macOS:** `/Users/<username>/.spek-cli/config.json`
|
|
195
|
+
- **Linux:** `/home/<username>/.spek-cli/config.json`
|
|
196
|
+
|
|
197
|
+
## Tips
|
|
198
|
+
|
|
199
|
+
### 1. Organize by Version
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
mkdir -p specs/v1.0 specs/v1.1
|
|
203
|
+
cd specs/v1.0 && npx spek-cli -d file-id-v1
|
|
204
|
+
cd ../v1.1 && npx spek-cli -d file-id-v2
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 2. Use with Git
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
cd my-project
|
|
211
|
+
mkdir design-specs
|
|
212
|
+
cd design-specs
|
|
213
|
+
npx spek-cli -d <file-id>
|
|
214
|
+
git add .
|
|
215
|
+
git commit -m "Add design specs"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 3. Create a Script
|
|
219
|
+
|
|
220
|
+
**download-specs.sh:**
|
|
221
|
+
```bash
|
|
222
|
+
#!/bin/bash
|
|
223
|
+
mkdir -p specs/$(date +%Y%m%d)
|
|
224
|
+
cd specs/$(date +%Y%m%d)
|
|
225
|
+
npx spek-cli -d $1
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Usage:**
|
|
229
|
+
```bash
|
|
230
|
+
chmod +x download-specs.sh
|
|
231
|
+
./download-specs.sh abc123-def456-ghi789
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Need Help?
|
|
235
|
+
|
|
236
|
+
- **Documentation:** [Full README](./README.md)
|
|
237
|
+
- **Architecture:** [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md)
|
|
238
|
+
- **Examples:** [docs/USAGE_EXAMPLES.md](./docs/USAGE_EXAMPLES.md)
|
|
239
|
+
- **Testing:** [docs/TESTING.md](./docs/TESTING.md)
|
|
240
|
+
- **Workflow:** [docs/WORKFLOW.md](./docs/WORKFLOW.md)
|
|
241
|
+
|
|
242
|
+
## Summary
|
|
243
|
+
|
|
244
|
+
That's it! You're now ready to use `spek-cli` to download design specs from Directus.
|
|
245
|
+
|
|
246
|
+
**Quick Recap:**
|
|
247
|
+
1. ✅ Get file ID from Figma plugin
|
|
248
|
+
2. ✅ Run `npx spek-cli -d <file-id>`
|
|
249
|
+
3. ✅ Configure on first run (Directus URL + token)
|
|
250
|
+
4. ✅ Specs downloaded and extracted
|
|
251
|
+
5. ✅ Use with Cursor AI for code generation
|
|
252
|
+
|
|
253
|
+
**Happy coding! 🚀**
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# spek-cli
|
|
2
|
+
|
|
3
|
+
CLI tool to download and extract Figma design specs from Directus.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx spek-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Interactive Mode
|
|
14
|
+
|
|
15
|
+
Simply run without arguments to be prompted for the file ID:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx spek-cli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Direct Download
|
|
22
|
+
|
|
23
|
+
Download a specific file by ID:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx spek-cli -d <file-id>
|
|
27
|
+
# or
|
|
28
|
+
npx spek-cli --download <file-id>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### First Run Setup
|
|
32
|
+
|
|
33
|
+
On first run, you'll be prompted to configure:
|
|
34
|
+
|
|
35
|
+
1. **Directus Instance URL**: Your Directus instance (e.g., `https://my-instance.directus.app`)
|
|
36
|
+
2. **Access Token**: Your Directus access token for authentication
|
|
37
|
+
|
|
38
|
+
Configuration is saved to `~/.spek-cli/config.json`
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- ✅ Download files from Directus using official SDK
|
|
43
|
+
- ✅ Automatic authentication with access token
|
|
44
|
+
- ✅ Extract ZIP files to named folder (based on filename)
|
|
45
|
+
- ✅ Prompt before overwriting existing folders
|
|
46
|
+
- ✅ Auto-setup configuration on first run
|
|
47
|
+
- ✅ Interactive and direct command modes
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
Configuration file location: `~/.spek-cli/config.json`
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"directusUrl": "https://my-instance.directus.app",
|
|
56
|
+
"accessToken": "your-access-token",
|
|
57
|
+
"createdAt": "2026-02-13T..."
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Examples
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# First time - interactive setup
|
|
65
|
+
npx spek-cli
|
|
66
|
+
# Prompts for: Directus URL, Access Token, File ID
|
|
67
|
+
|
|
68
|
+
# Subsequent runs - direct download
|
|
69
|
+
npx spek-cli -d abc123-def456-ghi789
|
|
70
|
+
|
|
71
|
+
# Interactive mode (prompts for file ID only)
|
|
72
|
+
npx spek-cli
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Output Structure
|
|
76
|
+
|
|
77
|
+
When you download a file, it will be extracted into a folder named after the file:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# If the file in Directus is named "design-specs-v1.zip"
|
|
81
|
+
npx spek-cli -d abc123
|
|
82
|
+
|
|
83
|
+
# Creates structure:
|
|
84
|
+
./design-specs-v1/
|
|
85
|
+
├── README.md
|
|
86
|
+
├── manifest.json
|
|
87
|
+
├── components/
|
|
88
|
+
├── icons/
|
|
89
|
+
└── images/
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Error Handling
|
|
93
|
+
|
|
94
|
+
The CLI handles common errors gracefully:
|
|
95
|
+
|
|
96
|
+
- **Invalid authentication**: Check your access token
|
|
97
|
+
- **File not found**: Verify the file ID exists in Directus
|
|
98
|
+
- **Network errors**: Check your internet connection
|
|
99
|
+
- **Corrupted ZIP**: The downloaded file is invalid
|
|
100
|
+
- **Permission errors**: Ensure write access to current directory
|
|
101
|
+
|
|
102
|
+
## Help
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx spek-cli --help
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Version
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npx spek-cli --version
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
This CLI tool is part of the specs-figma monorepo.
|
|
117
|
+
|
|
118
|
+
### Build
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm run build
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Watch Mode
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm run dev
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Local Testing
|
|
131
|
+
|
|
132
|
+
**Linux/macOS:**
|
|
133
|
+
```bash
|
|
134
|
+
# Build first
|
|
135
|
+
npm run build
|
|
136
|
+
|
|
137
|
+
# Run locally
|
|
138
|
+
node dist/index.js -d <file-id>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Windows:**
|
|
142
|
+
```powershell
|
|
143
|
+
# Build first
|
|
144
|
+
npm run build
|
|
145
|
+
|
|
146
|
+
# Run locally
|
|
147
|
+
node dist/index.js -d <file-id>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Note for Windows users:** See [WINDOWS_DEVELOPMENT.md](./WINDOWS_DEVELOPMENT.md) for detailed Windows-specific development guide.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# CLI Tool Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`spek-cli` is a standalone CLI tool for downloading and extracting Figma design specs from Directus vault storage. It's built with TypeScript and uses the official Directus SDK for authentication and file downloads.
|
|
6
|
+
|
|
7
|
+
## Architecture Diagram
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
11
|
+
│ User │
|
|
12
|
+
└────────────────────┬────────────────────────────────────────┘
|
|
13
|
+
│
|
|
14
|
+
▼
|
|
15
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
16
|
+
│ CLI Entry Point │
|
|
17
|
+
│ (src/index.ts) │
|
|
18
|
+
│ • Parse arguments (-d, --download, --help, --version) │
|
|
19
|
+
│ • Orchestrate workflow │
|
|
20
|
+
└────────────┬────────────────────────────────────────────────┘
|
|
21
|
+
│
|
|
22
|
+
▼
|
|
23
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
24
|
+
│ Configuration Manager │
|
|
25
|
+
│ (src/config/manager.ts) │
|
|
26
|
+
│ • Check if config exists │
|
|
27
|
+
│ • Load from ~/.spek-cli/config.json │
|
|
28
|
+
│ • Save new configuration │
|
|
29
|
+
└────────────┬────────────────────────────────────────────────┘
|
|
30
|
+
│
|
|
31
|
+
▼
|
|
32
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
33
|
+
│ Prompts Module │
|
|
34
|
+
│ (src/prompts/index.ts) │
|
|
35
|
+
│ • Prompt for Directus URL (first run) │
|
|
36
|
+
│ • Prompt for access token (first run) │
|
|
37
|
+
│ • Prompt for file ID (interactive mode) │
|
|
38
|
+
│ • Prompt for overwrite confirmation │
|
|
39
|
+
└────────────┬────────────────────────────────────────────────┘
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
43
|
+
│ Directus Client │
|
|
44
|
+
│ (src/directus/client.ts) │
|
|
45
|
+
│ • Create authenticated Directus SDK client │
|
|
46
|
+
│ • Download file using readAssetRaw() │
|
|
47
|
+
│ • Handle authentication and errors │
|
|
48
|
+
└────────────┬────────────────────────────────────────────────┘
|
|
49
|
+
│
|
|
50
|
+
▼
|
|
51
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
52
|
+
│ Download Handler │
|
|
53
|
+
│ (src/download/handler.ts) │
|
|
54
|
+
│ • Download file to temp location │
|
|
55
|
+
│ • Validate ZIP file │
|
|
56
|
+
│ • Check for existing files │
|
|
57
|
+
│ • Extract to current working directory │
|
|
58
|
+
│ • Cleanup temp files │
|
|
59
|
+
└─────────────────────────────────────────────────────────────┘
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Module Breakdown
|
|
63
|
+
|
|
64
|
+
### 1. Entry Point (`src/index.ts`)
|
|
65
|
+
|
|
66
|
+
**Responsibilities:**
|
|
67
|
+
- Parse command-line arguments
|
|
68
|
+
- Check/initialize configuration
|
|
69
|
+
- Orchestrate the download workflow
|
|
70
|
+
- Handle errors and display results
|
|
71
|
+
|
|
72
|
+
**Key Functions:**
|
|
73
|
+
- `parseArgs()` - Parse CLI arguments
|
|
74
|
+
- `showHelp()` - Display help message
|
|
75
|
+
- `showVersion()` - Display version
|
|
76
|
+
- `main()` - Main entry point
|
|
77
|
+
|
|
78
|
+
**Flow:**
|
|
79
|
+
```
|
|
80
|
+
1. Parse arguments
|
|
81
|
+
2. Load or initialize config
|
|
82
|
+
3. Get file ID (from args or prompt)
|
|
83
|
+
4. Call download handler
|
|
84
|
+
5. Display result
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 2. Configuration Manager (`src/config/manager.ts`)
|
|
88
|
+
|
|
89
|
+
**Responsibilities:**
|
|
90
|
+
- Manage configuration file at `~/.spek-cli/config.json`
|
|
91
|
+
- Load, save, and validate configuration
|
|
92
|
+
- Ensure config directory exists
|
|
93
|
+
|
|
94
|
+
**Key Functions:**
|
|
95
|
+
- `configExists()` - Check if config file exists
|
|
96
|
+
- `loadConfig()` - Load configuration from disk
|
|
97
|
+
- `saveConfig()` - Save configuration to disk
|
|
98
|
+
- `getConfigPath()` - Get config file path
|
|
99
|
+
|
|
100
|
+
**Configuration Structure:**
|
|
101
|
+
```typescript
|
|
102
|
+
interface VaultConfig {
|
|
103
|
+
directusUrl: string; // e.g., https://my.directus.app
|
|
104
|
+
accessToken: string; // Directus access token
|
|
105
|
+
createdAt: string; // ISO timestamp
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Prompts Module (`src/prompts/index.ts`)
|
|
110
|
+
|
|
111
|
+
**Responsibilities:**
|
|
112
|
+
- Interactive user input collection
|
|
113
|
+
- Validation of user inputs
|
|
114
|
+
- Confirmation dialogs
|
|
115
|
+
|
|
116
|
+
**Key Functions:**
|
|
117
|
+
- `promptForConfig()` - First-run configuration setup
|
|
118
|
+
- `promptForFileId()` - Get file ID in interactive mode
|
|
119
|
+
- `promptOverwrite()` - Confirm overwrite of existing files
|
|
120
|
+
|
|
121
|
+
**Uses:** `prompts` package (v2.4.2) for user-friendly CLI prompts
|
|
122
|
+
|
|
123
|
+
### 4. Directus Client (`src/directus/client.ts`)
|
|
124
|
+
|
|
125
|
+
**Responsibilities:**
|
|
126
|
+
- Create authenticated Directus SDK client
|
|
127
|
+
- Download files from Directus assets
|
|
128
|
+
- Handle authentication and API errors
|
|
129
|
+
|
|
130
|
+
**Key Functions:**
|
|
131
|
+
- `createAuthenticatedClient()` - Initialize Directus client
|
|
132
|
+
- `downloadFile()` - Download file by ID
|
|
133
|
+
|
|
134
|
+
**Error Handling:**
|
|
135
|
+
- 401: Authentication failed
|
|
136
|
+
- 404: File not found
|
|
137
|
+
- Network errors: Connection issues
|
|
138
|
+
|
|
139
|
+
**Implementation Details:**
|
|
140
|
+
- Uses `@directus/sdk` with `authentication()` and `rest()` modules
|
|
141
|
+
- Converts `ReadableStream` to `Buffer` for file processing
|
|
142
|
+
- Sets access token before making requests
|
|
143
|
+
|
|
144
|
+
### 5. Download Handler (`src/download/handler.ts`)
|
|
145
|
+
|
|
146
|
+
**Responsibilities:**
|
|
147
|
+
- Orchestrate download and extraction process
|
|
148
|
+
- Validate ZIP files
|
|
149
|
+
- Check for file conflicts
|
|
150
|
+
- Extract to current working directory
|
|
151
|
+
- Cleanup temporary files
|
|
152
|
+
|
|
153
|
+
**Key Functions:**
|
|
154
|
+
- `checkExistingFiles()` - Check if extraction would overwrite files
|
|
155
|
+
- `handleDownload()` - Main download and extract workflow
|
|
156
|
+
|
|
157
|
+
**Flow:**
|
|
158
|
+
```
|
|
159
|
+
1. Download file from Directus
|
|
160
|
+
2. Save to temp file
|
|
161
|
+
3. Validate ZIP structure
|
|
162
|
+
4. Check for existing files
|
|
163
|
+
5. Prompt for overwrite if needed
|
|
164
|
+
6. Extract to CWD
|
|
165
|
+
7. Cleanup temp files
|
|
166
|
+
8. Return result
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Uses:** `adm-zip` for ZIP file operations
|
|
170
|
+
|
|
171
|
+
## Data Flow
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
User Input
|
|
175
|
+
↓
|
|
176
|
+
CLI Arguments / Prompts
|
|
177
|
+
↓
|
|
178
|
+
Configuration (from file or new setup)
|
|
179
|
+
↓
|
|
180
|
+
Directus SDK Client
|
|
181
|
+
↓
|
|
182
|
+
Download File (via Directus API)
|
|
183
|
+
↓
|
|
184
|
+
Temp File Storage
|
|
185
|
+
↓
|
|
186
|
+
ZIP Validation
|
|
187
|
+
↓
|
|
188
|
+
Overwrite Check
|
|
189
|
+
↓
|
|
190
|
+
Extract to CWD
|
|
191
|
+
↓
|
|
192
|
+
Cleanup & Result
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Error Handling Strategy
|
|
196
|
+
|
|
197
|
+
### Configuration Errors
|
|
198
|
+
- Missing config → Auto-trigger setup wizard
|
|
199
|
+
- Invalid config → Show error, suggest re-setup
|
|
200
|
+
|
|
201
|
+
### Authentication Errors
|
|
202
|
+
- 401 Unauthorized → Check access token message
|
|
203
|
+
- Invalid URL → Validation during setup
|
|
204
|
+
|
|
205
|
+
### Download Errors
|
|
206
|
+
- 404 Not Found → File ID doesn't exist
|
|
207
|
+
- Network errors → Connection issues
|
|
208
|
+
- Timeout → Retry suggestion
|
|
209
|
+
|
|
210
|
+
### Extraction Errors
|
|
211
|
+
- Invalid ZIP → Corrupted file message
|
|
212
|
+
- Permission errors → Write access issues
|
|
213
|
+
- Disk space → Insufficient space
|
|
214
|
+
|
|
215
|
+
### User Cancellation
|
|
216
|
+
- Ctrl+C during prompts → Graceful exit
|
|
217
|
+
- Overwrite declined → Cancel operation
|
|
218
|
+
|
|
219
|
+
## Dependencies
|
|
220
|
+
|
|
221
|
+
### Production Dependencies
|
|
222
|
+
- `@directus/sdk` (^17.0.0) - Official Directus SDK
|
|
223
|
+
- `prompts` (^2.4.2) - Interactive CLI prompts
|
|
224
|
+
- `adm-zip` (^0.5.10) - ZIP file operations
|
|
225
|
+
- `chalk` (^5.3.0) - Terminal colors
|
|
226
|
+
|
|
227
|
+
### Development Dependencies
|
|
228
|
+
- `typescript` (^5.3.3) - TypeScript compiler
|
|
229
|
+
- `@types/node` (^20.11.0) - Node.js type definitions
|
|
230
|
+
- `@types/adm-zip` (^0.5.5) - adm-zip type definitions
|
|
231
|
+
- `@types/prompts` (^2.4.9) - prompts type definitions
|
|
232
|
+
|
|
233
|
+
## Build System
|
|
234
|
+
|
|
235
|
+
**Compiler:** TypeScript 5.3.3
|
|
236
|
+
|
|
237
|
+
**Target:** ES2022 with Node.js modules
|
|
238
|
+
|
|
239
|
+
**Output:** `dist/` directory with compiled JavaScript + source maps
|
|
240
|
+
|
|
241
|
+
**Entry Point:** `dist/index.js` (with shebang for CLI execution)
|
|
242
|
+
|
|
243
|
+
## Configuration File Location
|
|
244
|
+
|
|
245
|
+
**Path:** `~/.spek-cli/config.json`
|
|
246
|
+
|
|
247
|
+
**Platform-specific:**
|
|
248
|
+
- Windows: `C:\Users\<username>\.spek-cli\config.json`
|
|
249
|
+
- macOS: `/Users/<username>/.spek-cli/config.json`
|
|
250
|
+
- Linux: `/home/<username>/.spek-cli/config.json`
|
|
251
|
+
|
|
252
|
+
## Security Considerations
|
|
253
|
+
|
|
254
|
+
1. **Access Token Storage**
|
|
255
|
+
- Stored in user's home directory
|
|
256
|
+
- File permissions should be restricted (user-only)
|
|
257
|
+
- Never logged or displayed in output
|
|
258
|
+
|
|
259
|
+
2. **HTTPS Enforcement**
|
|
260
|
+
- Directus URL validated to be valid URL
|
|
261
|
+
- SDK handles HTTPS connections
|
|
262
|
+
|
|
263
|
+
3. **Input Validation**
|
|
264
|
+
- URL validation during setup
|
|
265
|
+
- File ID passed through without modification
|
|
266
|
+
- No shell command injection risks
|
|
267
|
+
|
|
268
|
+
## Performance Characteristics
|
|
269
|
+
|
|
270
|
+
- **Download Speed:** Limited by network and Directus server
|
|
271
|
+
- **Memory Usage:** Streams file to temp, then loads ZIP into memory
|
|
272
|
+
- **Disk Usage:** Temporary file during download (auto-cleaned)
|
|
273
|
+
- **Startup Time:** ~100ms for config load + argument parsing
|
|
274
|
+
|
|
275
|
+
## Future Enhancements
|
|
276
|
+
|
|
277
|
+
Potential features for future versions:
|
|
278
|
+
|
|
279
|
+
1. **Progress Bar:** Show download progress for large files
|
|
280
|
+
2. **Resume Downloads:** Support partial download resume
|
|
281
|
+
3. **Batch Downloads:** Download multiple files at once
|
|
282
|
+
4. **Config Management:** Commands to view/edit/reset config
|
|
283
|
+
5. **Dry Run:** Preview what would be extracted without extracting
|
|
284
|
+
6. **Custom Output:** Specify extraction directory
|
|
285
|
+
7. **Compression:** Support other archive formats
|
|
286
|
+
8. **Logging:** Verbose mode with detailed logs
|