2013-08-07 07:25:25 +02:00
|
|
|
/*global module:false*/
|
|
|
|
module.exports = function(grunt) {
|
|
|
|
var path = require('path');
|
|
|
|
var SOURCE_DIR = 'src/';
|
|
|
|
var BUILD_DIR = 'build/';
|
|
|
|
|
2013-09-04 22:50:29 +02:00
|
|
|
// Load tasks.
|
|
|
|
require('matchdep').filterDev('grunt-*').forEach( grunt.loadNpmTasks );
|
|
|
|
|
2013-08-07 07:25:25 +02:00
|
|
|
// Project configuration.
|
|
|
|
grunt.initConfig({
|
|
|
|
clean: {
|
|
|
|
all: [BUILD_DIR],
|
|
|
|
dynamic: {
|
|
|
|
dot: true,
|
|
|
|
expand: true,
|
|
|
|
cwd: BUILD_DIR,
|
|
|
|
src: []
|
|
|
|
},
|
2013-08-31 00:16:43 +02:00
|
|
|
tinymce: {
|
|
|
|
src: [
|
|
|
|
'<%= concat.tinymce.dest %>',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce-schema.min.js',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/mark_loaded.js'
|
|
|
|
]
|
|
|
|
}
|
2013-08-07 07:25:25 +02:00
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
all: {
|
2013-08-29 22:45:17 +02:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
dot: true,
|
|
|
|
expand: true,
|
|
|
|
cwd: SOURCE_DIR,
|
|
|
|
src: ['**','!**/.{svn,git}/**'], // Ignore version control directories.
|
|
|
|
dest: BUILD_DIR
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'wp-config-sample.php',
|
|
|
|
dest: BUILD_DIR
|
|
|
|
}
|
|
|
|
]
|
2013-08-07 07:25:25 +02:00
|
|
|
},
|
|
|
|
dynamic: {
|
|
|
|
dot: true,
|
|
|
|
expand: true,
|
|
|
|
cwd: SOURCE_DIR,
|
|
|
|
dest: BUILD_DIR,
|
|
|
|
src: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cssmin: {
|
|
|
|
core: {
|
|
|
|
expand: true,
|
|
|
|
cwd: SOURCE_DIR,
|
|
|
|
dest: BUILD_DIR,
|
|
|
|
ext: '.min.css',
|
|
|
|
src: [
|
|
|
|
'wp-admin/css/*.css',
|
|
|
|
'wp-includes/css/*.css',
|
|
|
|
// Exceptions
|
|
|
|
'!wp-admin/css/farbtastic.css'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-08-30 06:06:34 +02:00
|
|
|
qunit: {
|
|
|
|
files: ['tests/qunit/**/*.html']
|
|
|
|
},
|
2013-08-07 07:25:25 +02:00
|
|
|
uglify: {
|
|
|
|
core: {
|
|
|
|
expand: true,
|
|
|
|
cwd: SOURCE_DIR,
|
|
|
|
dest: BUILD_DIR,
|
|
|
|
ext: '.min.js',
|
|
|
|
src: [
|
|
|
|
'wp-admin/js/*.js',
|
|
|
|
'wp-includes/js/*.js',
|
|
|
|
'wp-includes/js/plupload/handlers.js',
|
|
|
|
'wp-includes/js/plupload/wp-plupload.js',
|
|
|
|
'wp-includes/js/tinymce/plugins/wp*/js/*.js',
|
2013-08-31 00:16:43 +02:00
|
|
|
'wp-includes/js/tinymce/wp-tinymce-schema.js',
|
2013-08-07 07:25:25 +02:00
|
|
|
// Exceptions
|
|
|
|
'!wp-admin/js/custom-header.js', // Why? We should minify this.
|
|
|
|
'!wp-admin/js/farbtastic.js',
|
|
|
|
'!wp-admin/js/iris.min.js',
|
|
|
|
'!wp-includes/js/backbone.min.js',
|
|
|
|
'!wp-includes/js/swfobject.js',
|
2013-08-28 18:08:19 +02:00
|
|
|
'!wp-includes/js/underscore.min.js',
|
2013-08-31 00:16:43 +02:00
|
|
|
'!wp-includes/js/zxcvbn.min.js',
|
|
|
|
// Hard-coded in editimage.html
|
|
|
|
'!wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.js'
|
2013-08-07 07:25:25 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
tinymce: {
|
|
|
|
expand: true,
|
|
|
|
cwd: SOURCE_DIR,
|
|
|
|
dest: BUILD_DIR,
|
|
|
|
src: [
|
|
|
|
'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js',
|
2013-08-31 00:16:43 +02:00
|
|
|
'wp-includes/js/tinymce/plugins/wp*/editor_plugin_src.js',
|
|
|
|
'wp-includes/js/tinymce/mark_loaded_src.js'
|
2013-08-07 07:25:25 +02:00
|
|
|
],
|
|
|
|
// TinyMCE plugins use a nonstandard naming scheme: plugin files are named
|
|
|
|
// `editor_plugin_src.js`, and are compressed into `editor_plugin.js`.
|
|
|
|
rename: function(destBase, destPath) {
|
2013-08-31 00:16:43 +02:00
|
|
|
destPath = destPath.replace(/_src.js$/, '.js');
|
2013-08-07 07:25:25 +02:00
|
|
|
return path.join(destBase || '', destPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-08-31 00:16:43 +02:00
|
|
|
concat: {
|
|
|
|
tinymce: {
|
|
|
|
options: {
|
|
|
|
separator: '\n',
|
|
|
|
process: function( src, filepath ) {
|
|
|
|
return '// Source: ' + filepath.replace( BUILD_DIR, '' ) + '\n' + src;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
src: [
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/tiny_mce.js',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce-schema.min.js',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/themes/advanced/editor_template.js',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/plugins/*/editor_plugin.js',
|
|
|
|
BUILD_DIR + 'wp-includes/js/tinymce/mark_loaded.js'
|
|
|
|
],
|
|
|
|
dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
tinymce: {
|
|
|
|
options: {
|
|
|
|
mode: 'gzip',
|
|
|
|
level: 9
|
|
|
|
},
|
|
|
|
src: '<%= concat.tinymce.dest %>',
|
|
|
|
dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js.gz'
|
|
|
|
}
|
|
|
|
},
|
2013-08-07 07:25:25 +02:00
|
|
|
watch: {
|
|
|
|
all: {
|
|
|
|
files: [
|
|
|
|
SOURCE_DIR + '**',
|
|
|
|
// Ignore version control directories.
|
|
|
|
'!' + SOURCE_DIR + '**/.{svn,git}/**'
|
|
|
|
],
|
|
|
|
tasks: ['clean:dynamic', 'copy:dynamic'],
|
|
|
|
options: {
|
|
|
|
dot: true,
|
|
|
|
spawn: false,
|
|
|
|
interval: 2000
|
|
|
|
}
|
2013-08-30 06:06:34 +02:00
|
|
|
},
|
|
|
|
test: {
|
|
|
|
files: ['tests/qunit/**'],
|
|
|
|
tasks: ['qunit']
|
2013-08-07 07:25:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Register tasks.
|
2013-08-31 00:16:43 +02:00
|
|
|
grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core', 'uglify:core',
|
|
|
|
'uglify:tinymce', 'concat:tinymce', 'compress:tinymce', 'clean:tinymce']);
|
2013-08-07 07:25:25 +02:00
|
|
|
|
2013-08-30 06:06:34 +02:00
|
|
|
// Testing task.
|
|
|
|
grunt.registerTask('test', ['qunit']);
|
|
|
|
|
2013-08-07 07:25:25 +02:00
|
|
|
// Default task.
|
|
|
|
grunt.registerTask('default', ['build']);
|
|
|
|
|
|
|
|
// Add a listener to the watch task.
|
|
|
|
//
|
|
|
|
// On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic`
|
|
|
|
// configurations so that only the changed files are updated.
|
2013-08-31 00:16:43 +02:00
|
|
|
grunt.event.on('watch', function( action, filepath, target ) {
|
|
|
|
if ( target != 'all' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var relativePath = path.relative( SOURCE_DIR, filepath );
|
|
|
|
var cleanSrc = ( action == 'deleted' ) ? [relativePath] : [];
|
|
|
|
var copySrc = ( action == 'deleted' ) ? [] : [relativePath];
|
2013-08-07 07:25:25 +02:00
|
|
|
|
|
|
|
grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
|
|
|
|
grunt.config(['copy', 'dynamic', 'src'], copySrc);
|
|
|
|
});
|
|
|
|
};
|