Gruntfile.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. 'use strict';
  2. var fs = require('fs'),
  3. path = require('path'),
  4. helpers = require('@ambers/sdk').helpers;
  5. function findAmberPath(options) {
  6. var result;
  7. options.some(function (x) {
  8. var candidate = path.join(__dirname, x);
  9. return (
  10. fs.existsSync(path.join(candidate, 'support/boot.js')) ||
  11. fs.existsSync(path.join(candidate, 'base/boot.js'))
  12. ) && (result = candidate);
  13. });
  14. return result;
  15. }
  16. module.exports = function (grunt) {
  17. // These plugins provide necessary tasks.
  18. grunt.loadNpmTasks('grunt-contrib-clean');
  19. grunt.loadNpmTasks('grunt-contrib-requirejs');
  20. grunt.loadNpmTasks('grunt-exec');
  21. grunt.loadNpmTasks('@ambers/sdk');
  22. // Default task.
  23. grunt.registerTask('default', ['amdconfig:app', 'amberc:all']);
  24. grunt.registerTask('test', ['amdconfig:app', 'requirejs:test_runner', 'exec:test_runner', 'clean:test_runner']);
  25. grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
  26. grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
  27. var polyfillThenPromiseApp = function () {
  28. define(["require", "amber/es6-promise"], function (require, promiseLib) {
  29. promiseLib.polyfill();
  30. return new Promise(function (resolve, reject) {
  31. require(["__app__"], resolve, reject);
  32. });
  33. });
  34. };
  35. // Project configuration.
  36. grunt.initConfig({
  37. // Metadata.
  38. // pkg: grunt.file.readJSON(''),
  39. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  40. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  41. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  42. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  43. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  44. // task configuration
  45. amberc: {
  46. options: {
  47. amber_dir: findAmberPath(['../amber/lang', 'node_modules/@ambers/lang']),
  48. configFile: "config.js"
  49. },
  50. all: {
  51. src: [
  52. 'src/Web.st', 'src/Web-JQuery', 'src/Web-Snippets.st' // list all sources in dependency order
  53. // list all tests in dependency order
  54. ],
  55. amd_namespace: 'amber/web',
  56. libraries: ['amber/core/SUnit']
  57. }
  58. },
  59. amdconfig: {app: {dest: 'config.js'}},
  60. requirejs: {
  61. options: {
  62. useStrict: true
  63. },
  64. deploy: {
  65. options: {
  66. mainConfigFile: "config.js",
  67. rawText: {
  68. "app": '(' + polyfillThenPromiseApp + '());',
  69. "__app__": 'define(["deploy", "amber/core/Platform-Browser"],function(x){return x});'
  70. },
  71. pragmas: {
  72. excludeIdeData: true,
  73. excludeDebugContexts: true
  74. },
  75. include: ['config', 'node_modules/requirejs/require', 'app'],
  76. findNestedDependencies: true,
  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', 'amber/core/Platform-Browser'],
  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'],
  112. findNestedDependencies: true,
  113. insertRequire: ['app'],
  114. optimize: "none",
  115. wrap: helpers.nodeWrapperWithShebang,
  116. out: "test_runner.js"
  117. }
  118. }
  119. },
  120. exec: {
  121. test_runner: 'node test_runner.js'
  122. },
  123. clean: {
  124. test_runner: ['test_runner.js']
  125. }
  126. });
  127. };