@dotenvx/dotenvx 0.9.0 → 0.10.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.
- package/LICENSE +28 -0
- package/README.md +26 -0
- package/package.json +3 -2
- package/src/cli/actions/encrypt.js +3 -0
- package/src/cli/actions/precommit.js +55 -0
- package/src/cli/actions/run.js +3 -0
- package/src/cli/dotenvx.js +6 -3
- package/src/cli/examples.js +12 -1
- package/src/shared/createSpinner.js +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Scott Motte
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -426,6 +426,32 @@ More examples
|
|
|
426
426
|
* [dotenvx/docs](https://dotenvx.com/docs)
|
|
427
427
|
* [quickstart guide](https://dotenvx.com/docs/quickstart)
|
|
428
428
|
|
|
429
|
+
## Pre-commit
|
|
430
|
+
|
|
431
|
+
You can prevent `.env` files from being committed to code with this pre-commit hook.
|
|
432
|
+
|
|
433
|
+
Place this in `.git/hooks/pre-commit`
|
|
434
|
+
|
|
435
|
+
```
|
|
436
|
+
#!/bin/sh
|
|
437
|
+
dotenvx precommit --quiet
|
|
438
|
+
|
|
439
|
+
# Check dotenvx precommit exit status
|
|
440
|
+
if [ $? -ne 0 ]; then
|
|
441
|
+
echo "dotenvx pre-commit failed. run [dotenvx precommit] for more information"
|
|
442
|
+
exit 1
|
|
443
|
+
fi
|
|
444
|
+
exit 0
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
Make sure to make it executable.
|
|
448
|
+
|
|
449
|
+
```
|
|
450
|
+
chmod +x .git/hooks/pre-commit
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
You can simulate the pre-commit hook by running `dotenvx precommit` locally.
|
|
454
|
+
|
|
429
455
|
## Contributing
|
|
430
456
|
|
|
431
457
|
You can fork this repo and create [pull requests](https://github.com/dotenvx/dotenvx/pulls) or if you have questions or feedback:
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.10.0",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a better dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"commander": "^11.1.0",
|
|
32
32
|
"conf": "^10.2.0",
|
|
33
33
|
"dotenv": "^16.3.1",
|
|
34
|
+
"execa": "^5.1.1",
|
|
35
|
+
"ignore": "^5.3.0",
|
|
34
36
|
"open": "^8.4.2",
|
|
35
37
|
"ora": "^5.4.1",
|
|
36
38
|
"qrcode-terminal": "^0.12.0",
|
|
37
39
|
"update-notifier": "^5.1.0",
|
|
38
|
-
"execa": "^5.1.1",
|
|
39
40
|
"winston": "^3.11.0",
|
|
40
41
|
"xxhashjs": "^0.2.2"
|
|
41
42
|
},
|
|
@@ -4,6 +4,7 @@ const main = require('./../../lib/main')
|
|
|
4
4
|
const logger = require('./../../shared/logger')
|
|
5
5
|
const helpers = require('./../helpers')
|
|
6
6
|
const createSpinner = require('./../../shared/createSpinner')
|
|
7
|
+
const { AppendToIgnores } = require('./../ignores')
|
|
7
8
|
|
|
8
9
|
const spinner = createSpinner('encrypting')
|
|
9
10
|
|
|
@@ -11,6 +12,8 @@ const spinner = createSpinner('encrypting')
|
|
|
11
12
|
const ENCODING = 'utf8'
|
|
12
13
|
|
|
13
14
|
async function encrypt () {
|
|
15
|
+
new AppendToIgnores().run()
|
|
16
|
+
|
|
14
17
|
spinner.start()
|
|
15
18
|
await helpers.sleep(500) // better dx
|
|
16
19
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
const ignore = require('ignore')
|
|
4
|
+
|
|
5
|
+
const logger = require('./../../shared/logger')
|
|
6
|
+
|
|
7
|
+
function precommit () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
10
|
+
|
|
11
|
+
// 1. check for .gitignore file
|
|
12
|
+
if (!fs.existsSync('.gitignore')) {
|
|
13
|
+
logger.error('.gitignore missing')
|
|
14
|
+
logger.help('? add it with [touch .gitignore]')
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ig = ignore().add(fs.readFileSync('.gitignore').toString())
|
|
19
|
+
const files = fs.readdirSync(process.cwd())
|
|
20
|
+
const dotenvFiles = files.filter(file => file.match(/^\.env(\..+)?$/))
|
|
21
|
+
dotenvFiles.forEach(file => {
|
|
22
|
+
// check if that file is being ignored
|
|
23
|
+
if (ig.ignores(file)) {
|
|
24
|
+
switch (file) {
|
|
25
|
+
case '.env.example':
|
|
26
|
+
logger.warn(`${file} (currently ignored but should not be)`)
|
|
27
|
+
logger.help(`? add !${file} to .gitignore with [echo "!${file}" >> .gitignore]`)
|
|
28
|
+
break
|
|
29
|
+
case '.env.vault':
|
|
30
|
+
logger.warn(`${file} (currently ignored but should not be)`)
|
|
31
|
+
logger.help(`? add !${file} to .gitignore with [echo "!${file}" >> .gitignore]`)
|
|
32
|
+
break
|
|
33
|
+
default:
|
|
34
|
+
logger.success(file)
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
switch (file) {
|
|
39
|
+
case '.env.example':
|
|
40
|
+
logger.success('.env.example') // should not be ignored
|
|
41
|
+
break
|
|
42
|
+
case '.env.vault':
|
|
43
|
+
logger.success('.env.vault') // should not be ignored
|
|
44
|
+
break
|
|
45
|
+
default:
|
|
46
|
+
logger.error(`${file} not properly gitignored`)
|
|
47
|
+
logger.help(`? add ${file} to .gitignore with [echo ".env*" >> .gitignore]`)
|
|
48
|
+
process.exit(1)
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = precommit
|
package/src/cli/actions/run.js
CHANGED
|
@@ -2,10 +2,13 @@ const fs = require('fs')
|
|
|
2
2
|
const logger = require('./../../shared/logger')
|
|
3
3
|
const helpers = require('./../helpers')
|
|
4
4
|
const main = require('./../../lib/main')
|
|
5
|
+
const { AppendToIgnores } = require('./../ignores')
|
|
5
6
|
|
|
6
7
|
const ENCODING = 'utf8'
|
|
7
8
|
|
|
8
9
|
async function run () {
|
|
10
|
+
new AppendToIgnores().run()
|
|
11
|
+
|
|
9
12
|
const commandArgs = this.args
|
|
10
13
|
logger.debug(`process command [${commandArgs.join(' ')}]`)
|
|
11
14
|
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -7,7 +7,6 @@ const program = new Command()
|
|
|
7
7
|
const logger = require('./../shared/logger')
|
|
8
8
|
const helpers = require('./helpers')
|
|
9
9
|
const examples = require('./examples')
|
|
10
|
-
const { AppendToIgnores } = require('./ignores')
|
|
11
10
|
const packageJson = require('./../shared/packageJson')
|
|
12
11
|
|
|
13
12
|
// once a day check for any updates
|
|
@@ -23,8 +22,6 @@ program
|
|
|
23
22
|
.option('-v, --verbose', 'sets log level to verbose')
|
|
24
23
|
.option('-d, --debug', 'sets log level to debug')
|
|
25
24
|
.hook('preAction', (thisCommand, actionCommand) => {
|
|
26
|
-
new AppendToIgnores().run()
|
|
27
|
-
|
|
28
25
|
const options = thisCommand.opts()
|
|
29
26
|
|
|
30
27
|
if (options.logLevel) {
|
|
@@ -69,6 +66,12 @@ program.command('encrypt')
|
|
|
69
66
|
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', helpers.findEnvFiles('./'))
|
|
70
67
|
.action(require('./actions/encrypt'))
|
|
71
68
|
|
|
69
|
+
// dotenvx precommit
|
|
70
|
+
program.command('precommit')
|
|
71
|
+
.description('dotenvx precommit check')
|
|
72
|
+
.addHelpText('after', examples.precommit)
|
|
73
|
+
.action(require('./actions/precommit'))
|
|
74
|
+
|
|
72
75
|
// dotenvx hub
|
|
73
76
|
program.addCommand(require('./commands/hub'))
|
|
74
77
|
|
package/src/cli/examples.js
CHANGED
|
@@ -7,6 +7,8 @@ const createSpinner = function (initialMessage = '') {
|
|
|
7
7
|
return {
|
|
8
8
|
start: (message) => spinner.start(message),
|
|
9
9
|
succeed: (message) => spinner.succeed(chalk.keyword('green')(message)),
|
|
10
|
+
warn: (message) => spinner.warn(chalk.keyword('orangered')(message)),
|
|
11
|
+
info: (message) => spinner.info(chalk.keyword('blue')(message)),
|
|
10
12
|
done: (message) => spinner.succeed(message),
|
|
11
13
|
fail: (message) => spinner.fail(chalk.bold.red(message))
|
|
12
14
|
}
|