eduproj/compile-database/index.ts

28 lines
690 B
TypeScript
Raw Normal View History

2021-08-28 10:52:47 +00:00
import { readdir, readFile } from "fs/promises";
import { join } from "path";
import * as yaml from "js-yaml";
import { init } from "./db";
async function main() {
// TODO: configure this thru cmdline or something later
let materials_dir = "../material";
let db_file = "test.db";
let db = await init(db_file);
let names = await readdir(materials_dir);
await Promise.all(names
.filter(name => name.toLowerCase().endsWith(".yml"))
.map(async name => {
let path = join(materials_dir, name);
let rawData = await readFile(path, { encoding: "utf8" });
let parsedData = yaml.load(rawData);
console.log("data", parsedData);
})
);
}
main();