Correct Method to add to Grunt

I’m trying to include https://www.npmjs.org/package/grunt-deployments with the original Grunt file provided with Roots 7.0.0.

In package.json, under dev dependencies I’ve added ;

"grunt-deployments": "0.2.0"

This works well with npm install and grabs the files required.

Then, I’ve added the following after watch in Gruntfile.js;

deployments: {
    options: {
      // any should be defined options here
    },
    // "Local" target
    "local": {
      "title": "local",
      "database": "db",
      "user": "user",
      "pass": "pass",
      "host": "localhost",
      "url": "url"
      // note that the `local` target does not have an "ssh_host"
    },
    "stage": {
      "title": "stage",
      "database": "db",
      "user": "user",
      "pass": "pass",
      "host": "host",
      "url": "url",
      "ssh_host": "ssh"
    }
  }

I’ve also edited the registerTask to include it;

grunt.registerTask('dev', [
    'jshint',
    'less:dev',
    'autoprefixer:dev',
    'concat',
    'deployments'
  ]);

However when running grunt dev I get the following error;

Warning: Task "deployments" not found. Use --force to continue.

Not sure if I should try edit package.json under load-grunt-tasks? Sure I’ve just left out something?

Thanks in advance.

Did you enable the task per https://www.npmjs.org/package/grunt-deployments#getting-started ?

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-deployments');

Edit*

I’m still a bit of a Grunt newbie but slowly figuring it out. You may actually just need to add the module to the top of your Gruntfile.js as a required module:

require('grunt-deployments')(grunt);

Edit 2*

My first edit is actually taken care of when you add the dependency to package.json. Will chew on this some more.

Hi cfx,

I haven’t used loadNpmTasks, but roots doesn’t have any of this in the gruntfile.js, so it must be done through a different method. That’s definitely causing the issue.

Adding

require('grunt-deployments')(grunt); 

breaks it further.

Ok, it looks like it’s actually a usage issue. According to the docs, db_push and db_pull are the two available tasks.

Got it working with this config in Gruntfile.js:

deployments: {
  options: {
    'backups_dir': 'sql',
    'target': 'local'
  },
  local: {
    'title': 'Local',
    'database': 'roots',
    'user': 'user',
    'pass': 'pass',
    'host': 'localhost'
  },
  stage: {
  }
}

And registered the db_pull task.

  grunt.registerTask('dev', [
    'jshint',
    'less:dev',
    'autoprefixer:dev',
    'concat',
    'db_pull'
  ]);

There must be a way to pass the target when registering the task but not sure how to do that just now. Also, the docs say it will automatically save to backups/ directory but I found that not to be the case, so I have it save to sql/ which is a dir I created in my theme root.

Edit*

Be careful with this module though, it does not take database serialization into account (yet). See this issue for more: https://github.com/getdave/grunt-deployments/issues/13

I also posted about adding database dumps to your git workflow here: How to handle Database from Dev to Server?

Hi cfx,

Thanks so much, that did it. I actually don’t even need db_pull in the registerTask, I just manually push/pull with the CLI.

Will do some research on the db serialisation issue.

Thanks for the info and your help!