-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrollup.config.mjs
173 lines (145 loc) · 3.37 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* eslint-env node */
import path from 'node:path';
import { createRequire } from 'node:module';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import { capitalize, getAllCombinations, toKebabCase } from './tasks/util.mjs';
const require = createRequire(import.meta.url);
const outputDir = 'dist';
const domains = [
'base',
'camunda-cloud',
'camunda-platform'
];
const distributions = [
'modeler',
'viewer',
'navigatedViewer'
];
const buildMatrix = getAllCombinations(domains, distributions);
const styles = [
{
src: resolve('bpmn-js', '/dist/assets/diagram-js.css'),
dest: 'dist/assets'
},
{
src: resolve('bpmn-js', '/dist/assets/bpmn-js.css'),
dest: 'dist/assets'
},
{
src: resolve('bpmn-js', '/dist/assets/bpmn-font/{font,css}'),
dest: 'dist/assets/bpmn-font'
},
{
src: resolve('diagram-js-minimap', '/assets/diagram-js-minimap.css'),
dest: 'dist/assets'
},
{
src: resolve('@bpmn-io/properties-panel', '/dist/assets/properties-panel.css'),
dest: 'dist/assets'
},
{
src: resolve('bpmn-js-color-picker', '/colors/color-picker.css'),
dest: 'dist/assets'
},
{
src: resolve('bpmn-js-element-templates', '/dist/assets/element-templates.css'),
dest: 'dist/assets'
},
{
src: resolve('@bpmn-io/element-template-chooser', '/dist/element-template-chooser.css'),
dest: 'dist/assets'
},
].concat(buildMatrix.map(function([ domain, dist ]) {
return {
src: `styles/${domain}-${toKebabCase(dist)}.css`,
dest: 'dist/assets'
};
}));
const distros = buildMatrix.map(function([ domain, dist ]) {
return {
name: 'Bpmn' + capitalize(dist),
input: `${domain}/${capitalize(dist)}`,
output: `${domain}-${toKebabCase(dist)}`
};
});
const configs = distros.reduce(function(configs, distro) {
const {
input,
output,
name
} = distro;
return [
...configs,
{
input: `./lib/${input}.js`,
output: {
name: name,
file: `${outputDir}/${output}.development.js`,
format: 'umd'
},
plugins: pgl([
copyStyles(styles)
]),
onwarn
},
{
input: `./lib/${input}.js`,
output: {
name: name,
file: `${outputDir}/${output}.production.min.js`,
format: 'umd'
},
plugins: pgl([
terser()
]),
onwarn
}
];
}, []);
export default configs;
// helpers //////////////////////
function pgl(plugins = []) {
return [
nodeResolve({
mainFields: [
'browser',
'module',
'main'
]
}),
commonjs(),
json(),
...plugins
];
}
function copyStyles(styles) {
return copy({
targets: styles.map(function(sheet) {
return {
src: pathNormalize(sheet.src),
dest: pathNormalize(sheet.dest)
};
})
});
}
function resolve(module, sub) {
var pkg = require.resolve(module + '/package.json');
return path.dirname(pkg) + sub;
}
function pathNormalize(string) {
return path.normalize(string).split('\\').join('/');
}
function onwarn(warning, warn) {
const ERRORS_TO_IGNORE = [
'CIRCULAR_DEPENDENCY',
'THIS_IS_UNDEFINED'
];
if (ERRORS_TO_IGNORE.includes(warning.code)) {
return;
}
warn(warning);
}