2
0

grunt-amberc.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 (err) {
  54. done(err || true);
  55. });
  56. });
  57. function generateCompilerConfiguration(data, sourceFiles) {
  58. var configuration = amberc.createDefaultConfiguration();
  59. if (data.libraries != null) {
  60. configuration.load = data.libraries;
  61. }
  62. if (data.configFile != null) {
  63. configuration.configFile = data.configFile;
  64. }
  65. if (data.paths != null) {
  66. configuration.paths = data.paths;
  67. }
  68. if (sourceFiles != null) {
  69. configuration.stFiles = sourceFiles;
  70. }
  71. if (data.amd_namespace != null) {
  72. configuration.amdNamespace = data.amd_namespace;
  73. }
  74. if (data.output_dir != null) {
  75. configuration.outputDir = data.output_dir;
  76. }
  77. if (data.jsGlobals != null) {
  78. configuration.jsGlobals.push.apply(configuration.jsGlobals, data.jsGlobals);
  79. }
  80. if (data.verbose != null) {
  81. configuration.verbose = data.verbose;
  82. }
  83. return configuration;
  84. }
  85. };