-
Notifications
You must be signed in to change notification settings - Fork 142
/
build.js
74 lines (54 loc) · 1.94 KB
/
build.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
const fs = require('fs');
const Terser = require('terser');
//*****************************************************************************
const package = require('./package.json');
const src = `${__dirname}/src`;
const dist = `${__dirname}/dist`;
const code = [
"src/shortcuts.js",
"node_modules/qolor/dist/Qolor.debug.js",
"src/lib/getSunPosition.js",
"src/GeoJSON.js",
"src/variables.js",
"src/geometry.js",
"src/functions.js",
"src/Request.js",
"src/Data.js",
"src/geometry/Extrusion.js",
"src/geometry/Cylinder.js",
"src/geometry/Pyramid.js",
"src/layers/index.js",
"src/layers/Buildings.js",
"src/layers/Simplified.js",
"src/layers/Shadows.js",
"src/layers/Picking.js",
"src/Debug.js",
"src/adapter.js"
];
//*****************************************************************************
function joinFiles (files) {
if (!files.push) {
files = [files];
}
return files.map(file => fs.readFileSync(file)).join('\n');
}
function copy (srcFile, distFile) {
fs.writeFileSync(distFile, fs.readFileSync(srcFile, 'utf8'));
}
//*****************************************************************************
function buildEngine (name, customJS) {
const commonJS = joinFiles(code);
let js = commonJS + '\n' + customJS;
js = js.replace(/\{\{VERSION\}\}/g, package.version);
js = `const OSMBuildings = (function() {\n${js}\n return OSMBuildings;\n}());`;
fs.writeFileSync(`${dist}/OSMBuildings-${name}.debug.js`, js);
fs.writeFileSync(`${dist}/OSMBuildings-${name}.js`, Terser.minify(js).code);
copy(`${src}/engines/index-${name}.html`, `${dist}/index-${name}.html`);
}
//*****************************************************************************
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist);
}
buildEngine('Leaflet', fs.readFileSync(`${src}/engines/Leaflet.js`));
buildEngine('OpenLayers', fs.readFileSync(`${src}/engines/OpenLayers.js`));
copy(`${src}/OSMBuildings.css`, `${dist}/OSMBuildings.css`);