@dotenc/cli 0.1.2 → 0.1.4
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/commands/edit.js +5 -4
- package/dist/commands/init.js +5 -5
- package/dist/commands/run.js +8 -3
- package/dist/commands/token/export.js +2 -1
- package/dist/commands/token/import.js +2 -1
- package/dist/helpers/createEnvironment.js +0 -1
- package/dist/helpers/createLocalEnvironment.js +2 -10
- package/dist/helpers/crypto.js +0 -2
- package/dist/helpers/homeConfig.js +0 -1
- package/dist/helpers/projectConfig.js +0 -1
- package/dist/helpers/token.js +0 -1
- package/dist/program.js +2 -1
- package/package.json +1 -1
- /package/dist/{commands/prompts → prompts}/chooseEnvironment.js +0 -0
- /package/dist/{commands/prompts → prompts}/createEnvironment.js +0 -0
package/dist/commands/edit.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash } from "../helpers/createHash.js";
|
|
|
7
7
|
import { decrypt, encrypt } from "../helpers/crypto.js";
|
|
8
8
|
import { getDefaultEditor } from "../helpers/getDefaultEditor.js";
|
|
9
9
|
import { getToken } from "../helpers/token.js";
|
|
10
|
-
import { chooseEnvironmentPrompt } from "
|
|
10
|
+
import { chooseEnvironmentPrompt } from "../prompts/chooseEnvironment.js";
|
|
11
11
|
export const editCommand = async (environmentArg) => {
|
|
12
12
|
let environment = environmentArg;
|
|
13
13
|
if (!environment) {
|
|
@@ -15,7 +15,8 @@ export const editCommand = async (environmentArg) => {
|
|
|
15
15
|
}
|
|
16
16
|
const environmentFilePath = path.join(process.cwd(), `.env.${environment}.enc`);
|
|
17
17
|
if (!existsSync(environmentFilePath)) {
|
|
18
|
-
|
|
18
|
+
console.error(`Environment file not found: ${environmentFilePath}`);
|
|
19
|
+
return;
|
|
19
20
|
}
|
|
20
21
|
const token = await getToken(environment);
|
|
21
22
|
const tempFilePath = path.join(os.tmpdir(), `.env.${environment}`);
|
|
@@ -28,7 +29,8 @@ export const editCommand = async (environmentArg) => {
|
|
|
28
29
|
execSync(`${editor} ${tempFilePath}`, { stdio: "inherit" });
|
|
29
30
|
}
|
|
30
31
|
catch (error) {
|
|
31
|
-
|
|
32
|
+
console.error(`Failed to open editor: ${editor}`);
|
|
33
|
+
return;
|
|
32
34
|
}
|
|
33
35
|
const newContent = await fs.readFile(tempFilePath, "utf-8");
|
|
34
36
|
const finalHash = createHash(newContent);
|
|
@@ -40,5 +42,4 @@ export const editCommand = async (environmentArg) => {
|
|
|
40
42
|
console.log(`Encrypted environment file for "${environment}" and saved it to ${environmentFilePath}.`);
|
|
41
43
|
}
|
|
42
44
|
await fs.unlink(tempFilePath);
|
|
43
|
-
console.debug(`Temporary file deleted: ${tempFilePath}`);
|
|
44
45
|
};
|
package/dist/commands/init.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createEnvironment } from "../helpers/createEnvironment.js";
|
|
|
3
3
|
import { createLocalEnvironment } from "../helpers/createLocalEnvironment.js";
|
|
4
4
|
import { createProject } from "../helpers/createProject.js";
|
|
5
5
|
import { addToken } from "../helpers/token.js";
|
|
6
|
-
import { createEnvironmentPrompt } from "
|
|
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();
|
|
@@ -22,8 +22,8 @@ export const initCommand = async (environmentArg) => {
|
|
|
22
22
|
// Output success message
|
|
23
23
|
console.log("Initialization complete!");
|
|
24
24
|
console.log("Next steps:");
|
|
25
|
-
console.log(`1. Use "dotenc edit
|
|
26
|
-
console.log(`2. Use "dotenc run -e ${environment} <command> [args...]" to run your application.`);
|
|
27
|
-
console.log('3. Use "dotenc init
|
|
28
|
-
console.log("4. Use the git-ignored .env file
|
|
25
|
+
console.log(`1. Use "dotenc edit ${environment}" to securely edit your environment variables.`);
|
|
26
|
+
console.log(`2. Use "dotenc run -e ${environment} <command> [args...]" or "DOTENC_ENV=${environment} dotenc run <command> [args...]" to run your application.`);
|
|
27
|
+
console.log('3. Use "dotenc init [environment]" to initialize a new environment.');
|
|
28
|
+
console.log("4. Use the git-ignored .env file for local development. It will have priority over any encrypted environment variables.");
|
|
29
29
|
};
|
package/dist/commands/run.js
CHANGED
|
@@ -5,12 +5,17 @@ import path from "node:path";
|
|
|
5
5
|
import { decrypt } from "../helpers/crypto.js";
|
|
6
6
|
import { parseEnv } from "../helpers/parseEnv.js";
|
|
7
7
|
import { getToken } from "../helpers/token.js";
|
|
8
|
-
export const runCommand = async (
|
|
8
|
+
export const runCommand = async (command, args, options) => {
|
|
9
9
|
// Get the environment
|
|
10
|
-
const environment =
|
|
10
|
+
const environment = options.env || process.env.DOTENC_ENV;
|
|
11
|
+
if (!environment) {
|
|
12
|
+
console.error('No environment provided. Use -e or set DOTENC_ENV to the environment you want to run the command in.\nTo start a new environment, use "dotenc init [environment]".');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
11
15
|
const environmentFilePath = path.join(process.cwd(), `.env.${environment}.enc`);
|
|
12
16
|
if (!existsSync(environmentFilePath)) {
|
|
13
|
-
|
|
17
|
+
console.error(`Environment file not found: ${environmentFilePath}`);
|
|
18
|
+
return;
|
|
14
19
|
}
|
|
15
20
|
const token = await getToken(environment);
|
|
16
21
|
const content = await decrypt(token, environmentFilePath);
|
|
@@ -4,7 +4,8 @@ export const tokenExportCommand = async (environmentArg) => {
|
|
|
4
4
|
const environment = environmentArg;
|
|
5
5
|
const { projectId } = await getProjectConfig();
|
|
6
6
|
if (!projectId) {
|
|
7
|
-
|
|
7
|
+
console.error('No project found. Run "dotenc init" to create one.');
|
|
8
|
+
return;
|
|
8
9
|
}
|
|
9
10
|
const token = await getToken(environment);
|
|
10
11
|
console.log(`Token for the ${environment} environment: ${token}`);
|
|
@@ -4,7 +4,8 @@ export const tokenImportCommand = async (token, environmentArg) => {
|
|
|
4
4
|
const environment = environmentArg;
|
|
5
5
|
const { projectId } = await getProjectConfig();
|
|
6
6
|
if (!projectId) {
|
|
7
|
-
|
|
7
|
+
console.error('No project found. Run "dotenc init" to create one.');
|
|
8
|
+
return;
|
|
8
9
|
}
|
|
9
10
|
await addToken(projectId, environment, token);
|
|
10
11
|
console.log(`Token imported to the ${environment} environment.`);
|
|
@@ -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
|
};
|
package/dist/helpers/crypto.js
CHANGED
|
@@ -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) {
|
|
@@ -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)) {
|
package/dist/helpers/token.js
CHANGED
|
@@ -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
CHANGED
|
@@ -26,7 +26,8 @@ program
|
|
|
26
26
|
.description("edit an environment")
|
|
27
27
|
.action(editCommand);
|
|
28
28
|
program
|
|
29
|
-
.command("run <
|
|
29
|
+
.command("run <command> [args...]")
|
|
30
|
+
.addOption(new Option("-e, --environment <environment>", "the environment to run the command in"))
|
|
30
31
|
.description("run a command in an environment")
|
|
31
32
|
.action(runCommand);
|
|
32
33
|
const token = program.command("token").description("Manage stored tokens");
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|