optikit 1.1.1 → 1.2.0

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/CLAUDE.md +239 -0
  3. package/CODE_QUALITY.md +398 -0
  4. package/ENHANCEMENTS.md +310 -0
  5. package/FEATURE_ENHANCEMENTS.md +435 -0
  6. package/README.md +46 -13
  7. package/SAFETY_FEATURES.md +396 -0
  8. package/USAGE.md +225 -41
  9. package/VERSION_MANAGEMENT.md +438 -0
  10. package/dist/cli.js +116 -7
  11. package/dist/commands/build/releases.js +57 -0
  12. package/dist/commands/buildReleases.js +48 -74
  13. package/dist/commands/clean/flutter.js +51 -0
  14. package/dist/commands/clean/ios.js +109 -0
  15. package/dist/commands/cleanProject.js +34 -4
  16. package/dist/commands/cleanProjectIos.js +17 -7
  17. package/dist/commands/config/init.js +54 -0
  18. package/dist/commands/config/rollback.js +161 -0
  19. package/dist/commands/generateModule.js +39 -11
  20. package/dist/commands/init.js +54 -0
  21. package/dist/commands/openProject.js +17 -0
  22. package/dist/commands/project/devices.js +188 -0
  23. package/dist/commands/project/generate.js +143 -0
  24. package/dist/commands/project/open.js +63 -0
  25. package/dist/commands/project/setup.js +46 -0
  26. package/dist/commands/rollback.js +161 -0
  27. package/dist/commands/setupVSCode.js +27 -21
  28. package/dist/commands/updateVersions.js +13 -1
  29. package/dist/commands/version/bump.js +161 -0
  30. package/dist/commands/version/update.js +91 -0
  31. package/dist/commands/version.js +161 -0
  32. package/dist/constants.js +131 -0
  33. package/dist/utils/backupHelpers.js +88 -0
  34. package/dist/utils/buildHelpers.js +55 -0
  35. package/dist/utils/commandHelpers.js +51 -0
  36. package/dist/utils/configHelpers.js +80 -0
  37. package/dist/utils/dryRunHelpers.js +103 -0
  38. package/dist/utils/fileHelpers.js +2 -1
  39. package/dist/utils/helpers/build.js +55 -0
  40. package/dist/utils/helpers/dryRun.js +103 -0
  41. package/dist/utils/helpers/file.js +24 -0
  42. package/dist/utils/helpers/string.js +3 -0
  43. package/dist/utils/helpers/version.js +80 -0
  44. package/dist/utils/services/backup.js +88 -0
  45. package/dist/utils/services/command.js +51 -0
  46. package/dist/utils/services/config.js +80 -0
  47. package/dist/utils/services/exec.js +132 -0
  48. package/dist/utils/services/logger.js +15 -0
  49. package/dist/utils/validationHelpers.js +101 -0
  50. package/dist/utils/validators/validation.js +101 -0
  51. package/dist/utils/versionHelpers.js +80 -0
  52. package/package.json +1 -1
  53. package/src/cli.ts +165 -7
  54. package/src/commands/build/releases.ts +79 -0
  55. package/src/commands/clean/flutter.ts +58 -0
  56. package/src/commands/{cleanProjectIos.ts → clean/ios.ts} +19 -10
  57. package/src/commands/config/init.ts +63 -0
  58. package/src/commands/config/rollback.ts +200 -0
  59. package/src/commands/project/devices.ts +246 -0
  60. package/src/commands/{generateModule.ts → project/generate.ts} +47 -17
  61. package/src/commands/{openProject.ts → project/open.ts} +26 -5
  62. package/src/commands/project/setup.ts +50 -0
  63. package/src/commands/version/bump.ts +202 -0
  64. package/src/commands/{updateVersions.ts → version/update.ts} +22 -6
  65. package/src/constants.ts +144 -0
  66. package/src/utils/helpers/build.ts +80 -0
  67. package/src/utils/helpers/dryRun.ts +124 -0
  68. package/src/utils/{fileHelpers.ts → helpers/file.ts} +3 -2
  69. package/src/utils/helpers/version.ts +109 -0
  70. package/src/utils/services/backup.ts +109 -0
  71. package/src/utils/services/command.ts +76 -0
  72. package/src/utils/services/config.ts +106 -0
  73. package/src/utils/{execHelpers.ts → services/exec.ts} +1 -1
  74. package/src/utils/validators/validation.ts +122 -0
  75. package/src/commands/buildReleases.ts +0 -102
  76. package/src/commands/cleanProject.ts +0 -25
  77. package/src/commands/setupVSCode.ts +0 -44
  78. /package/src/utils/{stringHelpers.ts → helpers/string.ts} +0 -0
  79. /package/src/utils/{loggerHelpers.ts → services/logger.ts} +0 -0
