secure-env-ts
Advanced tools
Comparing version 1.2.9 to 1.3.0
113
dist/cli.js
@@ -33,2 +33,3 @@ #! /usr/bin/env node | ||
const minimist_1 = __importDefault(require("minimist")); | ||
const colorette_1 = require("colorette"); | ||
const cryptography_1 = require("./cryptography"); | ||
@@ -39,3 +40,2 @@ const log_1 = __importStar(require("./utils/log")); | ||
const diff = __importStar(require("diff")); | ||
const colors_1 = __importDefault(require("colors")); | ||
const inquirer_1 = __importDefault(require("inquirer")); | ||
@@ -53,25 +53,30 @@ const command_exists_1 = require("command-exists"); | ||
else if (argv.edit || argv.e) { | ||
const decrypted = (0, cryptography_1.decrypt)({ secret, inputFile, outputFile, decryptionAlgo: encryptionAlgo }); | ||
const decrypted = (0, cryptography_1.decrypt)({ | ||
secret, | ||
inputFile, | ||
outputFile, | ||
decryptionAlgo: encryptionAlgo, | ||
}); | ||
if (!decrypted) { | ||
process.exit(1); | ||
} | ||
const file = '.env.temp'; | ||
const file = ".env.temp"; | ||
const path = `./${file}`; | ||
const clean = () => fs_1.default.existsSync(path) && fs_1.default.unlinkSync(path); | ||
process.on('exit', clean); | ||
process.on('SIGINT', clean); | ||
process.on('SIGUSR1', clean); | ||
process.on('SIGUSR2', clean); | ||
process.on('uncaughtException', clean); | ||
process.on("exit", clean); | ||
process.on("SIGINT", clean); | ||
process.on("SIGUSR1", clean); | ||
process.on("SIGUSR2", clean); | ||
process.on("uncaughtException", clean); | ||
fs_1.default.writeFileSync(path, decrypted); | ||
console.log(colors_1.default.bold.white('Opening your text editor...')); | ||
const code = (0, command_exists_1.sync)('code') ? 'code' : null; | ||
const nano = (0, command_exists_1.sync)('nano') ? 'nano' : null; | ||
const atom = (0, command_exists_1.sync)('atom') ? 'atom' : null; | ||
const sublime = (0, command_exists_1.sync)('subl') ? 'subl' : null; | ||
const vim = (0, command_exists_1.sync)('vim') ? 'vim' : null; | ||
const usersEditor = process.env.EDITOR || nano || code || sublime || atom || vim || 'vi'; | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)("Opening your text editor..."))); | ||
const code = (0, command_exists_1.sync)("code") ? "code" : null; | ||
const nano = (0, command_exists_1.sync)("nano") ? "nano" : null; | ||
const atom = (0, command_exists_1.sync)("atom") ? "atom" : null; | ||
const sublime = (0, command_exists_1.sync)("subl") ? "subl" : null; | ||
const vim = (0, command_exists_1.sync)("vim") ? "vim" : null; | ||
const usersEditor = process.env.EDITOR || nano || code || sublime || atom || vim || "vi"; | ||
const childProcess = (0, child_process_1.spawn)(usersEditor, [file], { | ||
stdio: 'inherit', | ||
detached: true | ||
stdio: "inherit", | ||
detached: true, | ||
}); | ||
@@ -86,30 +91,44 @@ let saved = false; | ||
const envVarsDiff = diff.diffLines(decrypted, newEnvVars.toString()); | ||
const removed = (envVarsDiff.filter(line => line.removed))?.map((line) => line.value); | ||
const added = (envVarsDiff.filter(line => line.added))?.map((line) => line.value); | ||
const removed = envVarsDiff | ||
.filter((line) => line.removed) | ||
?.map((line) => line.value); | ||
const added = envVarsDiff | ||
.filter((line) => line.added) | ||
?.map((line) => line.value); | ||
if (!removed.length && !added.length) { | ||
abort(); | ||
} | ||
console.log(colors_1.default.bold.white('Your changes:')); | ||
console.log('\n'); | ||
console.log(colors_1.default.bold.underline.red('Removed:')); | ||
console.log('\n'); | ||
console.log(colors_1.default.red(removed.join('\n'))); | ||
console.log('\n'); | ||
console.log(colors_1.default.bold.underline.green('Added:')); | ||
console.log('\n'); | ||
console.log(colors_1.default.green(added.join('\n'))); | ||
console.log('\n'); | ||
inquirer_1.default.prompt([{ | ||
name: 'continue', | ||
type: 'string', | ||
message: 'Encrypt? Yes/ No', | ||
}]).then((answers) => { | ||
if (['yes', 'y'].includes(answers.continue.toLowerCase())) { | ||
(0, cryptography_1.encrypt)({ secret, inputFile: file, outputFile: inputFile, encryptionAlgo, isEdit: true })?.then(() => { | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)("Your changes:"))); | ||
console.log("\n"); | ||
console.log((0, colorette_1.bold)((0, colorette_1.underline)((0, colorette_1.red)("Removed:")))); | ||
console.log("\n"); | ||
console.log((0, colorette_1.red)(removed.join("\n"))); | ||
console.log("\n"); | ||
console.log((0, colorette_1.bold)((0, colorette_1.underline)((0, colorette_1.green)("Added:")))); | ||
console.log("\n"); | ||
console.log((0, colorette_1.green)(added.join("\n"))); | ||
console.log("\n"); | ||
inquirer_1.default | ||
.prompt([ | ||
{ | ||
name: "continue", | ||
type: "string", | ||
message: "Encrypt? Yes/ No", | ||
}, | ||
]) | ||
.then((answers) => { | ||
if (["yes", "y"].includes(answers.continue.toLowerCase())) { | ||
(0, cryptography_1.encrypt)({ | ||
secret, | ||
inputFile: file, | ||
outputFile: inputFile, | ||
encryptionAlgo, | ||
isEdit: true, | ||
})?.then(() => { | ||
fs_1.default.unlinkSync(path); | ||
console.log('\n'); | ||
console.log(colors_1.default.bold.white(`All done!`)); | ||
console.log(colors_1.default.bold.white(`The Environment file "${inputFile}" has been edited.`)); | ||
console.log(colors_1.default.bold.white(`Don't forget to push and commit "${inputFile}"".`)); | ||
console.log('\n'); | ||
console.log("\n"); | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)(`All done!`))); | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)(`The Environment file "${inputFile}" has been edited.`))); | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)(`Don't forget to push and commit "${inputFile}"".`))); | ||
console.log("\n"); | ||
process.exit(0); | ||
@@ -123,4 +142,4 @@ }); | ||
}; | ||
if (usersEditor !== 'code') { | ||
childProcess.on('exit', diffAndSave); | ||
if (usersEditor !== "code") { | ||
childProcess.on("exit", diffAndSave); | ||
} | ||
@@ -130,3 +149,3 @@ else { | ||
if (evenType === "change") { | ||
console.log(colors_1.default.bold.white(`File saved!`)); | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)(`File saved!`))); | ||
diffAndSave(); | ||
@@ -139,5 +158,5 @@ watcher.close(); | ||
fs_1.default.unlinkSync(path); | ||
console.log('\n'); | ||
console.log(colors_1.default.bold.white(`Aborted no changes made.`)); | ||
console.log('\n'); | ||
console.log("\n"); | ||
console.log((0, colorette_1.bold)((0, colorette_1.white)(`Aborted no changes made.`))); | ||
console.log("\n"); | ||
process.exit(0); | ||
@@ -144,0 +163,0 @@ }; |
{ | ||
"name": "secure-env-ts", | ||
"version": "1.2.9", | ||
"version": "1.3.0", | ||
"description": "Use ENVs securely with encryption", | ||
@@ -49,2 +49,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"colorette": "^2.0.16", | ||
"colors": "^1.4.0", | ||
@@ -51,0 +52,0 @@ "command-exists": "^1.2.9", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31110
452
6
+ Addedcolorette@^2.0.16
+ Addedcolorette@2.0.20(transitive)