-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
228 lines (208 loc) · 6.21 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
'use strict';
module.exports = function(grunt) {
// Initialize configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: [
'js/**/*.js',
],
options: {
expr: true,
globals: {
jQuery: true,
console: true,
module: true,
document: true,
},
},
},
jscs: {
src: [
'js/**/*.js'
],
options: {}
},
copy: {
main: {
files: [{
expand: true,
nonull: true,
src: [
'readme.txt',
//'CHANGELOG.md',
'*.php',
'includes/**',
'admin/**',
'!**/scss/**',
],
dest: 'build/'
}],
},
},
clean: {
build: ["build/*"],
},
wp_deploy: {
options: {
svn_url: "https://plugins.svn.wordpress.org/{plugin-slug}/",
plugin_slug: 'wp-content-security-policy',
// svn_user: 'your-wp-repo-username',
build_dir: 'build', //relative path to your build directory
assets_dir: 'wp-assets', //relative path to your assets directory (optional).
max_buffer: 1024 * 1024
},
release: {
// nothing
},
trunk: {
options: {
deploy_trunk: true,
deploy_tag: false,
}
},
assets: {
options: {
deploy_trunk: false,
deploy_tag: false,
}
}
},
delegate: {
sass: {
src: ['<%= sass.dev.files.src %>**/*.scss'],
dest: '<%= sass.dev.files.dest %>'
}
},
sass: {
dist: {
options: {
outputStyle: 'compressed',
sourceComments: false,
sourcemap: 'none'
},
files: [{
expand: true,
cwd: 'admin/scss',
src: ['*.scss'],
dest: 'build/admin/css',
ext: '.min.css'
}
]
},
dev: {
options: {
outputStyle: 'expanded',
sourceComments: false,
sourceMapEmbed: true,
},
files: [{
expand: true,
cwd: 'admin/scss',
src: ['*.scss'],
dest: 'admin/css',
ext: '.css'
}
]
}
},
postcss: {
options: {
map: true, // inline sourcemaps.
processors: [
require('autoprefixer')({
browsers: ['>1%', 'last 2 versions', 'IE 9', 'IE 10']
}) // add vendor prefixes
]
},
dev: {
files: [{
expand: true,
cwd: 'admin/css',
src: ['**/*.css'],
dest: 'admin/css',
ext: '.css'
}]
},
dist: {
files: [{
expand: true,
cwd: 'build/admin/css',
src: ['**/*.css'],
dest: 'build/admin/css',
ext: '.css'
}]
}
},
// uglify targets are dynamically generated by the minify task
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= ugtargets[grunt.task.current.target].filename %> <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %> */\n',
report: 'min',
},
},
minify: {
dist: {
files: grunt.file.expandMapping(['admin/js/**/*.js', '!admin/js/**/*.min.js'], '', {
rename: function(destBase, destPath) {
return destBase + destPath.replace('.js', '.min.js');
}
})
},
},
});
// load all standard tasks
require('load-grunt-tasks')(grunt, {
scope: 'devDependencies'
});
// delegate stuff
grunt.registerTask('delegate', function() {
grunt.task.run(this.args.join(':'));
});
// dynamically generate uglify targets
grunt.registerMultiTask('minify', function() {
this.files.forEach(function(file) {
var path = file.src[0],
target = path.match(/([^.]*)\.js/)[1];
// store some information about this file in config
grunt.config('ugtargets.' + target, {
path: path,
filename: path.split('/').pop()
});
// create and run an uglify target for this file
grunt.config('uglify.' + target + '.files', [{
src: [path],
dest: path.replace(/^(.*)\.js$/, '$1.min.js')
}]);
grunt.task.run('uglify:' + target);
});
});
grunt.registerTask('build', [
'clean:build',
'newer:sass:dist',
'newer:postcss:dist',
'newer:minify',
'copy:main',
]);
grunt.registerTask('deploy', [
'jscs',
'build',
'wp_deploy:release'
]);
grunt.registerTask('trunk', [
'build',
'wp_deploy:trunk'
]);
grunt.registerTask('assets', [
'clean:build',
'copy:main',
'copy:meta',
'wp_deploy:assets'
]);
grunt.registerTask('default', [
'jscs',
'newer:delegate:sass:dev',
'newer:postcss:dev',
'newer:minify'
]);
};