Skip to content

Commit

Permalink
feat(emit-asset): added file list on compilation
Browse files Browse the repository at this point in the history
feat(emit-asset): added file list on compilation
  • Loading branch information
matteobertoldo authored Jul 29, 2022
2 parents 4414a87 + aedf979 commit 4629794
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 120,
"printWidth": 140,
"singleQuote": true,
"semi": true,
"tabWidth": 2,
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@prettier/plugin-xml": "^2.2.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/fs-extra": "^9.0.13",
"clean-terminal-webpack-plugin": "^3.0.0",
"commitlint": "^17.0.2",
"eslint": "^8.17.0",
Expand Down
24 changes: 13 additions & 11 deletions src/webpack-mjml-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const fs = require('fs-extra');
const glob = require('glob');
const mjml2html = require('mjml');
const packageJSON = require('../package.json'); // eslint-disable-line import/extensions
const webpack = require('webpack');
const { RawSource } = webpack.sources;
const { NoSourceFilesWarning } = require('./errors/');
const { basename } = require('path');

/**
* @param {string} inputPath The path where `.mjml` files are located.
Expand All @@ -25,7 +28,7 @@ const WebpackMjmlStore = function (inputPath, options) {
WebpackMjmlStore.prototype.apply = function (compiler) {
const that = this;
compiler.hooks.make.tapAsync(packageJSON.name, function (compilation, callback) {
glob(`${that.inputPath}/**/*.mjml`, function (err, files) {
glob(`${that.inputPath}/**/*.mjml`, async function (err, files) {
if (err) {
throw err;
}
Expand All @@ -37,18 +40,17 @@ WebpackMjmlStore.prototype.apply = function (compiler) {

for (const index in files) {
const file = files[index];
if (compilation.fileDependencies.add) {
compilation.fileDependencies.add(file);
} else {
compilation.fileDependencies.push(file);
}

const initialFile = file.replace(
that.inputPath,
that.options.outputPath === process.cwd() ? compilation.outputOptions.path : that.options.outputPath
);
const dist = that.options.outputPath === process.cwd() ? compilation.outputOptions.path : that.options.outputPath;
const initialFile = file.replace(that.inputPath, dist);
const outputFile = initialFile.replace('.mjml', that.options.extension);

that.tasks.push(that.handleFile(file, outputFile));
compilation.fileDependencies.add(file);

const data = await that.convertFile(file);
compilation.emitAsset(basename(outputFile), new RawSource(data), {
javascriptModule: false
});
}

Promise.all(that.tasks).then(callback());
Expand Down

0 comments on commit 4629794

Please sign in to comment.