@karmaniverous/get-dotenv 5.2.6 → 6.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 (55) hide show
  1. package/README.md +106 -70
  2. package/dist/cliHost.d.ts +232 -226
  3. package/dist/cliHost.mjs +777 -545
  4. package/dist/config.d.ts +7 -2
  5. package/dist/env-overlay.d.ts +21 -9
  6. package/dist/env-overlay.mjs +14 -19
  7. package/dist/getdotenv.cli.mjs +1366 -1163
  8. package/dist/index.d.ts +415 -242
  9. package/dist/index.mjs +1364 -1414
  10. package/dist/plugins-aws.d.ts +149 -94
  11. package/dist/plugins-aws.mjs +307 -195
  12. package/dist/plugins-batch.d.ts +153 -99
  13. package/dist/plugins-batch.mjs +277 -95
  14. package/dist/plugins-cmd.d.ts +140 -94
  15. package/dist/plugins-cmd.mjs +636 -502
  16. package/dist/plugins-demo.d.ts +140 -94
  17. package/dist/plugins-demo.mjs +237 -46
  18. package/dist/plugins-init.d.ts +140 -94
  19. package/dist/plugins-init.mjs +129 -12
  20. package/dist/plugins.d.ts +166 -103
  21. package/dist/plugins.mjs +977 -840
  22. package/package.json +15 -53
  23. package/templates/cli/ts/plugins/hello.ts +27 -6
  24. package/templates/config/js/getdotenv.config.js +1 -1
  25. package/templates/config/ts/getdotenv.config.ts +9 -2
  26. package/dist/cliHost.cjs +0 -1875
  27. package/dist/cliHost.d.cts +0 -409
  28. package/dist/cliHost.d.mts +0 -409
  29. package/dist/config.cjs +0 -252
  30. package/dist/config.d.cts +0 -55
  31. package/dist/config.d.mts +0 -55
  32. package/dist/env-overlay.cjs +0 -163
  33. package/dist/env-overlay.d.cts +0 -50
  34. package/dist/env-overlay.d.mts +0 -50
  35. package/dist/index.cjs +0 -4140
  36. package/dist/index.d.cts +0 -457
  37. package/dist/index.d.mts +0 -457
  38. package/dist/plugins-aws.cjs +0 -667
  39. package/dist/plugins-aws.d.cts +0 -158
  40. package/dist/plugins-aws.d.mts +0 -158
  41. package/dist/plugins-batch.cjs +0 -616
  42. package/dist/plugins-batch.d.cts +0 -180
  43. package/dist/plugins-batch.d.mts +0 -180
  44. package/dist/plugins-cmd.cjs +0 -1113
  45. package/dist/plugins-cmd.d.cts +0 -178
  46. package/dist/plugins-cmd.d.mts +0 -178
  47. package/dist/plugins-demo.cjs +0 -307
  48. package/dist/plugins-demo.d.cts +0 -158
  49. package/dist/plugins-demo.d.mts +0 -158
  50. package/dist/plugins-init.cjs +0 -289
  51. package/dist/plugins-init.d.cts +0 -162
  52. package/dist/plugins-init.d.mts +0 -162
  53. package/dist/plugins.cjs +0 -2283
  54. package/dist/plugins.d.cts +0 -210
  55. package/dist/plugins.d.mts +0 -210
