Gruntfile.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. 'use strict';
  2. var fs = require('fs'),
  3. path = require('path');
  4. function findAmberPath(options) {
  5. var result;
  6. options.some(function (x) {
  7. var candidate = path.join(__dirname, x);
  8. return fs.existsSync(path.join(candidate, 'support/boot.js')) && (result = candidate);
  9. });
  10. return result;
  11. }
  12. module.exports = function (grunt) {
  13. var helpers = require('@ambers/sdk').helpers;
  14. // These plugins provide necessary tasks.
  15. grunt.loadNpmTasks('grunt-execute');
  16. grunt.loadNpmTasks('grunt-contrib-clean');
  17. grunt.loadNpmTasks('grunt-contrib-less');
  18. grunt.loadNpmTasks('grunt-contrib-requirejs');
  19. grunt.loadNpmTasks('grunt-contrib-watch');
  20. grunt.loadNpmTasks('@ambers/sdk');
  21. // Default task.
  22. grunt.registerTask('default', ['amdconfig:helios', 'less', 'amberc:all']);
  23. grunt.registerTask('test', ['amdconfig:helios', 'requirejs:test_runner', 'execute:test_runner', 'clean:test_runner']);
  24. grunt.registerTask('devel', ['amdconfig:helios']);
  25. var polyfillThenPromiseApp = function () {
  26. define(["require", "amber/es2015-polyfills"], function (require) {
  27. return new Promise(function (resolve, reject) {
  28. require(["__app__"], resolve, reject);
  29. });
  30. });
  31. };
  32. // Project configuration.
  33. grunt.initConfig({
  34. // Metadata.
  35. // pkg: grunt.file.readJSON(''),
  36. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  37. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  38. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  39. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  40. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  41. // task configuration
  42. less: {
  43. development: {
  44. files: {
  45. 'resources/helios.css': 'resources/helios.less'
  46. }
  47. }
  48. },
  49. amberc: {
  50. options: {
  51. amber_dir: findAmberPath(['../..', 'bower_components/amber']),
  52. configFile: "config.js"
  53. },
  54. all: {
  55. output_dir: 'src',
  56. src: [
  57. // list all sources in dependency order
  58. 'src/Helios-Core.st', 'src/Helios-Exceptions.st', 'src/Helios-Announcements.st',
  59. 'src/Helios-KeyBindings.st', 'src/Helios-Layout.st', 'src/Helios-Helpers.st',
  60. 'src/Helios-Commands-Core.st',
  61. 'src/Helios-Commands-Tools.st', 'src/Helios-Commands-Browser.st', 'src/Helios-Commands-SUnit.st',
  62. 'src/Helios-References.st', 'src/Helios-Inspector.st', 'src/Helios-Browser.st',
  63. 'src/Helios-Transcript.st', 'src/Helios-Workspace.st', 'src/Helios-Debugger.st',
  64. 'src/Helios-SUnit.st',
  65. // list all tests in dependency order
  66. 'src/Helios-Browser-Tests.st', 'src/Helios-Workspace-Tests.st', 'src/Helios-SUnit-Tests.st'
  67. ],
  68. libraries: ['amber_core/SUnit', 'amber/web/Web'],
  69. amd_namespace: 'helios',
  70. jsGlobals: ['navigator']
  71. }
  72. },
  73. requirejs: {
  74. options: {
  75. useStrict: true
  76. },
  77. test_runner: {
  78. options: {
  79. mainConfigFile: "config.js",
  80. rawText: {
  81. "jquery": "/* do not load in node test runner */",
  82. "__app__": "(" + function () {
  83. define(["amber/deploy", "helios/all", "amber_core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  84. amber.initialize().then(function () {
  85. amber.globals.NodeTestRunner._main();
  86. });
  87. });
  88. } + "());",
  89. "app": "(" + polyfillThenPromiseApp + "());"
  90. },
  91. paths: {"amber_devkit": helpers.libPath},
  92. pragmas: {
  93. excludeIdeData: true
  94. },
  95. include: ['app', 'amber/lazypack', '__app__'],
  96. insertRequire: ['app'],
  97. optimize: "none",
  98. wrap: helpers.nodeWrapperWithShebang,
  99. out: "test_runner.js"
  100. }
  101. }
  102. },
  103. amdconfig: {helios: {dest: 'config.js'}},
  104. execute: {
  105. test_runner: {
  106. src: ['test_runner.js']
  107. }
  108. },
  109. clean: {
  110. test_runner: ['test_runner.js']
  111. },
  112. watch: {
  113. less: {
  114. files: ['resources/*.less'],
  115. tasks: ['less'],
  116. options: {
  117. spawn: false
  118. }
  119. }
  120. }
  121. });
  122. };