diff --git a/package.json b/package.json index ff345aa..585be28 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/webpack-mjml-store.js b/src/webpack-mjml-store.js index ea5c3ad..819f6f4 100644 --- a/src/webpack-mjml-store.js +++ b/src/webpack-mjml-store.js @@ -2,7 +2,7 @@ const mjmlEngine = require('mjml'); const glob = require('glob'); -const fs = require('fs'); +const fs = require('fs-extra'); const _ = require('lodash'); /** @@ -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()); } @@ -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} */