Skip to content

Commit

Permalink
Merge pull request #285 from mjmlio/fix-268
Browse files Browse the repository at this point in the history
fix #268
  • Loading branch information
kmcb777 authored Jul 17, 2019
2 parents 237ba87 + 184fd8e commit 3bff07a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/actions/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import trash from 'trash'
import { replace } from 'react-router-redux'
import { kebabCase, find, endsWith } from 'lodash'

import takeScreenshot from 'helpers/takeScreenshot'
import { takeScreenshot } from 'helpers/takeScreenshot'

import { addAlert } from 'reducers/alerts'
import { openExternalFileOverlay, closeExternalFileOverlay } from 'reducers/externalFileOverlay'
Expand Down Expand Up @@ -191,14 +191,16 @@ async function massExport(state, asyncJob) {
const projBaseName = path.basename(p.get('path'))
const projSafeName = `${kebabCase(projBaseName)}.html`
const filePath = path.join(targetPath, projSafeName)
await asyncJob(filePath, p)
await asyncJob(filePath, p, targetPath)
}
return targetPath
}

export function exportSelectedProjectsToHTML() {
return (dispatch, getState) => {
const targetPath = massExport(getState(), (filePath, p) => fsWriteFile(filePath, p.get('html')))
return async (dispatch, getState) => {
const targetPath = await massExport(getState(), (filePath, p) =>
fsWriteFile(filePath, p.get('html')),
)
if (targetPath) {
dispatch(saveLastExportedFolder(targetPath))
}
Expand All @@ -208,17 +210,18 @@ export function exportSelectedProjectsToHTML() {
export function exportSelectedProjectsToImages(done) {
return async (dispatch, getState) => {
const state = getState()
const targetPath = await massExport(state, async (filePath, p) => {

const targetPath = await massExport(state, async (filePath, p, targetDir) => {
const html = p.get('html')
const previewSize = state.settings.get('previewSize')
const [mobileWidth, desktopWidth] = [previewSize.get('mobile'), previewSize.get('desktop')]
const [mobileScreenshot, desktopScreenshot] = await Promise.all([
takeScreenshot(html, mobileWidth),
takeScreenshot(html, desktopWidth),
takeScreenshot(html, mobileWidth, targetDir),
takeScreenshot(html, desktopWidth, targetDir),
])
await Promise.all([
fsWriteFile(`${filePath}_mobile.png`, mobileScreenshot),
fsWriteFile(`${filePath}_desktop.png`, desktopScreenshot),
fsWriteFile(`${filePath.replace(/.html$/, '')}_mobile.png`, mobileScreenshot),
fsWriteFile(`${filePath.replace(/.html$/, '')}_desktop.png`, desktopScreenshot),
])
})
if (targetPath) {
Expand Down

0 comments on commit 3bff07a

Please sign in to comment.