Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically update Grunt config fields

I have few projects in separate directories and want to build them in the same way. I want to define project name from task (as param). Grunt tasks will use this project path as root path. But I have several subfolders and do not want to update it manually I just want to update the project. There is any chance to do that?

grunt.initConfig({
  paths : {
    project : null,
    projectStylesheets : '<%= paths.project %>/stylesheets',
    // ...
  }
});   

grunt.registerTask('server', function(project) {
  // -> project = 'some_name'
  var paths = grunt.config.get('paths');
  paths.project = project;
  grunt.config.set('paths', paths);
  // -> { project: 'some_name', projectAssets: 'stylesheets' }
});

I was thinking about using JS functions outside he config but not sure is this the best practice.

like image 591
Vitalii Petrychuk Avatar asked May 08 '13 15:05

Vitalii Petrychuk


1 Answers

Try use registermultitask - http://gruntjs.com/api/grunt.task#grunt.task.registermultitask

grunt.initConfig({
    projectName1 : {
        projectStylesheets: 'path_to_stylesheets1',
    },
    projectName2 : {
        projectStylesheets: 'path_to_stylesheets2',
    }
})

grunt.registerMultiTask('server', function() {
    var path = grunt.data.projectStylesheets;    
    //operations with stylesheets
});

For build use 
grunt server:projectName1
grunt server:projectName2
like image 180
Boris Kirov Avatar answered Nov 07 '22 10:11

Boris Kirov