Gruntfile.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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(''),
  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/AmberWebsite.st', // list all sources in dependency order
  41. 'src/AmberWebsite-Tests.st' // list all tests in dependency order
  42. ],
  43. amd_namespace: 'amber/website',
  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. "helios/index": "",
  57. "app": '(' + polyfillThenPromiseApp + '());',
  58. "__app__": 'define(["deploy", "amber/core/Platform-Browser"],function(x){return x});'
  59. },
  60. pragmas: {
  61. excludeIdeData: true,
  62. excludeDebugContexts: true
  63. },
  64. include: ['config', 'node_modules/requirejs/require', 'app'],
  65. findNestedDependencies: true,
  66. exclude: ['helios/index'],
  67. optimize: "uglify2",
  68. out: "the.js"
  69. }
  70. },
  71. devel: {
  72. options: {
  73. mainConfigFile: "config.js",
  74. rawText: {
  75. "app": '(' + polyfillThenPromiseApp + '());',
  76. "__app__": 'define(["devel", "amber/core/Platform-Browser"],function(x){return x});'
  77. },
  78. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  79. exclude: ['devel', 'amber/core/Platform-Browser'],
  80. out: "the.js"
  81. }
  82. },
  83. test_runner: {
  84. options: {
  85. mainConfigFile: "config.js",
  86. rawText: {
  87. "jquery": "/* do not load in node test runner */",
  88. "__app__": "(" + function () {
  89. define(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  90. amber.initialize().then(function () {
  91. amber.globals.NodeTestRunner._main();
  92. });
  93. });
  94. } + "());",
  95. "app": "(" + polyfillThenPromiseApp + "());"
  96. },
  97. paths: {"amber_devkit": helpers.libPath},
  98. pragmas: {
  99. excludeIdeData: true
  100. },
  101. include: ['app'],
  102. findNestedDependencies: true,
  103. insertRequire: ['app'],
  104. optimize: "none",
  105. wrap: helpers.nodeWrapperWithShebang,
  106. out: "test_runner.js"
  107. }
  108. }
  109. },
  110. exec: {
  111. test_runner: 'node test_runner.js'
  112. },
  113. clean: {
  114. test_runner: ['test_runner.js']
  115. }
  116. });
  117. };