@softwareventures/maintain-project
Version:
Automatically create and maintain TypeScript projects with standard settings for Software Ventures Limited
35 lines • 1.63 kB
JavaScript
import { excludeNull, filterFn, mapFn } from "@softwareventures/array";
import { mapNullFn, notNull } from "@softwareventures/nullable";
import { mapResultFn, toNullable } from "../result/result.js";
import { splitWhereFn } from "../collections/arrays.js";
import { ignoreComment, ignoreEntry } from "./ignore.js";
export async function readIgnore({ path, dirname, basename, join, readDirectory, readText }) {
const dir = dirname(path);
const file = basename(path);
const subdirectories = readDirectory(dir)
.then(filterFn(entry => entry.isDirectory()))
.then(mapFn(entry => entry.name))
.then(mapFn(async (subdirectory) => readIgnore({
path: join(dir, subdirectory, file),
dirname,
basename,
join,
readDirectory,
readText
}).then((ignore) => [subdirectory, ignore])))
.then(async (ignores) => Promise.all(ignores))
.then(ignores => new Map(ignores));
const entries = readText(path)
.then(mapResultFn(text => text.split(/\r?\n|\r/u)))
.then(mapResultFn(splitWhereFn(line => /^\s*$/u.test(line))))
.then(mapResultFn(mapFn(mapFn(line => /^\s*(?:#\s*(.*)|(.*))\s*$/u.exec(line)))))
.then(mapResultFn(mapFn(excludeNull)))
.then(mapResultFn(mapFn(mapFn(([comment, entry]) => comment == null ? ignoreEntry(notNull(entry)) : ignoreComment(comment)))))
.then(toNullable)
.then(mapNullFn(() => []));
return Promise.all([subdirectories, entries]).then(([subdirectories, entries]) => ({
subdirectories,
entries
}));
}
//# sourceMappingURL=read.js.map