some cleanup

This commit is contained in:
Konstantin Käfer 2011-02-08 10:09:22 -05:00
parent 1091a3906b
commit 94507ac552
3 changed files with 19 additions and 37 deletions

View File

@ -8,10 +8,7 @@ require.paths.unshift(path.join(__dirname, '../lib'), path.join(__dirname, '../l
var carto = require('carto'); var carto = require('carto');
var args = process.argv.slice(1); var args = process.argv.slice(1);
var options = { var options = {};
silent: false,
json: false
};
args = args.filter(function (arg) { args = args.filter(function (arg) {
var match; var match;
@ -22,29 +19,19 @@ args = args.filter(function (arg) {
switch (arg) { switch (arg) {
case 'v': case 'v':
case 'version': case 'version':
sys.puts("cartoc " + carto.version.join('.') + " (MESS Compiler) [JavaScript]"); sys.puts("carto " + carto.version.join('.') + " (Carto map stylesheet compiler)");
process.exit(0); process.exit(0);
break; break;
case 'verbose':
options.verbose = true;
break;
case 'd':
case 'debug':
options.debug = true;
break;
case 's':
case 'silent':
options.silent = true;
break;
case 'b': case 'b':
case 'benchmark': case 'benchmark':
options.benchmark = true; options.benchmark = true;
break; break;
case 'h':
case 'help': default:
sys.puts("Usage: carto source"); sys.puts("Usage: carto <source MML file>");
sys.puts("Options:"); sys.puts("Options:");
sys.puts(" -j\tParse JSON map manifest"); sys.puts(" -v --version Parse JSON map manifest");
sys.puts(" -b --benchmark Outputs total compile time");
process.exit(0); process.exit(0);
break; break;
} }
@ -54,10 +41,6 @@ var input = args[1];
if (input && input[0] != '/') { if (input && input[0] != '/') {
input = path.join(process.cwd(), input); input = path.join(process.cwd(), input);
} }
var output = args[2];
if (output && output[0] != '/') {
output = path.join(process.cwd(), output);
}
if (!input) { if (!input) {
sys.puts("carto: no input files"); sys.puts("carto: no input files");
@ -68,15 +51,15 @@ if (options.benchmark) {
var start = +new Date; var start = +new Date;
} }
fs.readFile(input, 'utf-8', function (e, data) { fs.readFile(input, 'utf-8', function (err, data) {
if (e) { if (err) {
sys.puts("carto: " + e.cartoage); sys.puts("carto: " + err.message.replace(/^[A-Z]+, /, ''));
process.exit(1); process.exit(1);
} }
new carto.Renderer({ new carto.Renderer({
filename: input, filename: input,
debug: options.debug, benchmark: options.benchmark,
local_data_dir: path.dirname(input), local_data_dir: path.dirname(input),
}).render(data, function(err, output) { }).render(data, function(err, output) {
if (err) { if (err) {
@ -94,7 +77,7 @@ fs.readFile(input, 'utf-8', function (e, data) {
sys.puts(output); sys.puts(output);
} else { } else {
var duration = (+new Date) - start; var duration = (+new Date) - start;
console.log('Benchmark: ' + (duration) + 'ms'); console.log('TOTAL: ' + (duration) + 'ms');
} }
} }
}); });

View File

@ -5,7 +5,7 @@ var path = require('path'),
require.paths.unshift(path.join(__dirname, '..')); require.paths.unshift(path.join(__dirname, '..'));
var carto = { var carto = {
version: [1, 0, 40], version: [0, 1, 0],
Parser: require('carto/parser').Parser, Parser: require('carto/parser').Parser,
Renderer: require('carto/renderer').Renderer, Renderer: require('carto/renderer').Renderer,
External: require('carto/external'), External: require('carto/external'),

View File

@ -13,7 +13,6 @@ require.paths.unshift(path.join(__dirname, '..', 'lib'));
// This is node-only for the time being. // This is node-only for the time being.
carto.Renderer = function Renderer(env) { carto.Renderer = function Renderer(env) {
env = _.extend({}, env); env = _.extend({}, env);
if (!env.debug) env.debug = false;
if (!env.data_dir) env.data_dir = '/tmp/'; if (!env.data_dir) env.data_dir = '/tmp/';
if (!env.local_data_dir) env.local_data_dir = ''; if (!env.local_data_dir) env.local_data_dir = '';
if (!env.validation_data) env.validation_data = false; if (!env.validation_data) env.validation_data = false;
@ -201,9 +200,9 @@ carto.Renderer = function Renderer(env) {
), { filename: result[0] }); ), { filename: result[0] });
new carto.Parser(parse_env).parse(result[1], new carto.Parser(parse_env).parse(result[1],
function(err, tree) { function(err, tree) {
if (env.debug) console.warn('Parsing time: ' if (env.benchmark) console.warn('Parsing time: '
+ ((new Date - parsingTime)) + ((new Date - parsingTime))
+ 'ms (' + result[0] + ')'); + 'ms');
try { try {
next(err, [ next(err, [
result[0], result[0],
@ -299,7 +298,7 @@ carto.Renderer = function Renderer(env) {
} }
} }
if (env.debug) console.warn('Inheritance time: ' + ((new Date - inheritTime)) + 'ms'); if (env.benchmark) console.warn('Inheritance time: ' + ((new Date - inheritTime)) + 'ms');
return result; return result;
}, },
@ -464,12 +463,12 @@ carto.Renderer = function Renderer(env) {
this.localizeExternals(m, function(err, res) { this.localizeExternals(m, function(err, res) {
that.ensureSRS(res, function(err, res) { that.ensureSRS(res, function(err, res) {
that.localizeStyle(res, function(err, res) { that.localizeStyle(res, function(err, res) {
if (env.debug) console.warn('Localizing time: ' if (env.benchmark) console.warn('Localizing time: '
+ ((new Date - localizingTime)) + 'ms'); + ((new Date - localizingTime)) + 'ms');
that.style(res, function(err, m, res) { that.style(res, function(err, m, res) {
var compilingTime = +new Date; var compilingTime = +new Date;
that.template(err, m, res, function(err, res) { that.template(err, m, res, function(err, res) {
if (env.debug) console.warn('COMPILING TIME: ' if (env.benchmark) console.warn('Compiling time: '
+ ((new Date - compilingTime)) + 'ms'); + ((new Date - compilingTime)) + 'ms');
callback(err, res); callback(err, res);
}); });