2
0

grunt-amberc.js 3.2 KB

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