Gruntfile.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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('@ambers/sdk');
  8. var path = require('path'),
  9. helpers = require('@ambers/sdk').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/es6-promise"], function (require, promiseLib) {
  17. promiseLib.polyfill();
  18. return new Promise(function (resolve, reject) {
  19. require(["__app__"], resolve, reject);
  20. });
  21. });
  22. };
  23. // Project configuration.
  24. grunt.initConfig({
  25. // Metadata.
  26. // pkg: grunt.file.readJSON('{%= amberjson %}'),
  27. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  28. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  29. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  30. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  31. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  32. // task configuration
  33. amberc: {
  34. options: {
  35. amber_dir: path.join(__dirname, "node_modules", "@ambers", "lang"),
  36. configFile: "config.js"
  37. },
  38. all: {
  39. src: [
  40. 'src/{%= name %}.st', // list all sources in dependency order
  41. 'src/{%= name %}-Tests.st' // list all tests in dependency order
  42. ],
  43. amd_namespace: '{%= namespace %}',
  44. libraries: ['amber/core/SUnit', 'amber/web/Web', 'silk/Silk']
  45. }
  46. },
  47. amdconfig: {app: {dest: 'config.js'}},
  48. requirejs: {
  49. options: {
  50. useStrict: true
  51. },
  52. deploy: {
  53. options: {
  54. mainConfigFile: "config.js",
  55. rawText: {
  56. "app": '(' + polyfillThenPromiseApp + '());',
  57. "__app__": 'define(["deploy", "amber/core/Platform-Browser"],function(x){return x});'
  58. },
  59. pragmas: {
  60. excludeIdeData: true,
  61. excludeDebugContexts: true
  62. },
  63. include: ['config', 'node_modules/requirejs/require', 'app'],
  64. findNestedDependencies: true,
  65. optimize: "uglify2",
  66. out: "the.js"
  67. }
  68. },
  69. devel: {
  70. options: {
  71. mainConfigFile: "config.js",
  72. rawText: {
  73. "app": '(' + polyfillThenPromiseApp + '());',
  74. "__app__": 'define(["devel", "amber/core/Platform-Browser"],function(x){return x});'
  75. },
  76. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  77. exclude: ['devel', 'amber/core/Platform-Browser'],
  78. out: "the.js"
  79. }
  80. },
  81. test_runner: {
  82. options: {
  83. mainConfigFile: "config.js",
  84. rawText: {
  85. "jquery": "/* do not load in node test runner */",
  86. "__app__": "(" + function () {
  87. define(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  88. amber.initialize().then(function () {
  89. amber.globals.NodeTestRunner._main();
  90. });
  91. });
  92. } + "());",
  93. "app": "(" + polyfillThenPromiseApp + "());"
  94. },
  95. paths: {"amber_devkit": helpers.libPath},
  96. pragmas: {
  97. excludeIdeData: true
  98. },
  99. include: ['app'],
  100. findNestedDependencies: true,
  101. insertRequire: ['app'],
  102. optimize: "none",
  103. wrap: helpers.nodeWrapperWithShebang,
  104. out: "test_runner.js"
  105. }
  106. }
  107. },
  108. exec: {
  109. test_runner: 'node test_runner.js'
  110. },
  111. clean: {
  112. test_runner: ['test_runner.js']
  113. }
  114. });
  115. };