-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
53 lines (47 loc) · 1.15 KB
/
start.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
// Load required libraries
require("isomorphic-fetch");
require("dotenv").config();
const async = require("async");
const args = require("args-parser")(process.argv);
const { crawler } = require("./utils");
const fs = require("fs");
const scriptsDir = "./metadata/";
(async () => {
let scripts = fs.readdirSync(scriptsDir);
let dry_run = false;
// Test for particular script only
if ("test_script" in args) {
scripts = scripts.filter((script) => {
return script.includes(args.test_script);
});
}
// Turn on dry run mode
if (args.dry_run) {
dry_run = true;
}
const fn = scripts.map((script) => {
return async () => {
try {
const {
indexId,
schema,
worksheets,
sheetId,
} = require(`${scriptsDir}${script}`);
await crawler(worksheets, {
dry_run: dry_run,
indexId: indexId,
schema: schema,
sheetId: sheetId,
});
return script;
} catch (e) {
throw e;
}
};
});
async.series(fn, (error, script) => {
if (error) throw error;
console.log(`"${script}" executed`);
});
})();