560e73bac5
Added Leafdoc comments to Layer.js Leafdoc comments for Popup, Layer Leafdoc comments: L.Evented, inheritances, minor tilelayer Leafdoc comments: gridlayer & tilelayer options Leafdoc comments: tilelayer, marker drag Typos Leafdoc: switch to shorthand method params Leafdoc: Switch to shorthands in marker drag, WMS. Leafdoc: Vector layers Leafdoc: Layer group, feature group, geojson Leafdoc: LatLng, Point, Bounds, Icons. Leafdoc: Controls. Leafdoc: DOM & utils. Leafdoc: "jake docs" now builds the documentation Leafdoc: Commit actual templates instead of symlinks Leafdoc: Fix broken build, have jake print out uglifyjs errors Leafdoc: Several L.Map bits. Leafdoc: Map handlers Leafdoc: Map events, L.CRS, misc. fixes Leafdoc: Fixed ordering of classes by using new leafdoc features Leafdoc: Misc bits at the bottom of the docs 🍂doc: Map panes 🍂doc: CRSs, projections and their templates 🍂doc: miniclasses for map methods' options Leafdoc: Cleanup L.Class, mark uninheritable sections, use Leafdoc 0.3.0 🍂doc: miniclasses for event types, bump to Leafdoc 1.0.0 🍂doc: Make linter happy after branch rebase 🍂doc: Tweaked headers for inherited stuff. 🍂doc: Tweaking section headers (white, padding, triangles) Leafdoc: upgrade to 1.2, document SVG&Canvas, and misc bits 🍂doc: minor CSS tweaks, version in filename, typo. Add missing bits - supersedes #4105, #4065, #4031 🍂doc: moved sections around, minor typos & fixes Typo about LocationEvent
219 lines
4.8 KiB
JavaScript
219 lines
4.8 KiB
JavaScript
var fs = require('fs'),
|
|
UglifyJS = require('uglify-js'),
|
|
zlib = require('zlib'),
|
|
MagicString = require('magic-string'),
|
|
|
|
deps = require('./deps.js').deps;
|
|
|
|
function getFiles(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(' * ' + i);
|
|
addFiles(deps[i].src);
|
|
} else {
|
|
console.log(' ' + i);
|
|
}
|
|
} else {
|
|
addFiles(deps[i].src);
|
|
}
|
|
}
|
|
|
|
console.log('');
|
|
|
|
var files = [];
|
|
|
|
for (var src in memo) {
|
|
files.push('src/' + src);
|
|
}
|
|
|
|
return files;
|
|
}
|
|
|
|
exports.getFiles = getFiles;
|
|
|
|
function getSizeDelta(newContent, oldContent, fixCRLF) {
|
|
if (!oldContent) {
|
|
return ' (new)';
|
|
}
|
|
if (newContent === oldContent) {
|
|
return ' (unchanged)';
|
|
}
|
|
if (fixCRLF) {
|
|
newContent = newContent.replace(/\r\n?/g, '\n');
|
|
oldContent = oldContent.replace(/\r\n?/g, '\n');
|
|
}
|
|
var delta = newContent.length - oldContent.length;
|
|
|
|
return delta === 0 ? '' : ' (' + (delta > 0 ? '+' : '') + delta + ' bytes)';
|
|
}
|
|
|
|
function loadSilently(path) {
|
|
try {
|
|
return fs.readFileSync(path, 'utf8');
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function bundleFiles(files, copy) {
|
|
var bundle = new MagicString.Bundle();
|
|
|
|
for (var i = 0, len = files.length; i < len; i++) {
|
|
bundle.addSource({
|
|
filename: files[i],
|
|
content: new MagicString( fs.readFileSync(files[i], 'utf8') + '\n\n' )
|
|
});
|
|
}
|
|
|
|
bundle.prepend(
|
|
copy + '(function (window, document, undefined) {'
|
|
).append('}(window, document));');
|
|
|
|
return bundle;
|
|
}
|
|
|
|
function bytesToKB(bytes) {
|
|
return (bytes / 1024).toFixed(2) + ' KB';
|
|
};
|
|
|
|
exports.build = function (callback, version, compsBase32, buildName) {
|
|
|
|
var files = getFiles(compsBase32);
|
|
|
|
console.log('Bundling and compressing ' + files.length + ' files...');
|
|
|
|
var copy = fs.readFileSync('src/copyright.js', 'utf8').replace('{VERSION}', version),
|
|
|
|
filenamePart = 'leaflet' + (buildName ? '-' + buildName : ''),
|
|
pathPart = 'dist/' + filenamePart,
|
|
srcPath = pathPart + '-src.js',
|
|
mapPath = pathPart + '-src.map',
|
|
srcFilename = filenamePart + '-src.js',
|
|
mapFilename = filenamePart + '-src.map',
|
|
|
|
bundle = bundleFiles(files, copy),
|
|
newSrc = bundle.toString() + '\n//# sourceMappingURL=' + mapFilename,
|
|
|
|
oldSrc = loadSilently(srcPath),
|
|
srcDelta = getSizeDelta(newSrc, oldSrc, true);
|
|
|
|
console.log('\tUncompressed: ' + bytesToKB(newSrc.length) + srcDelta);
|
|
|
|
if (newSrc !== oldSrc) {
|
|
fs.writeFileSync(srcPath, newSrc);
|
|
fs.writeFileSync(mapPath, bundle.generateMap({
|
|
file: srcFilename,
|
|
includeContent: true,
|
|
hires: false
|
|
}));
|
|
console.log('\tSaved to ' + srcPath);
|
|
}
|
|
|
|
var path = pathPart + '.js',
|
|
oldCompressed = loadSilently(path),
|
|
newCompressed;
|
|
|
|
try {
|
|
newCompressed = copy + UglifyJS.minify(newSrc, {
|
|
warnings: true,
|
|
fromString: true
|
|
}).code;
|
|
} catch(err) {
|
|
console.error('UglifyJS failed to minify the files');
|
|
console.error(err);
|
|
callback(err);
|
|
}
|
|
|
|
var delta = getSizeDelta(newCompressed, oldCompressed);
|
|
|
|
console.log('\tCompressed: ' + bytesToKB(newCompressed.length) + delta);
|
|
|
|
var newGzipped,
|
|
gzippedDelta = '';
|
|
|
|
function done() {
|
|
if (newCompressed !== oldCompressed) {
|
|
fs.writeFileSync(path, newCompressed);
|
|
console.log('\tSaved to ' + path);
|
|
}
|
|
console.log('\tGzipped: ' + bytesToKB(newGzipped.length) + gzippedDelta);
|
|
callback();
|
|
}
|
|
|
|
zlib.gzip(newCompressed, function (err, gzipped) {
|
|
if (err) { return; }
|
|
newGzipped = gzipped;
|
|
if (oldCompressed && (oldCompressed !== newCompressed)) {
|
|
zlib.gzip(oldCompressed, function (err, oldGzipped) {
|
|
if (err) { return; }
|
|
gzippedDelta = getSizeDelta(gzipped, oldGzipped);
|
|
done();
|
|
});
|
|
} else {
|
|
done();
|
|
}
|
|
});
|
|
};
|
|
|
|
exports.test = function(complete, fail) {
|
|
var karma = require('karma'),
|
|
testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
|
|
|
|
testConfig.browsers = ['PhantomJS'];
|
|
|
|
function isArgv(optName) {
|
|
return process.argv.indexOf(optName) !== -1;
|
|
}
|
|
|
|
if (isArgv('--chrome')) {
|
|
testConfig.browsers.push('Chrome');
|
|
}
|
|
if (isArgv('--safari')) {
|
|
testConfig.browsers.push('Safari');
|
|
}
|
|
if (isArgv('--ff')) {
|
|
testConfig.browsers.push('Firefox');
|
|
}
|
|
if (isArgv('--ie')) {
|
|
testConfig.browsers.push('IE');
|
|
}
|
|
|
|
if (isArgv('--cov')) {
|
|
testConfig.preprocessors = {
|
|
'src/**/*.js': 'coverage'
|
|
};
|
|
testConfig.coverageReporter = {
|
|
type : 'html',
|
|
dir : 'coverage/'
|
|
};
|
|
testConfig.reporters = ['coverage'];
|
|
}
|
|
|
|
console.log('Running tests...');
|
|
|
|
var server = new karma.Server(testConfig, function(exitCode) {
|
|
if (!exitCode) {
|
|
console.log('\tTests ran successfully.\n');
|
|
complete();
|
|
} else {
|
|
process.exit(exitCode);
|
|
}
|
|
});
|
|
server.start();
|
|
};
|