@mtndev/cli 0.0.1

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 (72) hide show
  1. package/cjs/__chunks/4SFWHCB3.cjs +133 -0
  2. package/cjs/__chunks/B2KFW7T7.cjs +1 -0
  3. package/cjs/__chunks/EMMC33QA.cjs +401 -0
  4. package/cjs/__chunks/FEZT3HUT.cjs +52 -0
  5. package/cjs/__chunks/INFOPAHN.cjs +117 -0
  6. package/cjs/__chunks/J36P6UNE.cjs +75 -0
  7. package/cjs/__chunks/LQMP4ZKY.cjs +22 -0
  8. package/cjs/__chunks/NIMXXHJQ.cjs +92 -0
  9. package/cjs/__chunks/WNJ3ZYLI.cjs +1 -0
  10. package/cjs/__chunks/YCCIX4ZQ.cjs +100 -0
  11. package/cjs/commands/doppler/handler.cjs +9 -0
  12. package/cjs/commands/doppler/handler.d.ts +5 -0
  13. package/cjs/commands/doppler/index.cjs +41 -0
  14. package/cjs/commands/doppler/index.d.ts +3 -0
  15. package/cjs/commands/doppler/schema.cjs +8 -0
  16. package/cjs/commands/doppler/schema.d.ts +50 -0
  17. package/cjs/commands/doppler/utils/exec.cjs +12 -0
  18. package/cjs/commands/doppler/utils/exec.d.ts +52 -0
  19. package/cjs/commands/doppler/utils.cjs +30 -0
  20. package/cjs/commands/doppler/utils.d.ts +69 -0
  21. package/cjs/commands/icons/handler.cjs +8 -0
  22. package/cjs/commands/icons/handler.d.ts +5 -0
  23. package/cjs/commands/icons/index.cjs +31 -0
  24. package/cjs/commands/icons/index.d.ts +3 -0
  25. package/cjs/commands/icons/schema.cjs +16 -0
  26. package/cjs/commands/icons/schema.d.ts +86 -0
  27. package/cjs/commands/icons/utils.cjs +13 -0
  28. package/cjs/commands/icons/utils.d.ts +52 -0
  29. package/cjs/commands/index.cjs +84 -0
  30. package/cjs/commands/index.d.ts +2 -0
  31. package/cjs/commands/schema.cjs +8 -0
  32. package/cjs/commands/schema.d.ts +26 -0
  33. package/cjs/index.cjs +5 -0
  34. package/cjs/index.d.ts +2 -0
  35. package/esm/__chunks/46HGXFME.js +0 -0
  36. package/esm/__chunks/6G4PXXKF.js +75 -0
  37. package/esm/__chunks/FL7AILGH.js +133 -0
  38. package/esm/__chunks/HJSXC6HP.js +117 -0
  39. package/esm/__chunks/O262GK4B.js +401 -0
  40. package/esm/__chunks/OXGTO4KT.js +22 -0
  41. package/esm/__chunks/QSRTFPAA.js +100 -0
  42. package/esm/__chunks/SJXQJ7RS.js +92 -0
  43. package/esm/__chunks/SNCKIAOR.js +0 -0
  44. package/esm/__chunks/XPAQNFHZ.js +52 -0
  45. package/esm/commands/doppler/handler.d.ts +5 -0
  46. package/esm/commands/doppler/handler.js +9 -0
  47. package/esm/commands/doppler/index.d.ts +3 -0
  48. package/esm/commands/doppler/index.js +41 -0
  49. package/esm/commands/doppler/schema.d.ts +50 -0
  50. package/esm/commands/doppler/schema.js +8 -0
  51. package/esm/commands/doppler/utils/exec.d.ts +52 -0
  52. package/esm/commands/doppler/utils/exec.js +12 -0
  53. package/esm/commands/doppler/utils.d.ts +69 -0
  54. package/esm/commands/doppler/utils.js +30 -0
  55. package/esm/commands/icons/handler.d.ts +5 -0
  56. package/esm/commands/icons/handler.js +8 -0
  57. package/esm/commands/icons/index.d.ts +3 -0
  58. package/esm/commands/icons/index.js +31 -0
  59. package/esm/commands/icons/schema.d.ts +86 -0
  60. package/esm/commands/icons/schema.js +16 -0
  61. package/esm/commands/icons/utils.d.ts +52 -0
  62. package/esm/commands/icons/utils.js +13 -0
  63. package/esm/commands/index.d.ts +2 -0
  64. package/esm/commands/index.js +84 -0
  65. package/esm/commands/schema.d.ts +26 -0
  66. package/esm/commands/schema.js +8 -0
  67. package/esm/index.d.ts +2 -0
  68. package/esm/index.js +5 -0
  69. package/package.json +59 -0
  70. package/utils/input/package.json +8 -0
  71. package/utils/package/package.json +8 -0
  72. package/utils/validation/package.json +8 -0
