nodecompile.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // NOTE: This code is called using the jtalkc bash script - do not use directly.
  2. // The arguments variable is a series of .st filenames and category names.
  3. // If it is a .st file we import it, if it is a category name we export it
  4. // as aCategoryName.js.
  5. var sys = require('sys'), fs = require('fs');
  6. // Only care about our arguments, strip away node, all.js and debug flag.
  7. var arguments = process.argv.splice(4);
  8. // First argument is debugMode: "true" or "false"
  9. if (process.argv[2] == "true") {
  10. smalltalk.debugMode = true;
  11. } else {
  12. smalltalk.debugMode = false;
  13. }
  14. // Second argument is prefix: "no-silly-prefix" means none
  15. prefix = process.argv[3];
  16. if (prefix == "no-silly-prefix") {
  17. prefix = "";
  18. }
  19. console.log("Compiling in debugMode: " + smalltalk.debugMode);
  20. // If it ends with .st, import it, otherwise export category as .js
  21. arguments.forEach(function(val, index, array) {
  22. if (/\.st/.test(val)) {
  23. sys.puts("Reading file " + val);
  24. code = fs.readFileSync(val, "utf8");
  25. smalltalk.Importer._new()._import_(code._stream());
  26. } else {
  27. sys.puts("Exporting category " + val + " as " + prefix + val + ".js");
  28. fs.writeFileSync(prefix + val + ".js", smalltalk.Exporter._new()._exportCategory_(val));
  29. }
  30. });