Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Loëck Vézien committed Aug 23, 2017
1 parent 0e8b8c3 commit 26c7655
Show file tree
Hide file tree
Showing 52 changed files with 997 additions and 1,191 deletions.
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"lerna": "2.0.0-rc.5",
"packages": [
"packages/*"
],
"lerna": "2.0.0",
"packages": ["packages/*"],
"npmClient": "yarn",
"version": "4.0.0-alpha.2"
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
"postinstall": "lerna bootstrap"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-env": "^1.5.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"babel-register": "^6.26.0",
"es6-promisify": "^5.0.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.3.0",
"lerna": "^2.0.0-rc.5",
"opn": "^5.0.0",
"eslint": "^4.5.0",
"eslint-config-airbnb-base": "^11.3.2",
"eslint-plugin-import": "^2.7.0",
"lerna": "^2.0.0",
"opn": "^5.1.0",
"rimraf": "^2.6.1"
}
}
8 changes: 3 additions & 5 deletions packages/mjml-body/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BodyComponent } from 'mjml-core'

export default class MjBody extends BodyComponent {

static defaultAttributes = {
width: '600px',
}
Expand All @@ -25,13 +24,12 @@ export default class MjBody extends BodyComponent {
return `
<div
${this.htmlAttributes({
class: this.getAttribute('css-class'),
style: 'div',
})}
class: this.getAttribute('css-class'),
style: 'div',
})}
>
${this.renderChildren()}
</div>
`
}

}
23 changes: 16 additions & 7 deletions packages/mjml-body/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -537,20 +537,29 @@ [email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

mjml-core@^4.0.0-alpha:
version "4.0.0-alpha"
resolved "https://registry.yarnpkg.com/mjml-core/-/mjml-core-4.0.0-alpha.tgz#2f0b7ad9d78c804f2bbe97e03f2edc412477f972"
mjml-core@^4.0.0-alpha.2:
version "4.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/mjml-core/-/mjml-core-4.0.0-alpha.2.tgz#dd2951b106a5e77125c49c2b427726ff6b7125a7"
dependencies:
html-minifier "^3.5.2"
js-beautify "^1.6.14"
juice "^4.1.0"
lodash "^4.17.3"
mjml-validator "^4.0.0-alpha"
mjml-parser-xml "^4.0.0-alpha.2"
mjml-validator "^4.0.0-alpha.2"
object-path "^0.11.3"

mjml-validator@^4.0.0-alpha:
version "4.0.0-alpha"
resolved "https://registry.yarnpkg.com/mjml-validator/-/mjml-validator-4.0.0-alpha.tgz#908ead9cce345e454d23ff33f11febae45fd662f"
mjml-parser-xml@^4.0.0-alpha.2:
version "4.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/mjml-parser-xml/-/mjml-parser-xml-4.0.0-alpha.2.tgz#5a14fae35990d582ffeb3ee393a7b188f993b4a5"
dependencies:
htmlparser2 "^3.9.2"
lodash "^4.17.2"
mjml-core "^4.0.0-alpha.2"

mjml-validator@^4.0.0-alpha.2:
version "4.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/mjml-validator/-/mjml-validator-4.0.0-alpha.2.tgz#cf0de56709ff4c5576516acd8c593895f942f4eb"
dependencies:
lodash "^4.17.4"
warning "^3.0.0"
Expand Down
60 changes: 29 additions & 31 deletions packages/mjml-button/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BodyComponent } from 'mjml-core'

