e2sm 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,16 +1,25 @@
1
1
  {
2
2
  "name": "e2sm",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
+ "license": "MIT",
5
+ "author": "mfyuu",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mfyuu/e2sm.git"
9
+ },
4
10
  "bin": {
5
- "e2sm": "src/index.ts"
11
+ "e2sm": "dist/index.mjs"
6
12
  },
7
13
  "files": [
8
- "src/index.ts",
9
- "src/lib.ts"
14
+ "dist"
10
15
  ],
11
16
  "type": "module",
12
- "module": "src/index.ts",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
13
20
  "scripts": {
21
+ "build": "tsdown",
22
+ "prepublishOnly": "bun run build",
14
23
  "prepare": "lefthook install",
15
24
  "preinstall": "npx only-allow bun",
16
25
  "fmt": "oxfmt",
@@ -18,21 +27,24 @@
18
27
  "lint": "oxlint",
19
28
  "lint-types": "oxlint --type-aware",
20
29
  "check": "oxfmt && oxlint --type-aware",
21
- "typecheck": "tsc --noEmit"
22
- },
23
- "dependencies": {
24
- "@clack/prompts": "^0.11.0",
25
- "gunshi": "0.27.5"
30
+ "typecheck": "tsc --noEmit",
31
+ "test": "bun test",
32
+ "changeset": "changeset",
33
+ "version": "changeset version",
34
+ "release": "changeset publish"
26
35
  },
27
36
  "devDependencies": {
28
37
  "@changesets/changelog-github": "^0.5.2",
29
38
  "@changesets/cli": "^2.29.8",
39
+ "@clack/prompts": "^0.11.0",
30
40
  "@gunshi/docs": "0.27.5",
31
41
  "@types/bun": "latest",
42
+ "gunshi": "0.27.5",
32
43
  "lefthook": "^2.0.15",
33
44
  "oxfmt": "^0.26.0",
34
45
  "oxlint": "^1.41.0",
35
- "oxlint-tsgolint": "^0.11.1"
46
+ "oxlint-tsgolint": "^0.11.1",
47
+ "tsdown": "^0.20.0-beta.4"
36
48
  },
