forked from jellydn/justext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.js
28 lines (27 loc) · 744 Bytes
/
run.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
// Builds `stoplists.json` file from `stoplists/*.txt` files
var klaw = require("klaw");
const fsx = require("fs-extra");
const jetpack = require("fs-jetpack");
const logger = require("loglevel");
const items = [];
klaw("./lib/stoplists")
.on("data", (item) => {
const extPos = item.path.indexOf(".txt");
const slashPos = item.path.lastIndexOf("/");
if (extPos !== -1) {
const name = item.path.substr(slashPos + 1, extPos - slashPos - 1);
const data = jetpack.read(item.path);
items.push({
name,
data,
});
}
})
.on("end", () => {
fsx.outputJson("./lib/stoplists.json", items, (err) => {
if (err) {
logger.warn(err);
}
});
logger.info("done");
});