Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I'm not even joking.
// This was what I got, pasted into an email.
module.exports = function(grunt) {
//Grunt Globals
var ConcatOutputFileNameAndLocation="c:\\TestOutput.js";
var JavascriptDirectory = 'C:\\Work\\Patch29\\StaticContent\\RootAssets\\JsLib'
var MessageTaskStart = "StartingTask_";
var MessageTaskEnd = "EndingTask_";
var MessageTaskERR = "Error_";
var MessageTaskReturnObjectValue = "ReturnObjectValue_";
var arryOfFiles = new Array();
var stringOfFiles;
//Grunt Functions
function readFiles()
{
var tmparry = new Array();
console.log(MessageTaskStart + 'readFiles()');
var fs = require('fs');
tmparry = fs.readdirSync(JavascriptDirectory).filter(function(file) { return file.substr(-3) == '.js'});
tmparry.forEach(function(item)
{
arryOfFiles.push("'" + JavascriptDirectory + item + "'");
});
console.log(MessageTaskEnd + 'readFiles()');
//console.log(MessageTaskReturnObjectValue + arryOfFiles);
//console.log(arryOfFiles.toString());
stringOfFiles = arryOfFiles.toString();
return true;
}
//Grunt Tasks
grunt.registerInitTask('ReadFiles','Read Files',function() {var done = this.async(); done(readFiles()); });
//Grunt Commands
grunt.task.run('ReadFiles');
grunt.registerTask('ReadFiles','ReadFiles',readFiles());
grunt.registerTask('default', 'concat');
//Grunt Init
grunt.initConfig(
{
concat: {
dist: {
src: [stringOfFiles],
dest:ConcatOutputFileNameAndLocation
}
}
});
};
// This is probably how it should've been done.
module.exports = function(grunt) {
// Grunt Init
grunt.initConfig({
concat: {
dist: {
src: ['StaticContent/RootAssets/JsLib/**/*.js'],
dest: 'TestOutput.js'
}
}
});
// Grunt Tasks
grunt.registerTask('default', 'concat');
};
@treasonx
Copy link

treasonx commented Apr 18, 2012

I love seeing new Array() in JavaScript it reminds me of Java :)

@sindresorhus
Copy link

sindresorhus commented Apr 18, 2012

lol. Someone has not heard of globbing or read the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment