-
Notifications
You must be signed in to change notification settings - Fork 16
/
cli.js
68 lines (63 loc) · 2.12 KB
/
cli.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
#!/usr/bin/env node
const nepalGeojson = require('./index');
const fs = require('fs');
const args = process.argv.slice(2);
const command = args[0];
const selector = args[1] || null;
const error = () => {
console.log(`Nepal Geojson
nepal-geojson [option]
Options:
district KATHMANDU provides geojson file of the selected district
province provides geojson file of the boundary of selected province
province:withDistricts provides geojson file of the selected province with districts
country provides geojson file of the boundary of entire country
country:withProvinces provides geojson file of the entire country with province level boundaries
country:withDistricts provides geojson file of the entire country with district level boundaries
acesmndr 2018-2021
`);
};
const writeFile = (filename, content) => {
if (!fs.existsSync('geojson')) {
fs.mkdirSync('geojson');
}
fs.writeFileSync(`./geojson/${filename}.geojson`, JSON.stringify(content));
};
let selected = null;
switch (command) {
case 'country':
writeFile('nepal', nepalGeojson.country());
break;
case 'country:withProvinces':
writeFile('nepal-with-provinces', nepalGeojson.countryWithProvinces());
break;
case 'country:withDistricts':
writeFile('nepal-with-districts', nepalGeojson.countryWithDistricts());
break;
case 'province':
if (!selector) {
error();
break;
}
selected = Number(selector);
writeFile(`Province-${selected}`, nepalGeojson.province(selected));
break;
case 'province:withDistricts':
if (!selector) {
error();
break;
}
selected = Number(selector);
writeFile(`Province-${selected}-with-districts`, nepalGeojson.provinceWithDistricts(selected));
break;
case 'district':
if (!selector) {
error();
break;
}
selected = selector.toLocaleUpperCase();
writeFile(`${selected}-district`, nepalGeojson.district(selected));
break;
default:
error();
}