Skip to content

Commit

Permalink
[#2599] Add a utility for generating the CSS files
Browse files Browse the repository at this point in the history
Requires the less npm package to be installed. This should eventually
be moved into a paster command.

Usage:

    $ npm install less
    $ ./bin/less                # Works in development
    $ ENV=production ./bin/less # Generate production file.
  • Loading branch information
aron committed Jun 26, 2012
1 parent 2db796e commit 5e9cae7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bin/less
@@ -0,0 +1,38 @@
#!/usr/bin/env node

var fs = require('fs'),
path = require('path'),
exec = require('child_process').exec,
watch = path.join(__dirname, '..', 'ckan', 'public', 'base', 'less'),
debug = process.env.ENV !== 'production';

function now() {
return new Date().toISOString().replace('T', ' ').substr(0, 19);
}

function compile(event, filename) {
var start = Date.now(),
filename = 'main.css';

if (debug) {
filename = 'main.debug.css';
}

exec('`npm bin`/lessc ckan/public/base/less/main.less > ckan/public/base/css/' + filename, function (err, stdout, stderr) {
var duration = Date.now() - start;

if (err) {
console.log('An error occurred running the less command:');
console.log(err.message);
}
else if (stderr || stdout) {
console.log(stdout, stderr);
} else {
console.log('[%s] recompiled ' + filename + ' in %sms', now(), duration);
}
});
}

console.log('Watching %s', watch);
fs.watch(watch, compile);
compile();

0 comments on commit 5e9cae7

Please sign in to comment.