Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify file to test from the command line #5

Closed
diomededavid opened this issue Dec 12, 2016 · 5 comments
Closed

Specify file to test from the command line #5

diomededavid opened this issue Dec 12, 2016 · 5 comments

Comments

@diomededavid
Copy link

How can i specify a file I would like to test from the the command line?

@fritx
Copy link
Owner

fritx commented Dec 12, 2016

@diomededavid what do you mean?

I guess you want to edit/comment some of the lines in gulpfile.js?
https://github.com/fritx/gulp-mail/blob/master/gulpfile.js#L8-L10

@justin713
Copy link
Collaborator

@diomededavid I'm sure you've found this by now, but you can use yargs to pass command-line options to your gulp tasks. For example,

$ gulp send --to me@mydomain.com --message email.html

where send is the task defined and configured for sending an email, something like:

function send () {
	var config = {...} // where ... is your valid SMTP (or other) config
	var config.to = yargs.argv.to;
	var message = yargs.argv.message;

	return gulp.src(message)
		.pipe(gulp_mail(config))
		.pipe(gulp.dest('dist'));
}

You probably will want to define defaults and check for values / errors, but that's basically that.

@diomededavid
Copy link
Author

diomededavid commented Feb 18, 2017

@justin713 Thanks. I did get it to do the test, and the entire script runs using: "gulp mail --message filename.html". I receive the email test, but all the the inlined CSS get stripped out.

I am using Foundation for emails. Here is the function I am using.

`
function mail() {
var awsURL = !!CONFIG && !!CONFIG.aws && !!CONFIG.aws.url ? CONFIG.aws.url : false;
var message = yargs.argv.message;

if (EMAIL) {
CONFIG.mail.to = [EMAIL];
}

return gulp.src('dist/**/' + message)
.pipe($.if(!!awsURL, $.replace(/=('|")(/?assets/img)/g, "=$1"+ awsURL)))
.pipe($.mail(CONFIG.mail))
.pipe(gulp.dest('dist'));
}`

@justin713
Copy link
Collaborator

@diomededavid The only thing I can recommend is to check that the file(s) being sourced by the mail() function are properly inlined. gulp-mail itself doesn't do any transformations to the source, so it's more likely to be a problem with the gulp task responsible for doing the inlining.

@hughker
Copy link

hughker commented Jul 7, 2021

@diomededavid — found this via a Google Search as I was trying to do this as well. So here is what I did to handle only sending to a specific template, for reference you'll be editing the gulpfile.babel.js.

Put this below the PRODUCTION + EMAIL towards the top:

const TEMPLATE = yargs.argv.template;

Replace your current function mail() with the following:

// Send either a specified template to email for testing or just send them all.
// If no AWS creds then do not replace img urls.
// Ex: npm run mail -- --template filename.html
function mail() {
  var awsURL = !!CONFIG && !!CONFIG.aws && !!CONFIG.aws.url ? CONFIG.aws.url : false;
  if (TEMPLATE) {
    var mailSource = 'dist/**/' + TEMPLATE;
  } else {
    var mailSource = 'dist/**/*.html';
  }

  if (EMAIL) {
    CONFIG.mail.to = [EMAIL];
  }

  return gulp.src(mailSource)
    .pipe($.if(!!awsURL, $.replace(/=('|")(\/?assets\/img)/g, "=$1"+ awsURL)))
    .pipe($.mail(CONFIG.mail))
    .pipe(gulp.dest('dist'));
}

Then to run the new script with your specific template you'd do npm run mail -- --template filename.html — I hope this helps you or anybody else who is trying to do this too as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants