2
0

grunt-amberc.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. module.exports = function (grunt) {
  2. var amberc = require('..').amberc;
  3. /**
  4. A full example entry for a Gruntfile.js is available below.
  5. Please note that the verbose level is either specified globally
  6. or on a target specific level.
  7. However, it can additionally be triggered on the commandline by
  8. adding the '-v' or '--verbose' flag.
  9. Example Gruntfile.js entry:
  10. amberc: {
  11. options: {
  12. amber_dir: process.cwd(), // REQUIRED
  13. verbose: true // optional
  14. },
  15. helloWorld: {
  16. // this 'options' object is optional as well as all parameters inside it
  17. // they can be used to override the global 'options'
  18. options: {
  19. verbose: true
  20. },
  21. src: ['projects/HelloWorld/src/HelloWorld.st'], // REQUIRED
  22. output_dir: 'projects/HelloWorld/src', // optional
  23. libraries: 'Web', // optional
  24. jsGlobals: ['global1', 'global2'], // optional
  25. amd_namespace: 'MyNamespace', // optional (default: 'amber')
  26. },
  27. },
  28. */
  29. grunt.registerMultiTask('amberc', 'Compile Smalltalk files with the amberc compiler', function () {
  30. // mark task as async task
  31. var done = this.async();
  32. var options = this.options({
  33. amber_dir: undefined,
  34. configFile: null,
  35. paths: {},
  36. verbose: grunt.option('verbose') || false
  37. });
  38. this.data.verbose = options.verbose;
  39. this.data.configFile = options.configFile;
  40. this.data.paths = options.paths;
  41. // mark required properties
  42. this.requiresConfig('amberc.options.amber_dir');
  43. // raise error on missing source files
  44. if (this.filesSrc.length === 0) {
  45. grunt.fail.fatal('No source files to compile or link.');
  46. }
  47. // create and initialize amberc
  48. var compiler = new amberc.Compiler(grunt.config('amberc.options.amber_dir'));
  49. // generate the amberc configuration out of the given target properties
  50. var configuration = generateCompilerConfiguration(this.data, this.filesSrc);
  51. // run the compiler and call the async callback once finished
  52. var self = this;
  53. compiler.main(configuration, function () {
  54. // signal that task has finished
  55. done();
  56. });
  57. });
  58. function generateCompilerConfiguration(data, sourceFiles) {
  59. var configuration = amberc.createDefaultConfiguration();
  60. if (data.libraries != null) {
  61. configuration.load = data.libraries;
  62. }
  63. if (data.configFile != null) {
  64. configuration.configFile = data.configFile;
  65. }
  66. if (data.paths != null) {
  67. configuration.paths = data.paths;
  68. }
  69. if (sourceFiles != null) {
  70. configuration.stFiles = sourceFiles;
  71. }
  72. if (data.amd_namespace != null) {
  73. configuration.amdNamespace = data.amd_namespace;
  74. }
  75. if (data.output_dir != null) {
  76. configuration.outputDir = data.output_dir;
  77. }
  78. if (data.jsGlobals != null) {
  79. configuration.jsGlobals.push.apply(configuration.jsGlobals, data.jsGlobals);
  80. }
  81. if (data.verbose != null) {
  82. configuration.verbose = data.verbose;
  83. }
  84. return configuration;
  85. }
  86. };