add components configuration to jake build

This commit is contained in:
mourner 2011-12-12 11:42:42 +02:00
parent 12b46ae1c4
commit f2a2868ed3
4 changed files with 57 additions and 168 deletions

View File

@ -3,15 +3,31 @@ var fs = require('fs'),
jshint = require('jshint'), jshint = require('jshint'),
deps = require('./build/deps.js').deps; deps = require('./build/deps.js').deps;
function getFiles() { function getFiles(compsBase32) {
var memo = {}, var memo = {},
i, srcs, j, len; i, srcs, j, len,
comps;
if (compsBase32) {
comps = parseInt(compsBase32, 32).toString(2).split('');
console.log('Managing dependencies...')
}
var log = [];
for (i in deps) { for (i in deps) {
srcs = deps[i].src; srcs = deps[i].src;
if (!comps || (parseInt(comps.pop(), 2) === 1)) {
if (comps) {
console.log('\t* ' + i);
}
for (j = 0, len = srcs.length; j < len; j++) { for (j = 0, len = srcs.length; j < len; j++) {
memo[srcs[j]] = true; memo[srcs[j]] = true;
} }
} else if (comps) {
console.log('\t ' + i);
}
} }
var files = [], var files = [],
@ -24,7 +40,7 @@ function getFiles() {
return files; return files;
} }
function myUglify(code){ function myUglify(code) {
var pro = uglify.uglify; var pro = uglify.uglify;
var ast = uglify.parser.parse(code); var ast = uglify.parser.parse(code);
@ -33,7 +49,7 @@ function myUglify(code){
ast = pro.ast_squeeze_more(ast); ast = pro.ast_squeeze_more(ast);
return pro.gen_code(ast); return pro.gen_code(ast);
}; }
function combineFiles(files) { function combineFiles(files) {
var content = ''; var content = '';
@ -47,11 +63,12 @@ var COPYRIGHT = "/*\n Copyright (c) 2010-2011, CloudMade, Vladimir Agafonkin\n"
" Leaflet is a modern open source JavaScript library for interactive maps.\n" + " Leaflet is a modern open source JavaScript library for interactive maps.\n" +
" http://leaflet.cloudmade.com\n*/\n"; " http://leaflet.cloudmade.com\n*/\n";
var SAVE_PATH = 'dist/leaflet.js'; task('build', function (compsBase32, buildName) {
var name = buildName || 'custom',
savePath = 'dist/leaflet' + (compsBase32 ? '-' + name : '') + '.js';
var files = getFiles(); var files = getFiles(compsBase32);
task('build', function () {
console.log('Concatenating ' + files.length + ' files...'); console.log('Concatenating ' + files.length + ' files...');
var content = combineFiles(files); var content = combineFiles(files);
@ -60,13 +77,14 @@ task('build', function () {
console.log('Compressing...'); console.log('Compressing...');
var compressed = COPYRIGHT + myUglify(content); var compressed = COPYRIGHT + myUglify(content);
fail("Helo world");
console.log('Compressed size: ' + compressed.length); console.log('Compressed size: ' + compressed.length);
fs.writeFileSync(SAVE_PATH, compressed, 'utf8'); fs.writeFileSync(savePath, compressed, 'utf8');
console.log('Saved to ' + SAVE_PATH); console.log('Saved to ' + savePath);
}); });
task('default', ['build']); task('default', ['build']);
// TODO task('lint')

View File

@ -1,71 +0,0 @@
../dist/leaflet.js: Makefile
java -jar ../lib/closure-compiler/compiler.jar \
--js ../src/Leaflet.js \
--js ../src/core/Util.js \
--js ../src/core/Class.js \
--js ../src/core/Events.js \
--js ../src/core/Browser.js \
--js ../src/geometry/Point.js \
--js ../src/geometry/Bounds.js \
--js ../src/geometry/Transformation.js \
--js ../src/geometry/LineUtil.js \
--js ../src/geometry/PolyUtil.js \
--js ../src/dom/DomEvent.js \
--js ../src/dom/DomEvent.DoubleTap.js \
--js ../src/dom/DomUtil.js \
--js ../src/dom/Draggable.js \
--js ../src/dom/transition/Transition.js \
--js ../src/dom/transition/Transition.Native.js \
--js ../src/dom/transition/Transition.Timer.js \
--js ../src/geo/LatLng.js \
--js ../src/geo/LatLngBounds.js \
--js ../src/geo/projection/Projection.js \
--js ../src/geo/projection/Projection.SphericalMercator.js \
--js ../src/geo/projection/Projection.LonLat.js \
--js ../src/geo/projection/Projection.Mercator.js \
--js ../src/geo/crs/CRS.js \
--js ../src/geo/crs/CRS.EPSG3857.js \
--js ../src/geo/crs/CRS.EPSG4326.js \
--js ../src/geo/crs/CRS.EPSG3395.js \
--js ../src/map/Map.js \
--js ../src/map/ext/Map.Geolocation.js \
--js ../src/map/ext/Map.Popup.js \
--js ../src/map/ext/Map.PanAnimation.js \
--js ../src/map/ext/Map.ZoomAnimation.js \
--js ../src/map/ext/Map.Control.js \
--js ../src/layer/LayerGroup.js \
--js ../src/layer/FeatureGroup.js \
--js ../src/layer/tile/TileLayer.js \
--js ../src/layer/tile/TileLayer.WMS.js \
--js ../src/layer/tile/TileLayer.Canvas.js \
--js ../src/layer/ImageOverlay.js \
--js ../src/layer/Popup.js \
--js ../src/layer/marker/Icon.js \
--js ../src/layer/marker/Marker.js \
--js ../src/layer/marker/Marker.Popup.js \
--js ../src/layer/vector/Path.js \
--js ../src/layer/vector/Path.Popup.js \
--js ../src/layer/vector/Path.SVG.js \
--js ../src/layer/vector/Path.VML.js \
--js ../src/layer/vector/canvas/Path.Canvas.js \
--js ../src/layer/vector/Polyline.js \
--js ../src/layer/vector/canvas/Polyline.Canvas.js \
--js ../src/layer/vector/Polygon.js \
--js ../src/layer/vector/canvas/Polygon.Canvas.js \
--js ../src/layer/vector/MultiPoly.js \
--js ../src/layer/vector/Circle.js \
--js ../src/layer/vector/canvas/Circle.Canvas.js \
--js ../src/layer/vector/CircleMarker.js \
--js ../src/layer/GeoJSON.js \
--js ../src/handler/Handler.js \
--js ../src/handler/MapDrag.js \
--js ../src/handler/TouchZoom.js \
--js ../src/handler/ScrollWheelZoom.js \
--js ../src/handler/DoubleClickZoom.js \
--js ../src/handler/ShiftDragZoom.js \
--js ../src/handler/MarkerDrag.js \
--js ../src/control/Control.js \
--js ../src/control/Control.Zoom.js \
--js ../src/control/Control.Attribution.js \
--js ../src/control/Control.Layers.js \
--js_output_file ../dist/leaflet.js

View File

@ -1,71 +0,0 @@
@echo off
java -jar ../lib/closure-compiler/compiler.jar ^
--js ../src/Leaflet.js ^
--js ../src/core/Util.js ^
--js ../src/core/Class.js ^
--js ../src/core/Events.js ^
--js ../src/core/Browser.js ^
--js ../src/geometry/Point.js ^
--js ../src/geometry/Bounds.js ^
--js ../src/geometry/Transformation.js ^
--js ../src/geometry/LineUtil.js ^
--js ../src/geometry/PolyUtil.js ^
--js ../src/dom/DomEvent.js ^
--js ../src/dom/DomEvent.DoubleTap.js ^
--js ../src/dom/DomUtil.js ^
--js ../src/dom/Draggable.js ^
--js ../src/dom/transition/Transition.js ^
--js ../src/dom/transition/Transition.Native.js ^
--js ../src/dom/transition/Transition.Timer.js ^
--js ../src/geo/LatLng.js ^
--js ../src/geo/LatLngBounds.js ^
--js ../src/geo/projection/Projection.js ^
--js ../src/geo/projection/Projection.SphericalMercator.js ^
--js ../src/geo/projection/Projection.LonLat.js ^
--js ../src/geo/projection/Projection.Mercator.js ^
--js ../src/geo/crs/CRS.js ^
--js ../src/geo/crs/CRS.EPSG3857.js ^
--js ../src/geo/crs/CRS.EPSG4326.js ^
--js ../src/geo/crs/CRS.EPSG3395.js ^
--js ../src/map/Map.js ^
--js ../src/map/ext/Map.Geolocation.js ^
--js ../src/map/ext/Map.Popup.js ^
--js ../src/map/ext/Map.PanAnimation.js ^
--js ../src/map/ext/Map.ZoomAnimation.js ^
--js ../src/map/ext/Map.Control.js ^
--js ../src/layer/LayerGroup.js ^
--js ../src/layer/FeatureGroup.js ^
--js ../src/layer/tile/TileLayer.js ^
--js ../src/layer/tile/TileLayer.WMS.js ^
--js ../src/layer/tile/TileLayer.Canvas.js ^
--js ../src/layer/ImageOverlay.js ^
--js ../src/layer/Popup.js ^
--js ../src/layer/marker/Icon.js ^
--js ../src/layer/marker/Marker.js ^
--js ../src/layer/marker/Marker.Popup.js ^
--js ../src/layer/vector/Path.js ^
--js ../src/layer/vector/Path.Popup.js ^
--js ../src/layer/vector/Path.SVG.js ^
--js ../src/layer/vector/Path.VML.js ^
--js ../src/layer/vector/canvas/Path.Canvas.js ^
--js ../src/layer/vector/Polyline.js ^
--js ../src/layer/vector/canvas/Polyline.Canvas.js ^
--js ../src/layer/vector/Polygon.js ^
--js ../src/layer/vector/canvas/Polygon.Canvas.js ^
--js ../src/layer/vector/MultiPoly.js ^
--js ../src/layer/vector/Circle.js ^
--js ../src/layer/vector/canvas/Circle.Canvas.js ^
--js ../src/layer/vector/CircleMarker.js ^
--js ../src/layer/GeoJSON.js ^
--js ../src/handler/Handler.js ^
--js ../src/handler/MapDrag.js ^
--js ../src/handler/TouchZoom.js ^
--js ../src/handler/ScrollWheelZoom.js ^
--js ../src/handler/DoubleClickZoom.js ^
--js ../src/handler/ShiftDragZoom.js ^
--js ../src/handler/MarkerDrag.js ^
--js ../src/control/Control.js ^
--js ../src/control/Control.Zoom.js ^
--js ../src/control/Control.Attribution.js ^
--js ../src/control/Control.Layers.js ^
--js_output_file ../dist/leaflet.js

View File

@ -52,7 +52,7 @@
color: #777; color: #777;
} }
#command { #command, #command2 {
width: 100%; width: 100%;
} }
</style> </style>
@ -69,14 +69,19 @@
<ul id="deplist"></ul> <ul id="deplist"></ul>
<p> <p>
Download <a href="http://closure-compiler.googlecode.com/files/compiler-latest.zip">Closure Compiler</a>, extract it into <code>lib/closure-compiler</code> directory and run this command in the <code>build</code> directory:<br /> To build using UglifyJS, <a href="http://nodejs.org/#download">install Node</a>, run <code>npm install -g jake</code>, then <code>npm install -g uglify-js</code>, then run this in the root Leaflet directory:<br />
<input type="text" id="command2" />
</p>
<p>
To build using Closure Compiler, <a href="http://closure-compiler.googlecode.com/files/compiler-latest.zip">download</a> and extract it into <code>lib/closure-compiler</code> directory and run this command in the root Leaflet directory:<br />
<input type="text" id="command" /> <input type="text" id="command" />
</p> </p>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var deplist = document.getElementById('deplist'), var deplist = document.getElementById('deplist'),
commandInput = document.getElementById('command'); commandInput = document.getElementById('command'),
commandInput2 = document.getElementById('command2');
document.getElementById('select-all').onclick = function() { document.getElementById('select-all').onclick = function() {
var checks = deplist.getElementsByTagName('input'); var checks = deplist.getElementsByTagName('input');
@ -101,22 +106,29 @@
function updateCommand() { function updateCommand() {
var files = {}; var files = {};
var checks = deplist.getElementsByTagName('input'); var checks = deplist.getElementsByTagName('input');
var compsStr = '';
for (var i = 0; i < checks.length; i++) { for (var i = 0; i < checks.length; i++) {
if (checks[i].checked) { if (checks[i].checked) {
var srcs = deps[checks[i].id].src; var srcs = deps[checks[i].id].src;
for (var j = 0; j < srcs.length; j++) { for (var j = 0; j < srcs.length; j++) {
files[srcs[j]] = true; files[srcs[j]] = true;
} }
compsStr = '1' + compsStr;
} else {
compsStr = '0' + compsStr;
} }
} }
var command = 'java -jar ../lib/closure-compiler/compiler.jar '; var command = 'java -jar lib/closure-compiler/compiler.jar ';
for (var src in files) { for (var src in files) {
command += '--js ../src/' + src + ' '; command += '--js src/' + src + ' ';
} }
command += '--js_output_file ../dist/leaflet-custom.js'; command += '--js_output_file dist/leaflet-custom.js';
commandInput.value = command; commandInput.value = command;
commandInput2.value = 'jake build[' + parseInt(compsStr, 2).toString(32) + ']';
} }
commandInput.onclick = function() { commandInput.onclick = function() {
@ -127,7 +139,7 @@
function onCheckboxChange() { function onCheckboxChange() {
if (this.checked) { if (this.checked) {
var depDeps = deps[this.id].deps; var depDeps = deps[this.id].deps;
if (!depDeps) { return; } if (depDeps) {
for (var i = 0; i < depDeps.length; i++) { for (var i = 0; i < depDeps.length; i++) {
var check = document.getElementById(depDeps[i]); var check = document.getElementById(depDeps[i]);
if (!check.checked) { if (!check.checked) {
@ -135,13 +147,14 @@
check.onchange(); check.onchange();
} }
} }
}
} else { } else {
var checks = deplist.getElementsByTagName('input'); var checks = deplist.getElementsByTagName('input');
for (var i = 0; i < checks.length; i++) { for (var i = 0; i < checks.length; i++) {
var dep = deps[checks[i].id]; var dep = deps[checks[i].id];
if (!dep.deps) { continue; } if (!dep.deps) { continue; }
for (var j = 0; j < dep.deps.length; j++) { for (var j = 0; j < dep.deps.length; j++) {
if (dep.deps[j] == this.id) { if (dep.deps[j] === this.id) {
if (checks[i].checked) { if (checks[i].checked) {
checks[i].checked = false; checks[i].checked = false;
checks[i].onchange(); checks[i].onchange();