Skip to content

Commit

Permalink
Use promises for callbacks (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnCuppens authored Oct 4, 2019
1 parent a285c28 commit 643d632
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
9 changes: 5 additions & 4 deletions lib/gulp/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const plumber = require('gulp-plumber');
const config = require('./config.js');

// CSS task
function css(cb) {
config.scss.forEach(scss => {
cssCompile({src: config.src_base_path + scss.src, dest: config.dest_base_path + scss.dest});
function css() {
const tasks = config.scss.map(scss => {
return cssCompile({src: config.src_base_path + scss.src, dest: config.dest_base_path + scss.dest});
});
cb();

return Promise.all(tasks);
}

async function getPostCSSConfiguration() {
Expand Down
14 changes: 8 additions & 6 deletions lib/gulp/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ const plumber = require('gulp-plumber');
const config = require('./config.js');

// CSS task
function img(cb) {
config.img.forEach(img => {
imgCompile({src: config.src_base_path + img.src, dest: config.dest_base_path + img.dest});
function img() {
const imgTasks = config.img.map(img => {
return imgCompile({src: config.src_base_path + img.src, dest: config.dest_base_path + img.dest});
});
config['svg-sprite'].forEach(svg => {
svgSprite({src: config.src_base_path + svg.src, dest: config.dest_base_path + svg.dest, name: svg.name});

const spriteTasks = config['svg-sprite'].map(svg => {
return svgSprite({src: config.src_base_path + svg.src, dest: config.dest_base_path + svg.dest, name: svg.name});
});
cb();

return Promise.all(imgTasks.concat(spriteTasks));
}

// Optimize Images
Expand Down
13 changes: 7 additions & 6 deletions lib/gulp/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ const gulp = require('gulp');
const plumber = require('gulp-plumber');
const config = require('./config.js');

function js(cb) {
config.js.forEach(js => {
jsCompile({src: config.src_base_path + js.src, dest: config.dest_base_path + js.dest});
function js() {
const jsTasks = config.js.map(js => {
return jsCompile({src: config.src_base_path + js.src, dest: config.dest_base_path + js.dest});
});

config['js-concat'].forEach(js => {
jsConcat({src: config.src_base_path + js.src, dest: config.dest_base_path + js.dest, name: js.name});
const jsConcatTasks = config['js-concat'].map(js => {
return jsConcat({src: config.src_base_path + js.src, dest: config.dest_base_path + js.dest, name: js.name});
});
cb();

return Promise.all(jsTasks.concat(jsConcatTasks));
}

function jsCompile({src, dest, browserSync = false}) {
Expand Down

0 comments on commit 643d632

Please sign in to comment.