adds support for browserify
this pr also changes some code to make compatible with the browser. It exposes the global variable "carto" One of the problems is mapnik reference, the module is not read to work with browserify since it loads modules dynamically. It does not make sense to make it compatible since mapnik-reference is not going to be used so people must to set the reference needed before parse/render: carto.tree.Reference.setData(reference)
This commit is contained in:
parent
b19ade3850
commit
2e00705b64
11
Makefile
11
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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user