Refactor build to use native promises

This commit is contained in:
Dan Mindru 2019-09-03 10:42:46 +02:00
parent d8baffdca4
commit 41f6dced8f
3 changed files with 64 additions and 37 deletions

55
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "responsive-html-email-signature",
"version": "5.0.0",
"version": "5.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -4011,7 +4011,8 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
"bundled": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@ -4029,11 +4030,13 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -4046,15 +4049,18 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -4157,7 +4163,8 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true
"bundled": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -4167,6 +4174,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -4179,17 +4187,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
"bundled": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -4206,6 +4217,7 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -4278,7 +4290,8 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -4288,6 +4301,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -4363,7 +4377,8 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true
"bundled": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@ -4393,6 +4408,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -4410,6 +4426,7 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -4448,11 +4465,13 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true
"bundled": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true
"bundled": true,
"optional": true
}
}
},
@ -8808,7 +8827,8 @@
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"gauge": {
"version": "2.6.0",
@ -8844,6 +8864,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -8853,26 +8874,30 @@
"code-point-at": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
},
"dependencies": {
"number-is-nan": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
}
}
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
},
"dependencies": {
"number-is-nan": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
}
}
}

View File

@ -41,16 +41,16 @@
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2",
"klaw": "^3.0.0",
"node-sass": "^4.12.0",
"q": "^1.5.1"
"node-sass": "^4.12.0"
},
"resolutions": {
"graceful-fs": "^4.1.15"
},
"scripts": {
"create": "gulp",
"start": "gulp",
"once": "gulp run-pipeline",
"deploy": "npm run test && cp -r dist demo && git push origin `git subtree split --prefix demo develop`:gh-pages --force",
"test": "node ./node_modules/.bin/ava"
"test": "npm run once && node ./node_modules/.bin/ava"
},
"devDependencies": {
"ava": "^2.3.0"

View File

@ -8,7 +8,6 @@ const gulp = require('gulp'),
rename = require('gulp-rename'),
klaw = require('klaw'),
fs = require('fs'),
Q = require('q'),
del = require('del'),
jsonlint = require('jsonlint'),
inlineimg = require('gulp-inline-images-no-http'),
@ -19,7 +18,9 @@ function buildTask(options) {
gulp.task(
'build',
function build(done) {
/** Makes templates for a given directory & its configurations.
/**
* Makes templates for a given directory & its configurations.
*
* @function makeTemplates
* @param {String} dir Directory to make templates from.
* @param {Array} confItems A list of configurations objects (usually persons) to make templates from.
@ -43,22 +44,23 @@ function buildTask(options) {
}
})
.on('end', function finishedTemplateDirWalk() {
conf.stylesheets = stylesheets
.filter(function filterFiles(file) {
const context = {
...conf,
stylesheets: stylesheets
.filter(function filterFiles (file) {
/* Read only CSS files. */
return file.match(/.*\.css/) ? true : false;
})
.reduce(function(prev, current, index, acc) {
.reduce(function (prev, current, index, acc) {
var cssPath = path.win32.basename(current);
return (prev += '<link rel="stylesheet" href="' + cssPath + '">');
}, '');
}, '')
}
options
.src([cwd + '/**/*.html', '!' + cwd + '/**/*.inc.html'])
.pipe(
preprocess({
context: conf
})
preprocess({ context })
)
.pipe(inlineimg())
.pipe(
@ -83,12 +85,12 @@ function buildTask(options) {
});
}
/** Clean up & then read 'src' to generate templates (build entry point). */
del(options.dist)
/* Clean up & then read 'src' to generate templates (build entry point). */
return del(options.dist)
.then(function buildStart() {
/**
* Loop through dirs and load their conf files.
* Promisify all 'makeTemplate' calls and when resolved, make a call to the task (`cb`) to let gulp know we're done.
* Promisify all 'makeTemplate' calls and when resolved, let gulp know we're done.
*/
var files = [];
var promises = [];
@ -110,7 +112,7 @@ function buildTask(options) {
promises.push(makeTemplates(dir, confItems));
});
Q.all(promises);
Promise.all(promises);
})
.then(() => done())
.catch((err) => console.log(err));