-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblm.js
75 lines (65 loc) · 1.89 KB
/
blm.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { program } = require("commander");
const { BLM } = require("./lib/blm");
/**
* Initialize command line options
*/
function initialise() {
program.version("0.0.1");
program
.option("-i, --interactive", "Replace interactively", false)
.option("-j, --json", "Dump changes as json", false)
.option("-p, --path <path>", "Path (File/Dir) to transform", "./")
.option("-w, --wordsFile <file>", "Words File", "./lib/words.json")
.option("-r, --replaceAll", "Replace all instances", false)
.option("-v, --verbose", "Verbosity of JSON output", false)
.option("-s, --summary", "Summary", true)
.parse(process.argv);
process.on("SIGINT", function() {
console.log("Terminating...");
process.exit();
});
}
/**
* Print Summary of inappropriate words in file/directory
*/
async function printSummary() {
await BLM.use(program.wordsFile).with(program.path).printSummary();
}
/**
* Dump JSON of inappropriate words in file/directory along with line/lineno.
*/
async function dumpJSON() {
await BLM.use(program.wordsFile)
.with(program.path)
.dumpJSON(program.verbose);
}
/**
* Replace inappropriate words with words present in dictionary.
*/
async function replaceAllWords() {
await BLM.use(program.wordsFile).withDirectory(program.path).replace();
}
/**
* Replace inappropriate words interactively
*/
async function replaceAllWordsInteractive() {
await BLM.use(program.wordsFile).with(program.path).replaceInteractive();
}
/**
* Main driver function
*/
async function main() {
initialise();
if (program.json) {
return dumpJSON();
}
if (program.replaceAll === true) {
if (program.interactive === true) {
return replaceAllWordsInteractive();
} else {
return replaceAllWords();
}
}
return printSummary();
}
main();