dotenv-diff 1.4.0 → 1.5.0

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.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/dist/cli.js +51 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -39,6 +39,17 @@ dotenv-diff --check-values
39
39
 
40
40
  When using the `--check-values` option, the tool will also compare the actual values of the variables in `.env` and `.env.example`. It will report any mismatches found and it also compares values if .env.example defines a non-empty expected value.
41
41
 
42
+ ## CI usage
43
+
44
+ Run non-interactively in CI environments with:
45
+
46
+ ```bash
47
+ dotenv-diff --ci # never create files, exit 1 if required files are missing
48
+ dotenv-diff --yes # auto-create missing files without prompts
49
+ ```
50
+
51
+ You can also use `-y` as a shorthand for `--yes`.
52
+
42
53
  ## Automatic file creation prompts
43
54
 
44
55
  If one of the files is missing, `dotenv-diff` will ask if you want to create it from the other:
package/dist/cli.js CHANGED
@@ -19,9 +19,16 @@ program
19
19
  .name('dotenv-diff')
20
20
  .description('Compare .env and .env.example files')
21
21
  .option('--check-values', 'Compare actual values if example has values')
22
+ .option('--ci', 'Run non-interactively and never create files')
23
+ .option('-y, --yes', 'Run non-interactively and answer Yes to prompts')
22
24
  .parse(process.argv);
23
25
  const options = program.opts();
24
26
  const checkValues = options.checkValues ?? false;
27
+ const isCiMode = Boolean(options.ci);
28
+ const isYesMode = Boolean(options.yes);
29
+ if (isCiMode && isYesMode) {
30
+ console.log(chalk.yellow('⚠️ Both --ci and --yes provided; proceeding with --yes.'));
31
+ }
25
32
  const cwd = process.cwd();
26
33
  const envFiles = fs
27
34
  .readdirSync(cwd)
@@ -43,17 +50,28 @@ if (envFiles.length === 0 && !exampleExists) {
43
50
  // Case 2: .env is missing but .env.example exists
44
51
  if (!envExists && exampleExists) {
45
52
  console.log(chalk.yellow('📄 .env file not found.'));
46
- const response = await prompts({
47
- type: 'select',
48
- name: 'createEnv',
49
- message: '❓ Do you want to create a new .env file from .env.example?',
50
- choices: [
51
- { title: 'Yes', value: true },
52
- { title: 'No', value: false },
53
- ],
54
- initial: 0,
55
- });
56
- if (!response.createEnv) {
53
+ let createEnv = false;
54
+ if (isYesMode) {
55
+ createEnv = true;
56
+ }
57
+ else if (isCiMode) {
58
+ console.log(chalk.gray('🚫 Skipping .env creation (CI mode).'));
59
+ process.exit(1);
60
+ }
61
+ else {
62
+ const response = await prompts({
63
+ type: 'select',
64
+ name: 'createEnv',
65
+ message: '❓ Do you want to create a new .env file from .env.example?',
66
+ choices: [
67
+ { title: 'Yes', value: true },
68
+ { title: 'No', value: false },
69
+ ],
70
+ initial: 0,
71
+ });
72
+ createEnv = Boolean(response.createEnv);
73
+ }
74
+ if (!createEnv) {
57
75
  console.log(chalk.gray('🚫 Skipping .env creation.'));
58
76
  process.exit(0);
59
77
  }
@@ -65,17 +83,28 @@ if (!envExists && exampleExists) {
65
83
  // Case 3: .env exists, but .env.example is missing
66
84
  if (envExists && !exampleExists) {
67
85
  console.log(chalk.yellow('📄 .env.example file not found.'));
68
- const response = await prompts({
69
- type: 'select',
70
- name: 'createExample',
71
- message: '❓ Do you want to create a new .env.example file from .env?',
72
- choices: [
73
- { title: 'Yes', value: true },
74
- { title: 'No', value: false },
75
- ],
76
- initial: 0,
77
- });
78
- if (!response.createExample) {
86
+ let createExample = false;
87
+ if (isYesMode) {
88
+ createExample = true;
89
+ }
90
+ else if (isCiMode) {
91
+ console.log(chalk.gray('🚫 Skipping .env.example creation (CI mode).'));
92
+ process.exit(1);
93
+ }
94
+ else {
95
+ const response = await prompts({
96
+ type: 'select',
97
+ name: 'createExample',
98
+ message: '❓ Do you want to create a new .env.example file from .env?',
99
+ choices: [
100
+ { title: 'Yes', value: true },
101
+ { title: 'No', value: false },
102
+ ],
103
+ initial: 0,
104
+ });
105
+ createExample = Boolean(response.createExample);
106
+ }
107
+ if (!createExample) {
79
108
  console.log(chalk.gray('🚫 Skipping .env.example creation.'));
80
109
  process.exit(0);
81
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotenv-diff",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "description": "A small CLI and library to find differences between .env and .env.example files.",
6
6
  "bin": {