forked from openstreetmap/iD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_src.js
102 lines (86 loc) · 2.4 KB
/
build_src.js
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
/* eslint-disable no-console */
const buble = require('@rollup/plugin-buble');
const colors = require('colors/safe');
const commonjs = require('rollup-plugin-commonjs');
const includePaths = require('rollup-plugin-includepaths');
const json = require('rollup-plugin-json');
const nodeResolve = require('rollup-plugin-node-resolve');
const rollup = require('rollup');
const shell = require('shelljs');
// const visualizer = require('rollup-plugin-visualizer');
let _currBuild = null;
function buildSrc() {
if (_currBuild) return _currBuild;
const START = '🏗 ' + colors.yellow('Building source...');
const END = '👍 ' + colors.green('source built');
console.log('');
console.log(START);
console.time(END);
return _currBuild =
Promise.resolve()
.then(() => buildBundle())
.then(() => {
console.timeEnd(END);
console.log('');
_currBuild = null;
})
.catch((err) => {
console.error(err);
console.log('');
_currBuild = null;
process.exit(1);
});
}
function buildBundle() {
console.log('📦 ' + colors.yellow('Bundling JavaScript...'));
// Start clean
shell.rm('-f', [
'dist/iD.js',
'dist/iD.js.map',
// 'docs/statistics.html'
]);
let prom =
rollup.rollup({
input: './modules/id.js',
onwarn: onWarn,
plugins: [
includePaths({
paths: ['node_modules/d3/node_modules'], // npm2 or windows
include: {
'martinez-polygon-clipping': 'node_modules/martinez-polygon-clipping/dist/martinez.umd.js'
}
}),
nodeResolve({
mainFields: ['module', 'main'],
browser: false,
dedupe: ['object-inspect']
}),
commonjs(),
json({ indent: '' }),
buble(),
// viz causes src build to take about 3x longer; skip
// visualizer({
// filename: 'docs/statistics.html',
// sourcemap: true
// })
]
})
.then((bundle) => {
return bundle.write({
format: 'iife',
file: 'dist/iD.js',
sourcemap: true,
strict: false
});
});
return prom;
}
function onWarn(warning, warn) {
// skip certain warnings
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
if (warning.code === 'EVAL') return;
// Use default for everything else
console.log(colors.yellow(warning.code));
warn(warning);
}
module.exports = buildSrc;