Skip to content

Commit

Permalink
fix #270 look for another mjml if no index.mjml in project for previe…
Browse files Browse the repository at this point in the history
…w in list
  • Loading branch information
kmcb777 committed May 22, 2019
1 parent c62a487 commit 5195f84
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/actions/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'os'
import path from 'path'
import trash from 'trash'
import { replace } from 'react-router-redux'
import kebabCase from 'lodash/kebabCase'
import { kebabCase, find, endsWith } from 'lodash'

import takeScreenshot from 'helpers/takeScreenshot'

Expand All @@ -22,6 +22,7 @@ import {
recursiveCopy,
fileDialog,
fsReadFile,
fsReadDir,
fsAccess,
fsRename,
fsWriteFile,
Expand Down Expand Up @@ -90,7 +91,16 @@ async function loadProject(p, mjmlPath) {
res.isOK = await isValidDir(p)
if (res.isOK) {
try {
const indexFilePath = path.join(p, 'index.mjml')
let indexFilePath = path.join(p, 'index.mjml')
const indexExists = await fileExists(indexFilePath)

if (!indexExists) {
const dir = await fsReadDir(p)
const fallback = find(dir, name => endsWith(name, '.mjml'))

if (fallback) indexFilePath = path.join(p, fallback)
}

const mjmlContent = await fsReadFile(indexFilePath, { encoding: 'utf8' })
const { html: htmlContent } = await mjml2html(mjmlContent, indexFilePath, mjmlPath)
res.html = htmlContent
Expand Down

0 comments on commit 5195f84

Please sign in to comment.