grunt-amberc.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module.exports = function (grunt) {
  2. var amberc = require('../lib/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. verbose: grunt.option('verbose') || false
  35. });
  36. this.data.verbose = options.verbose;
  37. // mark required properties
  38. this.requiresConfig('amberc.options.amber_dir');
  39. // raise error on missing source files
  40. if (this.filesSrc.length === 0) {
  41. grunt.fail.fatal('No source files to compile or link.');
  42. }
  43. // create and initialize amberc
  44. var compiler = new amberc.Compiler(grunt.config('amberc.options.amber_dir'));
  45. // generate the amberc configuration out of the given target properties
  46. var configuration = generateCompilerConfiguration(this.data, this.filesSrc);
  47. // run the compiler and call the async callback once finished
  48. var self = this;
  49. compiler.main(configuration, function () {
  50. // signal that task has finished
  51. done();
  52. });
  53. });
  54. function generateCompilerConfiguration(data, sourceFiles) {
  55. var configuration = amberc.createDefaultConfiguration();
  56. if (data.libraries != null) {
  57. configuration.load = data.libraries;
  58. }
  59. if (sourceFiles != null) {
  60. configuration.stFiles = sourceFiles;
  61. }
  62. if (data.amd_namespace != null) {
  63. configuration.amdNamespace = data.amd_namespace;
  64. }
  65. if (data.output_dir != null) {
  66. configuration.outputDir = data.output_dir;
  67. }
  68. if (data.jsGlobals != null) {
  69. configuration.jsGlobals.push.apply(configuration.jsGlobals, data.jsGlobals);
  70. }
  71. if (data.verbose != null) {
  72. configuration.verbose = data.verbose;
  73. }
  74. return configuration;
  75. }
  76. };