2017-05-15 16:03:47 -04:00
|
|
|
var gulp = require('gulp');
|
2019-01-22 06:00:10 -05:00
|
|
|
var pump = require('pump');
|
2017-05-15 16:03:47 -04:00
|
|
|
|
|
|
|
// gulp plugins and utils
|
|
|
|
var livereload = require('gulp-livereload');
|
|
|
|
var postcss = require('gulp-postcss');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
2017-09-18 12:37:00 -04:00
|
|
|
var zip = require('gulp-zip');
|
2018-10-08 07:04:07 -04:00
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
var filter = require('gulp-filter');
|
2019-01-22 06:00:10 -05:00
|
|
|
var beeper = require('beeper');
|
2017-05-15 16:03:47 -04:00
|
|
|
|
|
|
|
// postcss plugins
|
|
|
|
var autoprefixer = require('autoprefixer');
|
|
|
|
var colorFunction = require('postcss-color-function');
|
|
|
|
var cssnano = require('cssnano');
|
|
|
|
var customProperties = require('postcss-custom-properties');
|
|
|
|
var easyimport = require('postcss-easy-import');
|
|
|
|
|
|
|
|
var nodemonServerInit = function () {
|
|
|
|
livereload.listen(1234);
|
|
|
|
};
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
function handleError(done) {
|
|
|
|
return function (err) {
|
|
|
|
if (err) {
|
|
|
|
beeper();
|
|
|
|
}
|
|
|
|
return done(err);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:41:06 -04:00
|
|
|
gulp.task('build', ['css', 'js'], function (/* cb */) {
|
2017-05-15 16:03:47 -04:00
|
|
|
return nodemonServerInit();
|
|
|
|
});
|
|
|
|
|
2018-10-12 01:41:06 -04:00
|
|
|
gulp.task('generate', ['css', 'js']);
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
gulp.task('css', function (done) {
|
2017-05-15 16:03:47 -04:00
|
|
|
var processors = [
|
|
|
|
easyimport,
|
|
|
|
customProperties,
|
|
|
|
colorFunction(),
|
|
|
|
autoprefixer({browsers: ['last 2 versions']}),
|
|
|
|
cssnano()
|
|
|
|
];
|
2017-09-18 12:37:00 -04:00
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
|
|
|
gulp.src('assets/css/*.css'),
|
|
|
|
sourcemaps.init(),
|
|
|
|
postcss(processors),
|
|
|
|
sourcemaps.write('.'),
|
|
|
|
gulp.dest('assets/built/'),
|
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
2017-05-15 16:03:47 -04:00
|
|
|
});
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
gulp.task('js', function (done) {
|
2018-10-12 01:41:06 -04:00
|
|
|
var jsFilter = filter(['**/*.js'], {restore: true});
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
|
|
|
gulp.src('assets/js/*.js'),
|
|
|
|
sourcemaps.init(),
|
|
|
|
jsFilter,
|
|
|
|
uglify(),
|
|
|
|
jsFilter.restore,
|
|
|
|
sourcemaps.write('.'),
|
|
|
|
gulp.dest('assets/built/'),
|
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
2018-10-12 01:41:06 -04:00
|
|
|
});
|
|
|
|
|
2017-05-15 16:03:47 -04:00
|
|
|
gulp.task('watch', function () {
|
|
|
|
gulp.watch('assets/css/**', ['css']);
|
|
|
|
});
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
gulp.task('zip', ['css', 'js'], function (done) {
|
2017-09-18 12:37:00 -04:00
|
|
|
var targetDir = 'dist/';
|
|
|
|
var themeName = require('./package.json').name;
|
|
|
|
var filename = themeName + '.zip';
|
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
|
|
|
gulp.src([
|
|
|
|
'**',
|
|
|
|
'!node_modules', '!node_modules/**',
|
|
|
|
'!dist', '!dist/**'
|
|
|
|
]),
|
|
|
|
zip(filename),
|
|
|
|
gulp.dest(targetDir)
|
|
|
|
], handleError(done));
|
2017-09-18 12:37:00 -04:00
|
|
|
});
|
|
|
|
|
2017-05-15 16:03:47 -04:00
|
|
|
gulp.task('default', ['build'], function () {
|
|
|
|
gulp.start('watch');
|
|
|
|
});
|