Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const path = require('path');
- const fs = require('fs');
- const argv = process.argv.slice(2);
- let [filename, prefix = ''] = argv;
- if (prefix) {
- prefix = `${prefix}_`;
- }
- const jsonPath = path.resolve(__dirname, filename);
- const outputPath = '.env_generated';
- const credsObj = require(jsonPath);
- let objString = '{';
- const envGetter = envKey => `process.env["${envKey}"]`;
- const envFile = Object.keys(credsObj).map(k => {
- const envKey = `${prefix}${k.toUpperCase()}`;
- objString += `\n\t"${k}": ${envGetter(envKey)},`;
- const credsObj2 = credsObj[k];
- const envValue = `"${credsObj2.replace(/\r?\n/g, '\\n')}"`;
- return `${envKey}=${envValue}`;
- }).join('\n');
- objString += '\n}';
- fs.writeFileSync(outputPath, envFile);
- const cp = require('child_process');
- const clip = cp.exec('pbcopy', (_err, _stdout, _stderr) => {/* optionally do something */});
- clip.stdin.write(objString);
- clip.stdin.end(() => process.stdout.write(`\rCopied ${objString.length} characters.\n`));
Add Comment
Please, Sign In to add comment