I did something similar to what Jakell suggested, but I decided to use globe templates (as Florian F. suggested). I added a new Grunt task:
var fs = require("fs");
grunt.registerTask("filelist", "Lists files in a directory as JSON string to file", function() {
var list,
done = this.async(),
output = grunt.config("filelist.images.output"),
outputVariable = grunt.config("filelist.images.outputVariable"),
patterns = grunt.config("filelist.images.patterns"),
headerComment = '/* This file was auto-generated using Grunt task `filelist`. */\n';
list = grunt.file.expand(patterns);
fs.writeFile(output,
headerComment + outputVariable + ' = ' + JSON.stringify(list) + ';',
function (err) {
if (err) {
throw err;
}
grunt.log.writeln("List of " + list.length + " files saved to " + output);
done();
});
});
:
filelist: {
images: {
output: "app/generated/image-list.js",
outputVariable: "game.imageList",
patterns: ["app/resources/img/**/*"],
},
},
, <script>, JS. , !:)