Gruntfile.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var path = require('path');
  2. module.exports = function (grunt) {
  3. grunt.loadNpmTasks('grunt-contrib-jshint');
  4. grunt.loadNpmTasks('grunt-contrib-clean');
  5. grunt.loadNpmTasks('grunt-contrib-requirejs');
  6. grunt.loadNpmTasks('grunt-exec');
  7. grunt.loadTasks('./sdk/tasks');
  8. var helpers = require('./sdk').helpers;
  9. grunt.registerTask('default', ['peg', 'build:all']);
  10. grunt.registerTask('peg', ['exec:build_parser']);
  11. grunt.registerTask('build:all', ['amberc:lang', 'amberc:tests', 'build:cli', 'amberc:dev']);
  12. grunt.registerTask('build:cli', ['amberc:cli', 'amdconfig', 'requirejs:cli']);
  13. grunt.registerTask('test', ['amdconfig', 'requirejs:test_runner', 'exec:test_runner', 'clean:test_runner']);
  14. grunt.registerTask('devel', ['amdconfig']);
  15. var polyfillThenPromiseApp = function () {
  16. define(["require", "amber/es6-promise"], function (require, promiseLib) {
  17. promiseLib.polyfill();
  18. return new Promise(function (resolve, reject) {
  19. require(["__app__"], resolve, reject);
  20. });
  21. });
  22. };
  23. grunt.initConfig({
  24. pkg: grunt.file.readJSON('package.json'),
  25. meta: {
  26. banner: '/*!\n <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n License: <%= pkg.license.type %> \n*/\n'
  27. },
  28. amdconfig: {amber: {dest: 'config.js'}},
  29. amberc: {
  30. options: {
  31. amber_dir: path.join(process.cwd(), "lang"),
  32. closure_jar: ''
  33. },
  34. lang: {
  35. output_dir: 'lang/src',
  36. src: ['lang/src/Kernel-Helpers.st',
  37. 'lang/src/Kernel-Objects.st', 'lang/src/Kernel-Classes.st', 'lang/src/Kernel-Methods.st', 'lang/src/Kernel-Collections.st',
  38. 'lang/src/Kernel-Infrastructure.st', 'lang/src/Kernel-Promises.st', 'lang/src/Kernel-Exceptions.st', 'lang/src/Kernel-Announcements.st',
  39. 'lang/src/Platform-Services.st', 'lang/src/Platform-ImportExport.st', 'lang/src/Platform-Browser.st', 'lang/src/Platform-Node.st',
  40. 'lang/src/Platform-DOM.st',
  41. 'lang/src/Kernel-Dag.st', 'lang/src/Compiler-Core.st', 'lang/src/Compiler-AST.st',
  42. 'lang/src/Compiler-IR.st', 'lang/src/Compiler-Inlining.st', 'lang/src/Compiler-Semantic.st', 'lang/src/Compiler-Interpreter.st',
  43. 'lang/src/SUnit.st'
  44. ],
  45. jsGlobals: ['navigator']
  46. },
  47. tests: {
  48. output_dir: 'lang/src',
  49. src: ['lang/src/Kernel-Tests.st', 'lang/src/Compiler-Tests.st', 'lang/src/Platform-DOM-Tests.st', 'lang/src/SUnit-Tests.st'],
  50. libraries: ['amber/core/SUnit'],
  51. jsGlobals: ['navigator']
  52. },
  53. cli: {
  54. output_dir: 'cli/src',
  55. src: ['cli/src/AmberCli.st'],
  56. amd_namespace: 'amber_cli'
  57. },
  58. dev: {
  59. output_dir: 'sdk/lib',
  60. src: ['sdk/lib/NodeTestRunner.st'],
  61. amd_namespace: 'amber_devkit'
  62. }
  63. },
  64. requirejs: {
  65. options: {
  66. useStrict: true
  67. },
  68. cli: {
  69. options: {
  70. mainConfigFile: "config.js",
  71. rawText: {
  72. "helios/index": "",
  73. "__app__": "(" + function () {
  74. define(["amber/devel", "amber/core/Platform-Node", "amber_cli/AmberCli"], function (amber) {
  75. amber.initialize().then(function () {
  76. amber.globals.AmberCli._main();
  77. });
  78. });
  79. } + "());",
  80. "app": '(' + polyfillThenPromiseApp + '());'
  81. },
  82. pragmas: {
  83. // none, for repl to have all info
  84. },
  85. include: ['app'],
  86. findNestedDependencies: true,
  87. exclude: ['helios/index'],
  88. insertRequire: ['app'],
  89. optimize: "none",
  90. wrap: helpers.nodeWrapperWithShebang,
  91. out: "cli/dist/amber-cli.js"
  92. }
  93. },
  94. test_runner: {
  95. options: {
  96. mainConfigFile: "config.js",
  97. rawText: {
  98. "__app__": "(" + function () {
  99. define(["amber/devel", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  100. amber.initialize().then(function () {
  101. amber.globals.NodeTestRunner._main();
  102. });
  103. });
  104. } + "());",
  105. "app": '(' + polyfillThenPromiseApp + '());'
  106. },
  107. paths: {"amber_devkit": helpers.libPath},
  108. pragmas: {
  109. // none, amber tests test contexts as well as eg. class copying which needs sources
  110. },
  111. include: ['app'],
  112. findNestedDependencies: true,
  113. insertRequire: ['app'],
  114. optimize: "none",
  115. wrap: helpers.nodeWrapperWithShebang,
  116. out: "test_runner.js"
  117. }
  118. }
  119. },
  120. exec: {
  121. build_parser: 'cd lang && npm run build:parser',
  122. test_runner: 'node test_runner.js'
  123. },
  124. clean: {
  125. test_runner: ['test_runner.js']
  126. },
  127. jshint: {
  128. amber: ['lang/src/*.js', 'lang/base/[^p]*.js'],
  129. cli: ['cli/src/*.js', 'cli/dist/*.js'],
  130. dev: ['sdk/lib/*.js'],
  131. grunt: ['Gruntfile.js', 'grunt-tasks/*.js', 'sdk/tasks/*.js']
  132. }
  133. });
  134. };