37
49
  "peerDependencies": {
38
50
  "typescript": "^5"
package/src/index.ts DELETED
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env bun
2
- import * as p from "@clack/prompts";
3
- import { cli, define } from "gunshi";
4
- import pkg from "../package.json";
5
- import { parseEnvContent, validateUnknownFlags } from "./lib";
6
-
7
- function isCancel(value: unknown): value is symbol {
8
- return p.isCancel(value);
9
- }
10
-
11
- const command = define({
12
- name: "e2sm",
13
- description: "Upload .env file to AWS Secrets Manager",
14
- args: {
15
- dryRun: {
16
- type: "boolean",
17
- short: "d",
18
- toKebab: true,
19
- description: "Preview JSON output without uploading",
20
- },
21
- profile: {
22
- type: "string",
23
- short: "p",
24
- description: "AWS profile to use",
25
- },
26
- input: {
27
- type: "string",
28
- short: "i",
29
- description: "Path to the .env file (skip interactive prompt)",
30
- },
31
- name: {
32
- type: "string",
33
- short: "n",
34
- description: "Secret name for AWS Secrets Manager (skip interactive prompt)",
35
- },
36
- region: {
37
- type: "string",
38
- short: "r",
39
- description: "AWS region to use (e.g., ap-northeast-1)",
40
- },
41
- },
42
- run: async (ctx) => {
43
- // Validate unknown flags first
44
- const unknownFlagError = validateUnknownFlags(ctx.tokens, ctx.args);
45
- if (unknownFlagError) {
46
- console.error(unknownFlagError);
47
- process.exit(1);
48
- }
49
-
50
- const isDryRun = ctx.values.dryRun;
51
- const profile = ctx.values.profile;
52
- const inputFlag = ctx.values.input;
53
- const nameFlag = ctx.values.name;
54
- const region = ctx.values.region;
55
-
56
- p.intro(`e2sm v${pkg.version} - env to AWS Secrets Manager`);
57
-
58
- // 1. Get env file path (from flag or interactively)
59
- let envFilePath: string;
60
-
61
- if (inputFlag) {
62
- envFilePath = inputFlag;
63
- } else {
64
- const result = await p.text({
65
- message: "Enter the path to your .env file:",
66
- placeholder: ".env.local",
67
- defaultValue: ".env.local",
68
- });
69
-
70
- if (isCancel(result)) {
71
- p.cancel("Operation cancelled");
72
- process.exit(0);
73
- }
74
-
75
- envFilePath = result;
76
- }
77
-
78
- // 2. Read and parse env file
79
- const file = Bun.file(envFilePath);
80
- const exists = await file.exists();
81
-
82
- if (!exists) {
83
- p.cancel(`File not found: ${envFilePath}`);
84
- process.exit(1);
85
- }
86
-
87
- const content = await file.text();
88
- const envData = parseEnvContent(content);
89
-
90
- if (Object.keys(envData).length === 0) {
91
- p.cancel("No valid environment variables found in the file");
92
- process.exit(1);
93
- }
94
-
95
- const jsonString = JSON.stringify(envData);
96
-
97
- // 3. Dry-run mode: preview with jq
98
- if (isDryRun) {
99
- p.log.info("Dry-run mode: Previewing JSON output");
100
- const jqResult = await Bun.$`echo ${jsonString} | jq -C .`.text();
101
- console.log(jqResult);
102
- p.outro("Dry-run complete");
103
- return;
104
- }
105
-
106
- // 4. Get secret name (from flag or interactively)
107
- let secretName: string;
108
-
109
- if (nameFlag) {
110
- secretName = nameFlag;
111
- } else {
112
- const result = await p.text({
113
- message: "Enter the secret name for AWS Secrets Manager:",
114
- placeholder: "my-app/default",
115
- defaultValue: "my-app/default",
116
- });
117
-
118
- if (isCancel(result)) {
119
- p.cancel("Operation cancelled");
120
- process.exit(0);
121
- }
122
-
123
- secretName = result;
124
- }
125
-
126
- // 5. Upload to AWS Secrets Manager
127
- const spinner = p.spinner();
128
- spinner.start("Uploading to AWS Secrets Manager...");
129
-
130
- const profileArgs = profile ? ["--profile", profile] : [];
131
- const regionArgs = region ? ["--region", region] : [];
132
-
133
- // First, try to check if the secret already exists
134
- const describeResult =
135
- await Bun.$`aws secretsmanager describe-secret --secret-id ${secretName} ${profileArgs} ${regionArgs} 2>/dev/null`.nothrow();
136
-
137
- if (describeResult.exitCode === 0) {
138
- // Secret exists, update it
139
- const updateResult =
140
- await Bun.$`aws secretsmanager put-secret-value --secret-id ${secretName} --secret-string ${jsonString} ${profileArgs} ${regionArgs}`.nothrow();
141
-
142
- if (updateResult.exitCode !== 0) {
143
- spinner.stop("Failed to update secret");
144
- p.cancel(`Error: ${updateResult.stderr.toString()}`);
145
- process.exit(1);
146
- }
147
-
148
- spinner.stop("Secret updated successfully");
149
- } else {
150
- // Secret doesn't exist, create it
151
- const createResult =
152
- await Bun.$`aws secretsmanager create-secret --name ${secretName} --secret-string ${jsonString} ${profileArgs} ${regionArgs}`.nothrow();
153
-
154
- if (createResult.exitCode !== 0) {
155
- spinner.stop("Failed to create secret");
156
- p.cancel(`Error: ${createResult.stderr.toString()}`);
157
- process.exit(1);
158
- }
159
-
160
- spinner.stop("Secret created successfully");
161
- }
162
-
163
- p.outro(`Secret '${secretName}' has been saved to AWS Secrets Manager`);
164
- },
165
- });
166
-
167
- await cli(process.argv.slice(2), command, {
168
- version: pkg.version,
169
- });
package/src/lib.ts DELETED
@@ -1,90 +0,0 @@
1
- import type { ArgSchema, ArgToken } from "gunshi";
2
-
3
- export function toKebabCase(str: string): string {
4
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
5
- }
6
-
7
- /**
8
- * Validates that all provided flags are known options.
9
- * @returns Error message if an unknown flag is found, null otherwise
10
- */
11
- export function validateUnknownFlags(
12
- tokens: ArgToken[],
13
- args: Record<string, ArgSchema>,
14
- ): string | null {
15
- // Build set of known option names
16
- const knownOptions = new Set<string>();
17
-
18
- // Built-in options
19
- knownOptions.add("help");
20
- knownOptions.add("h");
21
- knownOptions.add("version");
22
- knownOptions.add("v");
23
-
24
- // User-defined options
25
- for (const [key, schema] of Object.entries(args)) {
26
- knownOptions.add(key);
27
- knownOptions.add(toKebabCase(key));
28
-
29
- if (schema.short) {
30
- knownOptions.add(schema.short);
31
- }
32
- }
33
-
34
- // Check for unknown options
35
- for (const token of tokens) {
36
- if (token.kind === "option" && token.name) {
37
- // Handle --no- prefix for negatable options
38
- const name = token.name.startsWith("no-") ? token.name.slice(3) : token.name;
39
-
40
- if (!knownOptions.has(name)) {
41
- return `Unknown option: --${token.name}`;
42
- }
43
- }
44
- }
45
-
46
- return null;
47
- }
48
-
49
- export function parseEnvContent(content: string): Record<string, string> {
50
- const result: Record<string, string> = {};
51
-
52
- for (const line of content.split("\n")) {
53
- const trimmed = line.trim();
54
-
55
- // Skip empty lines and comments
56
- if (trimmed === "" || trimmed.startsWith("#")) {
57
- continue;
58
- }
59
-
60
- const equalIndex = trimmed.indexOf("=");
61
- if (equalIndex === -1) {
62
- continue;
63
- }
64
-
65
- const key = trimmed.slice(0, equalIndex).trim();
66
- let value = trimmed.slice(equalIndex + 1).trim();
67
-
68
- // Check if value is quoted
69
- const isQuoted =
70
- (value.startsWith('"') && value.endsWith('"')) ||
71
- (value.startsWith("'") && value.endsWith("'"));
72
-
73
- // Remove surrounding quotes if present
74
- if (isQuoted) {
75
- value = value.slice(1, -1);
76
- } else {
77
- // Remove inline comment for unquoted values
78
- const commentIndex = value.indexOf("#");
79
- if (commentIndex !== -1) {
80
- value = value.slice(0, commentIndex).trim();
81
- }
82
- }
83
-
84
- if (key) {
85
- result[key] = value;
86
- }
87
- }
88
-
89
- return result;
90
- }