I need to recursively concat the JavaScript files contained within a directory but ensuring that the files within the current directory be added before digging into the other contained directories, ex:
src/
- module1/
- config.js
- index.js
- module2/
- index.js
- main.js
Using the solution presented in here, I was able to recursively get the files with this:
// get all module directories
grunt.file.expand("src/*").forEach(function (dir) {
// get the module name from the directory name
var dirName = dir.substr(dir.lastIndexOf('/') + 1);
// create a subtask for each module, find all src files
// and combine into a single js file per module
concat.main.src.push(dir + '/**/*.js');
});
console.log(concat.main.src);
but when I check into the concat.main.src then the order isn't the way I needed:
//console.log output
['src/module1/**/*.js',
'src/module2/**/*.js',
'src/main.js']
The order I need is:
['src/main.js',
'src/module1/**/*.js',
'src/module2/**/*.js']
Any ideas on how can I achieve this?