-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGruntfile.js
155 lines (145 loc) · 3.87 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*global module:false*/
module.exports = function(grunt) {
var path = require('path');
var SOURCE_DIR = 'src/';
var BUILD_DIR = 'build/';
// Project configuration.
grunt.initConfig({
clean: {
all: [BUILD_DIR],
dynamic: {
dot: true,
expand: true,
cwd: BUILD_DIR,
src: []
},
svn: [SOURCE_DIR]
},
copy: {
all: {
dot: true,
expand: true,
cwd: SOURCE_DIR,
src: ['**','!**/.{svn,git}/**'], // Ignore version control directories.
dest: BUILD_DIR
},
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'
]
}
},
svn: {
core: {
repository: 'https://core.svn.wordpress.org/trunk/',
dest: SOURCE_DIR
}
},
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',
// 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',
'!wp-includes/js/underscore.min.js'
]
},
tinymce: {
expand: true,
cwd: SOURCE_DIR,
dest: BUILD_DIR,
src: [
'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js',
'wp-includes/js/tinymce/plugins/wp*/editor_plugin_src.js'
],
// 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) {
destPath = destPath.replace('/editor_plugin_src.js', '/editor_plugin.js');
return path.join(destBase || '', destPath);
}
}
},
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
}
}
}
});
// Load tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Register tasks.
grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core',
'uglify:core', 'uglify:tinymce']);
// Add a temporary setup task for preparing the directory using existing repositories.
grunt.registerTask('setup', ['clean:all', 'svn']);
// Add an svn task for checking out repositories.
grunt.registerMultiTask('svn', 'Check out a Subversion repository.', function() {
var done = this.async();
var args = ['checkout', '--ignore-externals', this.data.repository];
if (this.data.dest) {
args.push(this.data.dest);
}
grunt.util.spawn({
cmd: 'svn',
args: args,
opts: {stdio: 'inherit'}
}, done);
});
// 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.
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];
grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
grunt.config(['copy', 'dynamic', 'src'], copySrc);
});
};