2019-07-31 11:03:32 +00:00
|
|
|
import { terser } from 'rollup-plugin-terser';
|
2020-12-01 23:34:28 +00:00
|
|
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
|
|
import commonjs from '@rollup/plugin-commonjs';
|
2018-04-02 21:15:15 +00:00
|
|
|
import json from 'rollup-plugin-json';
|
|
|
|
import license from 'rollup-plugin-license';
|
|
|
|
import replace from 'rollup-plugin-replace';
|
|
|
|
|
|
|
|
import {
|
|
|
|
readFileSync
|
|
|
|
} from 'fs';
|
|
|
|
|
|
|
|
import pkg from './package.json';
|
|
|
|
|
|
|
|
const outputDir = 'dist';
|
|
|
|
|
|
|
|
const distros = [
|
|
|
|
{
|
|
|
|
input: 'Viewer',
|
|
|
|
output: 'bpmn-viewer'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'NavigatedViewer',
|
|
|
|
output: 'bpmn-navigated-viewer'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'Modeler',
|
|
|
|
output: 'bpmn-modeler'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const configs = distros.reduce(function(configs, distro) {
|
|
|
|
const {
|
|
|
|
input,
|
|
|
|
output
|
|
|
|
} = distro;
|
|
|
|
|
|
|
|
return [
|
|
|
|
...configs,
|
|
|
|
{
|
|
|
|
input: `./lib/${input}.js`,
|
|
|
|
output: {
|
|
|
|
name: 'BpmnJS',
|
|
|
|
file: `${outputDir}/${output}.development.js`,
|
|
|
|
format: 'umd'
|
|
|
|
},
|
|
|
|
plugins: pgl([
|
|
|
|
banner(output)
|
2021-11-03 10:40:28 +00:00
|
|
|
], 'development')
|
2018-04-02 21:15:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: `./lib/${input}.js`,
|
|
|
|
output: {
|
|
|
|
name: 'BpmnJS',
|
|
|
|
file: `${outputDir}/${output}.production.min.js`,
|
|
|
|
format: 'umd'
|
|
|
|
},
|
|
|
|
plugins: pgl([
|
|
|
|
banner(output, true),
|
2019-07-31 11:03:32 +00:00
|
|
|
terser({
|
2018-04-02 21:15:15 +00:00
|
|
|
output: {
|
|
|
|
comments: /license|@preserve/
|
|
|
|
}
|
|
|
|
})
|
2021-11-03 10:40:28 +00:00
|
|
|
], 'production')
|
2018-04-02 21:15:15 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
export default configs;
|
|
|
|
|
|
|
|
|
|
|
|
// helpers //////////////////////
|
|
|
|
|
|
|
|
function banner(bundleName, minified) {
|
|
|
|
|
|
|
|
const bannerName = (
|
|
|
|
minified
|
|
|
|
? 'banner-min'
|
|
|
|
: 'banner'
|
|
|
|
);
|
|
|
|
|
|
|
|
const bannerTemplate = readFileSync(`${__dirname}/resources/${bannerName}.txt`, 'utf8');
|
|
|
|
|
|
|
|
const banner = processTemplate(bannerTemplate, {
|
|
|
|
version: pkg.version,
|
|
|
|
date: today(),
|
|
|
|
name: bundleName
|
|
|
|
});
|
|
|
|
|
|
|
|
return license({
|
|
|
|
banner
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:40:28 +00:00
|
|
|
function pgl(plugins=[], env='production') {
|
2018-04-02 21:15:15 +00:00
|
|
|
return [
|
|
|
|
replace({
|
2021-11-03 10:40:28 +00:00
|
|
|
'process.env.NODE_ENV': JSON.stringify(env)
|
2018-04-02 21:15:15 +00:00
|
|
|
}),
|
2022-04-06 19:38:27 +00:00
|
|
|
nodeResolve(),
|
2018-04-02 21:15:15 +00:00
|
|
|
commonjs(),
|
|
|
|
json(),
|
|
|
|
...plugins
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function pad(n) {
|
|
|
|
if (n < 10) {
|
|
|
|
return '0' + n;
|
|
|
|
} else {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function today() {
|
|
|
|
const d = new Date();
|
|
|
|
|
|
|
|
return [
|
|
|
|
d.getFullYear(),
|
|
|
|
pad(d.getMonth() + 1),
|
2018-10-25 15:51:35 +00:00
|
|
|
pad(d.getDate())
|
2018-04-02 21:15:15 +00:00
|
|
|
].join('-');
|
|
|
|
}
|
|
|
|
|
|
|
|
function processTemplate(str, args) {
|
|
|
|
return str.replace(/\{\{\s*([^\s]+)\s*\}\}/g, function(_, n) {
|
|
|
|
|
|
|
|
var replacement = args[n];
|
|
|
|
|
|
|
|
if (!replacement) {
|
|
|
|
throw new Error('unknown template {{ ' + n + '}}');
|
|
|
|
}
|
|
|
|
|
|
|
|
return replacement;
|
|
|
|
});
|
|
|
|
}
|