1
0

amberc-grunt.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module.exports = function(grunt) {
  2. var path = require('path');
  3. var amberc = require('../../bin/amberc.js');
  4. /**
  5. Full config looks like this:
  6. amberc: {
  7. _config: {
  8. amber_dir: process.cwd(), // REQUIRED
  9. closure_jar: '' // optional
  10. },
  11. helloWorld: {
  12. src: ['HelloWorld.st'], // REQUIRED
  13. working_dir: 'projects/HelloWorld', // optional
  14. main_class: 'HelloWorld', // optional
  15. output_name: 'helloWorld', // optional
  16. libraries: 'Canvas', // optional
  17. init: 'myInit', // optional
  18. main_file: 'myMain.js', // optional
  19. deploy: true, // optional
  20. output_suffix: 'mySuffix', // optional
  21. library_suffix: '-0.9', // optional
  22. },
  23. },
  24. */
  25. grunt.registerMultiTask('amberc', 'Compile Smalltalk files with the amberc compiler', function() {
  26. // mark required properties
  27. this.requiresConfig('amberc._config.amber_dir');
  28. this.requiresConfig(['amberc', this.target, 'src']);
  29. // change working directory if the working_dir property is set on the target
  30. var current_dir = process.cwd();
  31. var working_dir = this.data.working_dir;
  32. if (undefined !== working_dir) {
  33. grunt.file.setBase(working_dir);
  34. }
  35. // mark task as async task
  36. var done = this.async();
  37. // create and initialize amberc
  38. var compiler = new amberc.Compiler(grunt.config('amberc._config.amber_dir'), grunt.config('amberc._config.closure_jar'));
  39. // generate the amberc parameter string out of the given target properties
  40. var parameters = generateParameterArray(this.data);
  41. // run the compiler
  42. // change back to the old working directory and call the async callback once finished
  43. compiler.main(parameters, function(){
  44. grunt.file.setBase(current_dir);
  45. done();
  46. });
  47. });
  48. function generateParameterArray(data) {
  49. var parameters = [];
  50. var libraries = data.libraries;
  51. if (undefined !== libraries) {
  52. parameters.push('-l');
  53. parameters.push(libraries.join(','));
  54. }
  55. var initFile = data.init;
  56. if (undefined !== initFile) {
  57. parameters.push('-i');
  58. parameters.push(initFile);
  59. }
  60. var mainClass = data.main_class;
  61. if (undefined !== mainClass) {
  62. parameters.push('-m');
  63. parameters.push(mainClass);
  64. }
  65. var mainFile = data.main_file;
  66. if (undefined !== initFile) {
  67. parameters.push('-M');
  68. parameters.push(mainFile);
  69. }
  70. if (true === data.deploy) {
  71. parameters.push('-d');
  72. }
  73. var outputSuffix = data.output_suffix;
  74. if (undefined !== outputSuffix) {
  75. parameters.push('-s');
  76. parameters.push(outputSuffix);
  77. }
  78. var librarySuffix = data.library_suffix;
  79. if (undefined !== librarySuffix) {
  80. parameters.push('-S');
  81. parameters.push(librarySuffix);
  82. }
  83. var sourceFiles = data.src;
  84. if (undefined !== sourceFiles) {
  85. parameters.push.apply(parameters, sourceFiles);
  86. }
  87. var outpuName = data.output_name;
  88. if (undefined !== outpuName) {
  89. parameters.push(outpuName);
  90. }
  91. return parameters;
  92. }
  93. };