-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
188 lines (159 loc) · 4.55 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
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
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const config = require('./package.json');
//////////////////////////////////////////////
//
// Front-end build tasks
//
////////////////////////////////////////////////
// ----------------------------------------
//
// Styles: Compile scss to css and minify.
//
// ----------------------------------------
gulp.task('styles', function() {
gulp.src('./assets/src/scss/*.scss')
.pipe($.sass())
.pipe($.cleanCss())
.on('error', $.sass.logError)
.pipe( gulp.dest('./assets/build/css/') );
});
// ----------------------------------------
//
// Scripts: Minify js.
//
// ----------------------------------------
gulp.task('scripts', function() {
return gulp.src('./assets/src/js/*.js')
.pipe($.uglify())
.pipe(gulp.dest('./assets/build/js/'));
});
// ----------------------------------------
//
// Watch/Default: Watch asset folders for
// changes and rerun tasks as needed.
//
// ----------------------------------------
gulp.task('watch', function() {
gulp.watch('./assets/src/scss/**/*.scss', ['styles']);
gulp.watch('./assets/src/js/**/*.js', ['scripts']);
});
gulp.task('default', ['styles', 'scripts', 'watch']);
gulp.task('build', ['styles', 'scripts']);
//////////////////////////////////////////////
//
// Automated deployment to wp.org plugin repo
//
//////////////////////////////////////////////
const WP_REPO = 'http://plugins.svn.wordpress.org/stream-manager/';
const ENTRY_FILE = 'stream-manager.php';
const BUILD_FILES = [
'./assets/**/*',
'./includes/**/*',
'./README.txt',
'./README.md',
'./stream-manager.php'
];
// ----------------------------------------
//
// Git: Checkout the master branch from git
// and pull down the latest.
//
// ----------------------------------------
gulp.task('git:checkout', function(done) {
return $.git.checkout('master', function (err) {
if (err) throw err;
done();
});
});
gulp.task('git:pull', function(done) {
return $.git.pull('origin', 'master', function (err) {
if (err) throw err;
done();
});
});
gulp.task('git', $.sequence('git:checkout', 'git:pull'));
// ----------------------------------------
//
// Version: Update the version number and
// commit and push the update
//
// ----------------------------------------
gulp.task('version:plugin', function() {
return gulp.src([ENTRY_FILE], { base: './' })
.pipe($.replace(/(Version:\s+)([\d|.]+)/, '$1' + config.version))
.pipe(gulp.dest('.'));
});
gulp.task('version:readme', function() {
return gulp.src(['README.txt'], { base: './' })
.pipe($.replace(/(Stable tag:\s+)([\d|.]+)/, '$1' + config.version))
.pipe(gulp.dest('.'));
});
gulp.task('version:commit', function() {
return gulp.src([ENTRY_FILE, 'README.txt'])
.pipe($.git.commit('Updated version #'));
});
gulp.task('version:push', function() {
return $.git.push('origin', 'master', function (err) {
if (err) throw err;
});
})
gulp.task('version', $.sequence(
'version:plugin',
'version:readme',
'version:commit',
'version:push'
));
// ----------------------------------------
//
// Svn: Checkout the SVN repository from wp.org.
// Clean out what's already in the tag
// and trunk folders, copy our files into
// the svn repo, and commit the updates.
//
// ----------------------------------------
gulp.task('svn:checkout', function(done) {
return $.svn.checkout(WP_REPO, 'svn', function(err){
if(err) throw err;
done();
});
});
gulp.task('svn:delete', function() {
return gulp.src(['./svn/tags/' + config.version + '/*', './svn/trunk/*'], {read:false})
.pipe($.clean());
});
gulp.task('svn:copy', ['build'], function() {
return gulp.src(BUILD_FILES, { base: './' })
.pipe(gulp.dest('./svn/tags/' + config.version))
.pipe(gulp.dest('./svn/trunk'));
});
gulp.task('svn:add', function(done){
return $.svn.add('svn/*', {args: '--force'}, function(err){
if(err) throw err;
done();
});
});
gulp.task('svn:commit', function(done){
return $.svn.commit('Releasing tag ' + config.version, {cwd: './svn'}, function(err){
if(err) throw err;
done();
});
});
gulp.task('svn:cleanup', function() {
return gulp.src('./svn', {read:false})
.pipe($.clean());
});
gulp.task('svn', $.sequence(
'svn:checkout',
'svn:delete',
'svn:copy',
'svn:add',
'svn:commit',
'svn:cleanup'
));
// -------------------------------------
//
// Everything! Release the plugin to the wp plugin repo.
//
// -------------------------------------
gulp.task('release', $.sequence('git', 'version', 'svn'));