Skip to content

Instantly share code, notes, and snippets.

@jeremy2
Created January 30, 2012 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremy2/1705248 to your computer and use it in GitHub Desktop.
Save jeremy2/1705248 to your computer and use it in GitHub Desktop.
dumb less parser to extract color info as JSON. TODO: clean this up, test and make it into a generally usable tool
function readColors() {
var file = 'public/stylesheets/less/_colors.less';
var data = fs.readFileSync(file, 'utf-8');
data = data.replace(/(.*): *(.*);/gm, '"$1":"$2",');
data = data.replace(/\/\/.*$/gm, '');
var i = data.lastIndexOf(',');
data = data.substring(0,i);
data = '{'+ data +'}';
data = JSON.parse(data);
console.log('json: '+ JSON.stringify(data));
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment