2010-03-22 07:18:47 +08:00
|
|
|
var path = require('path'),
|
|
|
|
fs = require('fs');
|
2010-03-13 16:34:48 +08:00
|
|
|
|
|
|
|
require.paths.unshift(__dirname);
|
|
|
|
|
|
|
|
var less = {
|
|
|
|
version: [2, 0, 0],
|
2010-03-22 07:18:47 +08:00
|
|
|
Parser: require('less/parser').Parser,
|
|
|
|
importer: require('less/parser').importer,
|
2010-03-13 16:34:48 +08:00
|
|
|
tree: require('less/tree')
|
|
|
|
};
|
|
|
|
|
|
|
|
['color', 'directive', 'operation', 'dimension',
|
|
|
|
'keyword', 'variable', 'ruleset', 'element',
|
|
|
|
'selector', 'quoted', 'expression', 'rule',
|
2010-03-20 05:50:48 +08:00
|
|
|
'call', 'url', 'alpha', 'import',
|
2010-03-13 16:34:48 +08:00
|
|
|
'mixin', 'comment'
|
|
|
|
].forEach(function (n) {
|
|
|
|
require(path.join('less', 'tree', n));
|
|
|
|
});
|
|
|
|
|
2010-03-23 08:59:11 +08:00
|
|
|
less.Parser.importer = function (file, paths, callback, context) {
|
2010-03-22 07:18:47 +08:00
|
|
|
var pathname;
|
|
|
|
|
|
|
|
paths.unshift('.');
|
|
|
|
|
|
|
|
for (var i = 0; i < paths.length; i++) {
|
|
|
|
try {
|
|
|
|
pathname = path.join(paths[i], file);
|
|
|
|
fs.statSync(pathname);
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
pathname = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pathname) {
|
|
|
|
fs.stat(pathname, function (e, stats) {
|
|
|
|
if (e) process.stdio.writeError(e);
|
|
|
|
|
|
|
|
fs.open(pathname, process.O_RDONLY, stats.mode, function (e, fd) {
|
|
|
|
if (e) process.stdio.writeError(e);
|
|
|
|
|
|
|
|
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
|
|
|
|
if (e) process.stdio.writeError(e);
|
|
|
|
|
|
|
|
new(less.Parser)({
|
|
|
|
paths: [path.dirname(pathname)]
|
|
|
|
}).parse(data, function (e, root) {
|
|
|
|
if (e) process.stdio.writeError(e);
|
2010-03-23 08:59:11 +08:00
|
|
|
callback.call(context || null, root);
|
2010-03-22 07:18:47 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
process.stdio.writeError("file '" + file + "' wasn't found.\n");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-13 16:34:48 +08:00
|
|
|
require('less/functions');
|
|
|
|
require('ext/array');
|
|
|
|
|
2010-03-19 04:42:25 +08:00
|
|
|
for (var k in less) { exports[k] = less[k] }
|
2010-03-13 16:34:48 +08:00
|
|
|
|