2017-05-15 20:03:47 +00:00
|
|
|
var gulp = require('gulp');
|
|
|
|
|
|
|
|
// gulp plugins and utils
|
|
|
|
var gutil = require('gulp-util');
|
|
|
|
var livereload = require('gulp-livereload');
|
|
|
|
var postcss = require('gulp-postcss');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
2017-09-18 16:37:00 +00:00
|
|
|
var zip = require('gulp-zip');
|
2018-10-08 11:04:07 +00:00
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
var filter = require('gulp-filter');
|
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');
|
|
|
|
|
|
|
|
var swallowError = function swallowError(error) {
|
|
|
|
gutil.log(error.toString());
|
|
|
|
gutil.beep();
|
|
|
|
this.emit('end');
|
|
|
|
};
|
|
|
|
|
|
|
|
var nodemonServerInit = function () {
|
|
|
|
livereload.listen(1234);
|
|
|
|
};
|
|
|
|
|
2018-10-12 05:41:06 +00:00
|
|
|
gulp.task('build', ['css', 'js'], function (/* cb */) {
|
2017-05-15 20:03:47 +00:00
|
|
|
return nodemonServerInit();
|
|
|
|
});
|
|
|
|
|
2018-10-12 05:41:06 +00:00
|
|
|
gulp.task('generate', ['css', 'js']);
|
|
|
|
|
2017-05-15 20:03:47 +00:00
|
|
|
gulp.task('css', function () {
|
|
|
|
var processors = [
|
|
|
|
easyimport,
|
|
|
|
customProperties,
|
|
|
|
colorFunction(),
|
|
|
|
autoprefixer({browsers: ['last 2 versions']}),
|
|
|
|
cssnano()
|
|
|
|
];
|
2017-09-18 16:37:00 +00:00
|
|
|
|
|
|
|
return gulp.src('assets/css/*.css')
|
2017-05-15 20:03:47 +00:00
|
|
|
.on('error', swallowError)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(postcss(processors))
|
|
|
|
.pipe(sourcemaps.write('.'))
|
2017-06-16 12:23:03 +00:00
|
|
|
.pipe(gulp.dest('assets/built/'))
|
2017-05-15 20:03:47 +00:00
|
|
|
.pipe(livereload());
|
|
|
|
});
|
|
|
|
|
2018-10-12 05:41:06 +00:00
|
|
|
gulp.task('js', function () {
|
|
|
|
var jsFilter = filter(['**/*.js'], {restore: true});
|
|
|
|
|
|
|
|
return gulp.src('assets/js/*.js')
|
|
|
|
.on('error', swallowError)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(jsFilter)
|
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(jsFilter.restore)
|
|
|
|
.pipe(sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest('assets/built/'))
|
|
|
|
.pipe(livereload());
|
|
|
|
});
|
|
|
|
|
2017-05-15 20:03:47 +00:00
|
|
|
gulp.task('watch', function () {
|
|
|
|
gulp.watch('assets/css/**', ['css']);
|
|
|
|
});
|
|
|
|
|
2018-10-12 05:41:06 +00:00
|
|
|
gulp.task('zip', ['css', 'js'], function () {
|
2017-09-18 16:37:00 +00:00
|
|
|
var targetDir = 'dist/';
|
|
|
|
var themeName = require('./package.json').name;
|
|
|
|
var filename = themeName + '.zip';
|
|
|
|
|
2017-10-23 09:52:52 +00:00
|
|
|
return gulp.src([
|
|
|
|
'**',
|
|
|
|
'!node_modules', '!node_modules/**',
|
2017-10-24 11:08:26 +00:00
|
|
|
'!dist', '!dist/**'
|
2017-10-23 09:52:52 +00:00
|
|
|
])
|
2017-09-18 16:37:00 +00:00
|
|
|
.pipe(zip(filename))
|
|
|
|
.pipe(gulp.dest(targetDir));
|
|
|
|
});
|
|
|
|
|
2017-05-15 20:03:47 +00:00
|
|
|
gulp.task('default', ['build'], function () {
|
|
|
|
gulp.start('watch');
|
|
|
|
});
|