@karmaniverous/get-dotenv 4.6.0-0 → 5.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.
- package/README.md +130 -23
- package/dist/cliHost.cjs +1089 -0
- package/dist/cliHost.d.cts +191 -0
- package/dist/cliHost.d.mts +191 -0
- package/dist/cliHost.d.ts +191 -0
- package/dist/cliHost.mjs +1085 -0
- package/dist/config.cjs +247 -0
- package/dist/config.d.cts +53 -0
- package/dist/config.d.mts +53 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.mjs +242 -0
- package/dist/env-overlay.cjs +163 -0
- package/dist/env-overlay.d.cts +48 -0
- package/dist/env-overlay.d.mts +48 -0
- package/dist/env-overlay.d.ts +48 -0
- package/dist/env-overlay.mjs +161 -0
- package/dist/getdotenv.cli.mjs +2788 -734
- package/dist/index.cjs +902 -280
- package/dist/index.d.cts +122 -64
- package/dist/index.d.mts +122 -64
- package/dist/index.d.ts +122 -64
- package/dist/index.mjs +904 -283
- package/dist/plugins-aws.cjs +618 -0
- package/dist/plugins-aws.d.cts +176 -0
- package/dist/plugins-aws.d.mts +176 -0
- package/dist/plugins-aws.d.ts +176 -0
- package/dist/plugins-aws.mjs +616 -0
- package/dist/plugins-batch.cjs +569 -0
- package/dist/plugins-batch.d.cts +198 -0
- package/dist/plugins-batch.d.mts +198 -0
- package/dist/plugins-batch.d.ts +198 -0
- package/dist/plugins-batch.mjs +567 -0
- package/dist/plugins-init.cjs +282 -0
- package/dist/plugins-init.d.cts +180 -0
- package/dist/plugins-init.d.mts +180 -0
- package/dist/plugins-init.d.ts +180 -0
- package/dist/plugins-init.mjs +280 -0
- package/getdotenv.config.json +19 -0
- package/package.json +88 -17
- package/templates/cli/ts/index.ts +9 -0
- package/templates/cli/ts/plugins/hello.ts +17 -0
- package/templates/config/js/getdotenv.config.js +15 -0
- package/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/templates/config/json/public/getdotenv.config.json +12 -0
- package/templates/config/public/getdotenv.config.json +13 -0
- package/templates/config/ts/getdotenv.config.ts +16 -0
- package/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/templates/config/yaml/public/getdotenv.config.yaml +10 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { Command } from 'commander';
|
|
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
|
+
/** * Per-invocation context shared with plugins and actions. */
|
|
99
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
100
|
+
optionsResolved: TOptions;
|
|
101
|
+
dotenv: ProcessEnv;
|
|
102
|
+
plugins?: Record<string, unknown>;
|
|
103
|
+
pluginConfigs?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
107
|
+
*
|
|
108
|
+
* Responsibilities:
|
|
109
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
110
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
111
|
+
* - Provide a namespacing helper (ns).
|
|
112
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
113
|
+
*
|
|
114
|
+
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
115
|
+
*/
|
|
116
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
117
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
118
|
+
private _plugins;
|
|
119
|
+
/** One-time installation guard */
|
|
120
|
+
private _installed;
|
|
121
|
+
constructor(alias?: string);
|
|
122
|
+
/**
|
|
123
|
+
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
124
|
+
*/
|
|
125
|
+
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the current invocation context (if any).
|
|
128
|
+
*/
|
|
129
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
130
|
+
/** * Convenience helper to create a namespaced subcommand.
|
|
131
|
+
*/
|
|
132
|
+
ns(name: string): Command;
|
|
133
|
+
/**
|
|
134
|
+
* Register a plugin for installation (parent level).
|
|
135
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
136
|
+
*/
|
|
137
|
+
use(plugin: GetDotenvCliPlugin): this;
|
|
138
|
+
/**
|
|
139
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
140
|
+
* Runs only once per CLI instance.
|
|
141
|
+
*/
|
|
142
|
+
install(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
145
|
+
*/
|
|
146
|
+
private _runAfterResolve;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Public plugin contract used by the GetDotenv CLI host. */ interface GetDotenvCliPlugin {
|
|
150
|
+
id?: string /**
|
|
151
|
+
* Setup phase: register commands and wiring on the provided CLI instance. * Runs parent → children (pre-order).
|
|
152
|
+
*/;
|
|
153
|
+
setup: (cli: GetDotenvCli) => void | Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
156
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
157
|
+
* Runs parent → children (pre-order).
|
|
158
|
+
*/
|
|
159
|
+
afterResolve?: (cli: GetDotenvCli, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
162
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
163
|
+
*/
|
|
164
|
+
configSchema?: ZodType;
|
|
165
|
+
/**
|
|
166
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
167
|
+
*/ children: GetDotenvCliPlugin[];
|
|
168
|
+
/**
|
|
169
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
170
|
+
*/
|
|
171
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
type InitPluginOptions = {
|
|
175
|
+
logger?: Logger;
|
|
176
|
+
};
|
|
177
|
+
declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
|
|
178
|
+
|
|
179
|
+
export { initPlugin };
|
|
180
|
+
export type { InitPluginOptions };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { stdin, stdout } from 'node:process';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { createInterface } from 'readline/promises';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
|
|
11
|
+
* .use(childA)
|
|
12
|
+
* .use(childB);
|
|
13
|
+
*/
|
|
14
|
+
const definePlugin = (spec) => {
|
|
15
|
+
const { children = [], ...rest } = spec;
|
|
16
|
+
const plugin = {
|
|
17
|
+
...rest,
|
|
18
|
+
children: [...children],
|
|
19
|
+
use(child) {
|
|
20
|
+
this.children.push(child);
|
|
21
|
+
return this;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return plugin;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const ensureDir = async (p) => {
|
|
28
|
+
await fs.ensureDir(p);
|
|
29
|
+
return p;
|
|
30
|
+
};
|
|
31
|
+
const writeFile = async (dest, data) => {
|
|
32
|
+
await ensureDir(path.dirname(dest));
|
|
33
|
+
await fs.writeFile(dest, data, 'utf-8');
|
|
34
|
+
};
|
|
35
|
+
const copyTextFile = async (src, dest, substitutions) => {
|
|
36
|
+
const contents = await fs.readFile(src, 'utf-8');
|
|
37
|
+
const out = substitutions && Object.keys(substitutions).length > 0
|
|
38
|
+
? Object.entries(substitutions).reduce((acc, [k, v]) => acc.split(k).join(v), contents)
|
|
39
|
+
: contents;
|
|
40
|
+
await writeFile(dest, out);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Ensure a set of lines exist (exact match) in a file. Creates the file
|
|
44
|
+
* when missing. Returns whether it was created or changed.
|
|
45
|
+
*/
|
|
46
|
+
const ensureLines = async (filePath, lines) => {
|
|
47
|
+
const exists = await fs.pathExists(filePath);
|
|
48
|
+
const current = exists ? await fs.readFile(filePath, 'utf-8') : '';
|
|
49
|
+
const curLines = current.split(/\r?\n/);
|
|
50
|
+
const have = new Set(curLines.filter((l) => l.length > 0));
|
|
51
|
+
let mutated = false;
|
|
52
|
+
for (const l of lines) {
|
|
53
|
+
if (!have.has(l)) {
|
|
54
|
+
curLines.push(l);
|
|
55
|
+
have.add(l);
|
|
56
|
+
mutated = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Normalize to LF and ensure trailing newline
|
|
60
|
+
const next = curLines.filter((l) => l.length > 0).join('\n') + '\n';
|
|
61
|
+
if (!exists) {
|
|
62
|
+
await writeFile(filePath, next);
|
|
63
|
+
return { created: true, changed: true };
|
|
64
|
+
}
|
|
65
|
+
if (mutated) {
|
|
66
|
+
await fs.writeFile(filePath, next, 'utf-8');
|
|
67
|
+
return { created: false, changed: true };
|
|
68
|
+
}
|
|
69
|
+
return { created: false, changed: false };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Templates root used by the scaffolder
|
|
73
|
+
const TEMPLATES_ROOT = path.resolve('templates');
|
|
74
|
+
|
|
75
|
+
const planConfigCopies = ({ format, withLocal, destRoot, }) => {
|
|
76
|
+
const copies = [];
|
|
77
|
+
if (format === 'json') {
|
|
78
|
+
copies.push({
|
|
79
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'json', 'public', 'getdotenv.config.json'),
|
|
80
|
+
dest: path.join(destRoot, 'getdotenv.config.json'),
|
|
81
|
+
});
|
|
82
|
+
if (withLocal) {
|
|
83
|
+
copies.push({
|
|
84
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'json', 'local', 'getdotenv.config.local.json'),
|
|
85
|
+
dest: path.join(destRoot, 'getdotenv.config.local.json'),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (format === 'yaml') {
|
|
90
|
+
copies.push({
|
|
91
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'yaml', 'public', 'getdotenv.config.yaml'),
|
|
92
|
+
dest: path.join(destRoot, 'getdotenv.config.yaml'),
|
|
93
|
+
});
|
|
94
|
+
if (withLocal) {
|
|
95
|
+
copies.push({
|
|
96
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'yaml', 'local', 'getdotenv.config.local.yaml'),
|
|
97
|
+
dest: path.join(destRoot, 'getdotenv.config.local.yaml'),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (format === 'js') {
|
|
102
|
+
copies.push({
|
|
103
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'js', 'getdotenv.config.js'),
|
|
104
|
+
dest: path.join(destRoot, 'getdotenv.config.js'),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
copies.push({
|
|
109
|
+
src: path.join(TEMPLATES_ROOT, 'config', 'ts', 'getdotenv.config.ts'),
|
|
110
|
+
dest: path.join(destRoot, 'getdotenv.config.ts'),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return copies;
|
|
114
|
+
};
|
|
115
|
+
const planCliCopies = ({ cliName, destRoot, }) => {
|
|
116
|
+
const subs = { __CLI_NAME__: cliName };
|
|
117
|
+
const base = path.join(destRoot, 'src', 'cli', cliName);
|
|
118
|
+
return [
|
|
119
|
+
{
|
|
120
|
+
src: path.join(TEMPLATES_ROOT, 'cli', 'ts', 'index.ts'),
|
|
121
|
+
dest: path.join(base, 'index.ts'),
|
|
122
|
+
subs,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
src: path.join(TEMPLATES_ROOT, 'cli', 'ts', 'plugins', 'hello.ts'),
|
|
126
|
+
dest: path.join(base, 'plugins', 'hello.ts'),
|
|
127
|
+
subs,
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Determine whether the current environment should be treated as non-interactive.
|
|
134
|
+
* CI heuristics include: CI, GITHUB_ACTIONS, BUILDKITE, TEAMCITY_VERSION, TF_BUILD.
|
|
135
|
+
*/
|
|
136
|
+
const isNonInteractive = () => {
|
|
137
|
+
const ciLike = process.env.CI ||
|
|
138
|
+
process.env.GITHUB_ACTIONS ||
|
|
139
|
+
process.env.BUILDKITE ||
|
|
140
|
+
process.env.TEAMCITY_VERSION ||
|
|
141
|
+
process.env.TF_BUILD;
|
|
142
|
+
return Boolean(ciLike) || !(stdin.isTTY && stdout.isTTY);
|
|
143
|
+
};
|
|
144
|
+
const promptDecision = async (filePath, logger, rl) => {
|
|
145
|
+
logger.log(`File exists: ${filePath}\nChoose: [o]verwrite, [e]xample, [s]kip, [O]verwrite All, [E]xample All, [S]kip All`);
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
147
|
+
while (true) {
|
|
148
|
+
const a = (await rl.question('> ')).trim();
|
|
149
|
+
const valid = ['o', 'e', 's', 'O', 'E', 'S'];
|
|
150
|
+
if (valid.includes(a))
|
|
151
|
+
return a;
|
|
152
|
+
logger.log('Please enter one of: o e s O E S');
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Requirements: Init scaffolding plugin with collision flow and CI detection.
|
|
158
|
+
* Note: Large file scheduled for decomposition; tracked in stan.todo.md.
|
|
159
|
+
*/
|
|
160
|
+
const initPlugin = (opts = {}) => definePlugin({
|
|
161
|
+
id: 'init',
|
|
162
|
+
setup(cli) {
|
|
163
|
+
const logger = opts.logger ?? console;
|
|
164
|
+
const cmd = cli
|
|
165
|
+
.ns('init')
|
|
166
|
+
.description('Scaffold getdotenv config files and a host-based CLI skeleton.')
|
|
167
|
+
.argument('[dest]', 'destination path (default: ./)', '.')
|
|
168
|
+
.option('--config-format <format>', 'config format: json|yaml|js|ts', 'json')
|
|
169
|
+
.option('--with-local', 'include .local config variant')
|
|
170
|
+
.option('--dynamic', 'include dynamic examples (JS/TS configs)')
|
|
171
|
+
.option('--cli-name <string>', 'CLI name for skeleton and tokens')
|
|
172
|
+
.option('--force', 'overwrite all existing files')
|
|
173
|
+
.option('--yes', 'skip all collisions (no overwrite)')
|
|
174
|
+
.action(async (destArg) => {
|
|
175
|
+
// Read options directly from the captured command instance.
|
|
176
|
+
// Cast to a plain record to satisfy exact-optional and lint safety.
|
|
177
|
+
const o = cmd.opts() ?? {};
|
|
178
|
+
const destRel = typeof destArg === 'string' && destArg.length > 0 ? destArg : '.';
|
|
179
|
+
const cwd = process.cwd();
|
|
180
|
+
const destRoot = path.resolve(cwd, destRel);
|
|
181
|
+
const formatInput = o.configFormat;
|
|
182
|
+
const formatRaw = typeof formatInput === 'string'
|
|
183
|
+
? formatInput.toLowerCase()
|
|
184
|
+
: 'json';
|
|
185
|
+
const format = (['json', 'yaml', 'js', 'ts'].includes(formatRaw)
|
|
186
|
+
? formatRaw
|
|
187
|
+
: 'json');
|
|
188
|
+
const withLocal = !!o.withLocal;
|
|
189
|
+
// dynamic flag reserved for future template variants; present for UX compatibility
|
|
190
|
+
void o.dynamic;
|
|
191
|
+
// CLI name default: --cli-name | basename(dest) | 'mycli'
|
|
192
|
+
const cliName = (typeof o.cliName === 'string' && o.cliName.length > 0
|
|
193
|
+
? o.cliName
|
|
194
|
+
: path.basename(destRoot) || 'mycli') || 'mycli';
|
|
195
|
+
// Precedence: --force > --yes > auto-detect(non-interactive => yes)
|
|
196
|
+
const force = !!o.force;
|
|
197
|
+
const yes = !!o.yes || (!force && isNonInteractive());
|
|
198
|
+
// Build copy plan
|
|
199
|
+
const cfgCopies = planConfigCopies({ format, withLocal, destRoot });
|
|
200
|
+
const cliCopies = planCliCopies({ cliName, destRoot });
|
|
201
|
+
const copies = [...cfgCopies, ...cliCopies];
|
|
202
|
+
// Interactive state
|
|
203
|
+
let globalDecision;
|
|
204
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
205
|
+
try {
|
|
206
|
+
for (const item of copies) {
|
|
207
|
+
const exists = await fs.pathExists(item.dest);
|
|
208
|
+
if (!exists) {
|
|
209
|
+
const subs = item.subs ?? {};
|
|
210
|
+
await copyTextFile(item.src, item.dest, subs);
|
|
211
|
+
logger.log(`Created ${path.relative(cwd, item.dest)}`);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
// Collision
|
|
215
|
+
if (force) {
|
|
216
|
+
const subs = item.subs ?? {};
|
|
217
|
+
await copyTextFile(item.src, item.dest, subs);
|
|
218
|
+
logger.log(`Overwrote ${path.relative(cwd, item.dest)}`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (yes) {
|
|
222
|
+
logger.log(`Skipped ${path.relative(cwd, item.dest)}`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
let decision = globalDecision;
|
|
226
|
+
if (!decision) {
|
|
227
|
+
const a = await promptDecision(item.dest, logger, rl);
|
|
228
|
+
if (a === 'O') {
|
|
229
|
+
globalDecision = 'overwrite';
|
|
230
|
+
decision = 'overwrite';
|
|
231
|
+
}
|
|
232
|
+
else if (a === 'E') {
|
|
233
|
+
globalDecision = 'example';
|
|
234
|
+
decision = 'example';
|
|
235
|
+
}
|
|
236
|
+
else if (a === 'S') {
|
|
237
|
+
globalDecision = 'skip';
|
|
238
|
+
decision = 'skip';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
decision =
|
|
242
|
+
a === 'o' ? 'overwrite' : a === 'e' ? 'example' : 'skip';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (decision === 'overwrite') {
|
|
246
|
+
const subs = item.subs ?? {};
|
|
247
|
+
await copyTextFile(item.src, item.dest, subs);
|
|
248
|
+
logger.log(`Overwrote ${path.relative(cwd, item.dest)}`);
|
|
249
|
+
}
|
|
250
|
+
else if (decision === 'example') {
|
|
251
|
+
const destEx = `${item.dest}.example`;
|
|
252
|
+
const subs = item.subs ?? {};
|
|
253
|
+
await copyTextFile(item.src, destEx, subs);
|
|
254
|
+
logger.log(`Wrote example ${path.relative(cwd, destEx)}`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
logger.log(`Skipped ${path.relative(cwd, item.dest)}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// Ensure .gitignore includes local config patterns.
|
|
261
|
+
const giPath = path.join(destRoot, '.gitignore');
|
|
262
|
+
const { created, changed } = await ensureLines(giPath, [
|
|
263
|
+
'getdotenv.config.local.*',
|
|
264
|
+
'*.local',
|
|
265
|
+
]);
|
|
266
|
+
if (created) {
|
|
267
|
+
logger.log(`Created ${path.relative(cwd, giPath)}`);
|
|
268
|
+
}
|
|
269
|
+
else if (changed) {
|
|
270
|
+
logger.log(`Updated ${path.relative(cwd, giPath)}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
rl.close();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
export { initPlugin };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"//": "Packaged root defaults for get-dotenv (lowest precedence).",
|
|
3
|
+
"dotenvToken": ".env",
|
|
4
|
+
"privateToken": "local",
|
|
5
|
+
"paths": "./",
|
|
6
|
+
"loadProcess": true,
|
|
7
|
+
"shell": true,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"git-status": {
|
|
10
|
+
"cmd": "git branch --show-current && git status -s -u",
|
|
11
|
+
"shell": true
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"excludeDynamic": false,
|
|
15
|
+
"excludeEnv": false,
|
|
16
|
+
"excludeGlobal": false,
|
|
17
|
+
"excludePrivate": false,
|
|
18
|
+
"excludePublic": false
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -16,15 +16,17 @@
|
|
|
16
16
|
"commander": "^14.0.1",
|
|
17
17
|
"dotenv": "^17.2.2",
|
|
18
18
|
"execa": "^9.6.0",
|
|
19
|
-
"fs-extra": "^11.3.
|
|
19
|
+
"fs-extra": "^11.3.2",
|
|
20
20
|
"globby": "^14",
|
|
21
21
|
"nanoid": "^5.1.5",
|
|
22
|
-
"package-directory": "^8.1.0"
|
|
22
|
+
"package-directory": "^8.1.0",
|
|
23
|
+
"yaml": "^2.8.1",
|
|
24
|
+
"zod": "^4.1.9"
|
|
23
25
|
},
|
|
24
26
|
"description": "Process dotenv files in an arbitrary location & optionally populate environment variables.",
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@dotenvx/dotenvx": "^1.
|
|
27
|
-
"@eslint/js": "^9.
|
|
28
|
+
"@dotenvx/dotenvx": "^1.50.1",
|
|
29
|
+
"@eslint/js": "^9.36.0",
|
|
28
30
|
"@rollup/plugin-alias": "^5.1.1",
|
|
29
31
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
30
32
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -32,25 +34,26 @@
|
|
|
32
34
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
33
35
|
"@types/fs-extra": "^11.0.4",
|
|
34
36
|
"@types/node": "^22",
|
|
37
|
+
"@vitest/eslint-plugin": "^1.3.6",
|
|
35
38
|
"@vitest/coverage-v8": "^3.2.4",
|
|
36
39
|
"auto-changelog": "^2.5.0",
|
|
37
|
-
"esbuild": "^0.
|
|
38
|
-
"eslint": "^9.
|
|
40
|
+
"esbuild": "^0.25.10",
|
|
41
|
+
"eslint": "^9.36.0",
|
|
39
42
|
"eslint-config-prettier": "^10.1.8",
|
|
40
43
|
"eslint-plugin-jsonc": "^2.20.1",
|
|
41
44
|
"eslint-plugin-prettier": "^5.5.4",
|
|
42
45
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
43
46
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
44
|
-
"
|
|
45
|
-
"fs-extra": "^11.3.1",
|
|
47
|
+
"fs-extra": "^11.3.2",
|
|
46
48
|
"globals": "^16.4.0",
|
|
47
49
|
"jsonc-eslint-parser": "^2.4.0",
|
|
48
50
|
"knip": "^5.63.1",
|
|
49
|
-
"
|
|
51
|
+
"npm-packlist": "^10.0.1",
|
|
52
|
+
"lefthook": "^1.13.1",
|
|
50
53
|
"prettier": "^3.6.2",
|
|
51
|
-
"release-it": "^19.0.
|
|
54
|
+
"release-it": "^19.0.5",
|
|
52
55
|
"rimraf": "^6.0.1",
|
|
53
|
-
"rollup": "^4.
|
|
56
|
+
"rollup": "^4.52.0",
|
|
54
57
|
"rollup-plugin-dts": "^6.2.3",
|
|
55
58
|
"tslib": "^2.8.1",
|
|
56
59
|
"tsx": "^4.20.5",
|
|
@@ -58,12 +61,12 @@
|
|
|
58
61
|
"typedoc-plugin-mdn-links": "^5.0.9",
|
|
59
62
|
"typedoc-plugin-replace-text": "^4.2.0",
|
|
60
63
|
"typescript": "^5.9.2",
|
|
61
|
-
"typescript-eslint": "^8.
|
|
64
|
+
"typescript-eslint": "^8.44.0",
|
|
62
65
|
"vite-tsconfig-paths": "^5.1.4",
|
|
63
66
|
"vitest": "^3.2.4"
|
|
64
67
|
},
|
|
65
68
|
"engines": {
|
|
66
|
-
"node": ">=
|
|
69
|
+
"node": ">=20"
|
|
67
70
|
},
|
|
68
71
|
"exports": {
|
|
69
72
|
".": {
|
|
@@ -75,10 +78,72 @@
|
|
|
75
78
|
"types": "./dist/index.d.cts",
|
|
76
79
|
"default": "./dist/index.cjs"
|
|
77
80
|
}
|
|
81
|
+
},
|
|
82
|
+
"./cliHost": {
|
|
83
|
+
"import": {
|
|
84
|
+
"types": "./dist/cliHost.d.mts",
|
|
85
|
+
"default": "./dist/cliHost.mjs"
|
|
86
|
+
},
|
|
87
|
+
"require": {
|
|
88
|
+
"types": "./dist/cliHost.d.cts",
|
|
89
|
+
"default": "./dist/cliHost.cjs"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"./plugins/aws": {
|
|
93
|
+
"import": {
|
|
94
|
+
"types": "./dist/plugins-aws.d.mts",
|
|
95
|
+
"default": "./dist/plugins-aws.mjs"
|
|
96
|
+
},
|
|
97
|
+
"require": {
|
|
98
|
+
"types": "./dist/plugins-aws.d.cts",
|
|
99
|
+
"default": "./dist/plugins-aws.cjs"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"./plugins/batch": {
|
|
103
|
+
"import": {
|
|
104
|
+
"types": "./dist/plugins-batch.d.mts",
|
|
105
|
+
"default": "./dist/plugins-batch.mjs"
|
|
106
|
+
},
|
|
107
|
+
"require": {
|
|
108
|
+
"types": "./dist/plugins-batch.d.cts",
|
|
109
|
+
"default": "./dist/plugins-batch.cjs"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"./plugins/init": {
|
|
113
|
+
"import": {
|
|
114
|
+
"types": "./dist/plugins-init.d.mts",
|
|
115
|
+
"default": "./dist/plugins-init.mjs"
|
|
116
|
+
},
|
|
117
|
+
"require": {
|
|
118
|
+
"types": "./dist/plugins-init.d.cts",
|
|
119
|
+
"default": "./dist/plugins-init.cjs"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"./config": {
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/config.d.mts",
|
|
125
|
+
"default": "./dist/config.mjs"
|
|
126
|
+
},
|
|
127
|
+
"require": {
|
|
128
|
+
"types": "./dist/config.d.cts",
|
|
129
|
+
"default": "./dist/config.cjs"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"./env/overlay": {
|
|
133
|
+
"import": {
|
|
134
|
+
"types": "./dist/env-overlay.d.mts",
|
|
135
|
+
"default": "./dist/env-overlay.mjs"
|
|
136
|
+
},
|
|
137
|
+
"require": {
|
|
138
|
+
"types": "./dist/env-overlay.d.cts",
|
|
139
|
+
"default": "./dist/env-overlay.cjs"
|
|
140
|
+
}
|
|
78
141
|
}
|
|
79
142
|
},
|
|
80
143
|
"files": [
|
|
81
|
-
"dist"
|
|
144
|
+
"dist",
|
|
145
|
+
"getdotenv.config.json",
|
|
146
|
+
"templates"
|
|
82
147
|
],
|
|
83
148
|
"homepage": "https://github.com/karmaniverous/get-dotenv#readme",
|
|
84
149
|
"keywords": [
|
|
@@ -120,7 +185,9 @@
|
|
|
120
185
|
"after:init": [
|
|
121
186
|
"npm run lint",
|
|
122
187
|
"npm run test",
|
|
123
|
-
"npm run build"
|
|
188
|
+
"npm run build",
|
|
189
|
+
"npm run verify:package",
|
|
190
|
+
"npm run verify:tarball"
|
|
124
191
|
],
|
|
125
192
|
"after:release": [
|
|
126
193
|
"git switch -c release/${version}",
|
|
@@ -142,6 +209,7 @@
|
|
|
142
209
|
"cli:dist": "node dist/getdotenv.cli.mjs",
|
|
143
210
|
"changelog": "auto-changelog",
|
|
144
211
|
"docs": "typedoc",
|
|
212
|
+
"pack:dry": "npm pack --dry-run",
|
|
145
213
|
"knip": "knip",
|
|
146
214
|
"lint": "eslint . eslint.config.ts",
|
|
147
215
|
"lint:fix": "eslint --fix . eslint.config.ts",
|
|
@@ -149,9 +217,12 @@
|
|
|
149
217
|
"release:pre": "dotenvx run -f .env.local -- release-it --no-git.requireBranch --github.prerelease --preRelease",
|
|
150
218
|
"stan:docs": "typedoc --emit none",
|
|
151
219
|
"test": "vitest run --coverage",
|
|
152
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
220
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
221
|
+
"verify:package": "node tools/verify-package.js",
|
|
222
|
+
"verify:smoke": "node tools/smoke.js",
|
|
223
|
+
"verify:tarball": "node tools/verify-tarball.js"
|
|
153
224
|
},
|
|
154
225
|
"type": "module",
|
|
155
226
|
"types": "dist/index.d.ts",
|
|
156
|
-
"version": "
|
|
227
|
+
"version": "5.0.0-1"
|
|
157
228
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GetDotenvCli } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
import { helloPlugin } from './plugins/hello';
|
|
5
|
+
|
|
6
|
+
const program: Command = new GetDotenvCli('__CLI_NAME__').use(helloPlugin());
|
|
7
|
+
|
|
8
|
+
await (program as unknown as GetDotenvCli).resolveAndLoad();
|
|
9
|
+
await program.parseAsync();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
export const helloPlugin = () =>
|
|
4
|
+
definePlugin({
|
|
5
|
+
id: 'hello',
|
|
6
|
+
setup(cli) {
|
|
7
|
+
cli
|
|
8
|
+
.ns('hello')
|
|
9
|
+
.description('Say hello with current dotenv context')
|
|
10
|
+
.action(async () => {
|
|
11
|
+
const ctx = cli.getCtx?.();
|
|
12
|
+
const name = '__CLI_NAME__';
|
|
13
|
+
|
|
14
|
+
console.log(`[${name}] dotenv keys:`, Object.keys(ctx?.dotenv ?? {}));
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
});
|