e2sm 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -9,3 +9,38 @@ npx e2sm
9
9
  npx e2sm --dry-run
10
10
  npx e2sm --help
11
11
  ```
12
+
13
+ ## Configuration
14
+
15
+ You can create a `.e2smrc.json` file to set default options.
16
+
17
+ ```json
18
+ {
19
+ "$schema": "https://unpkg.com/e2sm/schema.json",
20
+ "template": true,
21
+ "application": "my-app",
22
+ "stage": "dev",
23
+ "profile": "my-profile",
24
+ "region": "ap-northeast-1",
25
+ "input": ".env.local"
26
+ }
27
+ ```
28
+
29
+ ### Config file locations
30
+
31
+ 1. `./.e2smrc.json` (project) - takes precedence
32
+ 2. `~/.e2smrc.json` (global)
33
+
34
+ Only the first found config is used (no merging).
35
+
36
+ ### Priority
37
+
38
+ CLI flags always take precedence over config file values.
39
+
40
+ ```bash
41
+ # Uses profile from config
42
+ npx e2sm
43
+
44
+ # Overrides config with "prod-profile"
45
+ npx e2sm -p prod-profile
46
+ ```
package/dist/index.mjs CHANGED
@@ -3013,7 +3013,7 @@ BUILT_IN_PREFIX.codePointAt(0);
3013
3013
 
3014
3014
  //#endregion
3015
3015
  //#region package.json
3016
- var version = "0.3.0";
3016
+ var version = "0.4.0";
3017
3017
 
3018
3018
  //#endregion
3019
3019
  //#region src/lib.ts
@@ -3078,6 +3078,29 @@ function parseEnvContent(content) {
3078
3078
  }
3079
3079
  return result;
3080
3080
  }
3081
+ /**
3082
+ * Loads config from .e2smrc.json (project or global).
3083
+ * Returns empty object if no config found.
3084
+ */
3085
+ async function loadConfig() {
3086
+ const { homedir } = await import("node:os");
3087
+ const { join } = await import("node:path");
3088
+ const candidates = [join(process.cwd(), ".e2smrc.json"), join(homedir(), ".e2smrc.json")];
3089
+ for (const filePath of candidates) try {
3090
+ const file = Bun.file(filePath);
3091
+ if (await file.exists()) return await file.json();
3092
+ } catch {}
3093
+ return {};
3094
+ }
3095
+ /**
3096
+ * Merges CLI flags with config. CLI takes precedence.
3097
+ */
3098
+ function mergeWithConfig(cliValues, config) {
3099
+ return {
3100
+ ...config,
3101
+ ...Object.fromEntries(Object.entries(cliValues).filter(([, v$1]) => v$1 !== void 0))
3102
+ };
3103
+ }
3081
3104
 
3082
3105
  //#endregion
3083
3106
  //#region src/index.ts
@@ -3158,6 +3181,7 @@ const command = define({
3158
3181
  }
3159
3182
  },
3160
3183
  run: async (ctx) => {
3184
+ const config = await loadConfig();
3161
3185
  const unknownFlagError = validateUnknownFlags(ctx.tokens, ctx.args);
3162
3186
  if (unknownFlagError) {
3163
3187
  console.error(unknownFlagError);
@@ -3168,11 +3192,12 @@ const command = define({
3168
3192
  console.error(conflictError);
3169
3193
  process.exit(1);
3170
3194
  }
3195
+ const merged = mergeWithConfig(ctx.values, config);
3171
3196
  const isDryRun = ctx.values.dryRun;
3172
- const profile = ctx.values.profile;
3173
- const inputFlag = ctx.values.input;
3197
+ const profile = merged.profile;
3198
+ const inputFlag = merged.input;
3174
3199
  const nameFlag = ctx.values.name;
3175
- const region = ctx.values.region;
3200
+ const region = merged.region;
3176
3201
  Ie(`e2sm v${version} - env to AWS Secrets Manager`);
3177
3202
  let envFilePath;
3178
3203
  if (inputFlag) envFilePath = inputFlag;
@@ -3208,9 +3233,9 @@ const command = define({
3208
3233
  return;
3209
3234
  }
3210
3235
  let secretName;
3211
- const templateFlag = ctx.values.template;
3212
- const applicationFlag = ctx.values.application;
3213
- const stageFlag = ctx.values.stage;
3236
+ const templateFlag = merged.template;
3237
+ const applicationFlag = merged.application;
3238
+ const stageFlag = merged.stage;
3214
3239
  const useTemplateMode = isTemplateMode({
3215
3240
  template: templateFlag,
3216
3241
  application: applicationFlag,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e2sm",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "author": "mfyuu",
6
6
  "repository": {
@@ -11,7 +11,8 @@
11
11
  "e2sm": "dist/index.mjs"
12
12
  },
13
13
  "files": [
14
- "dist"
14
+ "dist",
15
+ "schema.json"
15
16
  ],
16
17
  "type": "module",
17
18
  "publishConfig": {
package/schema.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "e2sm configuration",
4
+ "type": "object",
5
+ "properties": {
6
+ "$schema": {
7
+ "type": "string"
8
+ },
9
+ "template": {
10
+ "type": "boolean",
11
+ "description": "Use template mode: generate secret name as $application/$stage"
12
+ },
13
+ "application": {
14
+ "type": "string",
15
+ "description": "Application name for template mode"
16
+ },
17
+ "stage": {
18
+ "type": "string",
19
+ "description": "Stage name for template mode"
20
+ },
21
+ "profile": {
22
+ "type": "string",
23
+ "description": "AWS profile to use"
24
+ },
25
+ "region": {
26
+ "type": "string",
27
+ "description": "AWS region to use"
28
+ },
29
+ "input": {
30
+ "type": "string",
31
+ "description": "Path to the .env file"
32
+ }
33
+ },
34
+ "additionalProperties": false
35
+ }