@dotenc/cli 0.1.3 → 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 -3
- 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/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);
|
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.`);
|
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
|