@mks2508/coolify-mks-cli-mcp 0.6.3 → 0.8.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 (60) hide show
  1. package/dist/cli/coolify-state.d.ts +92 -4
  2. package/dist/cli/coolify-state.d.ts.map +1 -1
  3. package/dist/cli/index.js +22149 -11456
  4. package/dist/cli/ui/highlighter.d.ts +28 -0
  5. package/dist/cli/ui/highlighter.d.ts.map +1 -0
  6. package/dist/cli/ui/index.d.ts +9 -0
  7. package/dist/cli/ui/index.d.ts.map +1 -0
  8. package/dist/cli/ui/spinners.d.ts +100 -0
  9. package/dist/cli/ui/spinners.d.ts.map +1 -0
  10. package/dist/cli/ui/tables.d.ts +103 -0
  11. package/dist/cli/ui/tables.d.ts.map +1 -0
  12. package/dist/coolify/index.d.ts +22 -3
  13. package/dist/coolify/index.d.ts.map +1 -1
  14. package/dist/coolify/types.d.ts +99 -1
  15. package/dist/coolify/types.d.ts.map +1 -1
  16. package/dist/examples/demo-ui.d.ts +8 -0
  17. package/dist/examples/demo-ui.d.ts.map +1 -0
  18. package/dist/index.cjs +322 -12
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.js +322 -12
  21. package/dist/index.js.map +1 -1
  22. package/dist/sdk.d.ts +41 -0
  23. package/dist/sdk.d.ts.map +1 -1
  24. package/dist/server/stdio.js +258 -9
  25. package/package.json +16 -4
  26. package/src/cli/actions.ts +9 -2
  27. package/src/cli/commands/create.ts +71 -5
  28. package/src/cli/commands/db.ts +37 -0
  29. package/src/cli/commands/delete.ts +6 -2
  30. package/src/cli/commands/deploy.ts +347 -49
  31. package/src/cli/commands/deployments.ts +6 -2
  32. package/src/cli/commands/diagnose.ts +3 -3
  33. package/src/cli/commands/env.ts +121 -22
  34. package/src/cli/commands/exec.ts +6 -2
  35. package/src/cli/commands/init.ts +937 -0
  36. package/src/cli/commands/logs.ts +224 -24
  37. package/src/cli/commands/main-menu.ts +21 -0
  38. package/src/cli/commands/projects.ts +312 -29
  39. package/src/cli/commands/restart.ts +6 -2
  40. package/src/cli/commands/service-logs.ts +14 -0
  41. package/src/cli/commands/show.ts +6 -2
  42. package/src/cli/commands/start.ts +6 -2
  43. package/src/cli/commands/status.ts +538 -0
  44. package/src/cli/commands/stop.ts +6 -2
  45. package/src/cli/commands/update.ts +27 -2
  46. package/src/cli/coolify-state.ts +164 -11
  47. package/src/cli/index.ts +91 -10
  48. package/src/cli/name-resolver.ts +228 -0
  49. package/src/cli/ui/banner.ts +276 -0
  50. package/src/cli/ui/highlighter.ts +176 -0
  51. package/src/cli/ui/index.ts +9 -0
  52. package/src/cli/ui/prompts.ts +155 -0
  53. package/src/cli/ui/screen.ts +606 -0
  54. package/src/cli/ui/select.ts +280 -0
  55. package/src/cli/ui/spinners.ts +256 -0
  56. package/src/cli/ui/tables.ts +407 -0
  57. package/src/coolify/index.ts +257 -12
  58. package/src/coolify/types.ts +103 -1
  59. package/src/examples/demo-ui.ts +78 -0
  60. package/src/sdk.ts +162 -0
