@dotenc/cli 0.1.1 → 0.1.3
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/dist/cli.js +3 -0
- package/dist/{src/commands → commands}/config.js +1 -1
- package/dist/{src/commands → commands}/debug.js +1 -1
- package/dist/{src/commands → commands}/edit.js +5 -6
- package/dist/{src/commands → commands}/init.js +5 -5
- package/dist/{src/commands → commands}/run.js +3 -3
- package/dist/{src/commands → commands}/token/export.js +2 -2
- package/dist/{src/commands → commands}/token/import.js +2 -2
- package/dist/{src/helpers → helpers}/createEnvironment.js +1 -2
- package/dist/{src/helpers → helpers}/createLocalEnvironment.js +2 -10
- package/dist/{src/helpers → helpers}/createProject.js +1 -1
- package/dist/{src/helpers → helpers}/crypto.js +0 -2
- package/dist/{src/helpers → helpers}/getDefaultEditor.js +1 -1
- package/dist/{src/helpers → helpers}/homeConfig.js +0 -1
- package/dist/{src/helpers → helpers}/projectConfig.js +0 -1
- package/dist/{src/helpers → helpers}/token.js +1 -2
- package/dist/program.js +46 -0
- package/package.json +5 -3
- package/dist/package.json +0 -47
- package/dist/src/cli.js +0 -42
- /package/dist/{src/commands → commands}/prompts/chooseEnvironment.js +0 -0
- /package/dist/{src/commands → commands}/prompts/createEnvironment.js +0 -0
- /package/dist/{src/helpers → helpers}/createHash.js +0 -0
- /package/dist/{src/helpers → helpers}/parseEnv.js +0 -0
package/dist/cli.js
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getHomeConfig, setHomeConfig } from "../helpers/homeConfig";
|
|
1
|
+
import { getHomeConfig, setHomeConfig } from "../helpers/homeConfig.js";
|
|
2
2
|
export const configCommand = async (key, value, options) => {
|
|
3
3
|
const config = await getHomeConfig();
|
|
4
4
|
if (options.remove) {
|
|
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { decrypt, encrypt } from "../helpers/crypto";
|
|
5
|
+
import { decrypt, encrypt } from "../helpers/crypto.js";
|
|
6
6
|
export const debugCommand = async () => {
|
|
7
7
|
const token = crypto.randomBytes(32).toString("base64");
|
|
8
8
|
const encryptedFilePath = path.join(os.tmpdir(), "dotenc.enc");
|
|
@@ -3,11 +3,11 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { createHash } from "../helpers/createHash";
|
|
7
|
-
import { decrypt, encrypt } from "../helpers/crypto";
|
|
8
|
-
import { getDefaultEditor } from "../helpers/getDefaultEditor";
|
|
9
|
-
import { getToken } from "../helpers/token";
|
|
10
|
-
import { chooseEnvironmentPrompt } from "./prompts/chooseEnvironment";
|
|
6
|
+
import { createHash } from "../helpers/createHash.js";
|
|
7
|
+
import { decrypt, encrypt } from "../helpers/crypto.js";
|
|
8
|
+
import { getDefaultEditor } from "../helpers/getDefaultEditor.js";
|
|
9
|
+
import { getToken } from "../helpers/token.js";
|
|
10
|
+
import { chooseEnvironmentPrompt } from "./prompts/chooseEnvironment.js";
|
|
11
11
|
export const editCommand = async (environmentArg) => {
|
|
12
12
|
let environment = environmentArg;
|
|
13
13
|
if (!environment) {
|
|
@@ -40,5 +40,4 @@ export const editCommand = async (environmentArg) => {
|
|
|
40
40
|
console.log(`Encrypted environment file for "${environment}" and saved it to ${environmentFilePath}.`);
|
|
41
41
|
}
|
|
42
42
|
await fs.unlink(tempFilePath);
|
|
43
|
-
console.debug(`Temporary file deleted: ${tempFilePath}`);
|
|
44
43
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import { createEnvironment } from "../helpers/createEnvironment";
|
|
3
|
-
import { createLocalEnvironment } from "../helpers/createLocalEnvironment";
|
|
4
|
-
import { createProject } from "../helpers/createProject";
|
|
5
|
-
import { addToken } from "../helpers/token";
|
|
6
|
-
import { createEnvironmentPrompt } from "./prompts/createEnvironment";
|
|
2
|
+
import { createEnvironment } from "../helpers/createEnvironment.js";
|
|
3
|
+
import { createLocalEnvironment } from "../helpers/createLocalEnvironment.js";
|
|
4
|
+
import { createProject } from "../helpers/createProject.js";
|
|
5
|
+
import { addToken } from "../helpers/token.js";
|
|
6
|
+
import { createEnvironmentPrompt } from "./prompts/createEnvironment.js";
|
|
7
7
|
export const initCommand = async (environmentArg) => {
|
|
8
8
|
// Generate a unique project ID
|
|
9
9
|
const { projectId } = await createProject();
|
|
@@ -2,9 +2,9 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { decrypt } from "../helpers/crypto";
|
|
6
|
-
import { parseEnv } from "../helpers/parseEnv";
|
|
7
|
-
import { getToken } from "../helpers/token";
|
|
5
|
+
import { decrypt } from "../helpers/crypto.js";
|
|
6
|
+
import { parseEnv } from "../helpers/parseEnv.js";
|
|
7
|
+
import { getToken } from "../helpers/token.js";
|
|
8
8
|
export const runCommand = async (environmentArg, command, args) => {
|
|
9
9
|
// Get the environment
|
|
10
10
|
const environment = environmentArg;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getProjectConfig } from "../../helpers/projectConfig";
|
|
2
|
-
import { getToken } from "../../helpers/token";
|
|
1
|
+
import { getProjectConfig } from "../../helpers/projectConfig.js";
|
|
2
|
+
import { getToken } from "../../helpers/token.js";
|
|
3
3
|
export const tokenExportCommand = async (environmentArg) => {
|
|
4
4
|
const environment = environmentArg;
|
|
5
5
|
const { projectId } = await getProjectConfig();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getProjectConfig } from "../../helpers/projectConfig";
|
|
2
|
-
import { addToken } from "../../helpers/token";
|
|
1
|
+
import { getProjectConfig } from "../../helpers/projectConfig.js";
|
|
2
|
+
import { addToken } from "../../helpers/token.js";
|
|
3
3
|
export const tokenImportCommand = async (token, environmentArg) => {
|
|
4
4
|
const environment = environmentArg;
|
|
5
5
|
const { projectId } = await getProjectConfig();
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { encrypt } from "./crypto";
|
|
3
|
+
import { encrypt } from "./crypto.js";
|
|
4
4
|
export const createEnvironment = async (name, token) => {
|
|
5
5
|
const filePath = path.join(process.cwd(), `.env.${name}.enc`);
|
|
6
6
|
if (existsSync(filePath)) {
|
|
7
7
|
throw new Error(`Environment "${name}" already exists.`);
|
|
8
8
|
}
|
|
9
9
|
await encrypt(token, `# ${name} environment\n`, filePath);
|
|
10
|
-
console.debug(`Environment "${name}" created.`);
|
|
11
10
|
};
|
|
@@ -13,17 +13,9 @@ export const createLocalEnvironment = async () => {
|
|
|
13
13
|
if (!isEnvIgnored) {
|
|
14
14
|
// Append the .env entry to the .gitignore file
|
|
15
15
|
await fs.appendFile(gitignorePath, `\n# Ignore local environment file\n${envEntry}\n`);
|
|
16
|
-
console.debug("Updated .gitignore to ignore .env file.");
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
console.debug(".env file is already ignored in .gitignore.");
|
|
20
16
|
}
|
|
21
17
|
const envPath = path.join(process.cwd(), ".env");
|
|
22
|
-
if (existsSync(envPath)) {
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
await fs.writeFile(envPath, "");
|
|
27
|
-
console.debug("Created .env file.");
|
|
18
|
+
if (!existsSync(envPath)) {
|
|
19
|
+
await fs.writeFile(envPath, "# Local environment variables\n");
|
|
28
20
|
}
|
|
29
21
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
-
import { getProjectConfig, setProjectConfig } from "./projectConfig";
|
|
2
|
+
import { getProjectConfig, setProjectConfig } from "./projectConfig.js";
|
|
3
3
|
export const createProject = async () => {
|
|
4
4
|
const config = await getProjectConfig();
|
|
5
5
|
if (config.projectId) {
|
|
@@ -27,7 +27,6 @@ export async function encrypt(token, input, outputFile) {
|
|
|
27
27
|
const result = Buffer.concat([iv, encrypted, authTag]);
|
|
28
28
|
// Write the encrypted file
|
|
29
29
|
await fs.writeFile(outputFile, result);
|
|
30
|
-
console.debug(`File encrypted successfully: ${outputFile}`);
|
|
31
30
|
}
|
|
32
31
|
/**
|
|
33
32
|
* Decrypts a file using AES-256-GCM.
|
|
@@ -56,7 +55,6 @@ export async function decrypt(token, inputFile) {
|
|
|
56
55
|
decipher.update(ciphertext),
|
|
57
56
|
decipher.final(),
|
|
58
57
|
]);
|
|
59
|
-
console.debug(`File decrypted successfully: ${inputFile}`);
|
|
60
58
|
return decrypted.toString();
|
|
61
59
|
}
|
|
62
60
|
catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
-
import { getHomeConfig } from "./homeConfig";
|
|
2
|
+
import { getHomeConfig } from "./homeConfig.js";
|
|
3
3
|
/**
|
|
4
4
|
* Determines the default text editor for the system.
|
|
5
5
|
* @returns {string} The command to launch the default text editor.
|
|
@@ -12,7 +12,6 @@ export const setHomeConfig = async (config) => {
|
|
|
12
12
|
await fs.writeFile(configPath, JSON.stringify(parsedConfig, null, 2), {
|
|
13
13
|
mode: 0o600,
|
|
14
14
|
});
|
|
15
|
-
console.debug("config.json saved");
|
|
16
15
|
};
|
|
17
16
|
export const getHomeConfig = async () => {
|
|
18
17
|
if (existsSync(configPath)) {
|
|
@@ -11,7 +11,6 @@ export const setProjectConfig = async (config) => {
|
|
|
11
11
|
await fs.writeFile(configPath, JSON.stringify(parsedConfig, null, 2), {
|
|
12
12
|
mode: 0o600,
|
|
13
13
|
});
|
|
14
|
-
console.debug(`dotenc.json saved for projectId "${parsedConfig.projectId}".`);
|
|
15
14
|
};
|
|
16
15
|
export const getProjectConfig = async () => {
|
|
17
16
|
if (existsSync(configPath)) {
|
|
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { getProjectConfig } from "./projectConfig";
|
|
5
|
+
import { getProjectConfig } from "./projectConfig.js";
|
|
6
6
|
export const getToken = async (environment) => {
|
|
7
7
|
if (process.env.DOTENC_TOKEN) {
|
|
8
8
|
return process.env.DOTENC_TOKEN;
|
|
@@ -36,5 +36,4 @@ export const addToken = async (projectId, environment, token) => {
|
|
|
36
36
|
await fs.writeFile(tokensFile, JSON.stringify(tokens, null, 2), {
|
|
37
37
|
mode: 0o600,
|
|
38
38
|
});
|
|
39
|
-
console.debug(`Token for project "${projectId}" and environment "${environment}" added successfully.`);
|
|
40
39
|
};
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { configCommand } from "./commands/config.js";
|
|
6
|
+
import { debugCommand } from "./commands/debug.js";
|
|
7
|
+
import { editCommand } from "./commands/edit.js";
|
|
8
|
+
import { initCommand } from "./commands/init.js";
|
|
9
|
+
import { runCommand } from "./commands/run.js";
|
|
10
|
+
import { tokenExportCommand } from "./commands/token/export.js";
|
|
11
|
+
import { tokenImportCommand } from "./commands/token/import.js";
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"), "utf8"));
|
|
15
|
+
const program = new Command();
|
|
16
|
+
program.name("dotenc").description(pkg.description).version(pkg.version);
|
|
17
|
+
if (process.env.NODE_ENV !== "production") {
|
|
18
|
+
program.command("debug").description("debug the CLI").action(debugCommand);
|
|
19
|
+
}
|
|
20
|
+
program
|
|
21
|
+
.command("init [environment]")
|
|
22
|
+
.description("initialize a new environment")
|
|
23
|
+
.action(initCommand);
|
|
24
|
+
program
|
|
25
|
+
.command("edit [environment]")
|
|
26
|
+
.description("edit an environment")
|
|
27
|
+
.action(editCommand);
|
|
28
|
+
program
|
|
29
|
+
.command("run <environment> <command> [args...]")
|
|
30
|
+
.description("run a command in an environment")
|
|
31
|
+
.action(runCommand);
|
|
32
|
+
const token = program.command("token").description("Manage stored tokens");
|
|
33
|
+
token
|
|
34
|
+
.command("import <environment> <token>")
|
|
35
|
+
.description("import a token for an environment")
|
|
36
|
+
.action(tokenImportCommand);
|
|
37
|
+
token
|
|
38
|
+
.command("export <environment>")
|
|
39
|
+
.description("export a token from an environment")
|
|
40
|
+
.action(tokenExportCommand);
|
|
41
|
+
program
|
|
42
|
+
.command("config <key> [value]")
|
|
43
|
+
.addOption(new Option("-r, --remove", "remove a configuration key"))
|
|
44
|
+
.description("manage global configuration")
|
|
45
|
+
.action(configCommand);
|
|
46
|
+
program.parse();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotenc/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "🔐 Secure, encrypted environment variables that live in your codebase",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"dotenc": "./dist/
|
|
7
|
+
"dotenc": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@biomejs/biome": "^1.9.4",
|
|
33
33
|
"@types/node": "^22.13.7",
|
|
34
|
+
"tsc-alias": "^1.8.11",
|
|
34
35
|
"tsx": "^4.19.3",
|
|
35
36
|
"typescript": "^5.8.2"
|
|
36
37
|
},
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"dev": "tsx src/cli.ts",
|
|
45
|
-
"
|
|
46
|
+
"start": "node dist/cli.js",
|
|
47
|
+
"build": "tsc && tsc-alias"
|
|
46
48
|
}
|
|
47
49
|
}
|
package/dist/package.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dotenc/cli",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "🔐 Secure, encrypted environment variables that live in your codebase",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"dotenc": "./dist/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"dev": "tsx src/cli.ts",
|
|
14
|
-
"build": "tsc"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"environment",
|
|
18
|
-
"variables",
|
|
19
|
-
"safe",
|
|
20
|
-
"secure",
|
|
21
|
-
"codebase",
|
|
22
|
-
"cli",
|
|
23
|
-
"command",
|
|
24
|
-
"line",
|
|
25
|
-
"tool",
|
|
26
|
-
"utility",
|
|
27
|
-
"env",
|
|
28
|
-
"box",
|
|
29
|
-
"dotenv",
|
|
30
|
-
"encrypted",
|
|
31
|
-
"codebase"
|
|
32
|
-
],
|
|
33
|
-
"author": "Ivan Filho <i@ivanfilho.com>",
|
|
34
|
-
"license": "MIT",
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@biomejs/biome": "^1.9.4",
|
|
37
|
-
"@types/node": "^22.13.7",
|
|
38
|
-
"tsx": "^4.19.3",
|
|
39
|
-
"typescript": "^5.8.2"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@paralleldrive/cuid2": "^2.2.2",
|
|
43
|
-
"commander": "^13.1.0",
|
|
44
|
-
"inquirer": "^12.4.2",
|
|
45
|
-
"zod": "^3.24.2"
|
|
46
|
-
}
|
|
47
|
-
}
|
package/dist/src/cli.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command, Option } from "commander";
|
|
3
|
-
import pkg from "../package.json" assert { type: "json" };
|
|
4
|
-
import { configCommand } from "./commands/config";
|
|
5
|
-
import { debugCommand } from "./commands/debug";
|
|
6
|
-
import { editCommand } from "./commands/edit";
|
|
7
|
-
import { initCommand } from "./commands/init";
|
|
8
|
-
import { runCommand } from "./commands/run";
|
|
9
|
-
import { tokenExportCommand } from "./commands/token/export";
|
|
10
|
-
import { tokenImportCommand } from "./commands/token/import";
|
|
11
|
-
const program = new Command();
|
|
12
|
-
program.name("dotenc").description(pkg.description).version(pkg.version);
|
|
13
|
-
if (process.env.NODE_ENV !== "production") {
|
|
14
|
-
program.command("debug").description("Debug the CLI").action(debugCommand);
|
|
15
|
-
}
|
|
16
|
-
program
|
|
17
|
-
.command("init [environment]")
|
|
18
|
-
.description("Initialize a new safe environment")
|
|
19
|
-
.action(initCommand);
|
|
20
|
-
program
|
|
21
|
-
.command("edit [environment]")
|
|
22
|
-
.description("Edit an environment")
|
|
23
|
-
.action(editCommand);
|
|
24
|
-
program
|
|
25
|
-
.command("run <environment> <command> [args...]")
|
|
26
|
-
.description("Run a command in an environment")
|
|
27
|
-
.action(runCommand);
|
|
28
|
-
const token = program.command("token").description("Manage stored tokens");
|
|
29
|
-
token
|
|
30
|
-
.command("import <environment> <token>")
|
|
31
|
-
.description("Import a token for an environment")
|
|
32
|
-
.action(tokenImportCommand);
|
|
33
|
-
token
|
|
34
|
-
.command("export <environment>")
|
|
35
|
-
.description("Export a token from an environment")
|
|
36
|
-
.action(tokenExportCommand);
|
|
37
|
-
program
|
|
38
|
-
.command("config <key> [value]")
|
|
39
|
-
.addOption(new Option("-r, --remove", "Remove a configuration key"))
|
|
40
|
-
.description("Manage global configuration")
|
|
41
|
-
.action(configCommand);
|
|
42
|
-
program.parse();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|