var fs = require('fs'), UglifyJS = require('uglify-js'), zlib = require('zlib'), SourceNode = require( 'source-map' ).SourceNode; 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; } } // Concatenate the files while building up a sourcemap for the concatenation, // and replace the line defining L.version with the string prepared in the jakefile function bundleFiles(files, copy, version) { var node = new SourceNode(null, null, null, ''); node.add(new SourceNode(null, null, null, copy + '(function (window, document, undefined) {')); for (var i = 0, len = files.length; i < len; i++) { var contents = fs.readFileSync(files[i], 'utf8'); if (files[i] === 'src/Leaflet.js') { contents = contents.replace( new RegExp('version: \'.*\''), 'version: ' + JSON.stringify(version) ); } var lines = contents.split('\n'); var lineCount = lines.length; var fileNode = new SourceNode(null, null, null, ''); fileNode.setSourceContent(files[i], contents); for (var j=0; j