-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
postinstall.js
65 lines (61 loc) · 1.93 KB
/
postinstall.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
const {
GEOCODER_POSTINSTALL_DUMP_DIRECTORY,
GEOCODER_POSTINSTALL_CITIES_FILE_OVERRIDE,
GEOCODER_POSTINSTALL_ADMIN1,
GEOCODER_POSTINSTALL_ADMIN2,
GEOCODER_POSTINSTALL_ADMIN3_AND_4,
GEOCODER_POSTINSTALL_ALTERNATE_NAMES,
GEOCODER_POSTINSTALL_COUNTRIES,
GEOCODER_POSTINSTALL_FAIL_SILENTLY,
} = process.env;
const values = [
GEOCODER_POSTINSTALL_DUMP_DIRECTORY,
GEOCODER_POSTINSTALL_CITIES_FILE_OVERRIDE,
GEOCODER_POSTINSTALL_ADMIN1,
GEOCODER_POSTINSTALL_ADMIN2,
GEOCODER_POSTINSTALL_ADMIN3_AND_4,
GEOCODER_POSTINSTALL_ALTERNATE_NAMES,
GEOCODER_POSTINSTALL_COUNTRIES,
];
if (values.every((val) => typeof val === 'undefined')) {
console.info(
'[local-reverse-geocoder] post-install: No env variables detected. Doing nothing.'
);
process.exit(0);
}
const geocoder = require('./index');
try {
console.info('[local-reverse-geocoder] post-install: Starting.');
geocoder.init(
{
dumpDirectory: GEOCODER_POSTINSTALL_DUMP_DIRECTORY,
citiesFileOverride: GEOCODER_POSTINSTALL_CITIES_FILE_OVERRIDE,
load: {
admin1: GEOCODER_POSTINSTALL_ADMIN1?.toLowerCase() === 'true',
admin2: GEOCODER_POSTINSTALL_ADMIN2?.toLowerCase() === 'true',
admin3And4: GEOCODER_POSTINSTALL_ADMIN3_AND_4?.toLowerCase() === 'true',
alternateNames:
GEOCODER_POSTINSTALL_ALTERNATE_NAMES?.toLowerCase() === 'true',
},
countries: GEOCODER_POSTINSTALL_COUNTRIES?.split(',') || [],
},
function () {
console.info('[local-reverse-geocoder] post-install: Finished.');
process.exit(0);
}
);
} catch (error) {
if (GEOCODER_POSTINSTALL_FAIL_SILENTLY?.toLowerCase() === 'true') {
console.warn(
'[local-reverse-geocoder] post-install: An error occurred. Detected fail-silently flag.',
error
);
process.exit(0);
} else {
console.error(
'[local-reverse-geocoder] post-install: An error occurred.',
error
);
process.exit(1);
}
}