Gruntfile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. module.exports = function(grunt) {
  2. var path = require('path');
  3. var SOURCE_DIR = 'wp/';
  4. var BUILD_DIR = 'build/';
  5. grunt.initConfig({
  6. clean: {
  7. all: [BUILD_DIR],
  8. dynamic: {
  9. dot: true,
  10. expand: true,
  11. cwd: BUILD_DIR,
  12. src: []
  13. },
  14. svn: [SOURCE_DIR]
  15. },
  16. copy: {
  17. all: {
  18. dot: true,
  19. expand: true,
  20. cwd: SOURCE_DIR,
  21. src: ['**','!**/.{svn,git}/**'], // Ignore version control directories.
  22. dest: BUILD_DIR
  23. },
  24. dynamic: {
  25. dot: true,
  26. expand: true,
  27. cwd: SOURCE_DIR,
  28. dest: BUILD_DIR,
  29. src: []
  30. }
  31. },
  32. cssmin: {
  33. core: {
  34. expand: true,
  35. cwd: SOURCE_DIR,
  36. dest: BUILD_DIR,
  37. ext: '.min.css',
  38. src: [
  39. 'wp-admin/css/*.css',
  40. 'wp-includes/css/*.css',
  41. // Exceptions
  42. '!wp-admin/css/farbtastic.css'
  43. ]
  44. }
  45. },
  46. svn: {
  47. core: {
  48. repository: 'https://core.svn.wordpress.org/trunk/',
  49. dest: SOURCE_DIR
  50. }
  51. },
  52. uglify: {
  53. core: {
  54. expand: true,
  55. cwd: SOURCE_DIR,
  56. dest: BUILD_DIR,
  57. ext: '.min.js',
  58. src: [
  59. 'wp-admin/js/*.js',
  60. 'wp-includes/js/*.js',
  61. 'wp-includes/js/plupload/handlers.js',
  62. 'wp-includes/js/plupload/wp-plupload.js',
  63. 'wp-includes/js/tinymce/plugins/wp*/js/*.js',
  64. // Exceptions
  65. '!wp-admin/js/custom-header.js', // Why? We should minify this.
  66. '!wp-admin/js/farbtastic.js',
  67. '!wp-admin/js/iris.min.js',
  68. '!wp-includes/js/backbone.min.js',
  69. '!wp-includes/js/swfobject.js',
  70. '!wp-includes/js/underscore.min.js'
  71. ]
  72. },
  73. tinymce: {
  74. expand: true,
  75. cwd: SOURCE_DIR,
  76. dest: BUILD_DIR,
  77. src: [
  78. 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js',
  79. 'wp-includes/js/tinymce/plugins/wp*/editor_plugin_src.js'
  80. ],
  81. // TinyMCE plugins use a nonstandard naming scheme: plugin files are named
  82. // `editor_plugin_src.js`, and are compressed into `editor_plugin.js`.
  83. rename: function(destBase, destPath) {
  84. destPath = destPath.replace('/editor_plugin_src.js', '/editor_plugin.js');
  85. return path.join(destBase || '', destPath);
  86. }
  87. }
  88. },
  89. watch: {
  90. all: {
  91. files: [
  92. SOURCE_DIR + '**',
  93. // Ignore version control directories.
  94. '!' + SOURCE_DIR + '**/.{svn,git}/**'
  95. ],
  96. tasks: ['clean:dynamic', 'copy:dynamic'],
  97. options: {
  98. dot: true,
  99. spawn: false,
  100. interval: 2000
  101. }
  102. }
  103. }
  104. });
  105. // Load tasks.
  106. grunt.loadNpmTasks('grunt-contrib-clean');
  107. grunt.loadNpmTasks('grunt-contrib-copy');
  108. grunt.loadNpmTasks('grunt-contrib-cssmin');
  109. grunt.loadNpmTasks('grunt-contrib-uglify');
  110. grunt.loadNpmTasks('grunt-contrib-watch');
  111. // Register tasks.
  112. grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core',
  113. 'uglify:core', 'uglify:tinymce']);
  114. // Default task.
  115. grunt.registerTask('default', ['build']);
  116. // Add a listener to the watch task.
  117. //
  118. // On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic`
  119. // configurations so that only the changed files are updated.
  120. grunt.event.on('watch', function(action, filepath, target) {
  121. if (target != 'all') return;
  122. var relativePath = path.relative(SOURCE_DIR, filepath);
  123. var cleanSrc = (action == 'deleted') ? [relativePath] : [];
  124. var copySrc = (action == 'deleted') ? [] : [relativePath];
  125. grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
  126. grunt.config(['copy', 'dynamic', 'src'], copySrc);
  127. });
  128. };