This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
162 lines (142 loc) · 3.74 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
// General.
var pkg = require('./package.json');
var project = pkg.name;
var title = pkg.title;
// Build.
var buildZipDestination = './build/';
var buildFiles = ['./**', '!build', '!build/**', '!node_modules/**', '!*.json', '!*.map', '!*.xml', '!gulpfile.js', '!*.sublime-project', '!*.sublime-workspace', '!*.sublime-gulp.cache', '!*.log', '!*.DS_Store', '!*.gitignore', '!TODO', '!*.git', '!*.ftppass', '!*.DS_Store', '!sftp.json', '!yarn.lock', '!*.md', '!package.lock'];
var cleanFiles = ['./build/'+project+'/', './build/'+project+' 2/', './build/'+project+'.zip' ];
var buildDestination = './build/'+project+'/';
var buildDestinationFiles = './build/'+project+'/**/*';
// Translation.
var text_domain = '@@textdomain';
var destFile = project+'.pot';
var packageName = pkg.title;
var bugReport = pkg.author_uri;
var lastTranslator = pkg.author;
var team = pkg.author_shop;
var translatePath = './languages';
var translatableFiles = ['./**/*.php'];
// Release.
var cleanSrcFiles = ['./build/'+project+'/src/'];
/**
* Load Plugins.
*/
var gulp = require('gulp');
var del = require('del');
var notify = require('gulp-notify');
var replace = require('gulp-replace-task');
var zip = require('gulp-zip');
var copy = require('gulp-copy');
var cache = require('gulp-cache');
var gulpif = require('gulp-if');
var wpPot = require('gulp-wp-pot');
/**
* Tasks.
*/
gulp.task('clearCache', function(done) {
cache.clearAll();
done();
});
gulp.task('clean', function(done) {
return del( cleanFiles );
done();
});
gulp.task('cleanSrc', function(done) {
return del( cleanSrcFiles );
done();
});
gulp.task('copy', function(done) {
return gulp.src( buildFiles )
.pipe( copy( buildDestination ) );
done();
});
gulp.task( 'updateVersion', function(done) {
return gulp.src( './*.php' )
.pipe( replace( {
patterns: [
{
match: /(\d+\.+\d+\.+\d)/,
replacement: pkg.version
},
],
usePrefix: false
} ) )
.pipe( gulp.dest( './' ) );
done();
});
gulp.task('variables', function(done) {
return gulp.src( buildDestinationFiles )
.pipe(replace({
patterns: [
{
match: 'pkg.name',
replacement: project
},
{
match: 'pkg.title',
replacement: pkg.title
},
{
match: 'pkg.version',
replacement: pkg.version
},
{
match: 'pkg.author',
replacement: pkg.author
},
{
match: 'pkg.author_shop',
replacement: pkg.author_shop
},
{
match: 'pkg.license',
replacement: pkg.license
},
{
match: 'textdomain',
replacement: pkg.name
},
{
match: 'pkg.description',
replacement: pkg.description
},
{
match: 'pkg.tested_up_to',
replacement: pkg.tested_up_to
}
]
}))
.pipe(gulp.dest( buildDestination ));
done();
});
gulp.task( 'translate', function (done) {
return gulp.src( translatableFiles )
.pipe( wpPot( {
domain : text_domain,
destFile : destFile,
package : project,
bugReport : bugReport,
lastTranslator: lastTranslator,
team : team
} ))
.pipe( gulp.dest( translatePath ) )
done();
});
gulp.task('zip', function(done) {
return gulp.src( buildDestination + '/**', { base: 'build' } )
.pipe( zip( project + '.zip' ) )
.pipe( gulp.dest( buildZipDestination ) );
done();
});
/**
* Release Tasks.
*/
gulp.task( 'release-notice', function(done) {
return gulp.src( './' )
.pipe( notify( { message: 'The v' + pkg.version + ' release of ' + title + ' has been built.', onLast: false } ) )
done();
});
gulp.task('build', gulp.series( 'clearCache', 'clean', 'updateVersion', 'copy', 'cleanSrc', 'variables', 'translate', 'zip', 'release-notice', function(done) {
done();
} ) );