package/src/sdk.ts CHANGED
@@ -180,6 +180,168 @@ class ApplicationsResource {
180
180
  async deleteEnv(uuid: string, key: string) {
181
181
  return unwrap(await this.svc.deleteEnvironmentVariable(uuid, key));
182
182
  }
183
+
184
+ /**
185
+ * Sync environment variables from a local .env file to Coolify.
186
+ *
187
+ * @param uuid - Application UUID
188
+ * @param options - Sync options
189
+ * @returns Sync result with changes applied
190
+ */
191
+ async syncEnv(
192
+ uuid: string,
193
+ options: {
194
+ /** Path to .env file (default: reads from .env in cwd) */
195
+ filePath?: string;
196
+ /** Preview changes without applying */
197
+ dryRun?: boolean;
198
+ /** Delete vars not in file */
199
+ prune?: boolean;
200
+ /** Callback for progress updates (optional) */
201
+ onProgress?: (update: {
202
+ type: 'add' | 'update' | 'remove';
203
+ key: string;
204
+ value?: string;
205
+ }) => void;
206
+ } = {},
207
+ ): Promise<{
208
+ added: Array<{ key: string; value: string }>;
209
+ updated: Array<{ key: string; value: string; oldValue: string }>;
210
+ removed: string[];
211
+ skipped: number;
212
+ }> {
213
+ const { filePath, dryRun = false, prune = false, onProgress } = options;
214
+
215
+ // 1. Read and parse .env file
216
+ let envContent: string;
217
+ try {
218
+ envContent = await Bun.file(filePath || '.env').text();
219
+ } catch {
220
+ throw new Error(
221
+ filePath
222
+ ? `Cannot read file: ${filePath}`
223
+ : 'No .env file found in current directory',
224
+ );
225
+ }
226
+
227
+ const localVars = this.parseEnvContent(envContent);
228
+
229
+ if (localVars.size === 0) {
230
+ return { added: [], updated: [], removed: [], skipped: 0 };
231
+ }
232
+
233
+ // 2. Get current vars from Coolify
234
+ const currentVarsList = await this.envVars(uuid);
235
+ const currentVars = new Map(
236
+ currentVarsList.map((v) => [v.key, v.value]),
237
+ );
238
+
239
+ // 3. Calculate changes
240
+ const toAdd: Array<{ key: string; value: string }> = [];
241
+ const toUpdate: Array<{
242
+ key: string;
243
+ value: string;
244
+ oldValue: string;
245
+ }> = [];
246
+ const toRemove: string[] = [];
247
+
248
+ for (const [key, value] of localVars.entries()) {
249
+ const currentValue = currentVars.get(key);
250
+ if (!currentValue) {
251
+ toAdd.push({ key, value });
252
+ } else if (currentValue !== value) {
253
+ toUpdate.push({ key, value, oldValue: currentValue });
254
+ }
255
+ }
256
+
257
+ if (prune) {
258
+ for (const key of currentVars.keys()) {
259
+ if (!localVars.has(key)) {
260
+ toRemove.push(key);
261
+ }
262
+ }
263
+ }
264
+
265
+ // 4. Apply changes (unless dry-run)
266
+ if (!dryRun) {
267
+ // Add new variables
268
+ for (const { key, value } of toAdd) {
269
+ await this.setEnv(uuid, key, value, false);
270
+ onProgress?.({ type: 'add', key, value });
271
+ }
272
+
273
+ // Update existing variables
274
+ for (const { key, value } of toUpdate) {
275
+ await this.setEnv(uuid, key, value, false);
276
+ onProgress?.({ type: 'update', key, value });
277
+ }
278
+
279
+ // Remove pruned variables
280
+ for (const key of toRemove) {
281
+ await this.deleteEnv(uuid, key);
282
+ onProgress?.({ type: 'remove', key });
283
+ }
284
+ } else {
285
+ // Report what would happen in dry-run
286
+ for (const { key, value } of toAdd) {
287
+ onProgress?.({ type: 'add', key, value });
288
+ }
289
+ for (const { key, value } of toUpdate) {
290
+ onProgress?.({ type: 'update', key, value });
291
+ }
292
+ for (const key of toRemove) {
293
+ onProgress?.({ type: 'remove', key });
294
+ }
295
+ }
296
+
297
+ return {
298
+ added: toAdd,
299
+ updated: toUpdate,
300
+ removed: toRemove,
301
+ skipped: currentVars.size - toUpdate.length - toRemove.length,
302
+ };
303
+ }
304
+
305
+ /**
306
+ * Parse .env file content into a Map.
307
+ * Handles comments, empty lines, and quoted values.
308
+ *
309
+ * @param content - The .env file content
310
+ * @returns Map of environment variables
311
+ */
312
+ private parseEnvContent(content: string): Map<string, string> {
313
+ const envVars = new Map<string, string>();
314
+ const lines = content.split('\n');
315
+
316
+ for (const line of lines) {
317
+ const trimmedLine = line.trim();
318
+ // Skip comments and empty lines
319
+ if (!trimmedLine || trimmedLine.startsWith('#')) {
320
+ continue;
321
+ }
322
+
323
+ // Parse KEY=VALUE format
324
+ const eqIndex = trimmedLine.indexOf('=');
325
+ if (eqIndex === -1) {
326
+ continue; // Skip invalid lines
327
+ }
328
+
329
+ const key = trimmedLine.slice(0, eqIndex).trim();
330
+ let value = trimmedLine.slice(eqIndex + 1).trim();
331
+
332
+ // Remove quotes if present
333
+ if (
334
+ (value.startsWith('"') && value.endsWith('"')) ||
335
+ (value.startsWith("'") && value.endsWith("'"))
336
+ ) {
337
+ value = value.slice(1, -1);
338
+ }
339
+
340
+ envVars.set(key, value);
341
+ }
342
+
343
+ return envVars;
344
+ }
183
345
  }
184
346
 
185
347
  class DatabasesResource {