carto/bin/messc
2011-01-25 09:46:35 -05:00

77 lines
1.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
sys = require('sys');
require.paths.unshift(path.join(__dirname, '../lib'), path.join(__dirname, '../lib/node'));
var mess = require('mess');
var args = process.argv.slice(1);
var options = {
silent: false,
json: false
};
args = args.filter(function (arg) {
var match;
if (match = arg.match(/^--?([a-z][0-9a-z-]*)$/i)) { arg = match[1] }
else { return arg }
switch (arg) {
case 'v':
case 'version':
sys.puts("messc " + mess.version.join('.') + " (MESS Compiler) [JavaScript]");
process.exit(0);
case 'verbose':
options.verbose = true;
break;
case 'd':
options.debug = true;
case 's':
case 'silent':
options.silent = true;
break;
case 'h':
case 'help':
sys.puts("Usage: messc source");
sys.puts("Options:");
sys.puts(" -j\tParse JSON map manifest");
process.exit(0);
}
});
var input = args[1];
if (input && input[0] != '/') {
input = path.join(process.cwd(), input);
}
var output = args[2];
if (output && output[0] != '/') {
output = path.join(process.cwd(), output);
}
if (!input) {
sys.puts("messc: no input files");
process.exit(1);
}
fs.readFile(input, 'utf-8', function (e, data) {
if (e) {
sys.puts("messc: " + e.message);
process.exit(1);
}
new mess.Renderer({
filename: input,
local_data_dir: path.dirname(input),
}).render(data, function(err, output) {
if (err) {
mess.writeError(err, options);
process.exit(1);
} else {
sys.puts(output);
}
});
});