diff --git a/Makefile b/Makefile index 60277de..682e3f5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,11 @@ # expresso = ./node_modules/.bin/mocha +BROWSERIFY = ./node_modules/.bin/browserify +TREE_FILES = $(shell ls ./lib/carto/tree/*.js) + +# generates the requirement options for browserify for modules loaded dinamically (see, lib/carto/index.js) +BROWSERIFY_REQUIRES = $(foreach var,$(TREE_FILES), -r $(var):$(subst .js,,$(subst ./lib/carto,.,$(var)))) lint: ./node_modules/.bin/jshint lib/carto/*.js lib/carto/tree/*.js @@ -17,4 +22,10 @@ endif check: test +dist: + mkdir -p dist + +dist/carto.uncompressed.js: dist $(shell $(BROWSERIFY) --list lib/carto/index.js) $(TREE_FILES) + $(BROWSERIFY) --require $(BROWSERIFY_REQUIRES) --debug lib/carto/index.js --standalone carto > $@ + .PHONY: test diff --git a/lib/carto/index.js b/lib/carto/index.js index a0265d8..3b96899 100644 --- a/lib/carto/index.js +++ b/lib/carto/index.js @@ -4,7 +4,9 @@ var util = require('util'), function getVersion() { - if (parseInt(process.version.split('.')[1], 10) > 4) { + if (typeof(this['window']) !== undefined) { + return require('../../package.json').version.split('.'); + } else if (parseInt(process.version.split('.')[1], 10) > 4) { return require('../../package.json').version.split('.'); } else { // older node diff --git a/lib/carto/tree/reference.js b/lib/carto/tree/reference.js index de0945a..64fe76f 100644 --- a/lib/carto/tree/reference.js +++ b/lib/carto/tree/reference.js @@ -5,7 +5,6 @@ (function(tree) { var _ = require('underscore'), - mapnik_reference = require('mapnik-reference'), ref = {}; ref.setData = function(data) { @@ -24,6 +23,7 @@ ref.setData = function(data) { }; ref.setVersion = function(version) { + var mapnik_reference = require('mapnik-reference'); if (mapnik_reference.version.hasOwnProperty(version)) { ref.setData(mapnik_reference.version[version]); return true; diff --git a/package.json b/package.json index 94fdc21..6c061a6 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ "jshint": "0.2.x", "sax": "0.1.x", "istanbul": "~0.2.14", - "coveralls": "~2.10.1" + "coveralls": "~2.10.1", + "browserify": "~7.0.0" }, "scripts": { "pretest": "npm install",