export default class MjButton extends BodyComponent {

static endingTag = true

static allowedAttributes = [
Expand Down Expand Up @@ -36,17 +35,17 @@ export default class MjButton extends BodyComponent {
]

static defaultAttributes = {
'align': 'center',
align: 'center',
'background-color': '#414141',
'border': 'none',
border: 'none',
'border-radius': '3px',
'color': '#ffffff',
color: '#ffffff',
'font-family': 'Ubuntu, Helvetica, Arial, sans-serif',
'font-size': '13px',
'font-weight': 'normal',
'inner-padding': '10px 25px',
'line-height': '120%',
'padding': '10px 25px',
padding: '10px 25px',
'text-decoration': 'none',
'text-transform': 'none',
'vertical-align': 'middle',
Expand All @@ -65,21 +64,21 @@ export default class MjButton extends BodyComponent {
'border-radius': this.getAttribute('border-radius'),
'border-right': this.getAttribute('border-right'),
'border-top': this.getAttribute('border-top'),
'color': this.getAttribute('color'),
'cursor': 'auto',
color: this.getAttribute('color'),
cursor: 'auto',
'font-style': this.getAttribute('font-style'),
'height': this.getAttribute('height'),
'padding': this.getAttribute('inner-padding'),
height: this.getAttribute('height'),
padding: this.getAttribute('inner-padding'),
},
content: {
'background': this.getAttribute('background-color'),
'color': this.getAttribute('color'),
background: this.getAttribute('background-color'),
color: this.getAttribute('color'),
'font-family': this.getAttribute('font-family'),
'font-size': this.getAttribute('font-size'),
'font-style': this.getAttribute('font-style'),
'font-weight': this.getAttribute('font-weight'),
'line-height': this.getAttribute('line-height'),
'Margin': '0',
Margin: '0',
'text-decoration': this.getAttribute('text-decoration'),
'text-transform': this.getAttribute('text-transform'),
},
Expand All @@ -92,31 +91,31 @@ export default class MjButton extends BodyComponent {
return `
<table
${this.htmlAttributes({
align: this.getAttribute('align'),
border: '0',
cellpadding: '0',
cellspacing: '0',
role: 'presentation',
style: 'table',
})}
align: this.getAttribute('align'),
border: '0',
cellpadding: '0',
cellspacing: '0',
role: 'presentation',
style: 'table',
})}
>
<tr>
<td
${this.htmlAttributes({
align: 'center',
bgcolor: this.getAttribute('background-color') === 'none' ? undefined : this.getAttribute('background-color'),
role: 'presentation',
style: 'td',
valign: this.getAttribute('vertical-align'),
})}
align: 'center',
bgcolor: this.getAttribute('background-color') === 'none' ? undefined : this.getAttribute('background-color'),
role: 'presentation',
style: 'td',
valign: this.getAttribute('vertical-align'),
})}
>
<${tag}
${this.htmlAttributes({
href: this.getAttribute('href'),
rel: this.getAttribute('rel'),
style: 'content',
target: tag === 'a' ? '_blank' : undefined,
})}
href: this.getAttribute('href'),
rel: this.getAttribute('rel'),
style: 'content',
target: tag === 'a' ? '_blank' : undefined,
})}
>
${this.getContent()}
</${tag}>
Expand All @@ -125,5 +124,4 @@ export default class MjButton extends BodyComponent {
</table>
`
}

}
6 changes: 3 additions & 3 deletions packages/mjml-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"chokidar": "^1.6.1",
"commander": "^2.9.0",
"commander": "^2.11.0",
"fs-promise": "^2.0.3",
"glob": "^7.1.1",
"lodash": "^4.17.4",
Expand All @@ -30,7 +30,7 @@
"mjml-validator": "^4.0.0-alpha.2"
},
"devDependencies": {
"chai": "^4.0.0",
"mocha": "^3.2.0"
"chai": "^4.1.1",
"mocha": "^3.5.0"
}
}
64 changes: 35 additions & 29 deletions packages/mjml-cli/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import timePad from './helpers/timePad'
import { version as cliVersion } from '../package.json'
import { version as coreVersion } from 'mjml-core/package.json'



