Explorar el Código

save compiler output to file

Vladislav Folts hace 11 años
padre
commit
5880c12f8c
Se han modificado 2 ficheros con 16 adiciones y 4 borrados
  1. 2 2
      test/compile.cmd
  2. 14 2
      test/compile.js

+ 2 - 2
test/compile.cmd

@@ -1,2 +1,2 @@
-SET NODE_PATH=.;%~dp0../src
-"C:\Program Files\nodejs\node.exe" compile.js %*
+@SET NODE_PATH=.;%~dp0../src
+@"C:\Program Files\nodejs\node.exe" compile.js %*

+ 14 - 2
test/compile.js

@@ -2,15 +2,27 @@
 
 var oc = require("oc");
 var fs = require("fs");
+var path = require("path");
 
 function compile(src){
     var text = fs.readFileSync(src, "utf8");
     var errors = "";
     var result = oc.compile(text, function(e){errors += "File \"" + src + "\", " + e;});
-    if (errors)
+    if (errors){
         console.info(errors);
-    else
+        return;
+    }
+
+    var fileName = path.basename(src);
+    if (path.extname(fileName) != ".ob"){
         console.info(result);
+        return;
+    }
+
+    fileName = fileName.substr(0, fileName.length - ".ob".length) + ".js";
+    fs.writeFileSync(fileName, result);
+    console.info("compiled to '" + fileName + "' - OK!");
+
 }
 
 function main(){