-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
91 lines (74 loc) · 2.1 KB
/
gulpfile.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
/* global require */
var gulp = require('gulp');
var less = require('gulp-less');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var readme = require('gulp-readme-to-markdown');
var del = require('del');
var path = require('path');
var merge = require('merge-stream');
// Return the foldername of a given file path.
function getSubdir(file) {
var dir = path.dirname(path.normalize(file));
return ('.' === dir) ? '' : dir;
}
// Run less, js and readme task and watch them for changes afterwards.
gulp.task('default', ['less', 'js', 'readme'], function() {
gulp.watch(['./js/*.js', '!./js/*.min.js'], ['js']);
gulp.watch('./styles/*.less', ['less']);
gulp.watch('./readme.txt', ['readme']);
});
// Compile and minify all *.less files in ./styles as *.css
gulp.task('less', function () {
return gulp.src(['./styles/*.less', '!**/_*.less'])
.pipe(less({
cleancss: true
}))
.pipe(gulp.dest('./styles/'));
});
// Minify all *.js files in ./js as *.min.js
gulp.task('js', function() {
return gulp.src([ './js/*.js', '!./js/*.min.js' ])
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./js'));
});
// Generate README.md etc from the WordPress readme.txt
gulp.task('readme', function() {
return gulp.src([ 'readme.txt' ])
.pipe(readme({
details: false,
screenshot_ext: 'jpg',
extract: {
'Changelog': 'CHANGELOG',
'Frequently Asked Questions': 'FAQ',
'Screenshots': null
}
}))
.pipe(gulp.dest('.'));
});
// Copy everything needed for a SVN release to the /build directory.
gulp.task('build', ['js', 'less', 'readme'], function() {
function copy() {
var sources = [
'img/*',
'js/*',
'lng/*',
'php/*',
'styles/*.css',
'*.php',
'*.txt',
'*.md'
];
var streams = [], stream;
sources.forEach(function(source) {
var dir = getSubdir(source);
stream = gulp.src(source).pipe(gulp.dest('./build/' + dir));
streams.push(stream);
});
return merge(streams);
}
return del('./build', copy);
});