-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·56 lines (49 loc) · 2.06 KB
/
index.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
const argv = require('minimist')(process.argv.slice(2));
const async = require('async');
const MapboxClient = require('@mapbox/mapbox-sdk');
const MapboxStyles = require('@mapbox/mapbox-sdk/services/styles');
const MapboxTilesets = require('@mapbox/mapbox-sdk/services/tilesets');
const MapboxDatasets = require('@mapbox/mapbox-sdk/services/datasets');
const MapboxUnpaginate = require('./MapboxUnpaginate');
const mapboxClient = MapboxClient({ accessToken: argv['access-token'] || process.env.MAPBOX_ACCESS_TOKEN });
const stylesService = MapboxStyles(mapboxClient);
const tilesetService = MapboxTilesets(mapboxClient);
const datasetsService = MapboxDatasets(mapboxClient);
const MAX_CONCURRENT = 5;
if (!argv.username) {
console.error('--username required')
process.exit(1);
}
if (argv['delete-all-datasets']) {
MapboxUnpaginate.listAllDatasets(datasetsService, (err, datasets) => {
if (err) {
console.error(err);
}
if (datasets.length) {
console.log(`Deleting ${datasets.length} datasets in ${datasets[0].owner}`)
async.parallelLimit(datasets.map((dataset) => {
return callback => {
if (dataset.owner === argv.username) {
if (argv['dry-run']) {
console.log(`DELETE ${dataset.owner}.${dataset.id} (${dataset.name})`)
callback(null, null);
} else {
datasetsService.deleteDataset({ datasetId: dataset.id })
.send()
.then(
response => { callback(null, response) },
error => { callback(error, null) }
);
}
}
}
}), MAX_CONCURRENT, (err, results) => {
if (err)
console.error(err);
});
} else {
console.log('No datasets');
}
})
}