chore(distro): rename dist files and omit .map

This renames distribution files to:

  {variant}.development.js
  {variant}.production.min.js

Additional changes:

* drops .map file; users should use .development bundle
  for easier debugging

Related to #725

BREAKING CHANGE:

* distribution files have been renamed; users must update their
  apps accordingly if they'd like to use newer bpmn-js dists
This commit is contained in:
Nico Rehwaldt 2018-01-08 09:21:24 +01:00 committed by Philipp Fromme
parent d9d0d9dcdb
commit ea17632311
1 changed files with 9 additions and 58 deletions

View File

@ -3,7 +3,6 @@
var browserify = require('browserify'), var browserify = require('browserify'),
derequire = require('browserify-derequire'), derequire = require('browserify-derequire'),
collapse = require('bundle-collapser/plugin'), collapse = require('bundle-collapser/plugin'),
concat = require('source-map-concat'),
fs = require('fs'), fs = require('fs'),
path = require('path'), path = require('path'),
flattenBundle = require('browser-pack-flat/plugin'), flattenBundle = require('browser-pack-flat/plugin'),
@ -18,10 +17,8 @@ var asyncSeries = require('./helpers').asyncSeries;
var BANNER = fs.readFileSync(__dirname + '/../resources/banner.txt', 'utf8'), var BANNER = fs.readFileSync(__dirname + '/../resources/banner.txt', 'utf8'),
BANNER_MIN = fs.readFileSync(__dirname + '/../resources/banner-min.txt', 'utf8'); BANNER_MIN = fs.readFileSync(__dirname + '/../resources/banner-min.txt', 'utf8');
var SOURCE_MAP_HEADER = '//# sourceMappingURL=data:application/json;charset=utf-8;base64,';
module.exports = function bundleAll(dest, targets, done) {
module.exports = function bundleAll(targets, done) {
var fns = Object.keys(targets).map(function(k) { var fns = Object.keys(targets).map(function(k) {
@ -31,7 +28,7 @@ module.exports = function bundleAll(targets, done) {
return function(done) { return function(done) {
console.log('\nbundle ' + variant); console.log('\nbundle ' + variant);
bundle(variant, entry, done); bundle(dest, variant, entry, done);
}; };
}); });
@ -39,36 +36,6 @@ module.exports = function bundleAll(targets, done) {
}; };
function extractSourceMap(content) {
var idx = content.indexOf(SOURCE_MAP_HEADER),
map, code;
if (idx !== -1) {
code = content.substring(0, idx);
map = content.substring(idx + SOURCE_MAP_HEADER.length);
map = new Buffer(map, 'base64').toString();
map = map.replace(/\\\\/g, '/'); // convert \\ -> /
var dir = __dirname;
var dirPattern = dir.replace(/\\/g, '/').replace(/\./g, '\\.') + '/';
var pattern = new RegExp(dirPattern, 'g');
map = map.replace(pattern, '');
return {
code: code,
map: JSON.parse(map)
};
} else {
throw new Error('no attached source map');
}
}
function Timer() { function Timer() {
this.reset(); this.reset();
@ -122,10 +89,9 @@ function today() {
].join('-'); ].join('-');
} }
function bundle(variant, entry, done) { function bundle(dest, variant, entry, done) {
var src = path.resolve(entry); var src = path.resolve(entry);
var dest = 'dist';
var config = { var config = {
variant: variant, variant: variant,
@ -187,9 +153,9 @@ function bundle(variant, entry, done) {
timer.done('minified'); timer.done('minified');
fs.writeFileSync(targetFileBase + '.min.js', minified.code, 'utf8'); fs.writeFileSync(targetFileBase + '.production.min.js', minified.code, 'utf8');
timer.done('saved'); timer.done('wrote ' + targetFileBase + '.production.min.js');
done(); done();
}); });
@ -199,7 +165,7 @@ function bundle(variant, entry, done) {
function(done) { function(done) {
timer.start('build dev'); timer.start('build dev');
browserify(Object.assign({ debug: true }, browserifyOptions)) browserify(browserifyOptions)
.plugin(collapse) .plugin(collapse)
.plugin(derequire) .plugin(derequire)
.add(src) .add(src)
@ -211,26 +177,11 @@ function bundle(variant, entry, done) {
return done(err); return done(err);
} }
try { var code = banner + result.toString('utf-8');
var bundled = extractSourceMap(result.toString('utf8'));
timer.done('extracted source map'); fs.writeFileSync(targetFileBase + '.development.js', code, 'utf8');
var bannerBundled = timer.done('wrote ' + targetFileBase + '.development.js');
concat([ bundled ])
.prepend(banner + '\n')
.add('//# sourceMappingURL=./' + variant + '.js.map')
.toStringWithSourceMap();
timer.done('added banner');
fs.writeFileSync(targetFileBase + '.js', bannerBundled.code, 'utf8');
fs.writeFileSync(targetFileBase + '.js.map', bannerBundled.map, 'utf8');
timer.done('all saved');
} catch (e) {
return done(e);
}
done(); done();
}); });