-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 1.1 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
const fs = require("fs");
const _ = require('lodash')
const crawl = require('./crawl')
const parse = require('./parse')
const getEml = require('./eml')
const getYaml = require('./meta')
const writeMeta = (format) => {
console.log(`Writing metadata ${format === 'coldp' ? 'yaml': 'eml'}`)
let pubDate = new Date().toISOString().split('T')[0];
const metadata = format === 'coldp' ? getYaml(pubDate) : getEml(pubDate);
const fileName = format === 'coldp' ? 'metadata.yaml' : 'eml.xml';
const eml = getEml(pubDate)
fs.writeFile(__dirname + `/data/${fileName}`, metadata, 'utf8', (err)=>{
if(err){
console.log(err)
// the build must fail if no eml
throw err
} else {
console.log(`Metadata written to ${fileName}. PubDate ${pubDate}`)
}
})
}
const FORMATS = ['dwc', 'coldp']
const format = _.get(process.argv.slice(2), '[0]');
if(!FORMATS.includes(format)){
console.log(
"Please provide a valid format, options are: " +
FORMATS.join(", ")
);
exit();
} else {
writeMeta(format)
crawl().then(parse[format])
};