e2sm 0.2.0 → 0.3.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 (2) hide show
  1. package/dist/index.mjs +84 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { stripVTControlCharacters } from "node:util";
2
+ import { inspect, stripVTControlCharacters } from "node:util";
3
3
  import y, { stdin, stdout } from "node:process";
4
4
  import * as g from "node:readline";
5
5
  import O from "node:readline";
@@ -3013,7 +3013,7 @@ BUILT_IN_PREFIX.codePointAt(0);
3013
3013
 
3014
3014
  //#endregion
3015
3015
  //#region package.json
3016
- var version = "0.2.0";
3016
+ var version = "0.3.0";
3017
3017
 
3018
3018
  //#endregion
3019
3019
  //#region src/lib.ts
@@ -3041,6 +3041,25 @@ function validateUnknownFlags(tokens, args) {
3041
3041
  }
3042
3042
  return null;
3043
3043
  }
3044
+ /**
3045
+ * Determines if template mode is active.
3046
+ */
3047
+ function isTemplateMode(flags) {
3048
+ return Boolean(flags.template || flags.application || flags.stage);
3049
+ }
3050
+ /**
3051
+ * Validates that --name flag is not used with template mode flags.
3052
+ */
3053
+ function validateNameTemplateConflict(flags) {
3054
+ if (flags.name && isTemplateMode(flags)) {
3055
+ const conflicting = [];
3056
+ if (flags.template) conflicting.push("--template");
3057
+ if (flags.application) conflicting.push("--application");
3058
+ if (flags.stage) conflicting.push("--stage");
3059
+ return `Cannot use --name with ${conflicting.join(", ")}`;
3060
+ }
3061
+ return null;
3062
+ }
3044
3063
  function parseEnvContent(content) {
3045
3064
  const result = {};
3046
3065
  for (const line of content.split("\n")) {
@@ -3121,6 +3140,21 @@ const command = define({
3121
3140
  type: "string",
3122
3141
  short: "r",
3123
3142
  description: "AWS region to use (e.g., ap-northeast-1)"
3143
+ },
3144
+ template: {
3145
+ type: "boolean",
3146
+ short: "t",
3147
+ description: "Use template mode: generate secret name as $application/$stage"
3148
+ },
3149
+ application: {
3150
+ type: "string",
3151
+ short: "a",
3152
+ description: "Application name for template mode (implies --template)"
3153
+ },
3154
+ stage: {
3155
+ type: "string",
3156
+ short: "s",
3157
+ description: "Stage name for template mode (implies --template)"
3124
3158
  }
3125
3159
  },
3126
3160
  run: async (ctx) => {
@@ -3129,6 +3163,11 @@ const command = define({
3129
3163
  console.error(unknownFlagError);
3130
3164
  process.exit(1);
3131
3165
  }
3166
+ const conflictError = validateNameTemplateConflict(ctx.values);
3167
+ if (conflictError) {
3168
+ console.error(conflictError);
3169
+ process.exit(1);
3170
+ }
3132
3171
  const isDryRun = ctx.values.dryRun;
3133
3172
  const profile = ctx.values.profile;
3134
3173
  const inputFlag = ctx.values.input;
@@ -3161,13 +3200,54 @@ const command = define({
3161
3200
  const jsonString = JSON.stringify(envData);
3162
3201
  if (isDryRun) {
3163
3202
  M.info("Dry-run mode: Previewing JSON output");
3164
- console.log(JSON.stringify(envData, null, 2));
3203
+ console.log(inspect(envData, {
3204
+ colors: true,
3205
+ depth: null
3206
+ }));
3165
3207
  Se("Dry-run complete");
3166
3208
  return;
3167
3209
  }
3168
3210
  let secretName;
3211
+ const templateFlag = ctx.values.template;
3212
+ const applicationFlag = ctx.values.application;
3213
+ const stageFlag = ctx.values.stage;
3214
+ const useTemplateMode = isTemplateMode({
3215
+ template: templateFlag,
3216
+ application: applicationFlag,
3217
+ stage: stageFlag
3218
+ });
3169
3219
  if (nameFlag) secretName = nameFlag;
3170
- else {
3220
+ else if (useTemplateMode) {
3221
+ let application;
3222
+ let stage;
3223
+ if (applicationFlag) application = applicationFlag;
3224
+ else {
3225
+ const result = await he({
3226
+ message: "Enter the application name:",
3227
+ placeholder: "my-app",
3228
+ defaultValue: "my-app"
3229
+ });
3230
+ if (isCancel(result)) {
3231
+ xe("Operation cancelled");
3232
+ process.exit(0);
3233
+ }
3234
+ application = result;
3235
+ }
3236
+ if (stageFlag) stage = stageFlag;
3237
+ else {
3238
+ const result = await he({
3239
+ message: "Enter the stage name:",
3240
+ placeholder: "dev",
3241
+ defaultValue: "dev"
3242
+ });
3243
+ if (isCancel(result)) {
3244
+ xe("Operation cancelled");
3245
+ process.exit(0);
3246
+ }
3247
+ stage = result;
3248
+ }
3249
+ secretName = `${application}/${stage}`;
3250
+ } else {
3171
3251
  const result = await he({
3172
3252
  message: "Enter the secret name for AWS Secrets Manager:",
3173
3253
  placeholder: "my-app/default",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e2sm",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "author": "mfyuu",
6
6
  "repository": {