forked from openstreetmap/iD
-
Notifications
You must be signed in to change notification settings - Fork 6
/
npmapInstall.js
56 lines (52 loc) · 1.9 KB
/
npmapInstall.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
console.log('***********************');
console.log('** NPMAP **');
console.log('***********************');
var configFile = __dirname + '/../../config.json';
var fs = require('fs');
var settingsFile = __dirname + '/js/id/npmap.js';
var configUrl = 'https://raw.githubusercontent.com/nationalparkservice/places-website/master/config.json';
var https = require('https');
var complete = function (config) {
var idSettings = config.iD;
var key = config.oauth.keys.filter(function (d) {
return d.name === 'iD';
})[0];
idSettings.settings.connection.oauth = {
consumerKey: key.consumerKey && key.consumerKey.indexOf('{{') === -1 ? key.consumerKey : 'CpIont3biEafgafInTYWkFlooQkcFLtGREu6yMG0',
external: config.oauth.external,
secret: key.consumerSecret && key.consumerSecret.indexOf('{{') === -1 ? key.consumerSecret : 'MFgSWe00v8EsddR9KI42uZZX61r2XL8JwEPxHY2p',
url: idSettings.settings.connection.api
};
fs.writeFileSync(settingsFile, 'iD.npmap = ' + JSON.stringify(idSettings, null, 4) + ';\n');
console.log('iD.npmap = ' + JSON.stringify(idSettings, null, 4) + ';\n');
console.log('***********************');
console.log('NPMap settings updated');
console.log('***********************');
};
// Check if our config file exists
if (fs.existsSync(configFile)) {
var readConfig = require('../../readConfig');
complete(readConfig(JSON.parse(fs.readFileSync(configFile))));
} else {
var getFile = function (url, callback) {
var file = '';
https.get(url, function (resp) {
resp.on('data', function (d) {
file += d.toString();
});
resp.on('error', function (e) {
console.log('error', e);
callback(e);
});
resp.on('end', function (d) {
console.log('hmm', JSON.parse(file));
callback(null, JSON.parse(file));
});
});
};
getFile(configUrl, function (e, r) {
if (!e) {
complete(r);
}
});
}