Gruntfile.js 5.0 KB

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