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

View File

@ -41,16 +41,16 @@
"gulp-rename": "^1.4.0", "gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2", "gulp-sass": "^4.0.2",
"klaw": "^3.0.0", "klaw": "^3.0.0",
"node-sass": "^4.12.0", "node-sass": "^4.12.0"
"q": "^1.5.1"
}, },
"resolutions": { "resolutions": {
"graceful-fs": "^4.1.15" "graceful-fs": "^4.1.15"
}, },
"scripts": { "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", "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": { "devDependencies": {
"ava": "^2.3.0" "ava": "^2.3.0"

View File

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