Gruntfile.js 4.6 KB

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