@@ -0,0 +1,117 @@
1
+ import {
2
+ checkDependencies,
3
+ generateAllIcons,
4
+ validateBaseIcons
5
+ } from "./FL7AILGH.js";
6
+ import {
7
+ iconsCommandMetadata,
8
+ iconsCommandOptionsSchema
9
+ } from "./6G4PXXKF.js";
10
+
11
+ // src/commands/icons/handler.js
12
+ import chalk from "chalk";
13
+ import { ZodError } from "zod";
14
+ async function iconsCommand(options) {
15
+ try {
16
+ const validatedOptions = iconsCommandOptionsSchema.parse(options);
17
+ if (validatedOptions.help) {
18
+ console.log(chalk.bold(`
19
+ Usage: mtn icons <input> [options]`));
20
+ console.log(chalk.gray(iconsCommandMetadata.description));
21
+ console.log(chalk.bold("\nOptions:"));
22
+ Object.entries(iconsCommandOptionsSchema.shape).forEach(
23
+ ([key, fieldSchema]) => {
24
+ if (key === "input") return;
25
+ const description = fieldSchema.description || "No description available";
26
+ const optionMeta = (
27
+ /** @type {any} */
28
+ iconsCommandMetadata.options[key]
29
+ );
30
+ const defaultValue = optionMeta?.default ?? false;
31
+ const alias = optionMeta?.alias ? chalk.cyan(`, -${optionMeta.alias}`) : "";
32
+ console.log(
33
+ chalk.cyan(` --${key}`) + alias + ` ${description} (default: ${defaultValue})`
34
+ );
35
+ }
36
+ );
37
+ console.log("");
38
+ return;
39
+ }
40
+ const { input, channels, iconTypes, verbose } = validatedOptions;
41
+ if (verbose) {
42
+ console.log(chalk.blue("\n\u{1F4F1} Icon Generation"));
43
+ console.log(chalk.gray(` Input directory: ${input}`));
44
+ console.log(chalk.gray(` Channels: ${channels.join(", ")}`));
45
+ console.log(chalk.gray(` Icon types: ${iconTypes.join(", ")}`));
46
+ }
47
+ checkDependencies(verbose);
48
+ validateBaseIcons(input, iconTypes, verbose);
49
+ const result = generateAllIcons({
50
+ baseDir: input,
51
+ channels,
52
+ iconTypes,
53
+ verbose
54
+ });
55
+ console.log(chalk.bold("\n\u{1F4CA} Summary:"));
56
+ console.log(
57
+ chalk.green(
58
+ ` \u2713 Successfully generated: ${result.success.length} icon(s)`
59
+ )
60
+ );
61
+ if (result.failed.length > 0) {
62
+ console.log(chalk.red(` \u2717 Failed: ${result.failed.length} icon(s)`));
63
+ result.failed.forEach(({ icon, error }) => {
64
+ console.log(chalk.red(` - ${icon}: ${error}`));
65
+ });
66
+ process.exit(1);
67
+ }
68
+ console.log(chalk.green(`
69
+ \u2705 All icons generated successfully!`));
70
+ } catch (error) {
71
+ if (error instanceof ZodError) {
72
+ console.error(chalk.red(`
73
+ \u274C Invalid command options:`));
74
+ error.errors.forEach((err) => {
75
+ console.error(chalk.red(` ${err.path.join(".")}: ${err.message}`));
76
+ });
77
+ process.exit(1);
78
+ }
79
+ const verbose = (
80
+ /** @type {any} */
81
+ options?.verbose || false
82
+ );
83
+ console.error(chalk.red(`
84
+ \u274C Icon generation failed:`));
85
+ if (error instanceof Error) {
86
+ console.error(chalk.red(` ${error.message}`));
87
+ if (verbose && error.stack) {
88
+ console.error(chalk.gray("\nStack trace:"));
89
+ console.error(chalk.gray(error.stack));
90
+ }
91
+ } else {
92
+ console.error(chalk.red(` ${String(error)}`));
93
+ }
94
+ console.error(chalk.yellow("\n\u{1F4A1} Troubleshooting tips:"));
95
+ console.error(
96
+ chalk.yellow(
97
+ " \u2022 Ensure ImageMagick is installed (brew install imagemagick)"
98
+ )
99
+ );
100
+ console.error(
101
+ chalk.yellow(
102
+ " \u2022 Make sure icon.png and adaptive-icon.png exist in the input directory"
103
+ )
104
+ );
105
+ console.error(
106
+ chalk.yellow(" \u2022 Verify the input directory path is correct")
107
+ );
108
+ console.error(
109
+ chalk.yellow(" \u2022 Use --verbose for detailed error information\n")
110
+ );
111
+ process.exit(1);
112
+ }
113
+ }
114
+
115
+ export {
116
+ iconsCommand
117
+ };
@@ -0,0 +1,401 @@
1
+ import {
2
+ exec
3
+ } from "./SJXQJ7RS.js";
4
+
5
+ // src/commands/doppler/utils.js
6
+ import { execSync } from "child_process";
7
+ import {
8
+ copyFileSync,
9
+ existsSync,
10
+ readFileSync,
11
+ renameSync,
12
+ unlinkSync,
13
+ writeFileSync
14
+ } from "fs";
15
+ import { createInterface } from "readline";
16
+ import chalk from "chalk";
17
+ var DEFAULT_DOPPLER_ENVIRONMENT = "dev";
18
+ function execDoppler(args, parser = "string", silent = false, verbose = false) {
19
+ const command = `doppler ${args.join(" ")}`;
20
+ let verbosity = "default";
21
+ if (verbose) {
22
+ verbosity = "verbose";
23
+ } else if (silent) {
24
+ verbosity = "silent";
25
+ }
26
+ return exec(command, {
27
+ verbosity,
28
+ stdoutParser: parser,
29
+ throwOnError: true
30
+ });
31
+ }
32
+ function checkDependencies(verbose = false) {
33
+ if (verbose) {
34
+ console.log(chalk.blue("\n\u{1F50D} Checking Doppler dependencies..."));
35
+ }
36
+ try {
37
+ execSync("which doppler", { stdio: "pipe" });
38
+ if (verbose) {
39
+ console.log(chalk.green(" \u2713 Doppler CLI is installed"));
40
+ }
41
+ } catch {
42
+ throw new Error(
43
+ "Doppler is not installed. Please install Doppler (brew install dopplerhq/cli/doppler), login, setup, and try again."
44
+ );
45
+ }
46
+ try {
47
+ execDoppler(["me"], "string", true, verbose);
48
+ if (verbose) {
49
+ console.log(chalk.green(" \u2713 Doppler is authenticated"));
50
+ }
51
+ } catch {
52
+ throw new Error(
53
+ "Doppler is not logged in. Please run 'doppler login' then 'doppler setup' and try again."
54
+ );
55
+ }
56
+ try {
57
+ execDoppler(["configs", "--json"], "json", true, verbose);
58
+ if (verbose) {
59
+ console.log(chalk.green(" \u2713 Doppler project is configured"));
60
+ }
61
+ } catch {
62
+ throw new Error(
63
+ "Doppler is not configured. Please run 'doppler setup' and try again."
64
+ );
65
+ }
66
+ }
67
+ function getConfigs(environment, verbose = false) {
68
+ if (verbose) {
69
+ console.log(
70
+ chalk.blue(
71
+ `
72
+ \u{1F4CB} Resolving configurations for environment: ${chalk.cyan(environment)}`
73
+ )
74
+ );
75
+ }
76
+ const availableConfigs = execDoppler(
77
+ ["configs", "--json"],
78
+ "json",
79
+ true,
80
+ verbose
81
+ );
82
+ const configNames = Array.isArray(availableConfigs) ? availableConfigs.map(
83
+ (config) => config.name
84
+ ) : [];
85
+ if (verbose && configNames.length > 0) {
86
+ console.log(
87
+ chalk.gray(` Available configurations: ${configNames.join(", ")}`)
88
+ );
89
+ }
90
+ if (environment === "all") {
91
+ if (configNames.length === 0) {
92
+ throw new Error("No configurations found in Doppler");
93
+ }
94
+ if (verbose) {
95
+ console.log(
96
+ chalk.green(` \u2713 Using all ${configNames.length} configurations`)
97
+ );
98
+ }
99
+ return configNames;
100
+ }
101
+ if (configNames.length > 0 && !configNames.includes(environment)) {
102
+ throw new Error(
103
+ `Configuration "${environment}" not found. Available configurations: ${configNames.join(", ")}`
104
+ );
105
+ }
106
+ if (verbose) {
107
+ console.log(chalk.green(` \u2713 Using configuration: ${environment}`));
108
+ }
109
+ return [environment];
110
+ }
111
+ function normalizeEscapeSequences(content) {
112
+ return content.replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\r/g, "\r");
113
+ }
114
+ function createDiff(oldContent, newContent) {
115
+ const oldLines = oldContent.split("\n");
116
+ const newLines = newContent.split("\n");
117
+ const diff = [];
118
+ const maxLines = Math.max(oldLines.length, newLines.length);
119
+ for (let i = 0; i < maxLines; i++) {
120
+ const oldLine = oldLines[i] || "";
121
+ const newLine = newLines[i] || "";
122
+ if (oldLine !== newLine) {
123
+ if (oldLine && !newLine) {
124
+ diff.push(`-${oldLine}`);
125
+ } else if (!oldLine && newLine) {
126
+ diff.push(`+${newLine}`);
127
+ } else {
128
+ diff.push(`-${oldLine}`);
129
+ diff.push(`+${newLine}`);
130
+ }
131
+ }
132
+ }
133
+ return diff;
134
+ }
135
+ function promptConfirmation(message) {
136
+ return new Promise((resolve) => {
137
+ const rl = createInterface({
138
+ input: process.stdin,
139
+ output: process.stdout
140
+ });
141
+ rl.question(message, (answer) => {
142
+ rl.close();
143
+ resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
144
+ });
145
+ });
146
+ }
147
+ async function downloadConfigs(options) {
148
+ const { environment, verbose } = options;
149
+ const actualEnvironment = environment ?? DEFAULT_DOPPLER_ENVIRONMENT;
150
+ const configs = getConfigs(actualEnvironment, verbose);
151
+ if (verbose) {
152
+ console.log(
153
+ chalk.blue(
154
+ `
155
+ \u2B07\uFE0F Starting download process for ${configs.length} configuration(s)...`
156
+ )
157
+ );
158
+ }
159
+ if (configs.length === 1 && environment !== "all") {
160
+ console.log(
161
+ "You can use -e all to download all configurations, or -e <env> for a specific environment."
162
+ );
163
+ }
164
+ for (const config of configs) {
165
+ const envFile = `.env.${config}`;
166
+ const backupFile = `${envFile}.backup`;
167
+ let backupMsg = "";
168
+ if (verbose) {
169
+ console.log(chalk.blue(`
170
+ \u{1F4E6} Processing config: ${chalk.cyan(config)}`));
171
+ }
172
+ try {
173
+ if (existsSync(envFile)) {
174
+ if (verbose) {
175
+ console.log(chalk.gray(` Creating backup: ${backupFile}`));
176
+ }
177
+ renameSync(envFile, backupFile);
178
+ backupMsg = "Backed up existing file, ";
179
+ }
180
+ if (verbose) {
181
+ console.log(chalk.gray(` Downloading secrets from Doppler...`));
182
+ }
183
+ const content = execDoppler(
184
+ [
185
+ "secrets",
186
+ "download",
187
+ "--no-file",
188
+ "--format",
189
+ "env",
190
+ "--config",
191
+ config
192
+ ],
193
+ "string",
194
+ !verbose,
195
+ // Only silent if not verbose
196
+ verbose
197
+ );
198
+ if (typeof content === "string") {
199
+ writeFileSync(envFile, content, "utf-8");
200
+ if (verbose) {
201
+ console.log(chalk.gray(` Written to: ${envFile}`));
202
+ }
203
+ } else {
204
+ throw new Error("Invalid content received from Doppler");
205
+ }
206
+ console.log(
207
+ `Config ${chalk.blue(config)}: ${backupMsg}downloaded successfully to ${chalk.green(envFile)}`
208
+ );
209
+ if (config === "dev" && !existsSync(".env")) {
210
+ copyFileSync(envFile, ".env");
211
+ console.log(
212
+ `Copied ${chalk.green(".env.dev")} to ${chalk.green(".env")}`
213
+ );
214
+ }
215
+ if (existsSync(backupFile)) {
216
+ if (verbose) {
217
+ console.log(chalk.gray(` Removing backup file`));
218
+ }
219
+ unlinkSync(backupFile);
220
+ }
221
+ } catch (error) {
222
+ console.error(`Failed to download ${config}: ${error?.message || error}`);
223
+ if (existsSync(backupFile)) {
224
+ renameSync(backupFile, envFile);
225
+ console.log(`Restored backup for ${envFile}`);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ async function uploadConfigs(options) {
231
+ const { environment, verbose } = options;
232
+ const configs = getConfigs(environment, verbose);
233
+ if (verbose) {
234
+ console.log(
235
+ chalk.blue(
236
+ `
237
+ \u2B06\uFE0F Starting upload process for ${configs.length} configuration(s)...`
238
+ )
239
+ );
240
+ }
241
+ for (const config of configs) {
242
+ const envFile = `.env.${config}`;
243
+ const backupFile = `${envFile}.doppler`;
244
+ const normalizedFile = `${envFile}.normalized`;
245
+ if (verbose) {
246
+ console.log(chalk.blue(`
247
+ \u{1F4E6} Processing config: ${chalk.cyan(config)}`));
248
+ }
249
+ try {
250
+ if (!existsSync(envFile)) {
251
+ console.log(
252
+ `Config ${config}: ${chalk.green(envFile)} does not exist. Skipping upload.`
253
+ );
254
+ continue;
255
+ }
256
+ if (verbose) {
257
+ console.log(
258
+ chalk.gray(` Creating backup of current Doppler config...`)
259
+ );
260
+ }
261
+ try {
262
+ const backupContent2 = execDoppler(
263
+ [
264
+ "secrets",
265
+ "download",
266
+ "--no-file",
267
+ "--format",
268
+ "env",
269
+ "--config",
270
+ config
271
+ ],
272
+ "string",
273
+ !verbose,
274
+ // Only silent if not verbose
275
+ verbose
276
+ );
277
+ if (typeof backupContent2 === "string") {
278
+ writeFileSync(backupFile, backupContent2, "utf-8");
279
+ if (verbose) {
280
+ console.log(chalk.gray(` Backup created: ${backupFile}`));
281
+ }
282
+ } else {
283
+ throw new Error("Invalid backup content received from Doppler");
284
+ }
285
+ } catch {
286
+ console.log(
287
+ `Config ${config}: Failed to create backup. Skipping upload.`
288
+ );
289
+ continue;
290
+ }
291
+ if (verbose) {
292
+ console.log(chalk.gray(` Reading local file: ${envFile}`));
293
+ }
294
+ const localContent = readFileSync(envFile, "utf-8");
295
+ const normalizedContent = normalizeEscapeSequences(localContent);
296
+ writeFileSync(normalizedFile, normalizedContent, "utf-8");
297
+ if (verbose) {
298
+ console.log(chalk.gray(` Comparing local changes with Doppler...`));
299
+ }
300
+ const backupContent = readFileSync(backupFile, "utf-8");
301
+ const diff = createDiff(backupContent, normalizedContent);
302
+ if (diff.length === 0) {
303
+ console.log(`Config ${config}: No differences found. Skipping upload.`);
304
+ unlinkSync(backupFile);
305
+ unlinkSync(normalizedFile);
306
+ continue;
307
+ }
308
+ if (verbose) {
309
+ console.log(chalk.yellow(` Found ${diff.length} line changes`));
310
+ }
311
+ console.log("\nChanges to be uploaded:");
312
+ for (const line of diff) {
313
+ if (line.startsWith("-")) {
314
+ console.log(chalk.red(line));
315
+ } else if (line.startsWith("+")) {
316
+ console.log(chalk.green(line));
317
+ }
318
+ }
319
+ const confirmed = await promptConfirmation(
320
+ "\nDo you want to proceed with the upload? (y/n) "
321
+ );
322
+ if (!confirmed) {
323
+ console.log(`Upload cancelled for ${chalk.green(envFile)}`);
324
+ unlinkSync(backupFile);
325
+ unlinkSync(normalizedFile);
326
+ continue;
327
+ }
328
+ if (verbose) {
329
+ console.log(chalk.gray(` Uploading to Doppler...`));
330
+ }
331
+ try {
332
+ execDoppler(
333
+ ["secrets", "upload", normalizedFile, "--config", config, "--silent"],
334
+ "string",
335
+ !verbose,
336
+ // Only silent if not verbose
337
+ verbose
338
+ );
339
+ if (config === "dev") {
340
+ console.log(
341
+ `Config ${chalk.blue(config)}: Successfully uploaded ${chalk.green(envFile)}`
342
+ );
343
+ } else {
344
+ console.log(
345
+ `Config ${config}: Successfully uploaded ${chalk.green(envFile)}`
346
+ );
347
+ }
348
+ } catch {
349
+ console.error(
350
+ `Config ${config}: Failed to upload ${chalk.green(envFile)}. Restoring previous configuration.`
351
+ );
352
+ try {
353
+ if (verbose) {
354
+ console.log(chalk.gray(` Restoring previous configuration...`));
355
+ }
356
+ execDoppler(
357
+ ["secrets", "upload", backupFile, "--config", config, "--silent"],
358
+ "string",
359
+ !verbose,
360
+ // Only silent if not verbose
361
+ verbose
362
+ );
363
+ console.log(
364
+ `Config ${config}: Successfully restored previous configuration`
365
+ );
366
+ } catch {
367
+ console.error(
368
+ `Config ${config}: Failed to restore previous configuration`
369
+ );
370
+ }
371
+ }
372
+ if (existsSync(backupFile)) {
373
+ unlinkSync(backupFile);
374
+ }
375
+ if (existsSync(normalizedFile)) {
376
+ unlinkSync(normalizedFile);
377
+ }
378
+ } catch (error) {
379
+ console.error(
380
+ `Error processing config ${config}: ${error?.message || error}`
381
+ );
382
+ if (existsSync(backupFile)) {
383
+ unlinkSync(backupFile);
384
+ }
385
+ if (existsSync(normalizedFile)) {
386
+ unlinkSync(normalizedFile);
387
+ }
388
+ }
389
+ }
390
+ }
391
+
392
+ export {
393
+ execDoppler,
394
+ checkDependencies,
395
+ getConfigs,
396
+ normalizeEscapeSequences,
397
+ createDiff,
398
+ promptConfirmation,
399
+ downloadConfigs,
400
+ uploadConfigs
401
+ };
@@ -0,0 +1,22 @@
1
+ // src/commands/schema.js
2
+ import { z } from "zod";
3
+ var globalOptionsSchema = z.object({
4
+ verbose: z.boolean().default(false).optional().describe("Enable verbose logging for detailed output and error traces")
5
+ });
6
+ var globalCommandsMetadata = {
7
+ name: "mtndev-cli",
8
+ version: "0.0.1",
9
+ description: "CLI tool for mtndev projects",
10
+ options: {
11
+ verbose: {
12
+ description: globalOptionsSchema.shape.verbose.description,
13
+ default: false,
14
+ alias: "v"
15
+ }
16
+ }
17
+ };
18
+
19
+ export {
20
+ globalOptionsSchema,
21
+ globalCommandsMetadata
22
+ };
@@ -0,0 +1,100 @@
1
+ import {
2
+ checkDependencies,
3
+ downloadConfigs,
4
+ uploadConfigs
5
+ } from "./O262GK4B.js";
6
+ import {
7
+ dopplerCommandMetadata,
8
+ dopplerCommandOptionsSchema
9
+ } from "./XPAQNFHZ.js";
10
+
11
+ // src/commands/doppler/handler.js
12
+ import chalk from "chalk";
13
+ import { ZodError } from "zod";
14
+ async function dopplerCommand(options) {
15
+ try {
16
+ const validatedOptions = dopplerCommandOptionsSchema.parse(options);
17
+ if (validatedOptions.help) {
18
+ console.log(
19
+ chalk.bold(`
20
+ Usage: @mtndev/cli doppler [options] <action>`)
21
+ );
22
+ console.log(chalk.gray(dopplerCommandMetadata.description));
23
+ console.log(chalk.bold("\nOptions:"));
24
+ Object.entries(dopplerCommandOptionsSchema.shape).forEach(
25
+ ([key, fieldSchema]) => {
26
+ if (key === "action") return;
27
+ const description = fieldSchema.description || "No description available";
28
+ const optionMeta = (
29
+ /** @type {any} */
30
+ dopplerCommandMetadata.options[key]
31
+ );
32
+ const defaultValue = optionMeta?.default ?? false;
33
+ const alias = optionMeta?.alias ? chalk.cyan(`, -${optionMeta.alias}`) : "";
34
+ console.log(
35
+ chalk.cyan(` --${key}`) + alias + ` ${description} (default: ${defaultValue})`
36
+ );
37
+ }
38
+ );
39
+ console.log("");
40
+ return;
41
+ }
42
+ const { action, environment, verbose } = validatedOptions;
43
+ checkDependencies(verbose);
44
+ if (action === "download") {
45
+ await downloadConfigs({ environment, verbose });
46
+ } else if (action === "upload") {
47
+ await uploadConfigs({ environment, verbose });
48
+ }
49
+ console.log(chalk.green(`
50
+ \u2705 Doppler ${action} completed successfully!`));
51
+ } catch (error) {
52
+ if (error instanceof ZodError) {
53
+ console.error(chalk.red(`
54
+ \u274C Invalid command options:`));
55
+ error.errors.forEach((err) => {
56
+ console.error(chalk.red(` ${err.path.join(".")}: ${err.message}`));
57
+ });
58
+ process.exit(1);
59
+ }
60
+ const action = (
61
+ /** @type {any} */
62
+ options?.action || "operation"
63
+ );
64
+ const verbose = (
65
+ /** @type {any} */
66
+ options?.verbose || false
67
+ );
68
+ console.error(chalk.red(`
69
+ \u274C Doppler ${action} failed:`));
70
+ if (error instanceof Error) {
71
+ console.error(chalk.red(` ${error.message}`));
72
+ if (verbose && error.stack) {
73
+ console.error(chalk.gray("\nStack trace:"));
74
+ console.error(chalk.gray(error.stack));
75
+ }
76
+ } else {
77
+ console.error(chalk.red(` ${String(error)}`));
78
+ }
79
+ console.error(chalk.yellow("\n\u{1F4A1} Troubleshooting tips:"));
80
+ console.error(
81
+ chalk.yellow(
82
+ " \u2022 Ensure Doppler CLI is installed (brew install dopplerhq/cli/doppler)"
83
+ )
84
+ );
85
+ console.error(
86
+ chalk.yellow(" \u2022 Make sure you're logged in (doppler login)")
87
+ );
88
+ console.error(
89
+ chalk.yellow(" \u2022 Verify project is configured (doppler setup)")
90
+ );
91
+ console.error(
92
+ chalk.yellow(" \u2022 Use --verbose for detailed error information\n")
93
+ );
94
+ process.exit(1);
95
+ }
96
+ }
97
+
98
+ export {
99
+ dopplerCommand
100
+ };