Gruntfile.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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:all', 'amberc:counter', 'amberc:todo']);
  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. all: {
  38. src: [
  39. 'src/Trapped.st', 'src/Trapped-Processors.st', // list all sources in dependency order
  40. // list all tests in dependency order
  41. ],
  42. amd_namespace: 'trapped',
  43. libraries: ['axxord/Axxord', 'amber_core/SUnit', 'amber/web/Web']
  44. },
  45. counter: {
  46. src: [
  47. 'example-counter/src/Trapped-Counter.st'
  48. ],
  49. amd_namespace: 'trapped-counter',
  50. libraries: ['amber_core/SUnit', 'amber/web/Web', 'axxord/Axxord']
  51. },
  52. todo: {
  53. src: [
  54. 'example-todo/src/Trapped-Todo.st'
  55. ],
  56. amd_namespace: 'trapped-todo',
  57. libraries: ['amber_core/SUnit', 'amber/web/Web', 'trapped/Trapped']
  58. }
  59. },
  60. amdconfig: {app: {dest: 'config.js'}},
  61. requirejs: {
  62. options: {
  63. useStrict: true
  64. },
  65. deploy: {
  66. options: {
  67. mainConfigFile: "config.js",
  68. rawText: {
  69. "app": '(' + polyfillThenPromiseApp + '());',
  70. "__app__": 'define(["deploy", "amber_core/Platform-Browser"],function(x){return x});'
  71. },
  72. pragmas: {
  73. excludeIdeData: true,
  74. excludeDebugContexts: true
  75. },
  76. include: ['config', 'node_modules/requirejs/require', 'app', 'amber/lazypack', '__app__'],
  77. optimize: "uglify2",
  78. out: "the.js"
  79. }
  80. },
  81. devel: {
  82. options: {
  83. mainConfigFile: "config.js",
  84. rawText: {
  85. "app": '(' + polyfillThenPromiseApp + '());',
  86. "__app__": 'define(["devel", "amber_core/Platform-Browser"],function(x){return x});'
  87. },
  88. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  89. exclude: ['devel'],
  90. out: "the.js"
  91. }
  92. },
  93. test_runner: {
  94. options: {
  95. mainConfigFile: "config.js",
  96. rawText: {
  97. "jquery": "/* do not load in node test runner */",
  98. "__app__": "(" + function () {
  99. define(["testing", "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. excludeIdeData: true
  110. },
  111. include: ['app', 'amber/lazypack', '__app__'],
  112. insertRequire: ['app'],
  113. optimize: "none",
  114. wrap: helpers.nodeWrapperWithShebang,
  115. out: "test_runner.js"
  116. }
  117. }
  118. },
  119. exec: {
  120. test_runner: 'node test_runner.js'
  121. },
  122. clean: {
  123. test_runner: ['test_runner.js']
  124. }
  125. });
  126. };