Last active
December 29, 2015 03:39
-
-
Save CrisFavero/7609001 to your computer and use it in GitHub Desktop.
small helper script for making cloud formation JSON lines from a regular file `node convertToJSON <filename>`
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
"use strict"; | |
var fs = require('fs'); | |
var readline = require('readline'); | |
var stream = require('stream'); | |
if(!process.argv[2]){ | |
console.log("usage: convertToJSON <filename>"); | |
process.exit(1); | |
} | |
var instream = fs.createReadStream(process.argv[2]); | |
var outstream = new stream(); | |
var rl = readline.createInterface(instream, outstream); | |
var first = true; | |
rl. | |
on('line', function(line) { | |
if(first) | |
console.log('['); | |
first =false; | |
console.log('\t"' +line.replace(/"/g, '\\"').trimRight()+'\\n",'); | |
}) | |
.on('close',function(){ | |
console.log(']'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment