You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

96 lines
2.5 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. 'use strict';
  6. var tasks = {},
  7. _ = require('underscore');
  8. function init(config) {
  9. var grunt = require('grunt'),
  10. expand = grunt.file.expand.bind(grunt.file),
  11. staticMode = 'quick',
  12. themes, root, staticDir, baseUrl, mapFile, host, port, files, requireJs;
  13. root = config.root;
  14. staticDir = config.static;
  15. port = config.port;
  16. files = config.files;
  17. themes = config.themes;
  18. _.each(themes, function (themeData, themeName) {
  19. var specs,
  20. configs,
  21. render;
  22. _.extend(themeData, {
  23. root: root,
  24. static: staticDir
  25. });
  26. host = _.template(config.host)({
  27. port: port++
  28. });
  29. render = renderTemplate.bind(null, themeData);
  30. mapFile = renderTemplate(themeData, files.compactMap);
  31. baseUrl = renderTemplate(themeData, files.requireBaseUrl);
  32. if (grunt.file.exists(mapFile)) {
  33. staticMode = 'compact';
  34. }
  35. if (config.singleTest) {
  36. files.specs = [config.singleTest];
  37. }
  38. specs = files.specs.map(render);
  39. specs = expand(specs).map(cutJsExtension);
  40. configs = files.requirejsConfigs[staticMode].map(render);
  41. requireJs = renderTemplate(themeData, files.requireJs[staticMode]);
  42. tasks[themeName] = {
  43. src: configs,
  44. options: {
  45. host: host,
  46. template: render(files.template),
  47. templateOptions: {
  48. baseUrl: baseUrl
  49. },
  50. vendor: requireJs,
  51. junit: {
  52. path: "var/log/js-unit/",
  53. consolidate: true
  54. },
  55. /**
  56. * @todo rename "helpers" to "specs" (implies overriding grunt-contrib-jasmine code)
  57. */
  58. helpers: specs,
  59. sandboxArgs: {
  60. args: ['--no-sandbox', '--disable-setuid-sandbox'],
  61. defaultViewport: {width: 400, height: 400, hasTouch: true}
  62. }
  63. }
  64. };
  65. });
  66. }
  67. function renderTemplate(data, template) {
  68. return _.template(template)(data);
  69. }
  70. function cutJsExtension(path) {
  71. return path.replace(/\.js$/, '');
  72. }
  73. function getTasks() {
  74. return tasks;
  75. }
  76. module.exports = {
  77. init: init,
  78. getTasks: getTasks
  79. };