can you use multiple gruntfiles and spawn new grunt tasks?

I am a beginner in using grunt, so some of what i'm saying might not make sense at all.

I am running a grunt job that manages multiple projects, so having a single gruntfile.js is overwhelming with 700+ lines of task configs. ( not to mention directory paths )

I was wondering, if it'd be possible to have a individual gruntfile.js inside each app directory.

and secondly, if its possible to create a gruntfile.js inside the root directory with coding

grunt.registerTask('build_app1', '', function(){
   // cd app1, run command: grunt build
})

if this isn't possible, wouldn't you think this could be the goal/future devs are striving to get to?

feedbacks?

For your first question :

Yes, you can do it. By default, "grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file".

For your second question :

I'm trying to find a similar solution to my project using Grunt. However, you can use this grunt plug-in : https://www.npmjs.com/package/grunt-shell.

There is another one : https://www.npmjs.com/package/grunt-exec

You can use also "grunt.util.spawn". See on the official Grunt web site.

It's easy to use it to execute some tasks shell.

An example based on what you want to do :

 grunt.registerTask('build_app1', '', function(numApp) {
     if('1' == numApp) {
       grunt.task.run(['shell:moveToApp1']);
     }
     else if (...) { //2, 3, 4, ...
     }
     grunt.task.run(['shell:buildApp']);
 });

 grunt.initConfig({
    shell: {
        moveToApp1 :{
            options: {
                stderr:true
            },
            command: function() {
                return 'cd app1';
        buildApp: {
            options: {
                stderr: true
            },
            command: function() {
                return 'grunt build';
            } 
        }
});

I think there is a better solution to change directory dynamically. I'm sure you will be find a solution for it.