Gruntfile.js 4.9 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-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 promiseApp = function () {
  29. define(["require"], function (require) {
  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. less: {
  46. development: {
  47. files: {
  48. 'resources/helios.css': 'resources/helios.less'
  49. }
  50. }
  51. },
  52. amberc: {
  53. options: {
  54. amber_dir: findAmberPath(['../amber/lang', 'node_modules/@ambers/lang']),
  55. configFile: "config.js"
  56. },
  57. all: {
  58. src: [
  59. // list all sources in dependency order
  60. 'src/Helios-Core.st', 'src/Helios-Exceptions.st', 'src/Helios-Announcements.st',
  61. 'src/Helios-KeyBindings.st', 'src/Helios-Layout.st', 'src/Helios-Helpers.st',
  62. 'src/Helios-Commands-Core.st',
  63. 'src/Helios-Commands-Tools.st', 'src/Helios-Commands-Browser.st', 'src/Helios-Commands-SUnit.st',
  64. 'src/Helios-References.st', 'src/Helios-Inspector.st', 'src/Helios-Browser.st',
  65. 'src/Helios-Transcript.st', 'src/Helios-Workspace.st', 'src/Helios-Debugger.st',
  66. 'src/Helios-SUnit.st',
  67. // list all tests in dependency order
  68. 'src/Helios-Browser-Tests.st', 'src/Helios-Workspace-Tests.st', 'src/Helios-SUnit-Tests.st'
  69. ],
  70. libraries: ['amber/core/SUnit', 'amber/web/Web'],
  71. amd_namespace: 'helios',
  72. jsGlobals: ['navigator']
  73. }
  74. },
  75. amdconfig: {app: {dest: 'config.js'}},
  76. requirejs: {
  77. options: {
  78. useStrict: true
  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(["amber/deploy", "helios/all", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  87. amber.initialize().then(function () {
  88. amber.globals.NodeTestRunner._main();
  89. });
  90. });
  91. } + "());",
  92. "app": "(" + promiseApp + "());"
  93. },
  94. paths: {"amber_devkit": helpers.libPath},
  95. pragmas: {
  96. excludeIdeData: true
  97. },
  98. include: ['app'],
  99. findNestedDependencies: true,
  100. insertRequire: ['app'],
  101. optimize: "none",
  102. wrap: helpers.nodeWrapperWithShebang,
  103. out: "test_runner.js"
  104. }
  105. }
  106. },
  107. exec: {
  108. test_runner: 'node test_runner.js'
  109. },
  110. clean: {
  111. test_runner: ['test_runner.js']
  112. },
  113. watch: {
  114. less: {
  115. files: ['resources/*.less'],
  116. tasks: ['less'],
  117. options: {
  118. spawn: false
  119. }
  120. }
  121. }
  122. });
  123. };