-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournal_vocabulary.ts
83 lines (75 loc) · 1.78 KB
/
journal_vocabulary.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* journal_vocabulary.ts turns the issn collection into an RDM style Journals vocabulary (YAML)
*/
import { parseArgs } from "@std/cli";
import {
apiPort,
Dataset,
// pathIdentifier,
yaml,
} from "./deps.ts";
import type { ISSN } from "./issn.ts";
import { licenseText, releaseDate, releaseHash, version } from "./version.ts";
import { fmtHelp, journalVocabularyHelpText } from "./helptext.ts";
const appName = "journal_vocabulary";
const ds = new Dataset(apiPort, "issn.ds");
/**
* toRDMObject() returns an abbreviated object that maps to RDM's vocabularies
*/
function toRDMObject(obj: ISSN): Object {
return {
id: obj.issn,
title: {
en: obj.name,
},
};
}
/* Generate the ISSN Journal vocabulary file for RDM. */
async function journal_vocabulary() {
const issn_list = (await ds.query("issn_names", [], {})) as ISSN[];
let l: object[] = [];
if (issn_list !== undefined) {
for (let item of issn_list) {
l.push(toRDMObject(item));
// l.push({"id": item.issn, "title": { "en": item.name});
// console.log(`DEBUG item ${item}`);
}
}
console.log(yaml.stringify(l));
}
function main() {
const app = parseArgs(Deno.args, {
alias: {
help: "h",
license: "l",
version: "v",
},
default: {
help: false,
version: false,
license: false,
},
});
if (app.help) {
console.log(
fmtHelp(
journalVocabularyHelpText,
appName,
version,
releaseDate,
releaseHash,
),
);
Deno.exit(0);
}
if (app.version) {
console.log(`${appName} ${version} ${releaseHash}`);
Deno.exit(0);
}
if (app.license) {
console.log(`${licenseText}`);
Deno.exit(0);
}
journal_vocabulary();
}
if (import.meta.main) main();