Guest User

Untitled

a guest
Feb 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. 'use strict';
  2. const path = require('path');
  3. const fs = require('fs');
  4.  
  5. const argv = process.argv.slice(2);
  6. let [filename, prefix = ''] = argv;
  7.  
  8. if (prefix) {
  9. prefix = `${prefix}_`;
  10. }
  11.  
  12. const jsonPath = path.resolve(__dirname, filename);
  13. const outputPath = '.env_generated';
  14.  
  15. const credsObj = require(jsonPath);
  16.  
  17. let objString = '{';
  18.  
  19. const envGetter = envKey => `process.env["${envKey}"]`;
  20.  
  21. const envFile = Object.keys(credsObj).map(k => {
  22.  
  23. const envKey = `${prefix}${k.toUpperCase()}`;
  24.  
  25. objString += `\n\t"${k}": ${envGetter(envKey)},`;
  26.  
  27. const credsObj2 = credsObj[k];
  28. const envValue = `"${credsObj2.replace(/\r?\n/g, '\\n')}"`;
  29.  
  30. return `${envKey}=${envValue}`;
  31. }).join('\n');
  32.  
  33. objString += '\n}';
  34.  
  35. fs.writeFileSync(outputPath, envFile);
  36.  
  37. const cp = require('child_process');
  38. const clip = cp.exec('pbcopy', (_err, _stdout, _stderr) => {/* optionally do something */});
  39. clip.stdin.write(objString);
  40. clip.stdin.end(() => process.stdout.write(`\rCopied ${objString.length} characters.\n`));
Add Comment
Please, Sign In to add comment