Skip to content

Instantly share code, notes, and snippets.

@gurdotan
Created March 23, 2015 10:43
Show Gist options
  • Save gurdotan/f5c14ddb20b6814daf61 to your computer and use it in GitHub Desktop.
Save gurdotan/f5c14ddb20b6814daf61 to your computer and use it in GitHub Desktop.
Unity Package Mass Labelling script - Node.js
{
"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"
}
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