markhuge / grunt-mailgun

MIT License
8 stars 8 forks source link

[error/question/help] Running mailgun taks from a taks folder. #7

Closed marocas closed 9 years ago

marocas commented 9 years ago

Hello, im geetin this error after i separeted my tasks from gruntfile.js to a folder _tasks, ATM im using grunt-load-configs and grunt-load-tasks on my project. Since i made this change, mailgun stoped working.

// _tasks/mailgun.js
module.exports = {
  mailer: {
    options: {
      key: '<%= cfg.email.key %>',
      sender: '<%= cfg.email.sender %>',
      recipient: '<%= cfg.email.recipient %>',
      subject: '<%= cfg.email.subject %>'
    },
    src: ['html/email.html)] 
// it send the email test but the task never stop running,  i have to cancel it with ctrl+c. 

    src: ['<%= cfg.dist %>'+grunt.option('template')] 
// cmd line : grunt send --template=email.html, i use this method to send test email.
and i get the error below.
  }
}; 
Loading _workflow/_tasks/mailgun.js...Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: grunt is not defined
>>     at Object.<anonymous> (C:\sites\bymailer\_workflow\_tasks\mailgun.js:9:29)
>>     at Module._compile (module.js:460:26)
>>     at Object.Module._extensions..js (module.js:478:10)
>>     at Module.load (module.js:355:32)
>>     at Function.Module._load (module.js:310:12)
>>     at Module.require (module.js:365:17)
>>     at require (module.js:384:17)
>>     at C:\sites\bymailer\node_modules\load-grunt-configs\lib\load-grunt-configs.js:72:30
>>     at Array.forEach (native)
>>     at module.exports (C:\sites\bymailer\node_modules\
load-grunt-configs\lib\load-grunt-configs.js:53:11)

Running tasks: send
>> [no-notifications] title: BY_Mailer
>> [no-notifications] message: Task "send" not found.
Warning: Task "send" not found. Use --force to continue.

If i change my module.exports like this to correct the missing grunt call:

// _tasks/mailgun.js
module.exports = function(grunt) {
  mailer: {
    options: {
      key: '<%= cfg.email.key %>',
      sender: '<%= cfg.email.sender %>',
      recipient: '<%= cfg.email.recipient %>',
      subject: '<%= cfg.email.subject %>'
    },
    src: ['<%= cfg.dist %>'+grunt.option('template')]
 // cmd line : grunt send --template=email.html
  }
}; 

i get this error:

Loading _workflow/_tasks/mailgun.js...Loading "Gruntfile.js" tasks...ERROR
>> C:\sites\bymailer\_workflow\_tasks\mailgun.js:5
>>       sender : '<%= cfg.email.sender %>',
>>                 ^

My taks worked fine on Gruntfile.js like this:

// gruntfile.js
'use strict';

module.exports = function(grunt) {

  var globalConfig = {
    cfg: globalConfig,
    email: {
      key:        'key-xpto',
      sender:     'noreplay@noreplay.org',
      recipient:  'xpto@gmail.com', 
    },
  };

  grunt.initConfig({

      cfg: globalConfig,
      pkg: grunt.file.readJSON('package.json'),

      // Use Mailgun option if you want to email the design to your inbox or to something like Litmus
      mailgun: {
        mailer: {
          options: {
            key:        '<%= cfg.email.key %>',         // Enter your Mailgun API key here
            sender:     '<%= cfg.email.sender %>',      // Change this
            recipient:  '<%= cfg.email.recipient %>',   // Change this
            subject:    '<%= cfg.email.subject %>'      // Change this
          },
          src: ['html/'+grunt.option('template')]
        }
      },

  });

  grunt.registerTask('send', ['mailgun']);
};

I must be missing something here, can you help me?

Best regards.

marocas commented 9 years ago

You can close this issue, its working now.

markhuge commented 9 years ago

@marocas Apologies, I don't remember even seeing this issue in my notifications. Glad it's working now.

marocas commented 7 years ago

Hi there @markhuge , this issue has returned. Can you look into it again when you have some time?