Guest User

Untitled

a guest
Jan 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/env node
  2.  
  3. const { promisify } = require('util');
  4. /* eslint-disable import/no-extraneous-dependencies */
  5. const glob = promisify(require('glob'));
  6. /* eslint-enable */
  7.  
  8. const cryptFile = require('../util/cryptFile');
  9.  
  10. const handler = async (command, secret, ...filePathArgs) => {
  11. const files = (await Promise.all(
  12. filePathArgs.map(pattern => glob(pattern)),
  13. )).reduce((acc, paths) => [...acc, ...paths], []);
  14.  
  15. const results = await cryptFile({
  16. command,
  17. secret,
  18. files,
  19. });
  20.  
  21. results.forEach(({ error, path }) => {
  22. if (error) { console.log(error, path); }
  23. });
  24.  
  25. console.log('Completed', command === 'encrypt' ? 'encrypting' : 'decrypting', 'files');
  26. };
  27.  
  28. handler(...process.argv.slice(2));
Add Comment
Please, Sign In to add comment