Gruntfile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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', 'bower_components/amber']),
  48. configFile: "config.js"
  49. },
  50. all: {
  51. src: [
  52. 'src/Wrappers-JQuery.st', // list all sources in dependency order
  53. // list all tests in dependency order
  54. ],
  55. amd_namespace: 'amber/jquery',
  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', 'amber/lazypack', '__app__'],
  76. optimize: "uglify2",
  77. out: "the.js"
  78. }
  79. },
  80. devel: {
  81. options: {
  82. mainConfigFile: "config.js",
  83. rawText: {
  84. "app": '(' + polyfillThenPromiseApp + '());',
  85. "__app__": 'define(["devel", "amber_core/Platform-Browser"],function(x){return x});'
  86. },
  87. include: ['config', 'node_modules/requirejs/require', 'app', '__app__'],
  88. exclude: ['devel'],
  89. out: "the.js"
  90. }
  91. },
  92. test_runner: {
  93. options: {
  94. mainConfigFile: "config.js",
  95. rawText: {
  96. "jquery": "/* do not load in node test runner */",
  97. "__app__": "(" + function () {
  98. define(["testing", "amber_core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  99. amber.initialize().then(function () {
  100. amber.globals.NodeTestRunner._main();
  101. });
  102. });
  103. } + "());",
  104. "app": "(" + polyfillThenPromiseApp + "());"
  105. },
  106. paths: {"amber_devkit": helpers.libPath},
  107. pragmas: {
  108. excludeIdeData: true
  109. },
  110. include: ['app', 'amber/lazypack', '__app__'],
  111. insertRequire: ['app'],
  112. optimize: "none",
  113. wrap: helpers.nodeWrapperWithShebang,
  114. out: "test_runner.js"
  115. }
  116. }
  117. },
  118. exec: {
  119. test_runner: 'node test_runner.js'
  120. },
  121. clean: {
  122. test_runner: ['test_runner.js']
  123. }
  124. });
  125. };