Gruntfile.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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:alybaba', '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. alybaba: {
  54. src: [
  55. 'src/Alybaba.st', // list all sources in dependency order
  56. // list all tests in dependency order
  57. ],
  58. amd_namespace: 'alybaba',
  59. libraries: ['amber_core/SUnit']
  60. },
  61. counter: {
  62. src: [
  63. 'example-counter/src/Trapped-Counter.st'
  64. ],
  65. amd_namespace: 'trapped-counter',
  66. libraries: ['amber_core/SUnit', 'amber/web/Web', 'trapped/Trapped-Backend']
  67. },
  68. todo: {
  69. src: [
  70. 'example-todo/src/Trapped-Todo.st'
  71. ],
  72. amd_namespace: 'trapped-todo',
  73. libraries: ['amber_core/SUnit', 'amber/web/Web', 'trapped/Trapped-Frontend', 'trapped/Trapped-Backend']
  74. }
  75. },
  76. amdconfig: {app: {dest: 'config.js'}},
  77. requirejs: {
  78. options: {
  79. useStrict: true
  80. },
  81. deploy: {
  82. options: {
  83. mainConfigFile: "config.js",
  84. rawText: {
  85. "app": '(' + polyfillThenPromiseApp + '());',
  86. "__app__": 'define(["deploy", "amber_core/Platform-Browser"],function(x){return x});'
  87. },
  88. pragmas: {
  89. excludeIdeData: true,
  90. excludeDebugContexts: true
  91. },
  92. include: ['config', 'node_modules/requirejs/require', 'app', 'amber/lazypack', '__app__'],
  93. optimize: "uglify2",
  94. out: "the.js"
  95. }
  96. },
  97. devel: {
  98. options: {
  99. mainConfigFile: "config.js",
  100. rawText: {
  101. "app": '(' + polyfillThenPromiseApp + '());',
  102. "__app__": 'define(["devel", "amber_core/Platform-Browser"],function(x){return x});'
  103. },
  104. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  105. exclude: ['devel'],
  106. out: "the.js"
  107. }
  108. },
  109. test_runner: {
  110. options: {
  111. mainConfigFile: "config.js",
  112. rawText: {
  113. "jquery": "/* do not load in node test runner */",
  114. "__app__": "(" + function () {
  115. define(["testing", "amber_core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  116. amber.initialize().then(function () {
  117. amber.globals.NodeTestRunner._main();
  118. });
  119. });
  120. } + "());",
  121. "app": "(" + polyfillThenPromiseApp + "());"
  122. },
  123. paths: {"amber_devkit": helpers.libPath},
  124. pragmas: {
  125. excludeIdeData: true
  126. },
  127. include: ['app', 'amber/lazypack', '__app__'],
  128. insertRequire: ['app'],
  129. optimize: "none",
  130. wrap: helpers.nodeWrapperWithShebang,
  131. out: "test_runner.js"
  132. }
  133. }
  134. },
  135. exec: {
  136. test_runner: 'node test_runner.js'
  137. },
  138. clean: {
  139. test_runner: ['test_runner.js']
  140. }
  141. });
  142. };