@@ -0,0 +1,396 @@
1
+ # OptiKit CLI - Safety & Validation Features
2
+
3
+ ## Overview
4
+
5
+ OptiKit now includes comprehensive safety and validation features to prevent data loss, ensure proper environment setup, and provide users with confidence when running potentially destructive operations.
6
+
7
+ ---
8
+
9
+ ## 🛡️ Pre-Flight Validation
10
+
11
+ All commands now perform validation checks before executing to ensure the environment is properly configured.
12
+
13
+ ### Validation Types
14
+
15
+ #### 1. Flutter Project Validation
16
+ **Function:** `validateFlutterProject()`
17
+ **Checks:**
18
+ - `pubspec.yaml` exists in current directory
19
+ - `pubspec.yaml` contains Flutter SDK reference
20
+
21
+ **Used by:** All commands
22
+
23
+ **Error Messages:**
24
+ ```
25
+ ❌ Not a Flutter project: pubspec.yaml not found.
26
+ ℹ️ Please run this command from the root of a Flutter project.
27
+ ```
28
+
29
+ #### 2. Flutter SDK Validation
30
+ **Function:** `validateFlutterSdk(useFvm: boolean)`
31
+ **Checks:**
32
+ - If using FVM: `.fvm/flutter_sdk` directory exists and `fvm` command available
33
+ - If not using FVM: global `flutter` command available
34
+
35
+ **Used by:** build commands, clean commands
36
+
37
+ **Error Messages:**
38
+ ```
39
+ ❌ FVM Flutter SDK not found at .fvm/flutter_sdk
40
+ ℹ️ Run 'fvm install' or use --disable-fvm flag.
41
+
42
+ OR
43
+
44
+ ❌ Flutter SDK not found.
45
+ ℹ️ Install Flutter: https://flutter.dev/docs/get-started/install
46
+ ```
47
+
48
+ #### 3. iOS Project Validation
49
+ **Function:** `validateIosProject()`
50
+ **Checks:**
51
+ - `ios/` directory exists
52
+ - Either `Runner.xcodeproj` or `Runner.xcworkspace` exists
53
+
54
+ **Used by:** iOS build commands, iOS clean command, open-ios command
55
+
56
+ **Error Messages:**
57
+ ```
58
+ ❌ iOS project directory not found.
59
+ ℹ️ Run 'flutter create .' to add iOS support.
60
+ ```
61
+
62
+ #### 4. Android Project Validation
63
+ **Function:** `validateAndroidProject()`
64
+ **Checks:**
65
+ - `android/` directory exists
66
+ - Either `build.gradle` or `build.gradle.kts` exists
67
+
68
+ **Used by:** Android build commands, open-android command
69
+
70
+ **Error Messages:**
71
+ ```
72
+ ❌ Android project directory not found.
73
+ ℹ️ Run 'flutter create .' to add Android support.
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 💾 Automatic Backup System
79
+
80
+ Critical files are automatically backed up before any destructive operations.
81
+
82
+ ### How It Works
83
+
84
+ 1. **Backup Creation:** Files are copied to `.optikit-backup/` directory with timestamp
85
+ 2. **Location:** Backups stored in same directory as original file
86
+ 3. **Naming:** `filename_YYYY-MM-DDTHH-MM-SS-mmmZ.ext`
87
+ 4. **Retention:** Last 5 backups are kept (configurable)
88
+ 5. **Cleanup:** Old backups automatically removed
89
+
90
+ ### Backed Up Files
91
+
92
+ | Command | Files Backed Up |
93
+ |---------|----------------|
94
+ | `clean-flutter` | `pubspec.lock` |
95
+ | `flutter-update-version` | `pubspec.yaml`, `ios/Runner.xcodeproj/project.pbxproj`, `ios/Runner/Info.plist` |
96
+
97
+ ### Example Backup Structure
98
+
99
+ ```
100
+ your-flutter-project/
101
+ ├── pubspec.yaml
102
+ ├── .optikit-backup/
103
+ │ ├── pubspec_2025-12-23T10-30-00-000Z.yaml
104
+ │ ├── pubspec_2025-12-23T11-15-30-000Z.yaml
105
+ │ └── pubspec_2025-12-23T12-45-10-000Z.yaml
106
+ ├── ios/
107
+ │ ├── Runner.xcodeproj/
108
+ │ │ ├── project.pbxproj
109
+ │ │ └── .optikit-backup/
110
+ │ │ └── project_2025-12-23T10-30-00-000Z.pbxproj
111
+ │ └── Runner/
112
+ │ ├── Info.plist
113
+ │ └── .optikit-backup/
114
+ │ └── Info_2025-12-23T10-30-00-000Z.plist
115
+ ```
116
+
117
+ ### Backup Functions
118
+
119
+ #### Create Backup
120
+ ```typescript
121
+ createBackup(filePath: string): string | null
122
+ ```
123
+ - Creates timestamped backup of file
124
+ - Returns backup path on success, null on failure
125
+ - Automatically creates `.optikit-backup/` directory
126
+
127
+ #### Restore Backup
128
+ ```typescript
129
+ restoreBackup(originalPath: string, backupPath: string): boolean
130
+ ```
131
+ - Copies backup file back to original location
132
+ - Returns true on success, false on failure
133
+
134
+ #### Cleanup Old Backups
135
+ ```typescript
136
+ cleanupBackups(directory: string, keepCount: number = 5): void
137
+ ```
138
+ - Removes old backups beyond keepCount
139
+ - Keeps most recent backups
140
+ - Called automatically (can be manual too)
141
+
142
+ ---
143
+
144
+ ## ⚠️ Overwrite Warnings
145
+
146
+ Commands that may overwrite existing data now display warnings.
147
+
148
+ ### Module Generation
149
+
150
+ **Command:** `optikit generate module <moduleName>`
151
+
152
+ **Warnings:**
153
+ ```
154
+ ⚠️ Module user_profile already exists at lib/module/user_profile
155
+ ℹ️ Files will be overwritten...
156
+ ```
157
+
158
+ Users are informed when modules will be overwritten, giving them a chance to cancel (Ctrl+C).
159
+
160
+ ### VSCode Settings
161
+
162
+ **Command:** `optikit setup-vscode`
163
+
164
+ **Messages:**
165
+ ```
166
+ ℹ️ .vscode directory already exists.
167
+ ```
168
+
169
+ Informs users when directories already exist before proceeding.
170
+
171
+ ---
172
+
173
+ ## 🔍 Validation Module API
174
+
175
+ ### Location
176
+ [src/utils/validationHelpers.ts](src/utils/validationHelpers.ts)
177
+
178
+ ### Functions
179
+
180
+ ```typescript
181
+ // Validates Flutter project structure
182
+ validateFlutterProject(): boolean
183
+
184
+ // Validates Flutter SDK availability
185
+ validateFlutterSdk(useFvm: boolean = false): Promise<boolean>
186
+
187
+ // Validates iOS project exists
188
+ validateIosProject(): boolean
189
+
190
+ // Validates Android project exists
191
+ validateAndroidProject(): boolean
192
+
193
+ // Check if specific file exists
194
+ checkFileExists(filePath: string): boolean
195
+ ```
196
+
197
+ ### Usage Example
198
+
199
+ ```typescript
200
+ import { validateFlutterProject, validateFlutterSdk } from "../utils/validationHelpers.js";
201
+
202
+ async function myCommand(noFvm: boolean) {
203
+ // Pre-flight validation
204
+ if (!validateFlutterProject()) {
205
+ process.exit(1);
206
+ }
207
+
208
+ if (!(await validateFlutterSdk(!noFvm))) {
209
+ process.exit(1);
210
+ }
211
+
212
+ // Proceed with command...
213
+ }
214
+ ```
215
+
216
+ ---
217
+
218
+ ## 💼 Backup Module API
219
+
220
+ ### Location
221
+ [src/utils/backupHelpers.ts](src/utils/backupHelpers.ts)
222
+
223
+ ### Functions
224
+
225
+ ```typescript
226
+ // Create timestamped backup
227
+ createBackup(filePath: string): string | null
228
+
229
+ // Restore from backup
230
+ restoreBackup(originalPath: string, backupPath: string): boolean
231
+
232
+ // Clean up old backups
233
+ cleanupBackups(directory: string, keepCount: number = 5): void
234
+
235
+ // Get backup directory path
236
+ getBackupPath(filePath: string): string
237
+ ```
238
+
239
+ ### Usage Example
240
+
241
+ ```typescript
242
+ import { createBackup } from "../utils/backupHelpers.js";
243
+
244
+ async function updateConfigFile() {
245
+ const configPath = "pubspec.yaml";
246
+
247
+ // Create backup before modification
248
+ const backupPath = createBackup(configPath);
249
+
250
+ if (!backupPath) {
251
+ LoggerHelpers.error("Failed to create backup");
252
+ process.exit(1);
253
+ }
254
+
255
+ // Safely modify file...
256
+ fs.writeFileSync(configPath, newContent);
257
+ }
258
+ ```
259
+
260
+ ---
261
+
262
+ ## 🎯 Command-Specific Safety Features
263
+
264
+ ### Build Commands
265
+ **Validation:**
266
+ - ✅ Flutter project exists
267
+ - ✅ Flutter SDK available (FVM or global)
268
+ - ✅ Platform project exists (iOS or Android)
269
+
270
+ **No backups:** Build commands don't modify source files
271
+
272
+ ### Clean Commands
273
+ **Validation:**
274
+ - ✅ Flutter project exists
275
+ - ✅ Flutter SDK available
276
+
277
+ **Backups:**
278
+ - `pubspec.lock` (before deletion)
279
+
280
+ **Step-by-step logging:** Each operation logged individually for clarity
281
+
282
+ ### Version Update
283
+ **Validation:**
284
+ - ✅ Flutter project exists
285
+ - ✅ Files exist before modification
286
+
287
+ **Backups:**
288
+ - `pubspec.yaml`
289
+ - `ios/Runner.xcodeproj/project.pbxproj`
290
+ - `ios/Runner/Info.plist`
291
+
292
+ ### Module Generation
293
+ **Validation:**
294
+ - ✅ Module name format (lowercase, numbers, underscores only)
295
+ - ✅ Module name not empty
296
+
297
+ **Warnings:**
298
+ - Module already exists (will overwrite)
299
+
300
+ ### Open Project Commands
301
+ **Validation:**
302
+ - ✅ Flutter project exists
303
+ - ✅ Platform project exists (iOS or Android)
304
+
305
+ ---
306
+
307
+ ## 📋 Error Handling Flow
308
+
309
+ ```
310
+ 1. Command invoked
311
+
312
+ 2. Pre-flight validation
313
+ ├─ ❌ Validation fails → Clear error message → Exit with code 1
314
+ └─ ✅ Validation passes
315
+
316
+ 3. Backup critical files (if destructive operation)
317
+ ├─ ❌ Backup fails → Warning logged → Continue (user decision)
318
+ └─ ✅ Backup succeeds
319
+
320
+ 4. Execute command
321
+ ├─ ❌ Command fails → Detailed error → Exit with code 1
322
+ └─ ✅ Command succeeds
323
+
324
+ 5. Success message → Exit with code 0
325
+ ```
326
+
327
+ ---
328
+
329
+ ## 🚀 Benefits
330
+
331
+ ### For Users
332
+ 1. **Confidence:** Know that files are backed up before changes
333
+ 2. **Clarity:** Clear error messages when something is missing
334
+ 3. **Safety:** Prevent accidental data loss
335
+ 4. **Recovery:** Easy restoration from backups if needed
336
+
337
+ ### For Developers
338
+ 1. **Reusable:** Validation and backup utilities can be used across commands
339
+ 2. **Consistent:** Same patterns applied everywhere
340
+ 3. **Maintainable:** Centralized validation logic
341
+ 4. **Testable:** Functions can be unit tested
342
+
343
+ ### For CI/CD
344
+ 1. **Fail Fast:** Invalid environments caught immediately
345
+ 2. **Clear Errors:** Detailed messages for debugging
346
+ 3. **Proper Exit Codes:** Scripts can handle failures correctly
347
+
348
+ ---
349
+
350
+ ## 📝 Best Practices
351
+
352
+ ### When Adding New Commands
353
+
354
+ 1. **Always validate** appropriate project structure
355
+ 2. **Backup files** before modifying them
356
+ 3. **Log each step** for better user feedback
357
+ 4. **Exit with code 1** on errors
358
+ 5. **Provide helpful** error messages with suggestions
359
+
360
+ ### For End Users
361
+
362
+ 1. **Review backups** in `.optikit-backup/` directories
363
+ 2. **Keep backups in .gitignore** (already configured)
364
+ 3. **Don't rely on backups** for critical data (use git!)
365
+ 4. **Report issues** if validation is too strict
366
+
367
+ ---
368
+
369
+ ## 🔧 Configuration
370
+
371
+ Currently, configuration is hardcoded but can be made configurable in the future:
372
+
373
+ - Backup retention count: 5 backups
374
+ - Backup location: `.optikit-backup/` in same directory as original file
375
+ - Timestamp format: ISO 8601 with special characters replaced
376
+
377
+ ---
378
+
379
+ ## 📌 Future Enhancements
380
+
381
+ Potential improvements for safety features:
382
+
383
+ 1. **Interactive Prompts:** Ask user confirmation before destructive operations
384
+ 2. **Dry-run Mode:** Preview changes without executing
385
+ 3. **Backup Compression:** Compress old backups to save space
386
+ 4. **Backup Export:** Export all backups to external location
387
+ 5. **Rollback Command:** Easy command to restore from last backup
388
+ 6. **Config File:** User-configurable safety settings
389
+ 7. **Backup Metadata:** Track what command created each backup
390
+ 8. **Smart Cleanup:** Clean backups based on age and importance
391
+
392
+ ---
393
+
394
+ **Version:** 1.1.1+safety
395
+ **Last Updated:** December 23, 2025
396
+ **Status:** ✅ Production Ready