forked from klokantech/tileserver-gl-styles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.js
56 lines (46 loc) · 1.44 KB
/
publish.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
#!/usr/bin/env node
'use strict';
var fs = require('fs');
if (fs.existsSync('styles')) {
require('child_process').execSync('rm -r styles', {stdio: 'inherit'});
}
var styles = fs.readdirSync('styles_modules');
for (var i = 0; i < styles.length; i++) {
var style = styles[i];
console.log('Downloading', style);
require('child_process').execSync(
('cd styles_modules/{s};' +
'wget -q -i url -O tmp.zip;' +
'unzip -o tmp.zip;' +
'rm tmp.zip;cd ../..')
.replace(/\{s\}/g, style), {
stdio: 'inherit'
});
var stylePath = 'styles_modules/' + style + '/style-local.json';
if (fs.existsSync(stylePath)) {
console.log('Preparing', style);
require('child_process').execSync(
('mkdir -p styles/{s} && ' +
'cp styles_modules/{s}/sprite* styles/{s}/ 2>/dev/null || :')
.replace(/\{s\}/g, style), {
stdio: 'inherit'
});
var styleJSON = JSON.parse(fs.readFileSync(stylePath, 'utf8'));
// only keep the first font -- it should be "Open Sans"
styleJSON.layers.forEach(function(layer) {
if (layer.layout && layer.layout['text-font']) {
layer.layout['text-font'] = layer.layout['text-font'].slice(0, 1);
}
});
fs.writeFileSync(
'styles/' + style + '/style.json',
JSON.stringify(styleJSON, null, 2),
'utf8'
);
}
}
/* PUBLISH */
console.log('Publishing to npm');
require('child_process').execSync('npm publish .', {
stdio: 'inherit'
});