amberc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env node
  2. var path = require('path');
  3. var amberc = require('./amberc.js');
  4. // get parameters passed to the command line script
  5. // discard the first two parameters which are the node binary and the script name
  6. var parameters = process.argv.slice(2);
  7. // check if at least one parameter was passed to the script
  8. if (1 > parameters.length) {
  9. print_usage();
  10. process.exit();
  11. }
  12. // Get Amber root directory from the location of this script so that
  13. // we can find the st and js directories etc.
  14. var amber_dir = path.normalize(path.join(path.dirname(process.argv[1]), '..'));
  15. // Get default location of compiler.jar
  16. var closure_jar = path.resolve(path.join(process.env['HOME'], 'compiler.jar'));
  17. var compiler = new amberc.Compiler(amber_dir, closure_jar);
  18. compiler.main(parameters);
  19. // print available flags
  20. var print_usage = function() {
  21. console.log('Usage: amberc [-l lib1,lib2...] [-i init_file] [-m main_class] [-M main_file]');
  22. console.log(' [-o] [-O|-A] [-d] [-s suffix] [-S suffix] [file1 [file2 ...]] [Program]');
  23. console.log('');
  24. console.log(' amberc compiles Amber files - either separately or into a complete runnable');
  25. console.log(' program. If no .st files are listed only a linking stage is performed.');
  26. console.log(' Files listed will be handled using the following rules:');
  27. console.log('');
  28. console.log(' *.js');
  29. console.log(' Files are linked (concatenated) in listed order.');
  30. console.log(' If not found we look in $AMBER/js/');
  31. console.log('');
  32. console.log(' *.st');
  33. console.log(' Files are compiled into .js files before concatenation.');
  34. console.log(' If not found we look in $AMBER/st/.');
  35. console.log('');
  36. console.log(' NOTE: Each .st file is currently considered to be a fileout of a single class');
  37. console.log(' category of the same name as the file!');
  38. console.log('');
  39. console.log(' If no <Program> is specified each given .st file will be compiled into');
  40. console.log(' a matching .js file. Otherwise a <Program>.js file is linked together based on');
  41. console.log(' the given options:');
  42. console.log(' -l library1,library2');
  43. console.log(' Add listed JavaScript libraries in listed order.');
  44. console.log(' Libraries are not separated by spaces or end with .js.');
  45. console.log('');
  46. console.log(' -i init_file');
  47. console.log(' Add library initializer <init_file> instead of default $AMBER/js/init.js ');
  48. console.log('');
  49. console.log(' -m main_class');
  50. console.log(' Add a call to the class method main_class>>main at the end of <Program>.');
  51. console.log('');
  52. console.log(' -M main_file');
  53. console.log(' Add <main_file> at the end of <Program.js> acting as #main.');
  54. console.log('');
  55. console.log(' -o');
  56. console.log(' Optimize each .js file using the Google closure compiler.');
  57. console.log(' Using Closure compiler found at ~/compiler.jar');
  58. console.log('');
  59. console.log(' -O');
  60. console.log(' Optimize final <Program>.js using the Google closure compiler.');
  61. console.log(' Using Closure compiler found at ~/compiler.jar');
  62. console.log('');
  63. console.log(' -A Same as -O but use --compilation_level ADVANCED_OPTIMIZATIONS');
  64. console.log('');
  65. console.log(' -d');
  66. console.log(' Additionally export code for deploy - stripped from source etc.');
  67. console.log(' Uses suffix ".deploy.js" in addition to any explicit suffic set by -s.');
  68. console.log('');
  69. console.log(' -s suffix');
  70. console.log(' Add <suffix> to compiled .js files. File.st is then compiled into');
  71. console.log(' File.<suffix>.js.');
  72. console.log('');
  73. console.log(' -S suffix');
  74. console.log(' Use <suffix> for all libraries accessed using -l. This makes it possible');
  75. console.log(' to have multiple flavors of Amber and libraries in the same place.');
  76. console.log('');
  77. console.log('');
  78. console.log(' Example invocations:');
  79. console.log('');
  80. console.log(' Just compile Kernel-Objects.st to Kernel-Objects.js:');
  81. console.log('');
  82. console.log(' amberc Kernel-Objects.st');
  83. console.log('');
  84. console.log(' Compile Hello.st to Hello.js and create complete program called Program.js.');
  85. console.log(' Additionally add a call to the class method Hello>>main:');
  86. console.log('');
  87. console.log(' amberc -m Hello Hello.st Program');
  88. console.log('');
  89. console.log(' Compile Cat1.st and Cat2.st files into corresponding .js files.');
  90. console.log(' Link them with myboot.js and myKernel.js and add myinit.js as custom');
  91. console.log(' initializer file. Add main.js last which contains the startup code');
  92. console.log(' and merge everything into a complete program named Program.js:');
  93. console.log('');
  94. console.log(' amberc -M main.js -i myinit.js myboot.js myKernel.js Cat1.st Cat2.st Program');
  95. };