-
Notifications
You must be signed in to change notification settings - Fork 26
/
update-datasets.ts
50 lines (36 loc) · 1.26 KB
/
update-datasets.ts
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
import {updateDataset, getLatestGithubTag} from "./dataset-update";
import * as path from 'path';
import * as fsp from 'fs/promises';
import { diff } from 'semver';
const dsConfigs = require('./datasources.config.json');
async function update_datasets() {
const dsGithubOwner = 'open-numbers';
const tags = (await Promise.all(Object.keys(dsConfigs).map(async ds => {
const tagVersion = await getLatestGithubTag(`github.com/${dsGithubOwner}/${dsConfigs[ds].path}`);
return {
path: dsConfigs[ds].path,
version: tagVersion,
versionPrev: "",
datasetPath: "",
}
}))).filter(tag => {
tag.datasetPath = path.resolve(tag.path);
try {
const dataPackage = require(path.resolve(tag.datasetPath, 'datapackage.json'));
tag.versionPrev = dataPackage.version;
} catch {}
return diff(tag.version || "0.0.0", tag.versionPrev || "0.0.0-a");
})
if (tags.length) {
const tmpPath = path.resolve("tmp");
await fsp.mkdir(tmpPath);
for (const tag of tags) {
console.log("update", tag.path, tag.versionPrev, "=>", tag.version);
await updateDataset(tag, tag.datasetPath, tmpPath);
}
await fsp.rmdir(tmpPath);
} else {
console.log("Nothing to update");
}
}
update_datasets();