/*
* The version number is the NPM
* version number. It should be the same as the MJML engine
Expand All @@ -32,7 +30,7 @@ const availableErrorOutputFormat = {

const error = e => console.log(e.stack || e) // eslint-disable-line no-console

const isDirectory = (file) => {
const isDirectory = file => {
try {
const outputPath = path.resolve(process.cwd(), file)

Expand All @@ -46,11 +44,12 @@ const isDirectory = (file) => {
* Render an input promise
*/
const render = (bufferPromise, { min, output, stdout, fileName, level }) => {
const handleError = message => fileName ? error(`File: ${fileName} \n${message}`) : error(message)
const handleError = message =>
fileName ? error(`File: ${fileName} \n${message}`) : error(message)

return bufferPromise
.then(mjml => mjml2html(mjml.toString(), { minify: min, filePath: fileName, level }))
.then((result) => {
.then(result => {
const { html, errors } = result

// non-blocking errors
Expand All @@ -64,15 +63,15 @@ const render = (bufferPromise, { min, output, stdout, fileName, level }) => {
return write(output, html)
}
})
.catch((e) => {
.catch(e => {
error(e.getMessages ? e.getMessages() : e)
throw e
})
}

const outputFileName = (input, output) => {
const outputIsDirectory = isDirectory(output)
const { ext, name } = path.parse((!output || outputIsDirectory) ? input : output)
const { ext, name } = path.parse(!output || outputIsDirectory ? input : output)
let dir = outputIsDirectory ? output : './'

if (output && !outputIsDirectory) {
Expand All @@ -91,29 +90,31 @@ const outputFileName = (input, output) => {
* Turns an MJML input file into a pretty HTML file
* min: boolean that specify the output format (pretty/minified)
*/
export const renderFiles = (input, options) => new Promise((resolve, reject) => {
glob(input, (err, files) => {
const processedFiles = []
export const renderFiles = (input, options) =>
new Promise((resolve, reject) => {
glob(input, (err, files) => {
const processedFiles = []

if (files.length > 1 && options.output && !isDirectory(options.output)) {
throw new Error('Output destination should be a directory instead of a file')
}

if (files.length > 1 && options.output && !isDirectory(options.output)) {
throw new Error('Output destination should be a directory instead of a file')
}
files.forEach(f => {
processedFiles.push(renderFile(f, options))
})

files.forEach((f) => {
processedFiles.push(renderFile(f, options))
Promise.all(processedFiles).then(resolve).catch(reject)
})

Promise.all(processedFiles).then(resolve).catch(reject)
})
})

export const renderFile = (file, { output, level, min, stdout }) => render(read(path.resolve(process.cwd(), file)), {
output: outputFileName(file, output),
fileName: file,
level,
min,
stdout,
})
export const renderFile = (file, { output, level, min, stdout }) =>
render(read(path.resolve(process.cwd(), file)), {
output: outputFileName(file, output),
fileName: file,
level,
min,
stdout,
})

/**
* Render based on input stream
Expand All @@ -123,15 +124,16 @@ export const renderStream = options => render(readStdin(process.stdin), options)
/**
* Validate an MJML document
*/
export const validate = (input, { format }) => read(input)
.then((content) => {
export const validate = (input, { format }) =>
read(input)
.then(content => {
const MJMLDocument = MJMLParser(content.toString())
const report = MJMLValidator(MJMLDocument)
const outputFormat = availableErrorOutputFormat[format] || availableErrorOutputFormat.text

error(outputFormat(report))
})
.catch((e) => {
.catch(e => {
error(`Error: ${e}`)
throw e
})
Expand All @@ -155,7 +157,11 @@ export const watch = (input, options) => {

dependencies = newDependencies

console.log(`[${timePad(now.getHours())}:${timePad(now.getMinutes())}:${timePad(now.getSeconds())}] Reloading MJML`) // eslint-disable-line no-console
console.log(
`[${timePad(now.getHours())}:${timePad(now.getMinutes())}:${timePad(
now.getSeconds(),
)}] Reloading MJML`,
) // eslint-disable-line no-console
renderFile(input, options)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/mjml-cli/src/helpers/promesify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const promisify = fn =>
(...args) =>
new Promise((resolve, reject) =>
fn(...args.concat((err, ...data) =>
err ? reject(err) : resolve(...data))))
(err ? reject(err) : resolve(...data)))))


export const write = promisify(fs.writeFile)
Expand Down
2 changes: 1 addition & 1 deletion packages/mjml-cli/test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const compareFiles = (fileToCompare, expectedFile) => {
const files = [fileToCompare, expectedFile]

return Promise.all(files.map(file => fsp.readFile(file, { encoding: 'utf8' })
.then(fileContent => format(fileContent))))
.then(fileContent => format(fileContent))))
.then((filesContentFormatted) => {
expect(filesContentFormatted[0]).to.equal(filesContentFormatted[1])
})
Expand Down
Loading

0 comments on commit 26c7655

Please sign in to comment.