nodecompile.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // NOTE: This code is called using the amberc 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 also produce deploy files: "true" or "false"
  9. var deploy = (process.argv[2] == "true");
  10. // Second argument is suffix: "no-silly-suffix" means none
  11. suffix = process.argv[3];
  12. if (suffix == "no-silly-suffix") {
  13. suffix = "";
  14. }
  15. // If it ends with .st, import it, otherwise export category as .js
  16. arguments.forEach(function(val, index, array) {
  17. if (/\.st/.test(val)) {
  18. sys.puts("Reading file " + val);
  19. code = fs.readFileSync(val, "utf8");
  20. smalltalk.Importer._new()._import_(code._stream());
  21. } else {
  22. sys.puts("Exporting " + (deploy ? "(debug + deploy)" : "(debug)") + " category "
  23. + val + " as " + val + suffix + ".js" + (deploy ? " and " + val + suffix + ".deploy.js" : ""));
  24. fs.writeFileSync(val + suffix + ".js", smalltalk.Exporter._new()._exportPackage_(val));
  25. if (deploy) {
  26. fs.writeFileSync(val + suffix + ".deploy.js", smalltalk.StrippedExporter._new()._exportPackage_(val));
  27. }
  28. }
  29. });