-
Notifications
You must be signed in to change notification settings - Fork 139
/
gulpfile.js
226 lines (183 loc) · 6.43 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
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
/**
* Gulpfile.
* Project Configuration for gulp tasks.
*/
var pkg = require('./package.json');
var project = pkg.name;
var slug = pkg.slug;
var version = pkg.version;
var projectURL = 'http://demo.merlinwp.dev/wp-admin/themes.php?page=merlin';
// Translations.
var text_domain = '@@textdomain';
var destFile = slug+'.pot';
var packageName = project;
var bugReport = pkg.author_uri;
var lastTranslator = pkg.author;
var team = pkg.author_shop;
var translatePath = './languages/' + destFile;
var translatableFiles = ['./**/*.php', '!merlin-config-sample.php', '!merlin-filters-sample.php' ];
// Styles.
var merlinStyleSRC = './assets/scss/merlin.scss'; // Path to main .scss file.
var merlinStyleDestination = './assets/css/'; // Path to place the compiled CSS file.
var merlinCssFiles = './assets/css/**/*.css'; // Path to main .scss file.
var merlinStyleWatchFiles = './assets/scss/**/*.scss'; // Path to all *.scss files inside css folder and inside them.
// Scripts.
var merlinScriptSRC = './assets/js/merlin.js'; // Path to JS custom scripts folder.
var merlinScriptDestination = './assets/js/'; // Path to place the compiled JS custom scripts file.
var merlinScriptFile = 'merlin'; // Compiled JS file name.
var merlinScriptWatchFiles = './assets/js/*.js'; // Path to all *.scss files inside css folder and inside them.
// Watch files.
var projectPHPWatchFiles = ['./**/*.php', '!_dist'];
// Build files.
var buildFiles = ['./**', '!node_modules/**', '!dist/', '!demo/**', '!composer.json', '!composer.lock', '!.gitattributes', '!phpcs.xml', '!package.json', '!package-lock.json', '!gulpfile.js', '!LICENSE', '!README.md', '!assets/scss/**', '!merlin-config-sample.php', '!merlin-filters-sample.php', '!CODE_OF_CONDUCT.md' ];
var buildDestination = './dist/merlin/';
var distributionFiles = './dist/merlin/**/*';
// Browsers you care about for autoprefixing. https://github.com/ai/browserslist
const AUTOPREFIXER_BROWSERS = [
'last 2 version',
'> 1%',
'ie >= 9',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4',
'bb >= 10'
];
/**
* Load Plugins.
*/
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var cache = require('gulp-cache');
var cleaner = require('gulp-clean');
var copy = require('gulp-copy');
var csscomb = require('gulp-csscomb');
var filter = require('gulp-filter');
var lineec = require('gulp-line-ending-corrector');
var minifycss = require('gulp-clean-css');
var notify = require('gulp-notify');
var reload = browserSync.reload;
var rename = require('gulp-rename');
var replace = require('gulp-replace-task');
var runSequence = require('gulp-run-sequence');
var sass = require('gulp-sass');
var sort = require('gulp-sort');
var uglify = require('gulp-uglify');
var wpPot = require('gulp-wp-pot');
var zip = require('gulp-zip');
var composer = require('gulp-composer');
/**
* Development Tasks.
*/
gulp.task('clear', function () {
cache.clearAll();
});
gulp.task( 'browser_sync', function() {
browserSync.init( {
// Project URL.
proxy: projectURL,
// `true` Automatically open the browser with BrowserSync live server.
// `false` Stop the browser from automatically opening.
open: true,
// Inject CSS changes.
injectChanges: true,
});
});
gulp.task('styles', function () {
gulp.src( merlinStyleSRC )
.pipe( sass( {
errLogToConsole: true,
outputStyle: 'expanded',
precision: 10
} ) )
.on( 'error', console.error.bind( console ) )
.pipe( autoprefixer( AUTOPREFIXER_BROWSERS ) )
.pipe( csscomb() )
.pipe( gulp.dest( merlinStyleDestination ) )
.pipe( browserSync.stream() )
.pipe( rename( { suffix: '.min' } ) )
.pipe( minifycss( {
maxLineLen: 10
}))
.pipe( gulp.dest( merlinStyleDestination ) )
.pipe( browserSync.stream() )
});
gulp.task( 'scripts', function() {
gulp.src( merlinScriptSRC )
.pipe( rename( {
basename: merlinScriptFile,
suffix: '.min'
}))
.pipe( uglify() )
.pipe( lineec() )
.pipe( gulp.dest( merlinScriptDestination ) )
});
gulp.task( 'default', ['clear', 'styles', 'scripts', 'browser_sync' ], function () {
gulp.watch( projectPHPWatchFiles, reload );
gulp.watch( merlinStyleWatchFiles, [ 'styles' ] );
});
gulp.task("composer", function () {
composer({ "async": false });
});
/**
* Build Tasks.
*/
gulp.task( 'build-translate', function () {
gulp.src( translatableFiles )
.pipe( sort() )
.pipe( wpPot( {
domain : text_domain,
destFile : destFile,
package : project,
bugReport : bugReport,
lastTranslator: lastTranslator,
team : team
} ))
.pipe( gulp.dest( translatePath ) )
});
gulp.task( 'build-clean', function () {
return gulp.src( ['./dist/*'] , { read: false } )
.pipe(cleaner());
});
gulp.task( 'build-copy', ['build-clean', 'composer'], function() {
return gulp.src( buildFiles )
.pipe( copy( buildDestination ) );
});
gulp.task( 'build-clean-and-copy', ['build-clean', 'build-copy' ], function () { } );
gulp.task('build-variables', ['build-clean-and-copy'], function () {
return gulp.src( distributionFiles )
.pipe( replace( {
patterns: [
{
match: 'pkg.version',
replacement: version
},
{
match: 'textdomain',
replacement: pkg.textdomain
}
]
}))
.pipe( gulp.dest( buildDestination ) );
});
gulp.task( 'build-zip', ['build-variables'] , function() {
return gulp.src( buildDestination+'/**' , { base: 'dist' } )
.pipe( zip( 'merlin.zip' ) )
.pipe( gulp.dest( './dist/' ) );
});
gulp.task( 'build-clean-after-zip', ['build-zip'], function () {
return gulp.src( [ buildDestination, '!/dist/' + slug + '-wp.zip'] , { read: false } )
.pipe(cleaner());
});
gulp.task( 'build-zip-and-clean', ['build-zip', 'build-clean-after-zip' ], function () { } );
gulp.task( 'build-notification', function () {
return gulp.src( '' )
.pipe( notify( { message: 'Your build of ' + packageName + ' is complete.', onLast: true } ) );
});
gulp.task('build', function(callback) {
runSequence( 'clear', 'build-clean', ['styles', 'scripts', 'build-translate'], 'build-clean-and-copy', 'build-variables', 'build-zip-and-clean', 'build-notification', callback);
});