Skip to content

Instantly share code, notes, and snippets.

@sergebat
Last active October 4, 2015 13:59
Show Gist options
  • Save sergebat/7b844813bb0d317624fe to your computer and use it in GitHub Desktop.
Save sergebat/7b844813bb0d317624fe to your computer and use it in GitHub Desktop.
Grunt target to find and replace in bulk colors of the uncompressed fla file (xfl)
var path = require('path');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
colorizefla: {
blacknwhite: {
colors: [
{name: "Color1", from: "#A8B89D", to: "#666666"},
{name: "Color2", from: "#C2D1B6", to: "#999999"}
]
},
ice: {
colors: [
{name: "Color1", from: "#A8B89D", to: "#7EB7D9"},
{name: "Color2", from: "#C2D1B6", to: "#9FCFED"},
]
}
}
});
grunt.registerMultiTask("colorizefla", function () {
var colorList = this.data.colors || [];
var suffix = this.target;
var base = "resources/img/skins/sprites";
var destination = base + "-" + suffix;
grunt.file.expand({cwd: base}, "**/*.*").forEach(function(file) {
var isXMLFile = grunt.file.isMatch("**/*.xml", file);
grunt.log.debug("Copy: " + file);
grunt.log.debug("File is XML: " + isXMLFile);
grunt.file.copy(path.join(base, file), path.join(destination, file), isXMLFile && {
process: function(content, srcpath) {
colorList.forEach( function(c) {
grunt.log.debug("Replacing: " + c.from + "-->" + c.to);
content = content.replace(new RegExp(c.from, "g"), c.to);
});
return content;
}
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment