mjml-cli not parsing multiple mjml files

Created on 26 Jun 2016  ·  17Comments  ·  Source: mjmlio/mjml

I'm trying to parse multiple *.mjml files in a directory. I want to write the corresponding parsed HTML files inside another directory.

Assuming I have a directory called mail-templates containing multiple .mjml files
Using the cli, i tried the following

$ mjml ./mail-templates/*.mjml -o ./mail-templates/dist
$ mjml -r ./mail-templates/*.mjml -o ./mail-templates/dist
$ mjml -r ./mail-templates/**/*.mjml -o ./mail-templates/dist/

In all the above cases, its writing a file ./mail-templates/dist.html with the rendered HTML. I looked into the parsing code, and it seems to have logic written for parsing multiple files though.

/*
 * Turns an MJML input file into a pretty HTML file
 * min: boolean that specify the output format (pretty/minified)
 */
export const renderFile = (input, options) => {
  const renderFiles = files => {
    files.forEach((file, index) => {
      const inFile = path.basename(file, '.mjml')
      let output

      if (options.output) {
        const extension = path.extname(options.output) || '.html'
        const outFile = path.join(path.dirname(options.output), path.basename(options.output, extension))

        if (files.length > 1) {
          output = `${outFile}-${index + 1}${extension}`
        } else {
          output = `${outFile}${extension}`
        }
      } else {
        const extension = path.extname(inFile) || '.html'
        output = `${inFile}${extension}`
      }

      const filePath = path.resolve(process.cwd(), file)

      render(read(filePath), { min: options.min, stdout: options.stdout, output })
    })
  }

  if (typeof input === 'string') {
    glob(input, (err, files) => renderFiles(files))
  } else {
    renderFiles(input)
  }
}

Am I doing anything wrong here? Using v2.2.0

CLI

Most helpful comment

Thanks @mehrdaad for being so nice with us, always a pleasure to maintain a free and open software.

This "shit" to use your own term, has been fixed in the 3.3.X branch if you read here https://github.com/mjmlio/mjml/issues/317#issuecomment-254526065 and here https://github.com/mjmlio/mjml/issues/317#issuecomment-269389582.

We did rewrite the whole project to have better control, better dev experience and more feature for developers in MJML4. It has been in Alpha + Beta for months now, and no one reported this issue during it in my knowledge.

Note that you should take a look at #1023 and a fix is in progress.

So @asaidi @mehrdaad and @thanosasimo, you should take a look at the current open issue on MJML4 and not comment on a closed/dead issue of 2016

All 17 comments

Hello @detj

glob should do the trick here, but I'll take a look at it !

It looks like the -o options doesn't work when using multiple files.

@iRyusa Right. So, if -o <path> where _path_ is a directory, it should dump all compiled files inside it? In terms of the CLI syntax I don't think any change is required. But yeah, we need glob to do its job.

@detj I found out what cause the issue, fix should be released in 2.4 !

Great! 👍

Hi @detj it's available in MJML 3 feel free to test it and give us feedback about it !

@iRyusa Tested with version 3.1.1. Works like a charm! 🎉

mjml ./templates/*.mjml -o ./templates/dist/

When using the same commands mentioned above,
mjml templates/*.mjml -o templates/dist/
nothing is compiled, and this is printed in the console:
Multiple input files, but output option should be either a directory or an empty string: templates/dist/ given
I'm i missing something? Or it's no longer available in MJML4...

mjml --version
mjml-core: 4.0.0
mjml-cli: 4.0.0

Can you try to remove final / please ?

On 9 Mar 2018, at 19:52, asaidi notifications@github.com wrote:

When using the same commands mentioned above,
mjml templates/*.mjml -o templates/dist/
nothing is compiled, and this is printed in the console:
Multiple input files, but output option should be either a directory or an empty string: templates/dist/ given
I'm i missing something? Or it's no longer available in MJML4...

mjml --version
mjml-core: 4.0.0
mjml-cli: 4.0.0


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Same error...

Can you try with relative path too ? ./templates/dist

On 9 Mar 2018, at 19:55, asaidi notifications@github.com wrote:

Same error...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

With mjml ./templates/*.mjml -o ./templates/dist i get the same error.
I also tried with an absolute path.

I think the issue is while processing multiple files in the input directory.
I only kept one template in the templates folder and run
mjml ./templates/*.mjml -o ./templates/dist
As a result, it generates a dist file with no extension in the templates folder.

You need to create the directory first

On 9 Mar 2018, at 21:23, asaidi notifications@github.com wrote:

With mjml ./templates/*.mjml -o ./templates/dist i get the same error.
I also tried with an absolute path.

I think the issue is while processing multiple files in the input directory.
I only kept one template in the templates folder and run
mjml ./templates/*.mjml -o ./templates/dist
As a result, it generates a dist file with no extension in the templates folder.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

2018-03-10

I created the folder but the same result.
No error at the console but no output file as well

Same shit. No one gonna fix this for 2 years?

Thanks @mehrdaad for being so nice with us, always a pleasure to maintain a free and open software.

This "shit" to use your own term, has been fixed in the 3.3.X branch if you read here https://github.com/mjmlio/mjml/issues/317#issuecomment-254526065 and here https://github.com/mjmlio/mjml/issues/317#issuecomment-269389582.

We did rewrite the whole project to have better control, better dev experience and more feature for developers in MJML4. It has been in Alpha + Beta for months now, and no one reported this issue during it in my knowledge.

Note that you should take a look at #1023 and a fix is in progress.

So @asaidi @mehrdaad and @thanosasimo, you should take a look at the current open issue on MJML4 and not comment on a closed/dead issue of 2016

Cool @iRyusa , thanks. And keep up the good work guys.

Was this page helpful?
0 / 5 - 0 ratings