From 5d9b73e87602d3faace5c940baa488f73fcc9180 Mon Sep 17 00:00:00 2001 From: KMcB Date: Mon, 20 May 2019 23:58:11 +0200 Subject: [PATCH 1/2] fix #268 lastExportedProject, fix export to images func import and file names --- src/actions/projects.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/actions/projects.js b/src/actions/projects.js index 004ce8a9..e811c52e 100644 --- a/src/actions/projects.js +++ b/src/actions/projects.js @@ -5,7 +5,7 @@ import trash from 'trash' import { replace } from 'react-router-redux' import kebabCase from 'lodash/kebabCase' -import takeScreenshot from 'helpers/takeScreenshot' +import { takeScreenshot } from 'helpers/takeScreenshot' import { addAlert } from 'reducers/alerts' import { openExternalFileOverlay, closeExternalFileOverlay } from 'reducers/externalFileOverlay' @@ -181,14 +181,14 @@ 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)) } @@ -198,17 +198,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) { From 184fd8ece1d9d3a2d260840f4052b159244418ae Mon Sep 17 00:00:00 2001 From: KMcB Date: Wed, 22 May 2019 18:46:15 +0200 Subject: [PATCH 2/2] prettier --- src/actions/projects.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/actions/projects.js b/src/actions/projects.js index e811c52e..8964fac5 100644 --- a/src/actions/projects.js +++ b/src/actions/projects.js @@ -188,7 +188,9 @@ async function massExport(state, asyncJob) { export function exportSelectedProjectsToHTML() { return async (dispatch, getState) => { - const targetPath = await massExport(getState(), (filePath, p) => fsWriteFile(filePath, p.get('html'))) + const targetPath = await massExport(getState(), (filePath, p) => + fsWriteFile(filePath, p.get('html')), + ) if (targetPath) { dispatch(saveLastExportedFolder(targetPath)) } @@ -198,7 +200,7 @@ export function exportSelectedProjectsToHTML() { export function exportSelectedProjectsToImages(done) { return async (dispatch, getState) => { const state = getState() - + const targetPath = await massExport(state, async (filePath, p, targetDir) => { const html = p.get('html') const previewSize = state.settings.get('previewSize')