Last active
April 22, 2019 15:01
-
-
Save a0viedo/6707a836b16621263a31e7bd149bb6d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
const split2 = require('split2'); | |
let port = Number(process.env.START_PORT); | |
const list =[]; | |
process.stdin.pipe(split2()) | |
.on('data', p => list.push(p)) | |
.on('end', function() { | |
const json = JSON.stringify({ | |
ip: process.env.PUBLIC_IP, | |
list: list.reverse().map((password, index) => { | |
if(index !== 0) { | |
port = port + 2; | |
} | |
return {port, password}; | |
}) | |
}); | |
fs.writeFileSync('./config.json', json); | |
console.log('Generated config.json'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "generate-config-file.js", | |
"version": "1.0.0", | |
"description": "", | |
"bin": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"split2": "^3.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment