#12 Get rid of wrench in favor of fs & fs-extra
This commit is contained in:
parent
05c40b8083
commit
c2bad1843c
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var gulp = require('gulp'),
|
var gulp = require('gulp'),
|
||||||
wrench = require('wrench'),
|
fs = require('fs'),
|
||||||
plumber = require('gulp-plumber');
|
plumber = require('gulp-plumber');
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
|
|
@ -17,8 +17,8 @@ var options = {
|
||||||
* Look for .js & .coffee files.
|
* Look for .js & .coffee files.
|
||||||
* Each file should correspond to a task.
|
* Each file should correspond to a task.
|
||||||
*/
|
*/
|
||||||
wrench
|
fs
|
||||||
.readdirSyncRecursive('./tasks')
|
.readdirSync('./tasks')
|
||||||
.filter(function readJSFiles(file) {
|
.filter(function readJSFiles(file) {
|
||||||
return (/\.(js|coffee)$/i).test(file);
|
return (/\.(js|coffee)$/i).test(file);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
11
package.json
11
package.json
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "responsive-html-email-signature",
|
"name": "responsive-html-email-signature",
|
||||||
"version": "4.0.0-rc.1",
|
"version": "4.0.0-rc.2",
|
||||||
"description": "Responsive template for email signatures",
|
"description": "Responsive template for email signatures",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -22,9 +22,10 @@
|
||||||
"url": "https://github.com/fadeit/responsive-html-email-signature/issues"
|
"url": "https://github.com/fadeit/responsive-html-email-signature/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/fadeit/responsive-html-email-signature#readme",
|
"homepage": "https://github.com/fadeit/responsive-html-email-signature#readme",
|
||||||
"devDependencies": {
|
"dependencies": {
|
||||||
"autoprefixer": "^6.3.6",
|
"autoprefixer": "^6.3.6",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
|
"fs-extra": "^0.30.0",
|
||||||
"gulp": "~3.9.1",
|
"gulp": "~3.9.1",
|
||||||
"gulp-autoprefixer": "^3.1.0",
|
"gulp-autoprefixer": "^3.1.0",
|
||||||
"gulp-david": "~0.4.2",
|
"gulp-david": "~0.4.2",
|
||||||
|
|
@ -38,8 +39,6 @@
|
||||||
"gulp-preprocess": "~2.0.0",
|
"gulp-preprocess": "~2.0.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
"gulp-sass": "^2.3.1",
|
"gulp-sass": "^2.3.1",
|
||||||
"q": "~1.4.1",
|
"q": "~1.4.1"
|
||||||
"wrench": "~1.5.8"
|
}
|
||||||
},
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
129
tasks/build.js
129
tasks/build.js
|
|
@ -6,83 +6,94 @@ var gulp = require('gulp'),
|
||||||
minifyInline = require('gulp-minify-inline'),
|
minifyInline = require('gulp-minify-inline'),
|
||||||
preprocess = require('gulp-preprocess'),
|
preprocess = require('gulp-preprocess'),
|
||||||
rename = require('gulp-rename'),
|
rename = require('gulp-rename'),
|
||||||
wrench = require('wrench'),
|
fsx = require('fs-extra'),
|
||||||
|
fs = require('fs'),
|
||||||
Q = require('q'),
|
Q = require('q'),
|
||||||
del = require('del'),
|
del = require('del'),
|
||||||
inlineimg = require('gulp-inline-image-html');
|
inlineimg = require('gulp-inline-image-html');
|
||||||
|
|
||||||
function buildTask(options){
|
function buildTask(options){
|
||||||
gulp.task('build', ['dupe', 'less', 'sass', 'postcss'], function build() {
|
gulp.task('build', ['dupe', 'less', 'sass', 'postcss'], function build() {
|
||||||
var promises = [];
|
|
||||||
|
|
||||||
/** 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.
|
||||||
*/
|
*/
|
||||||
function makeTemplates(dir, confItems){
|
function makeTemplates(dir, confItems){
|
||||||
confItems
|
confItems.forEach(function handleConf(conf){
|
||||||
.forEach(function handleConf(conf){
|
var cwd = options.workingDir + '/' + dir;
|
||||||
var cwd = options.workingDir + '/' + dir;
|
var stylesheets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find stylesheets relative to the CWD & generate <link> tags.
|
* Find stylesheets relative to the CWD & generate <link> tags.
|
||||||
* This way we can automagically inject them into <head>.
|
* This way we can automagically inject them into <head>.
|
||||||
*/
|
*/
|
||||||
conf.stylesheets = wrench
|
fsx
|
||||||
.readdirSyncRecursive(cwd)
|
.walk(cwd)
|
||||||
.filter(function filterFiles(file) {
|
.on('readable', function walkTemplateDir() {
|
||||||
/* Read only CSS files. */
|
var stylesheet;
|
||||||
return (file.match(/.*\.css/)) ? file : false;
|
|
||||||
})
|
|
||||||
.reduce(function(prev, current, index, acc){
|
|
||||||
return prev += '<link rel="stylesheet" href="' + current + '">';
|
|
||||||
}, '');
|
|
||||||
|
|
||||||
options
|
while (stylesheet = this.read()) {
|
||||||
.src([cwd + '/**/*.html', '!' + cwd + '/**/*.inc.html'])
|
var relativePath = __dirname.substring(0, __dirname.lastIndexOf('/')) + '/tmp/' + dir;
|
||||||
.pipe(preprocess({
|
stylesheets.push(stylesheet.path.replace(relativePath, ''));
|
||||||
context: conf
|
}
|
||||||
}))
|
})
|
||||||
.pipe(inlineimg(cwd))
|
.on('end', function finishedTemplateDirWalk() {
|
||||||
.pipe(inlineCss({
|
conf.stylesheets = stylesheets
|
||||||
applyTableAttributes: true,
|
.filter(function filterFiles(file) {
|
||||||
applyWidthAttributes: true,
|
/* Read only CSS files. */
|
||||||
preserveMediaQueries: true,
|
return (file.match(/.*\.css/)) ? true : false;
|
||||||
removeStyleTags: false
|
})
|
||||||
}))
|
.reduce(function(prev, current, index, acc){
|
||||||
.pipe(minifyHTML({quotes: true}))
|
return prev += '<link rel="stylesheet" href="' + current + '">';
|
||||||
.pipe(minifyInline())
|
}, '');
|
||||||
.pipe(rename(function rename(path){
|
|
||||||
path.dirname = dir;
|
options
|
||||||
path.basename += '-' + conf.id;
|
.src([cwd + '/**/*.html', '!' + cwd + '/**/*.inc.html'])
|
||||||
return path;
|
.pipe(preprocess({
|
||||||
}))
|
context: conf
|
||||||
.pipe(gulp.dest(options.dist));
|
}))
|
||||||
});
|
.pipe(inlineimg(cwd))
|
||||||
|
.pipe(inlineCss({
|
||||||
|
applyTableAttributes: true,
|
||||||
|
applyWidthAttributes: true,
|
||||||
|
preserveMediaQueries: true,
|
||||||
|
removeStyleTags: false
|
||||||
|
}))
|
||||||
|
.pipe(minifyHTML({quotes: true}))
|
||||||
|
.pipe(minifyInline())
|
||||||
|
.pipe(rename(function rename(path){
|
||||||
|
path.dirname = dir;
|
||||||
|
path.basename += '-' + conf.id;
|
||||||
|
return path;
|
||||||
|
}))
|
||||||
|
.pipe(gulp.dest(options.dist));
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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).then(function buildStart(){
|
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.
|
* 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.
|
||||||
wrench
|
*/
|
||||||
.readdirSyncRecursive('./' + options.workingDir)
|
var files = [];
|
||||||
.filter(function filterFiles(file) {
|
var promises = [];
|
||||||
/* Read only folders, skip files. */
|
|
||||||
return (!file.match('/') && !file.match(/^\.+/g)) ? file : false;
|
|
||||||
})
|
|
||||||
.forEach(function readConfigurations(dir){
|
|
||||||
/** NB: For 'watch' to properly work, the cache needs to be deleted before each require. */
|
|
||||||
var confPath = './../' + options.workingDir + '/' + dir + '/conf.js';
|
|
||||||
delete require.cache[require.resolve(confPath)];
|
|
||||||
promises.push(makeTemplates(dir, require(confPath)));
|
|
||||||
});
|
|
||||||
|
|
||||||
Q.all(promises);
|
fs
|
||||||
});
|
.readdirSync('./' + options.workingDir)
|
||||||
|
.forEach(function readConfigurations(dir){
|
||||||
|
/** NB: For 'watch' to properly work, the cache needs to be deleted before each require. */
|
||||||
|
var confPath = '../tmp/' + dir + '/conf.js';
|
||||||
|
delete require.cache[require.resolve(confPath)];
|
||||||
|
promises.push(makeTemplates(dir, require(confPath)));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Q.all(promises);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue