@suronai/cli 0.1.35 → 0.1.37

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.
@@ -1,61 +0,0 @@
1
- import { execSync } from "child_process";
2
- import { existsSync, readFileSync } from "fs";
3
- import { join } from "path";
4
-
5
- /**
6
- * Encrypts .env in-place using dotenvx.
7
- * On success: .env is encrypted, .env.keys contains the private key.
8
- * If dotenvx exits 0 but .env.keys doesn't exist, the file was already
9
- * encrypted — readPrivateKey() will throw a clear error explaining that.
10
- * @param {string} cwd
11
- */
12
- export function encryptDotenv(cwd) {
13
- if (!existsSync(join(cwd, ".env"))) {
14
- throw new Error(`.env not found in ${cwd}`);
15
- }
16
- // Strip all dotenvx keypair vars from the child environment.
17
- // If dotenvx sees DOTENV_PRIVATE_KEY *or* DOTENV_PUBLIC_KEY already set
18
- // it reuses that keypair and skips writing .env.keys entirely, which
19
- // breaks readPrivateKey() immediately after.
20
- const env = { ...process.env };
21
- for (const k of Object.keys(env)) {
22
- if (k.startsWith("DOTENV_PRIVATE_KEY") || k.startsWith("DOTENV_PUBLIC_KEY")) delete env[k];
23
- }
24
-
25
- try {
26
- const output = execSync("npx @dotenvx/dotenvx encrypt", {
27
- cwd,
28
- env,
29
- stdio: ["inherit", "pipe", "pipe"],
30
- }).toString();
31
- if (output) process.stdout.write(output);
32
- } catch (err) {
33
- const stderr = err.stderr?.toString() ?? "";
34
- const stdout = err.stdout?.toString() ?? "";
35
- if (stdout) process.stdout.write(stdout);
36
- throw new Error(`dotenvx encrypt failed: ${stderr || err}`);
37
- }
38
- }
39
-
40
- /**
41
- * Reads the private key out of .env.keys after encryption.
42
- * @param {string} cwd
43
- * @returns {string}
44
- */
45
- export function readPrivateKey(cwd) {
46
- const keysPath = join(cwd, ".env.keys");
47
- if (!existsSync(keysPath)) {
48
- throw new Error(
49
- ".env.keys not found after encryption.\n" +
50
- " Your .env may already be encrypted — restore plaintext values and run: suron init"
51
- );
52
- }
53
- const content = readFileSync(keysPath, "utf-8");
54
- const match = content.match(/DOTENV_PRIVATE_KEY(?:_\w+)?="?([^"\n]+)"?/);
55
- if (!match?.[1]) {
56
- throw new Error("Could not parse DOTENV_PRIVATE_KEY from .env.keys");
57
- }
58
- return match[1].trim();
59
- }
60
-
61
-