Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. var fs = require("fs");
  2.  
  3. if (process.argv.length != 3){
  4. throw "Needs to have a file to process";
  5. }
  6.  
  7. var inputFileName = process.argv[2];
  8. var outputFileName;
  9. var input = fs.readFileSync(inputFileName);
  10.  
  11. function stripComments(comjson){
  12. var jsopen = "var tmp__object = ";
  13. var jsmiddle = comjson;
  14. var semicolon = ";"
  15. var jsfull = jsopen + jsmiddle + semicolon;
  16. eval(jsfull);
  17. return JSON.stringify(tmp__object);
  18. }
  19.  
  20. function createOutputFileName(inFile){
  21. if(inFile.slice(-6) != ".comjs"){
  22. throw "File has invalid extension, must be '.comjs'";
  23. } else {
  24. return inFile.slice(0,-6) + ".json";
  25. }
  26. }
  27.  
  28. outputFileName = createOutputFileName(inputFileName);
  29. fs.writeFileSync(outputFileName, stripComments(input));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement