Gruntfile.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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']);
  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/Lyst.st' // list all sources in dependency order
  40. // list all tests in dependency order
  41. ],
  42. amd_namespace: 'lyst',
  43. libraries: ['amber_core/SUnit', 'amber/web/Web']
  44. }
  45. },
  46. amdconfig: {app: {dest: 'config.js'}},
  47. requirejs: {
  48. options: {
  49. useStrict: true
  50. },
  51. deploy: {
  52. options: {
  53. mainConfigFile: "config.js",
  54. rawText: {
  55. "app": '(' + polyfillThenPromiseApp + '());',
  56. "__app__": 'define(["deploy", "amber_core/Platform-Browser"],function(x){return x});'
  57. },
  58. pragmas: {
  59. excludeIdeData: true,
  60. excludeDebugContexts: true
  61. },
  62. include: ['config', 'node_modules/requirejs/require', 'app', 'amber/lazypack', '__app__'],
  63. optimize: "uglify2",
  64. out: "the.js"
  65. }
  66. },
  67. devel: {
  68. options: {
  69. mainConfigFile: "config.js",
  70. rawText: {
  71. "app": '(' + polyfillThenPromiseApp + '());',
  72. "__app__": 'define(["devel", "amber_core/Platform-Browser"],function(x){return x});'
  73. },
  74. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  75. exclude: ['devel'],
  76. out: "the.js"
  77. }
  78. },
  79. test_runner: {
  80. options: {
  81. mainConfigFile: "config.js",
  82. rawText: {
  83. "jquery": "/* do not load in node test runner */",
  84. "__app__": "(" + function () {
  85. define(["testing", "amber_core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  86. amber.initialize().then(function () {
  87. amber.globals.NodeTestRunner._main();
  88. });
  89. });
  90. } + "());",
  91. "app": "(" + polyfillThenPromiseApp + "());"
  92. },
  93. paths: {"amber_devkit": helpers.libPath},
  94. pragmas: {
  95. excludeIdeData: true
  96. },
  97. include: ['app', 'amber/lazypack', '__app__'],
  98. insertRequire: ['app'],
  99. optimize: "none",
  100. wrap: helpers.nodeWrapperWithShebang,
  101. out: "test_runner.js"
  102. }
  103. }
  104. },
  105. exec: {
  106. test_runner: 'node test_runner.js'
  107. },
  108. clean: {
  109. test_runner: ['test_runner.js']
  110. }
  111. });
  112. };