@@ -1,158 +0,0 @@
1
- import { Command } from 'commander';
2
- import { ZodType } from 'zod';
3
-
4
- /**
5
- * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
7
- /**
8
- * Dynamic variable function signature. Receives the current expanded variables
9
- * and the selected environment (if any), and returns either a string to set
10
- * or `undefined` to unset/skip the variable.
11
- */
12
- type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
13
- type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
14
- type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
15
- /**
16
- * Options passed programmatically to `getDotenv`.
17
- */
18
- interface GetDotenvOptions {
19
- /**
20
- * default target environment (used if `env` is not provided)
21
- */
22
- defaultEnv?: string;
23
- /**
24
- * token indicating a dotenv file
25
- */
26
- dotenvToken: string;
27
- /**
28
- * path to JS/TS module default-exporting an object keyed to dynamic variable functions
29
- */
30
- dynamicPath?: string;
31
- /**
32
- * Programmatic dynamic variables map. When provided, this takes precedence
33
- * over {@link GetDotenvOptions.dynamicPath}.
34
- */
35
- dynamic?: GetDotenvDynamic;
36
- /**
37
- * target environment
38
- */
39
- env?: string;
40
- /**
41
- * exclude dynamic variables from loading
42
- */
43
- excludeDynamic?: boolean;
44
- /**
45
- * exclude environment-specific variables from loading
46
- */
47
- excludeEnv?: boolean;
48
- /**
49
- * exclude global variables from loading
50
- */
51
- excludeGlobal?: boolean;
52
- /**
53
- * exclude private variables from loading
54
- */
55
- excludePrivate?: boolean;
56
- /**
57
- * exclude public variables from loading
58
- */
59
- excludePublic?: boolean;
60
- /**
61
- * load dotenv variables to `process.env`
62
- */
63
- loadProcess?: boolean;
64
- /**
65
- * log loaded dotenv variables to `logger`
66
- */
67
- log?: boolean;
68
- /**
69
- * logger object (defaults to console)
70
- */
71
- logger?: Logger;
72
- /**
73
- * if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
74
- */
75
- outputPath?: string;
76
- /**
77
- * array of input directory paths
78
- */
79
- paths?: string[];
80
- /**
81
- * filename token indicating private variables
82
- */
83
- privateToken?: string;
84
- /**
85
- * explicit variables to include
86
- */
87
- vars?: ProcessEnv;
88
- /**
89
- * Reserved: config loader flag (no-op).
90
- * The plugin-first host and generator paths already use the config
91
- * loader/overlay pipeline unconditionally (no-op when no config files
92
- * are present). This flag is accepted for forward compatibility but
93
- * currently has no effect.
94
- */
95
- useConfigLoader?: boolean;
96
- }
97
-
98
- /** src/cliHost/definePlugin.ts
99
- * Plugin contracts for the GetDotenv CLI host.
100
- *
101
- * This module exposes a structural public interface for the host that plugins
102
- * should use (GetDotenvCliPublic). Using a structural type at the seam avoids
103
- * nominal class identity issues (private fields) in downstream consumers.
104
- */
105
-
106
- /**
107
- * Structural public interface for the host exposed to plugins.
108
- * - Extends Commander.Command so plugins can attach options/commands/hooks.
109
- * - Adds host-specific helpers used by built-in plugins.
110
- *
111
- * Purpose: remove nominal class identity (private fields) from the plugin seam
112
- * to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
113
- */
114
- type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
115
- ns: (name: string) => Command;
116
- getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
117
- resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
118
- };
119
- /** Public plugin contract used by the GetDotenv CLI host. */
120
- interface GetDotenvCliPlugin {
121
- id?: string;
122
- /**
123
- * Setup phase: register commands and wiring on the provided CLI instance.
124
- * Runs parent → children (pre-order).
125
- */
126
- setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
127
- /**
128
- * After the dotenv context is resolved, initialize any clients/secrets
129
- * or attach per-plugin state under ctx.plugins (by convention).
130
- * Runs parent → children (pre-order).
131
- */
132
- afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
133
- /**
134
- * Optional Zod schema for this plugin's config slice (from config.plugins[id]).
135
- * When provided, the host validates the merged config under the guarded loader path.
136
- */
137
- configSchema?: ZodType;
138
- /**
139
- * Compositional children. Installed after the parent per pre-order.
140
- */
141
- children: GetDotenvCliPlugin[];
142
- /**
143
- * Compose a child plugin. Returns the parent to enable chaining.
144
- */
145
- use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
146
- }
147
-
148
- /** * Per-invocation context shared with plugins and actions. */
149
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
150
- optionsResolved: TOptions;
151
- dotenv: ProcessEnv;
152
- plugins?: Record<string, unknown>;
153
- pluginConfigs?: Record<string, unknown>;
154
- };
155
-
156
- declare const demoPlugin: () => GetDotenvCliPlugin;
157
-
158
- export { demoPlugin };
@@ -1,158 +0,0 @@
1
- import { Command } from 'commander';
2
- import { ZodType } from 'zod';
3
-
4
- /**
5
- * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
7
- /**
8
- * Dynamic variable function signature. Receives the current expanded variables
9
- * and the selected environment (if any), and returns either a string to set
10
- * or `undefined` to unset/skip the variable.
11
- */
12
- type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
13
- type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
14
- type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
15
- /**
16
- * Options passed programmatically to `getDotenv`.
17
- */
18
- interface GetDotenvOptions {
19
- /**
20
- * default target environment (used if `env` is not provided)
21
- */
22
- defaultEnv?: string;
23
- /**
24
- * token indicating a dotenv file
25
- */
26
- dotenvToken: string;
27
- /**
28
- * path to JS/TS module default-exporting an object keyed to dynamic variable functions
29
- */
30
- dynamicPath?: string;
31
- /**
32
- * Programmatic dynamic variables map. When provided, this takes precedence
33
- * over {@link GetDotenvOptions.dynamicPath}.
34
- */
35
- dynamic?: GetDotenvDynamic;
36
- /**
37
- * target environment
38
- */
39
- env?: string;
40
- /**
41
- * exclude dynamic variables from loading
42
- */
43
- excludeDynamic?: boolean;
44
- /**
45
- * exclude environment-specific variables from loading
46
- */
47
- excludeEnv?: boolean;
48
- /**
49
- * exclude global variables from loading
50
- */
51
- excludeGlobal?: boolean;
52
- /**
53
- * exclude private variables from loading
54
- */
55
- excludePrivate?: boolean;
56
- /**
57
- * exclude public variables from loading
58
- */
59
- excludePublic?: boolean;
60
- /**
61
- * load dotenv variables to `process.env`
62
- */
63
- loadProcess?: boolean;
64
- /**
65
- * log loaded dotenv variables to `logger`
66
- */
67
- log?: boolean;
68
- /**
69
- * logger object (defaults to console)
70
- */
71
- logger?: Logger;
72
- /**
73
- * if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
74
- */
75
- outputPath?: string;
76
- /**
77
- * array of input directory paths
78
- */
79
- paths?: string[];
80
- /**
81
- * filename token indicating private variables
82
- */
83
- privateToken?: string;
84
- /**
85
- * explicit variables to include
86
- */
87
- vars?: ProcessEnv;
88
- /**
89
- * Reserved: config loader flag (no-op).
90
- * The plugin-first host and generator paths already use the config
91
- * loader/overlay pipeline unconditionally (no-op when no config files
92
- * are present). This flag is accepted for forward compatibility but
93
- * currently has no effect.
94
- */
95
- useConfigLoader?: boolean;
96
- }
97
-
98
- /** src/cliHost/definePlugin.ts
99
- * Plugin contracts for the GetDotenv CLI host.
100
- *
101
- * This module exposes a structural public interface for the host that plugins
102
- * should use (GetDotenvCliPublic). Using a structural type at the seam avoids
103
- * nominal class identity issues (private fields) in downstream consumers.
104
- */
105
-
106
- /**
107
- * Structural public interface for the host exposed to plugins.
108
- * - Extends Commander.Command so plugins can attach options/commands/hooks.
109
- * - Adds host-specific helpers used by built-in plugins.
110
- *
111
- * Purpose: remove nominal class identity (private fields) from the plugin seam
112
- * to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
113
- */
114
- type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
115
- ns: (name: string) => Command;
116
- getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
117
- resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
118
- };
119
- /** Public plugin contract used by the GetDotenv CLI host. */
120
- interface GetDotenvCliPlugin {
121
- id?: string;
122
- /**
123
- * Setup phase: register commands and wiring on the provided CLI instance.
124
- * Runs parent → children (pre-order).
125
- */
126
- setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
127
- /**
128
- * After the dotenv context is resolved, initialize any clients/secrets
129
- * or attach per-plugin state under ctx.plugins (by convention).
130
- * Runs parent → children (pre-order).
131
- */
132
- afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
133
- /**
134
- * Optional Zod schema for this plugin's config slice (from config.plugins[id]).
135
- * When provided, the host validates the merged config under the guarded loader path.
136
- */
137
- configSchema?: ZodType;
138
- /**
139
- * Compositional children. Installed after the parent per pre-order.
140
- */
141
- children: GetDotenvCliPlugin[];
142
- /**
143
- * Compose a child plugin. Returns the parent to enable chaining.
144
- */
145
- use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
146
- }
147
-
148
- /** * Per-invocation context shared with plugins and actions. */
149
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
150
- optionsResolved: TOptions;
151
- dotenv: ProcessEnv;
152
- plugins?: Record<string, unknown>;
153
- pluginConfigs?: Record<string, unknown>;
154
- };
155
-
156
- declare const demoPlugin: () => GetDotenvCliPlugin;
157
-
158
- export { demoPlugin };
@@ -1,289 +0,0 @@
1
- 'use strict';
2
-
3
- var node_process = require('node:process');
4
- var fs = require('fs-extra');
5
- var path = require('path');
6
- var promises = require('readline/promises');
7
-
8
- /** src/cliHost/definePlugin.ts
9
- * Plugin contracts for the GetDotenv CLI host.
10
- *
11
- * This module exposes a structural public interface for the host that plugins
12
- * should use (GetDotenvCliPublic). Using a structural type at the seam avoids
13
- * nominal class identity issues (private fields) in downstream consumers.
14
- */
15
- /**
16
- * Define a GetDotenv CLI plugin with compositional helpers.
17
- *
18
- * @example
19
- * const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
20
- * .use(childA)
21
- * .use(childB);
22
- */
23
- const definePlugin = (spec) => {
24
- const { children = [], ...rest } = spec;
25
- const plugin = {
26
- ...rest,
27
- children: [...children],
28
- use(child) {
29
- this.children.push(child);
30
- return this;
31
- },
32
- };
33
- return plugin;
34
- };
35
-
36
- const ensureDir = async (p) => {
37
- await fs.ensureDir(p);
38
- return p;
39
- };
40
- const writeFile = async (dest, data) => {
41
- await ensureDir(path.dirname(dest));
42
- await fs.writeFile(dest, data, 'utf-8');
43
- };
44
- const copyTextFile = async (src, dest, substitutions) => {
45
- const contents = await fs.readFile(src, 'utf-8');
46
- const out = substitutions && Object.keys(substitutions).length > 0
47
- ? Object.entries(substitutions).reduce((acc, [k, v]) => acc.split(k).join(v), contents)
48
- : contents;
49
- await writeFile(dest, out);
50
- };
51
- /**
52
- * Ensure a set of lines exist (exact match) in a file. Creates the file
53
- * when missing. Returns whether it was created or changed.
54
- */
55
- const ensureLines = async (filePath, lines) => {
56
- const exists = await fs.pathExists(filePath);
57
- const current = exists ? await fs.readFile(filePath, 'utf-8') : '';
58
- const curLines = current.split(/\r?\n/);
59
- const have = new Set(curLines.filter((l) => l.length > 0));
60
- let mutated = false;
61
- for (const l of lines) {
62
- if (!have.has(l)) {
63
- curLines.push(l);
64
- have.add(l);
65
- mutated = true;
66
- }
67
- }
68
- // Normalize to LF and ensure trailing newline
69
- const next = curLines.filter((l) => l.length > 0).join('\n') + '\n';
70
- if (!exists) {
71
- await writeFile(filePath, next);
72
- return { created: true, changed: true };
73
- }
74
- if (mutated) {
75
- await fs.writeFile(filePath, next, 'utf-8');
76
- return { created: false, changed: true };
77
- }
78
- return { created: false, changed: false };
79
- };
80
-
81
- // Templates root used by the scaffolder
82
- const TEMPLATES_ROOT = path.resolve('templates');
83
-
84
- const planConfigCopies = ({ format, withLocal, destRoot, }) => {
85
- const copies = [];
86
- if (format === 'json') {
87
- copies.push({
88
- src: path.join(TEMPLATES_ROOT, 'config', 'json', 'public', 'getdotenv.config.json'),
89
- dest: path.join(destRoot, 'getdotenv.config.json'),
90
- });
91
- if (withLocal) {
92
- copies.push({
93
- src: path.join(TEMPLATES_ROOT, 'config', 'json', 'local', 'getdotenv.config.local.json'),
94
- dest: path.join(destRoot, 'getdotenv.config.local.json'),
95
- });
96
- }
97
- }
98
- else if (format === 'yaml') {
99
- copies.push({
100
- src: path.join(TEMPLATES_ROOT, 'config', 'yaml', 'public', 'getdotenv.config.yaml'),
101
- dest: path.join(destRoot, 'getdotenv.config.yaml'),
102
- });
103
- if (withLocal) {
104
- copies.push({
105
- src: path.join(TEMPLATES_ROOT, 'config', 'yaml', 'local', 'getdotenv.config.local.yaml'),
106
- dest: path.join(destRoot, 'getdotenv.config.local.yaml'),
107
- });
108
- }
109
- }
110
- else if (format === 'js') {
111
- copies.push({
112
- src: path.join(TEMPLATES_ROOT, 'config', 'js', 'getdotenv.config.js'),
113
- dest: path.join(destRoot, 'getdotenv.config.js'),
114
- });
115
- }
116
- else {
117
- copies.push({
118
- src: path.join(TEMPLATES_ROOT, 'config', 'ts', 'getdotenv.config.ts'),
119
- dest: path.join(destRoot, 'getdotenv.config.ts'),
120
- });
121
- }
122
- return copies;
123
- };
124
- const planCliCopies = ({ cliName, destRoot, }) => {
125
- const subs = { __CLI_NAME__: cliName };
126
- const base = path.join(destRoot, 'src', 'cli', cliName);
127
- return [
128
- {
129
- src: path.join(TEMPLATES_ROOT, 'cli', 'ts', 'index.ts'),
130
- dest: path.join(base, 'index.ts'),
131
- subs,
132
- },
133
- {
134
- src: path.join(TEMPLATES_ROOT, 'cli', 'ts', 'plugins', 'hello.ts'),
135
- dest: path.join(base, 'plugins', 'hello.ts'),
136
- subs,
137
- },
138
- ];
139
- };
140
-
141
- /**
142
- * Determine whether the current environment should be treated as non-interactive.
143
- * CI heuristics include: CI, GITHUB_ACTIONS, BUILDKITE, TEAMCITY_VERSION, TF_BUILD.
144
- */
145
- const isNonInteractive = () => {
146
- const ciLike = process.env.CI ||
147
- process.env.GITHUB_ACTIONS ||
148
- process.env.BUILDKITE ||
149
- process.env.TEAMCITY_VERSION ||
150
- process.env.TF_BUILD;
151
- return Boolean(ciLike) || !(node_process.stdin.isTTY && node_process.stdout.isTTY);
152
- };
153
- const promptDecision = async (filePath, logger, rl) => {
154
- logger.log(`File exists: ${filePath}\nChoose: [o]verwrite, [e]xample, [s]kip, [O]verwrite All, [E]xample All, [S]kip All`);
155
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
156
- while (true) {
157
- const a = (await rl.question('> ')).trim();
158
- const valid = ['o', 'e', 's', 'O', 'E', 'S'];
159
- if (valid.includes(a))
160
- return a;
161
- logger.log('Please enter one of: o e s O E S');
162
- }
163
- };
164
-
165
- /**
166
- * Requirements: Init scaffolding plugin with collision flow and CI detection.
167
- * Note: Large file scheduled for decomposition; tracked in stan.todo.md.
168
- */
169
- const initPlugin = (opts = {}) => definePlugin({
170
- id: 'init',
171
- setup(cli) {
172
- const logger = opts.logger ?? console;
173
- const cmd = cli
174
- .ns('init')
175
- .description('Scaffold getdotenv config files and a host-based CLI skeleton.')
176
- .argument('[dest]', 'destination path (default: ./)', '.')
177
- .option('--config-format <format>', 'config format: json|yaml|js|ts', 'json')
178
- .option('--with-local', 'include .local config variant')
179
- .option('--dynamic', 'include dynamic examples (JS/TS configs)')
180
- .option('--cli-name <string>', 'CLI name for skeleton and tokens')
181
- .option('--force', 'overwrite all existing files')
182
- .option('--yes', 'skip all collisions (no overwrite)')
183
- .action(async (destArg) => {
184
- // Read options directly from the captured command instance.
185
- // Cast to a plain record to satisfy exact-optional and lint safety.
186
- const o = cmd.opts() ?? {};
187
- const destRel = typeof destArg === 'string' && destArg.length > 0 ? destArg : '.';
188
- const cwd = process.cwd();
189
- const destRoot = path.resolve(cwd, destRel);
190
- const formatInput = o.configFormat;
191
- const formatRaw = typeof formatInput === 'string'
192
- ? formatInput.toLowerCase()
193
- : 'json';
194
- const format = (['json', 'yaml', 'js', 'ts'].includes(formatRaw)
195
- ? formatRaw
196
- : 'json');
197
- const withLocal = !!o.withLocal;
198
- // dynamic flag reserved for future template variants; present for UX compatibility
199
- void o.dynamic;
200
- // CLI name default: --cli-name | basename(dest) | 'mycli'
201
- const cliName = (typeof o.cliName === 'string' && o.cliName.length > 0
202
- ? o.cliName
203
- : path.basename(destRoot) || 'mycli') || 'mycli';
204
- // Precedence: --force > --yes > auto-detect(non-interactive => yes)
205
- const force = !!o.force;
206
- const yes = !!o.yes || (!force && isNonInteractive());
207
- // Build copy plan
208
- const cfgCopies = planConfigCopies({ format, withLocal, destRoot });
209
- const cliCopies = planCliCopies({ cliName, destRoot });
210
- const copies = [...cfgCopies, ...cliCopies];
211
- // Interactive state
212
- let globalDecision;
213
- const rl = promises.createInterface({ input: node_process.stdin, output: node_process.stdout });
214
- try {
215
- for (const item of copies) {
216
- const exists = await fs.pathExists(item.dest);
217
- if (!exists) {
218
- const subs = item.subs ?? {};
219
- await copyTextFile(item.src, item.dest, subs);
220
- logger.log(`Created ${path.relative(cwd, item.dest)}`);
221
- continue;
222
- }
223
- // Collision
224
- if (force) {
225
- const subs = item.subs ?? {};
226
- await copyTextFile(item.src, item.dest, subs);
227
- logger.log(`Overwrote ${path.relative(cwd, item.dest)}`);
228
- continue;
229
- }
230
- if (yes) {
231
- logger.log(`Skipped ${path.relative(cwd, item.dest)}`);
232
- continue;
233
- }
234
- let decision = globalDecision;
235
- if (!decision) {
236
- const a = await promptDecision(item.dest, logger, rl);
237
- if (a === 'O') {
238
- globalDecision = 'overwrite';
239
- decision = 'overwrite';
240
- }
241
- else if (a === 'E') {
242
- globalDecision = 'example';
243
- decision = 'example';
244
- }
245
- else if (a === 'S') {
246
- globalDecision = 'skip';
247
- decision = 'skip';
248
- }
249
- else {
250
- decision =
251
- a === 'o' ? 'overwrite' : a === 'e' ? 'example' : 'skip';
252
- }
253
- }
254
- if (decision === 'overwrite') {
255
- const subs = item.subs ?? {};
256
- await copyTextFile(item.src, item.dest, subs);
257
- logger.log(`Overwrote ${path.relative(cwd, item.dest)}`);
258
- }
259
- else if (decision === 'example') {
260
- const destEx = `${item.dest}.example`;
261
- const subs = item.subs ?? {};
262
- await copyTextFile(item.src, destEx, subs);
263
- logger.log(`Wrote example ${path.relative(cwd, destEx)}`);
264
- }
265
- else {
266
- logger.log(`Skipped ${path.relative(cwd, item.dest)}`);
267
- }
268
- }
269
- // Ensure .gitignore includes local config patterns.
270
- const giPath = path.join(destRoot, '.gitignore');
271
- const { created, changed } = await ensureLines(giPath, [
272
- 'getdotenv.config.local.*',
273
- '*.local',
274
- ]);
275
- if (created) {
276
- logger.log(`Created ${path.relative(cwd, giPath)}`);
277
- }
278
- else if (changed) {
279
- logger.log(`Updated ${path.relative(cwd, giPath)}`);
280
- }
281
- }
282
- finally {
283
- rl.close();
284
- }
285
- });
286
- },
287
- });
288
-
289
- exports.initPlugin = initPlugin;