Created
September 3, 2015 14:40
-
-
Save ada-lovecraft/bd8034e67c1130d63d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerMultiTask('pack', function() { | |
var objects = { | |
"meta": { | |
"generated": Date.now(), | |
"version": "1.0", | |
"app": "Pumpkinator Asset Packer", | |
"url": "http://some.url", | |
"copyright": "Hyfn 2015" | |
} | |
}; | |
var imageObj = { | |
// Loads an Image | |
"type": "image", | |
"key": "ball", | |
"url": "assets/sprites/shinyball.png", | |
"overwrite": true | |
}; | |
this.filesSrc.forEach(function(filepath) { | |
var matches = filepath.match(/\.\/src\/images\/anims\/(\S+)\/(\S+)/); | |
var objName = _.kebabCase(matches[1]); | |
var img = _.assign({}, imageObj, {key: _.kebabCase(matches[2].split('.')[0]), url:filepath.replace('./src/','')}); | |
if(!objects[objName]) { | |
objects[objName] = []; | |
} | |
objects[objName].push(img); | |
}); | |
var json = JSON.stringify(objects, null, 2); | |
json = json.replace(/^( *)"(\w+)"/gm, '$1$2').replace(/"/gm, '\'').replace(/(\'images\S+\')/gm, 'require($1)'); | |
grunt.file.write('src/creator/packs/anims.js', 'module.exports = ' + json); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment