-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·35 lines (31 loc) · 973 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
'use strict'
const fs = require("fs")
const prompt = require('prompt');
const addToken = (token) => {
if(process.argv.indexOf('--yes'.toLowerCase()) !== -1 || process.argv.indexOf('-y'.toLowerCase()) !== -1){
fs.appendFile('.env', `SECRET=${token}\n`, 'utf8');
}
else {
let schema = {
properties: {
filename: {
description: 'Enter the name of the file you would like to write the secret to \n Default is .env',
default: '.env'
},
key: {
description: 'Enter the name of the key you would like\n Default is SECRET',
default: 'SECRET'
}
}
};
prompt.get(schema, function (err, result) {
fs.appendFile(result.filename, `${result.key}=${token}\n`, 'utf8');
})
}
}
require('crypto').randomBytes(48, function(err, buffer) {
if(err) console.log("Something went wrong: ", err)
const token = buffer.toString('hex');
addToken(token);
});