Gruntfile.js 3.3 KB

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