Organizing Files.
/app
/components
/core
/extensions
- array.js
- string.js
/services
- logger.js
/lib
- core.js
Core.js
(function() {
'use strict';
angular.module('app.core',[]);
}());
I am looking to update core.js during each build by combining all other js files in that folder into it while preserving the original module declaration at the beginning.
This is the desired content for Core.js :
(function() {
'use strict';
angular.module('app.core',[]);
}());
// content of array.js
(function() {
'use strict';
var core = angular.module('app.core');
core.config( .....)
}());
// content of string.js
...
// content of logger.js
I have attempted using two grunt tasks, but I could not configure them to meet my requirements.
1) grunt-concat had the issue of appending the contents from the beginning instead of the end of the file as required, and it did not override the existing content.
2) grunt-copy did override, but it replaced the entire file.
I also tried using the process function for grunt copy.
copy: {
src: ['app/components/core/{,*/}*.js'],
dest: 'app/components/core/lib/core.js',
options:{
process : function(content, srcpath){
return content; // perform manipulation on content here.
}
}
}
This approach was problematic because I had to keep the angular module definition text in my Gruntfile and append it to the first content that enters the process function, making it messy.
process : function(content, srcpath){
if(isFirst) {
isFirst = false;
// append the angular module declaration here.
}
return content;
}
Is there a more elegant way to achieve this task?