-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.mjs
54 lines (43 loc) · 1.34 KB
/
run.mjs
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
import path from "node:path";
import fse from "fs-extra";
import { read } from "to-vfile";
import { remark } from "remark";
import remarkFrontmatter from "remark-frontmatter";
import remarkGfm from "remark-gfm";
import glob from "glob";
import { remarkDefinitionLinks } from "./dist/index.js";
let FIXTURES_DIR = path.join(process.cwd(), "__tests__", "fixtures");
let INPUT_DIR = path.join(FIXTURES_DIR, "before");
let OUTPUT_DIR = path.join(FIXTURES_DIR, "after");
main();
async function main() {
let files = glob.sync(`${INPUT_DIR}/**/*.md`, {
absolute: true,
nodir: true,
ignore: ["**/node_modules/**"],
});
for (let file of files) {
try {
let result = await remark()
.use({
settings: {
fences: true,
listItemIndent: "one",
tightDefinitions: true,
},
})
.use(remarkDefinitionLinks)
.use(remarkGfm)
.use(remarkFrontmatter, ["yaml", "toml"])
.process(await read(file));
let output = path.join(OUTPUT_DIR, path.relative(INPUT_DIR, file));
let dirname = path.dirname(output);
fse.ensureDirSync(dirname);
await fse.writeFile(output, result.toString());
console.log(`Processed ${file}`);
} catch (error) {
console.error(`Failed to process ${file}`);
console.error(error);
}
}
}