-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiblebrain_uploader.js
More file actions
95 lines (85 loc) · 2.29 KB
/
Copy pathbiblebrain_uploader.js
File metadata and controls
95 lines (85 loc) · 2.29 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
const fse = require("fs-extra");
const generateJsonHandler = require("./sofria_mediaId");
const populateDBHandler = require("./gqlquery_verses_by_usx");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const directoryArgConfig = (yargs) => {
return yargs.positional("directory", {
describe: "Folder where it should iterate to process the USX files",
demandOption: true,
default: "",
});
};
const validateDirectory = (directory) => {
if (!fse.existsSync(directory)) {
throw new Error(`ERROR: directory: ${directory} must exist.`);
}
if (!directory.endsWith("/")) {
directory += "/";
}
return directory;
};
const parseMissingVersesAllowed = (missingVersesAllowed) => {
let parsed = null;
if (missingVersesAllowed) {
try {
parsed = JSON.parse(missingVersesAllowed);
} catch (error) {
throw new Error(`Error parsing JSON: ${missingVersesAllowed}`);
}
}
return parsed;
};
const commandHandler = async (argv) => {
if (!argv.directory) {
console.error("Directory path is required");
process.exit(1);
}
argv.directory = validateDirectory(argv.directory);
if (argv.generateJson) {
await generateJsonHandler.run(argv.directory, argv.generateJson);
}
if (argv.populateDb) {
const missingVersesAllowed = parseMissingVersesAllowed(
argv.missingVersesAllowed
);
await populateDBHandler.run(
argv.directory,
argv.populateDb,
missingVersesAllowed
);
}
};
yargs(hideBin(process.argv))
.command(
"run [directory]",
"process the USX directory",
directoryArgConfig,
commandHandler
)
.option("generate-json", {
alias: "gj",
type: "string",
description:
"Directory path where it will generate the formatted json files",
})
.option("populate-db", {
alias: "pdb",
type: "string",
description: "Sqlite Database path where it will be the verses",
})
.option("missing-verses-allowed", {
alias: "mva",
type: "string",
description:
"JSON string about indexed array is sorted by book, chapter, and missing verses allowed list",
})
.strictCommands()
.demandCommand(1)
.fail(function (msg, err) {
if (err) throw err;
console.error("Error!");
console.error(msg);
process.exit(1);
})
.parse();