Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from tdeNL/feature/recursive-subdir
Browse files Browse the repository at this point in the history
Added recursive sub directory support
  • Loading branch information
jordikroon authored Jan 29, 2018
2 parents 775bbe1 + 3ae26dc commit d3007d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tde-webpack-mjml-plugin",
"version": "1.0.4",
"version": "1.1.0",
"description": "Webpack MJML plugin for converting MJML files to a given location",
"main": "index.js",
"repository": "https://github.com/tdeNL/tde-webpack-mjml-plugin",
Expand All @@ -13,8 +13,9 @@
"webpack": "2 || 3"
},
"dependencies": {
"lodash": "^4.17.4",
"fs-extra": "^5.0.0",
"glob": "^7.1.2",
"lodash": "^4.17.4",
"mjml": "^3.3.5"
}
}
20 changes: 19 additions & 1 deletion src/webpack-mjml-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const mjmlEngine = require('mjml');
const glob = require('glob');
const fs = require('fs');
const fs = require('fs-extra');
const _ = require('lodash');

/**
Expand Down Expand Up @@ -42,6 +42,7 @@ WebpackMjmlStore.prototype.apply = function (compiler) {
.replace('.mjml', that.options.extension);

that.convertFile(file)
.then((contents) => that.ensureFileExists(outputFile, contents))
.then((contents) => that.writeFile(outputFile, contents))
.then(callback());
}
Expand Down Expand Up @@ -87,6 +88,23 @@ WebpackMjmlStore.prototype.writeFile = function (file, contents) {
});
};

/**
* @param file
* @param contents
* @returns {Promise}
*/
WebpackMjmlStore.prototype.ensureFileExists = function (file, contents) {
return new Promise(function (resolve, reject) {
fs.ensureFile(file, function (err) {
if (err) {
throw err;
}

resolve(contents);
});
});
};

/**
* @type {WebpackMjmlStore}
*/
Expand Down

0 comments on commit d3007d8

Please sign in to comment.