Gruntfile.js.sample 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. // For performance use one level down: 'name/{,*/}*.js'
  6. // If you want to recursively match all subfolders, use: 'name/**/*.js'
  7. module.exports = function (grunt) {
  8. 'use strict';
  9. var _ = require('underscore'),
  10. path = require('path'),
  11. filesRouter = require('./dev/tools/grunt/tools/files-router'),
  12. configDir = './dev/tools/grunt/configs',
  13. tasks = grunt.file.expand('./dev/tools/grunt/tasks/*'),
  14. themes;
  15. filesRouter.set('themes', 'dev/tools/grunt/configs/themes');
  16. themes = filesRouter.get('themes');
  17. tasks = _.map(tasks, function(task){ return task.replace('.js', '') });
  18. tasks.push('time-grunt');
  19. tasks.forEach(function (task) {
  20. require(task)(grunt);
  21. });
  22. require('load-grunt-config')(grunt, {
  23. configPath: path.join(__dirname, configDir),
  24. init: true,
  25. jitGrunt: {
  26. staticMappings: {
  27. usebanner: 'grunt-banner'
  28. }
  29. }
  30. });
  31. _.each({
  32. /**
  33. * Assembling tasks.
  34. * ToDo: define default tasks.
  35. */
  36. default: function () {
  37. grunt.log.subhead('I\'m default task and at the moment I\'m empty, sorry :/');
  38. },
  39. /**
  40. * Production preparation task.
  41. */
  42. prod: function (component) {
  43. var tasks = [
  44. 'less',
  45. 'autoprefixer',
  46. 'cssmin',
  47. 'usebanner'
  48. ].map(function(task){
  49. return task + ':' + component;
  50. });
  51. if (typeof component === 'undefined') {
  52. grunt.log.subhead('Tip: Please make sure that u specify prod subtask. By default prod task do nothing');
  53. } else {
  54. grunt.task.run(tasks);
  55. }
  56. },
  57. /**
  58. * Refresh themes.
  59. */
  60. refresh: function () {
  61. var tasks = [
  62. 'clean',
  63. 'exec:all'
  64. ];
  65. _.each(themes, function(theme, name) {
  66. tasks.push('less:' + name);
  67. });
  68. grunt.task.run(tasks);
  69. },
  70. /**
  71. * Documentation
  72. */
  73. documentation: [
  74. 'replace:documentation',
  75. 'less:documentation',
  76. 'styledocco:documentation',
  77. 'usebanner:documentationCss',
  78. 'usebanner:documentationLess',
  79. 'usebanner:documentationHtml',
  80. 'clean:var',
  81. 'clean:pub'
  82. ],
  83. 'legacy-build': [
  84. 'mage-minify:legacy'
  85. ],
  86. spec: function (theme) {
  87. var runner = require('./dev/tests/js/jasmine/spec_runner');
  88. runner.init(grunt, { theme: theme });
  89. grunt.task.run(runner.getTasks());
  90. }
  91. }, function (task, name) {
  92. grunt.registerTask(name, task);
  93. });
  94. };