Skip to content

Commit

Permalink
(2.9.2) Updated gulp to handle errors for every stream
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Andy <[email protected]>
  • Loading branch information
pascalandy committed Feb 12, 2019
1 parent 6e35f35 commit 265453f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
74 changes: 41 additions & 33 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var gulp = require('gulp');
var pump = require('pump');

// gulp plugins and utils
var gutil = require('gulp-util');
var livereload = require('gulp-livereload');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');
var beeper = require('beeper');

// postcss plugins
var autoprefixer = require('autoprefixer');
Expand All @@ -16,23 +17,26 @@ 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);
};

function handleError(done) {
return function (err) {
if (err) {
beeper();
}
return done(err);
};
}

gulp.task('build', ['css', 'js'], function (/* cb */) {
return nodemonServerInit();
});

gulp.task('generate', ['css', 'js']);

gulp.task('css', function () {
gulp.task('css', function (done) {
var processors = [
easyimport,
customProperties,
Expand All @@ -41,45 +45,49 @@ gulp.task('css', function () {
cssnano()
];

return gulp.src('assets/css/*.css')
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
.pipe(livereload());
pump([
gulp.src('assets/css/*.css'),
sourcemaps.init(),
postcss(processors),
sourcemaps.write('.'),
gulp.dest('assets/built/'),
livereload()
], handleError(done));
});

gulp.task('js', function () {
gulp.task('js', function (done) {
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());
pump([
gulp.src('assets/js/*.js'),
sourcemaps.init(),
jsFilter,
uglify(),
jsFilter.restore,
sourcemaps.write('.'),
gulp.dest('assets/built/'),
livereload()
], handleError(done));
});

gulp.task('watch', function () {
gulp.watch('assets/css/**', ['css']);
});

gulp.task('zip', ['css', 'js'], function () {
gulp.task('zip', ['css', 'js'], function (done) {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';

return gulp.src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
])
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
pump([
gulp.src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
]),
zip(filename),
gulp.dest(targetDir)
], handleError(done));
});

gulp.task('default', ['build'], function () {
Expand Down
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@
"bugs": "https://github.com/firepress-org/FirePress_Klimax2/issues",
"contributors": "https://github.com/TryGhost/Casper/graphs/contributors",
"devDependencies": {
"autoprefixer": "6.3.6",
"cssnano": "3.7.1",
"gscan": "^2.0.0",
"gulp": "3.9.1",
"gulp-livereload": "3.8.1",
"gulp-postcss": "6.1.1",
"gulp-sourcemaps": "1.6.0",
"gulp-util": "3.0.7",
"gulp-watch": "4.3.8",
"gulp-zip": "4.0.0",
"postcss-color-function": "2.0.1",
"postcss-custom-properties": "5.0.1",
"postcss-easy-import": "1.0.1",
"gulp-filter": "5.1.0",
"gulp-uglify": "3.0.1"
"autoprefixer": "6.3.6",
"beeper": "^1.1.1",
"cssnano": "3.7.1",
"gscan": "^2.0.0",
"gulp": "3.9.1",
"gulp-filter": "5.1.0",
"gulp-livereload": "3.8.1",
"gulp-postcss": "6.1.1",
"gulp-sourcemaps": "1.6.0",
"gulp-uglify": "3.0.1",
"gulp-watch": "4.3.8",
"gulp-zip": "4.0.0",
"postcss-color-function": "2.0.1",
"postcss-custom-properties": "5.0.1",
"postcss-easy-import": "1.0.1",
"pump": "3.0.0"
},
"config": {
"posts_per_page": 25,
Expand Down

0 comments on commit 265453f

Please sign in to comment.