Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require("fs");
- if (process.argv.length != 3){
- throw "Needs to have a file to process";
- }
- var inputFileName = process.argv[2];
- var outputFileName;
- var input = fs.readFileSync(inputFileName);
- function stripComments(comjson){
- var jsopen = "var tmp__object = ";
- var jsmiddle = comjson;
- var semicolon = ";"
- var jsfull = jsopen + jsmiddle + semicolon;
- eval(jsfull);
- return JSON.stringify(tmp__object);
- }
- function createOutputFileName(inFile){
- if(inFile.slice(-6) != ".comjs"){
- throw "File has invalid extension, must be '.comjs'";
- } else {
- return inFile.slice(0,-6) + ".json";
- }
- }
- outputFileName = createOutputFileName(inputFileName);
- fs.writeFileSync(outputFileName, stripComments(input));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement