Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add build scripts from leaflet updated for our files.

  • Loading branch information...
commit b104ace6f8eda2b6fac34dfe7b6fdadcffe62806 1 parent 6992ce1
@danzel danzel authored
View
3  .gitignore
@@ -3,4 +3,5 @@ bin
obj
# mstest test results
-TestResults
+TestResults
+node_modules
View
67 Jakefile.js
@@ -0,0 +1,67 @@
+var build = require('./build/build.js'),
+ lint = require('./build/hint.js');
+
+var COPYRIGHT = '/*\n Copyright (c) 2012, Smartrak, David Leaver\n' +
+ ' Leaflet.markercluster is an open-source JavaScript library for Marker Clustering on leaflet powered maps.\n' +
+ ' https://github.com/danzel/Leaflet.markercluster\n*/\n';
+
+desc('Check Leaflet.markercluster source for errors with JSHint');
+task('lint', function () {
+
+ var files = build.getFiles();
+
+ console.log('Checking for JS errors...');
+
+ var errorsFound = lint.jshint(files);
+
+ if (errorsFound > 0) {
+ console.log(errorsFound + ' error(s) found.\n');
+ fail();
+ } else {
+ console.log('\tCheck passed');
+ }
+});
+
+desc('Combine and compress Leaflet.markercluster source files');
+task('build', ['lint'], function (compsBase32, buildName) {
+
+ var files = build.getFiles(compsBase32);
+
+ console.log('Concatenating ' + files.length + ' files...');
+
+ var content = build.combineFiles(files),
+ newSrc = COPYRIGHT + content,
+
+ pathPart = 'dist/leaflet.markercluster' + (buildName ? '-' + buildName : ''),
+ srcPath = pathPart + '-src.js',
+
+ oldSrc = build.load(srcPath),
+ srcDelta = build.getSizeDelta(newSrc, oldSrc);
+
+ console.log('\tUncompressed size: ' + newSrc.length + ' bytes (' + srcDelta + ')');
+
+ if (newSrc === oldSrc) {
+ console.log('\tNo changes');
+ } else {
+ build.save(srcPath, newSrc);
+ console.log('\tSaved to ' + srcPath);
+ }
+
+ console.log('Compressing...');
+
+ var path = pathPart + '.js',
+ oldCompressed = build.load(path),
+ newCompressed = COPYRIGHT + build.uglify(content),
+ delta = build.getSizeDelta(newCompressed, oldCompressed);
+
+ console.log('\tCompressed size: ' + newCompressed.length + ' bytes (' + delta + ')');
+
+ if (newCompressed === oldCompressed) {
+ console.log('\tNo changes');
+ } else {
+ build.save(path, newCompressed);
+ console.log('\tSaved to ' + path);
+ }
+});
+
+task('default', ['build']);
View
243 build/build.html
@@ -0,0 +1,243 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Leaflet.markercluster Build Helper</title>
+
+ <script type="text/javascript" src="deps.js"></script>
+
+ <style type="text/css">
+ body {
+ font: 12px/1.4 Verdana, sans-serif;
+ text-align: center;
+ padding: 2em 0;
+ }
+ #container {
+ text-align: left;
+ margin: 0 auto;
+ width: 780px;
+ }
+ #deplist {
+ list-style: none;
+ padding: 0;
+ }
+ #deplist li {
+ padding-top: 7px;
+ padding-bottom: 7px;
+ border-bottom: 1px solid #ddd;
+ }
+ #deplist li.heading {
+ border: none;
+ background: #ddd;
+ padding: 5px 10px;
+ margin-top: 25px;
+ border-radius: 5px;
+ }
+ #deplist input {
+ float: left;
+ margin-right: 5px;
+ display: inline;
+ }
+ #deplist label {
+ float: left;
+ width: 160px;
+ font-weight: bold;
+ }
+ #deplist div {
+ display: table-cell;
+ height: 1%;
+ }
+ #deplist .desc {
+ }
+
+ #deplist .deps {
+ color: #777;
+ }
+
+ #command {
+ width: 100%;
+ }
+ #command2 {
+ width: 200px;
+ }
+
+ #toolbar {
+ padding-bottom: 10px;
+ border-bottom: 1px solid #ddd;
+ }
+
+ h2 {
+ margin-top: 2em;
+ }
+ </style>
+</head>
+<body>
+ <div id="container">
+ <h1>Leaflet.markercluster Build Helper</h1>
+
+ <p id="toolbar">
+ <a id="select-all" href="#all">Select All</a> |
+ <a id="deselect-all" href="#none">Deselect All</a>
+ </p>
+
+ <ul id="deplist"></ul>
+
+ <h2>Building using Node and UglifyJS</h2>
+ <ol>
+ <li><a href="http://nodejs.org/#download">Download and install Node</a></li>
+ <li>Run this in the command line:<br />
+ <pre><code>npm install -g jake
+npm install jshint
+npm install uglify-js</code></pre></li>
+ <li>Run this command inside the Leaflet.markercluster directory: <br /><input type="text" id="command2" />
+ </ol>
+ <h2>Building using Closure Compiler</h2>
+ <ol>
+ <li><a href="http://closure-compiler.googlecode.com/files/compiler-latest.zip">Download Closure Compiler</a>, extract it into <code>closure-compiler</code> directory</li>
+ <li>Run this command in the root Leaflet directory: <br /><input type="text" id="command" /></li>
+ </ol>
+ </div>
+
+ <script type="text/javascript">
+ var deplist = document.getElementById('deplist'),
+ commandInput = document.getElementById('command'),
+ commandInput2 = document.getElementById('command2');
+
+ document.getElementById('select-all').onclick = function() {
+ var checks = deplist.getElementsByTagName('input');
+ for (var i = 0; i < checks.length; i++) {
+ checks[i].checked = true;
+ }
+ updateCommand();
+ return false;
+ };
+
+ document.getElementById('deselect-all').onclick = function() {
+ var checks = deplist.getElementsByTagName('input');
+ for (var i = 0; i < checks.length; i++) {
+ if (!checks[i].disabled) {
+ checks[i].checked = false;
+ }
+ }
+ updateCommand();
+ return false;
+ };
+
+ function updateCommand() {
+ var files = {};
+ var checks = deplist.getElementsByTagName('input');
+ var compsStr = '';
+
+ for (var i = 0, len = checks.length; i < len; i++) {
+ if (checks[i].checked) {
+ var srcs = deps[checks[i].id].src;
+ for (var j = 0, len2 = srcs.length; j < len2; j++) {
+ files[srcs[j]] = true;
+ }
+ compsStr = '1' + compsStr;
+ } else {
+ compsStr = '0' + compsStr;
+ }
+ }
+
+ var command = 'java -jar closure-compiler/compiler.jar ';
+ for (var src in files) {
+ command += '--js src/' + src + ' ';
+ }
+ command += '--js_output_file dist/leaflet-custom.js';
+
+ commandInput.value = command;
+
+ commandInput2.value = 'jake build[' + parseInt(compsStr, 2).toString(32) + ',custom]';
+ }
+
+ function inputSelect() {
+ this.focus();
+ this.select();
+ };
+
+ commandInput.onclick = inputSelect;
+ commandInput2.onclick = inputSelect;
+
+ function onCheckboxChange() {
+ if (this.checked) {
+ var depDeps = deps[this.id].deps;
+ if (depDeps) {
+ for (var i = 0; i < depDeps.length; i++) {
+ var check = document.getElementById(depDeps[i]);
+ if (!check.checked) {
+ check.checked = true;
+ check.onchange();
+ }
+ }
+ }
+ } else {
+ var checks = deplist.getElementsByTagName('input');
+ for (var i = 0; i < checks.length; i++) {
+ var dep = deps[checks[i].id];
+ if (!dep.deps) { continue; }
+ for (var j = 0; j < dep.deps.length; j++) {
+ if (dep.deps[j] === this.id) {
+ if (checks[i].checked) {
+ checks[i].checked = false;
+ checks[i].onchange();
+ }
+ }
+ }
+ }
+ }
+ updateCommand();
+ }
+
+ for (var name in deps) {
+ var li = document.createElement('li');
+
+ if (deps[name].heading) {
+ var heading = document.createElement('li');
+ heading.className = 'heading';
+ heading.appendChild(document.createTextNode(deps[name].heading));
+ deplist.appendChild(heading);
+ }
+
+ var div = document.createElement('div');
+
+ var label = document.createElement('label');
+
+ var check = document.createElement('input');
+ check.type = 'checkbox';
+ check.id = name;
+ label.appendChild(check);
+ check.onchange = onCheckboxChange;
+
+ if (name == 'Core') {
+ check.checked = true;
+ check.disabled = true;
+ }
+
+ label.appendChild(document.createTextNode(name));
+ label.htmlFor = name;
+
+ li.appendChild(label);
+
+ var desc = document.createElement('span');
+ desc.className = 'desc';
+ desc.appendChild(document.createTextNode(deps[name].desc));
+
+ var depText = deps[name].deps && deps[name].deps.join(', ');
+ if (depText) {
+ var depspan = document.createElement('span');
+ depspan.className = 'deps';
+ depspan.appendChild(document.createTextNode('Deps: ' + depText));
+ }
+
+ div.appendChild(desc);
+ div.appendChild(document.createElement('br'));
+ if (depText) { div.appendChild(depspan); }
+
+ li.appendChild(div);
+
+ deplist.appendChild(li);
+ }
+ updateCommand();
+ </script>
+</body>
+</html>
View
79 build/build.js
@@ -0,0 +1,79 @@
+var fs = require('fs'),
+ uglifyjs = require('uglify-js'),
+ deps = require('./deps.js').deps;
+
+exports.getFiles = function (compsBase32) {
+ var memo = {},
+ comps;
+
+ if (compsBase32) {
+ comps = parseInt(compsBase32, 32).toString(2).split('');
+ console.log('Managing dependencies...')
+ }
+
+ function addFiles(srcs) {
+ for (var j = 0, len = srcs.length; j < len; j++) {
+ memo[srcs[j]] = true;
+ }
+ }
+
+ for (var i in deps) {
+ if (comps) {
+ if (parseInt(comps.pop(), 2) === 1) {
+ console.log('\t* ' + i);
+ addFiles(deps[i].src);
+ } else {
+ console.log('\t ' + i);
+ }
+ } else {
+ addFiles(deps[i].src);
+ }
+ }
+
+ var files = [];
+
+ for (var src in memo) {
+ files.push('src/' + src);
+ }
+
+ return files;
+};
+
+exports.uglify = function (code) {
+ var pro = uglifyjs.uglify;
+
+ var ast = uglifyjs.parser.parse(code);
+ ast = pro.ast_mangle(ast, {mangle: true});
+ ast = pro.ast_squeeze(ast);
+ ast = pro.ast_squeeze_more(ast);
+
+ return pro.gen_code(ast) + ';';
+};
+
+exports.combineFiles = function (files) {
+ var content = '(function (window, undefined) {\n\n';
+ for (var i = 0, len = files.length; i < len; i++) {
+ content += fs.readFileSync(files[i], 'utf8') + '\n\n';
+ }
+ return content + '\n\n}(this));';
+};
+
+exports.save = function (savePath, compressed) {
+ return fs.writeFileSync(savePath, compressed, 'utf8');
+};
+
+exports.load = function (loadPath) {
+ try {
+ return fs.readFileSync(loadPath, 'utf8');
+ } catch (e) {
+ return null;
+ }
+};
+
+exports.getSizeDelta = function (newContent, oldContent) {
+ if (!oldContent) {
+ return 'new';
+ }
+ var delta = newContent.length - oldContent.length;
+ return (delta >= 0 ? '+' : '') + delta;
+};
View
30 build/deps.js
@@ -0,0 +1,30 @@
+var deps = {
+ Core: {
+ src: ['MarkerClusterGroup.js',
+ 'MarkerCluster.js'],
+ desc: 'The core of the library.'
+ },
+
+ QuickHull: {
+ src: ['MarkerCluster.QuickHull.js'],
+ desc: 'ConvexHull generation. Used to show the area outline of the markers within a cluster.',
+ heading: 'QuickHull'
+ },
+
+ Spiderfier: {
+ src: ['MarkerCluster.Spiderfier.js'],
+ desc: 'Provides the ability to show all of the child markers of a cluster.',
+ heading: 'Spiderfier'
+ },
+
+ Defaults: {
+ src: ['MarkerCluster.Default.js'],
+ deps: ['QuickHull', 'Spiderfier'],
+ desc: 'Provides sensible defaults for the Cluster.',
+ heading: 'Sensible Defaults'
+ }
+};
+
+if (typeof exports !== 'undefined') {
+ exports.deps = deps;
+}
View
30 build/hint.js
@@ -0,0 +1,30 @@
+var jshint = require('jshint').JSHINT,
+ fs = require('fs'),
+ config = require('./hintrc.js').config;
+
+function jshintSrc(path, src) {
+ jshint(src, config);
+
+ var errors = jshint.errors,
+ i, len, e, line;
+
+ for (i = 0, len = errors.length; i < len; i++) {
+ e = errors[i];
+ //console.log(e.evidence);
+ console.log(path + '\tline ' + e.line + '\tcol ' + e.character + '\t ' + e.reason);
+ }
+
+ return len;
+}
+
+exports.jshint = function (files) {
+ var errorsFound = 0;
+
+ for (var i = 0, len = files.length; i < len; i++) {
+ var src = fs.readFileSync(files[i], 'utf8');
+
+ errorsFound += jshintSrc(files[i], src);
+ }
+
+ return errorsFound;
+};
View
47 build/hintrc.js
@@ -0,0 +1,47 @@
+exports.config = {
+ "browser": true,
+ "node": true,
+ "predef": ["L"],
+
+ "debug": false,
+ "devel": false,
+
+ "es5": false,
+ "strict": false,
+ "globalstrict": false,
+
+ "asi": false,
+ "laxbreak": false,
+ "bitwise": true,
+ "boss": false,
+ "curly": true,
+ "eqnull": false,
+ "evil": false,
+ "expr": false,
+ "forin": true,
+ "immed": true,
+ "latedef": true,
+ "loopfunc": false,
+ "noarg": true,
+ "regexp": true,
+ "regexdash": false,
+ "scripturl": false,
+ "shadow": false,
+ "supernew": false,
+ "undef": true,
+ "funcscope": false,
+
+ "newcap": true,
+ "noempty": true,
+ "nonew": true,
+ "nomen": false,
+ "onevar": false,
+ "plusplus": false,
+ "sub": false,
+ "indent": 4,
+
+ "eqeqeq": true,
+ "trailing": true,
+ "white": true,
+ "smarttabs": true
+};
Please sign in to comment.
Something went wrong with that request. Please try again.