Skip to content

Commit

Permalink
Tweak CLI tool
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcL committed Nov 9, 2019
1 parent 81bd842 commit 7f15dd3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
20 changes: 13 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const yargs = require('yargs');
const chalk = require('chalk');
const convertAndCreateCampaign = require('../src');

const logError = error => console.error(chalk.bold.red(`❌ ${error}`));
const logSuccess = message => console.log(chalk.green(`✅ ${message}`));
const logError = message => console.error(chalk.red(`❌ - ${message}`));
const logWarning = message => console.error(chalk.yellow(`⚠️ - ${message}`));
const logSuccess = message => console.log(chalk.green(`✅ - ${message}`));

const { argv } = yargs
.usage('Usage: $0 [options]')
Expand Down Expand Up @@ -50,10 +51,13 @@ const { argv } = yargs

convertAndCreateCampaign(argv)
.then(data => {
const { email, campaign } = data;
if (email.errors.length > 0) {
throw new Error(email.errors.toString());
}
const {
email: { errors },
campaign,
} = data;
errors.forEach(error => {
logWarning(error.message);
});

logSuccess('Email created');

Expand All @@ -64,4 +68,6 @@ convertAndCreateCampaign(argv)
logSuccess(`Mailchimp campaign: ${editUrl}?id=${id}`);
}
})
.catch(error => logError(error));
.catch(error => {
logError(error);
});
3 changes: 2 additions & 1 deletion src/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const createMailchimpRenderer = originalRenderer => {
.join('&');

const newBaseUrl = `${protocol}//${hostname}${pathname}`;

const newHref =
newQueryParameters.length > 0
? `${newBaseUrl}${pathname}?${newQueryParameters}`
? `${newBaseUrl}?${newQueryParameters}`
: newBaseUrl;
return `<a href="${newHref}">${title}</a>`;
};
Expand Down
2 changes: 0 additions & 2 deletions src/markdownToHtmlEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const markdownToHtmlEmail = async options => {
keepMailChimpTags
);

console.log(fileData);

const mjmlRenderedTemplate = await renderHandlebars({
filename: mjmlTemplateFilename,
context: {
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/markdown.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Object {
"subject": "Email subject line",
"title": "Title of the email campaign in Mailchimp",
},
"html": "<p>Testing link in markdown: <a href=\\"https://test.com/path/to/api/path/to/api?param=*|MC:DATE|*&amp;another=true&amp;test=lets%20test\\">link</a></p>
"html": "<p>Testing link in markdown: <a href=\\"https://test.com/path/to/api?param=*|MC:DATE|*&amp;another=true&amp;test=lets%20test\\">link</a></p>
",
"markdown": "
Testing link in markdown: [link](https://test.com/path/to/api?param=*|MC:DATE|*&another=true&test=lets%20test)
Expand Down

0 comments on commit 7f15dd3

Please sign in to comment.