Created
March 23, 2015 10:43
-
-
Save gurdotan/f5c14ddb20b6814daf61 to your computer and use it in GitHub Desktop.
Unity Package Mass Labelling script - Node.js
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
{ | |
"name": "unity-mass-labeler", | |
"version": "0.0.1", | |
"description": "", | |
"main": "mass-labeler.js", | |
"dependencies": { | |
"lodash": "^3.5.0", | |
"recursive-readdir": "^1.2.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Gur Dotan", | |
"license": "MIT" | |
} |
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
var _ = require('lodash'); | |
var fs = require('fs'); | |
var recursive = require('recursive-readdir'); | |
// | |
// Fill in these: | |
// | |
var labels = ['FILL', 'IN', 'YOUR', 'LABELS', 'IN', 'THIS', 'ARRAY']; | |
var packagePath = 'FILL IN THE PATH TO YOUR ASSETS FOLDER'; | |
// ignore files with .png and .DS_STORE suffices | |
recursive(packagePath, ['*.png', '.DS_Store'], function (err, paths) { | |
// Files is an array of filename | |
console.log(paths); | |
_.each(paths, function(path) { | |
// Skip non meta files | |
if (!path.match(/\.meta$/)) return; | |
try { | |
var str = "labels:\n"; | |
str += _.map(labels, function(el) { | |
return '- ' + el + '\n' | |
}).join(''); | |
fs.appendFileSync(path, str); | |
console.log('Meta file written: ' + path); | |
} catch (e) { | |
console.log(e); | |
} | |
}); | |
console.log('Done'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment