Skip to content

Commit

Permalink
fix preview when using custom engine without autosave, fix keepComments
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcb777 committed Aug 5, 2019
1 parent f33594f commit a97c638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/actions/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function loadSettings() {
useTab: false,
tabSize: 2,
indentSize: 2,
preventAutoSave: false,
},
mjml: {
minify: false,
Expand Down
16 changes: 12 additions & 4 deletions src/helpers/mjml.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function(mjmlContent, filePath, mjmlPath = null, options = {}) {
const settings = await storageGet('settings')
const useMjmlConfig = get(settings, 'mjml.useMjmlConfig')
const mjmlConfigPath = get(settings, 'mjml.mjmlConfigPath')
const keepComments = get(settings, 'mjml.keepComments', true)
const preventAutoSave = get(settings, 'editor.preventAutoSave', false)

if (mjmlPath) {
let mjmlConfigOption = []
Expand All @@ -33,13 +35,19 @@ export default function(mjmlContent, filePath, mjmlPath = null, options = {}) {
'-s',
'--config.validationLevel=skip',
...(options.minify ? ['-m'] : []),
...(options.keepComments ? [] : ['--config.keepComments=0']),
...(keepComments ? [] : ['--config.keepComments=0']),
...mjmlConfigOption,
]

if (!mjmlContent.trim().startsWith('<mjml')) {
if (!mjmlContent.trim().startsWith('<mjml') || preventAutoSave) {
const stdinStream = new stream.Readable()
stdinStream.push(wrapIntoMJMLTags(mjmlContent))

if (!mjmlContent.trim().startsWith('<mjml')) {
stdinStream.push(wrapIntoMJMLTags(mjmlContent))
} else {
stdinStream.push(mjmlContent)
}

stdinStream.push(null)
args.push('-i')

Expand Down Expand Up @@ -68,7 +76,7 @@ export default function(mjmlContent, filePath, mjmlPath = null, options = {}) {
const mjmlOptions = {
filePath,
minify: !!options.minify,
keepComments: !!options.keepComments,
keepComments,
mjmlConfigPath: useMjmlConfig
? settings.mjml.mjmlConfigPath || path.dirname(filePath)
: null,
Expand Down

0 comments on commit a97c638

Please sign in to comment.