Gruntfile.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 'use strict';
  2. module.exports = function (grunt) {
  3. // These plugins provide necessary tasks.
  4. grunt.loadNpmTasks('grunt-contrib-clean');
  5. grunt.loadNpmTasks('grunt-contrib-requirejs');
  6. grunt.loadNpmTasks('grunt-exec');
  7. grunt.loadNpmTasks('amber-dev');
  8. var path = require('path'),
  9. helpers = require('amber-dev').helpers;
  10. // Default task.
  11. grunt.registerTask('default', ['amdconfig:app', 'amberc:axon', 'amberc:all']);
  12. grunt.registerTask('test', ['amdconfig:app', 'requirejs:test_runner', 'exec:test_runner', 'clean:test_runner']);
  13. grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
  14. grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
  15. var polyfillThenPromiseApp = function () {
  16. define(["require", "amber/es2015-polyfills"], function (require) {
  17. return new Promise(function (resolve, reject) {
  18. require(["__app__"], resolve, reject);
  19. });
  20. });
  21. };
  22. // Project configuration.
  23. grunt.initConfig({
  24. // Metadata.
  25. // pkg: grunt.file.readJSON(''),
  26. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  27. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  28. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  29. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  30. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  31. // task configuration
  32. amberc: {
  33. options: {
  34. amber_dir: path.join(__dirname, "bower_components", "amber"),
  35. configFile: "config.js"
  36. },
  37. axon: {
  38. src: [
  39. 'src/Axon.st', // list all sources in dependency order
  40. // list all tests in dependency order
  41. ],
  42. amd_namespace: 'axon',
  43. libraries: ['amber_core/SUnit']
  44. },
  45. all: {
  46. src: [
  47. 'src/Trapped-Backend.st', 'src/Trapped-Frontend.st', 'src/Trapped-Processors.st', // list all sources in dependency order
  48. 'src/Trapped-Tests.st' // list all tests in dependency order
  49. ],
  50. amd_namespace: 'trapped',
  51. libraries: ['axon/Axon', 'amber_core/SUnit', 'amber/web/Web']
  52. },
  53. counter: {
  54. src: [
  55. 'example-counter/src/Trapped-Counter.st'
  56. ],
  57. amd_namespace: 'trapped-counter',
  58. libraries: ['amber_core/SUnit', 'amber/web/Web', 'trapped/Trapped-Backend']
  59. },
  60. todo: {
  61. src: [
  62. 'example-todo/src/Trapped-Todo.st'
  63. ],
  64. amd_namespace: 'trapped-todo',
  65. libraries: ['amber_core/SUnit', 'amber/web/Web', 'trapped/Trapped-Frontend', 'trapped/Trapped-Backend']
  66. }
  67. },
  68. amdconfig: {app: {dest: 'config.js'}},
  69. requirejs: {
  70. options: {
  71. useStrict: true
  72. },
  73. deploy: {
  74. options: {
  75. mainConfigFile: "config.js",
  76. rawText: {
  77. "app": '(' + polyfillThenPromiseApp + '());',
  78. "__app__": 'define(["deploy", "amber_core/Platform-Browser"],function(x){return x});'
  79. },
  80. pragmas: {
  81. excludeIdeData: true,
  82. excludeDebugContexts: true
  83. },
  84. include: ['config', 'node_modules/requirejs/require', 'app', 'amber/lazypack', '__app__'],
  85. optimize: "uglify2",
  86. out: "the.js"
  87. }
  88. },
  89. devel: {
  90. options: {
  91. mainConfigFile: "config.js",
  92. rawText: {
  93. "app": '(' + polyfillThenPromiseApp + '());',
  94. "__app__": 'define(["devel", "amber_core/Platform-Browser"],function(x){return x});'
  95. },
  96. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  97. exclude: ['devel'],
  98. out: "the.js"
  99. }
  100. },
  101. test_runner: {
  102. options: {
  103. mainConfigFile: "config.js",
  104. rawText: {
  105. "jquery": "/* do not load in node test runner */",
  106. "__app__": "(" + function () {
  107. define(["testing", "amber_core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  108. amber.initialize().then(function () {
  109. amber.globals.NodeTestRunner._main();
  110. });
  111. });
  112. } + "());",
  113. "app": "(" + polyfillThenPromiseApp + "());"
  114. },
  115. paths: {"amber_devkit": helpers.libPath},
  116. pragmas: {
  117. excludeIdeData: true
  118. },
  119. include: ['app', 'amber/lazypack', '__app__'],
  120. insertRequire: ['app'],
  121. optimize: "none",
  122. wrap: helpers.nodeWrapperWithShebang,
  123. out: "test_runner.js"
  124. }
  125. }
  126. },
  127. exec: {
  128. test_runner: 'node test_runner.js'
  129. },
  130. clean: {
  131. test_runner: ['test_runner.js']
  132. }
  133. });
  134. };