casper/gulpfile.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

const {series, watch, src, dest} = require('gulp');
const pump = require('pump');
2017-05-15 20:03:47 +00:00
// gulp plugins and utils
var livereload = require('gulp-livereload');
var postcss = require('gulp-postcss');
var zip = require('gulp-zip');
var uglify = require('gulp-uglify');
var beeper = require('beeper');
2017-05-15 20:03:47 +00: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');
function serve(done) {
livereload.listen();
done();
}
2017-05-15 20:03:47 +00:00
const handleError = (done) => {
return function (err) {
if (err) {
beeper();
}
return done(err);
};
};
function css(done) {
2017-05-15 20:03:47 +00:00
var processors = [
easyimport,
customProperties({preserve: false}),
2017-05-15 20:03:47 +00:00
colorFunction(),
autoprefixer({browsers: ['last 2 versions']}),
cssnano()
];
pump([
src('assets/css/*.css', {sourcemaps: true}),
postcss(processors),
dest('assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
}
function js(done) {
pump([
src('assets/js/*.js', {sourcemaps: true}),
uglify(),
dest('assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
}
2017-05-15 20:03:47 +00:00
function zipper(done) {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';
pump([
src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
]),
zip(filename),
dest(targetDir)
], handleError(done));
}
const watcher = () => watch('assets/css/**', css);
const build = series(css, js);
const dev = series(build, serve, watcher);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = dev;