Question

I am intending to add a task to sails's (0.10 rc5) grunt build system.

tasks/config/asset-versioning.js

module.exports = function(grunt) {

  grunt.config.set('asset-versioning', {
    copy: {
      src: '.tmp/public/min/production.js',
      dest: '.tmp/public/min/production2.js'
    }
  });

  grunt.task.registerTask('asset-versioning', ['copy']);

  grunt.loadNpmTasks('grunt-contrib-copy');
};

tasks/register/prod.js

module.exports = function (grunt) {
    grunt.registerTask('prod', [
        'compileAssets',
        'concat',
        'uglify',
        'cssmin',
        'sails-linker:prodJs',
        'sails-linker:prodStyles',
        'sails-linker:devTpl',
        'asset-versioning' // Added the task config here
    ]);
};

After running sails lift --prod --verbose I am getting following error:

Grunt :: Warning: Task "asset-versioning" not found.
** Grunt :: An error occurred. **

What am I missing?


EDIT

Apparently I am missing to register my task.

Adding grunt.task.registerTask('asset-versioning'); to the first file. I am not getting any error, but my task is not running! Nothing is happening.

Was it helpful?

Solution

Okay, you're having this all mixed up. Copy is a predefined task, you just need to tweak its configs. Go to tasks/config/copy.js and add your custom configuration (in the grunt.config.set call)

productionfiles: {
  src: '.tmp/public/min/production.min.js',
  dest: '.tmp/public/min/production2.min.js'
}

Then, in the tasks/register/prod.js, make sure you call copy:productionfiles, and it will do the magic.

Copy.js

module.exports = function(grunt) {

    grunt.config.set('copy', {
        dev: {
            files: [{
                expand: true,
                cwd: './assets',
                src: ['**/*.!(coffee|less)'],
                dest: '.tmp/public'
            }]
        },
        build: {
            files: [{
                expand: true,
                cwd: '.tmp/public',
                src: ['**/*'],
                dest: 'www'
            }]
        },
    productionfiles: {
      src: '.tmp/public/min/production.min.js',
      dest: '.tmp/public/min/production2.min.js'
    }
    });

    grunt.loadNpmTasks('grunt-contrib-copy');
};

Prod.js

module.exports = function (grunt) {
    grunt.registerTask('prod', [
        'compileAssets',
        'concat',
        'uglify',
        'cssmin',
        'sails-linker:prodJs',
        'sails-linker:prodStyles',
        'sails-linker:devTpl',
        'sails-linker:prodJsJade',
        'sails-linker:prodStylesJade',
        'sails-linker:devTplJade',
        'copy:productionfiles'
    ]);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top