secure-env-ts
Advanced tools
Comparing version 1.2.5 to 1.2.6
112
dist/cli.js
@@ -57,2 +57,8 @@ #! /usr/bin/env node | ||
const path = `./${file}`; | ||
const clean = () => 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); | ||
fs_1.default.writeFileSync(path, decrypted); | ||
@@ -63,3 +69,3 @@ console.log(colors_1.default.bold.white('Opening your text editor...')); | ||
const vim = (0, command_exists_1.sync)('vim') ? 'vim' : null; | ||
const usersEditor = process.env.EDITOR || nano || code || vim || 'vi'; | ||
const usersEditor = "code" || process.env.EDITOR || nano || code || vim || 'vi'; | ||
const childProcess = (0, child_process_1.spawn)(usersEditor, [file], { | ||
@@ -69,3 +75,58 @@ stdio: 'inherit', | ||
}); | ||
childProcess.on('data', () => process.exit()); | ||
let saved = false; | ||
const diffAndSave = () => { | ||
if (saved) { | ||
return; | ||
} | ||
saved = true; | ||
const newEnvVars = fs_1.default.readFileSync(path); | ||
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); | ||
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(() => { | ||
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'); | ||
process.exit(0); | ||
}); | ||
} | ||
else { | ||
abort(); | ||
} | ||
}); | ||
}; | ||
if (!code) { | ||
childProcess.on('exit', diffAndSave); | ||
} | ||
else { | ||
const watcher = fs_1.default.watch(path, (evenType) => { | ||
if (evenType === "change") { | ||
console.log(colors_1.default.bold.white(`File saved!`)); | ||
diffAndSave(); | ||
watcher.close(); | ||
} | ||
}); | ||
} | ||
const abort = () => { | ||
@@ -78,49 +139,2 @@ fs_1.default.unlinkSync(path); | ||
}; | ||
let saved = false; | ||
fs_1.default.watch(path, (evenType) => { | ||
console.log(evenType); | ||
if (evenType === "change") { | ||
if (saved) { | ||
return; | ||
} | ||
saved = true; | ||
const newEnvVars = fs_1.default.readFileSync(path); | ||
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); | ||
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(() => { | ||
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'); | ||
process.exit(0); | ||
}); | ||
} | ||
else { | ||
abort(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -127,0 +141,0 @@ else { |
{ | ||
"name": "secure-env-ts", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "Use ENVs securely with encryption", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
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
30439
431