microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
63dce6b8a5ec2b25b203f52f4fe376f352ea51f4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

eng/common/scripts/check-docs.js

63lines · modecode

1// @ts-check
2
3// cspell:ignore astro
4// This script check the docs are compatible for astro to simplify migration
5// It check each docs has
6// - a `title:` frontmatter
7import { readFile, readdir } from "fs/promises";
8import { resolve } from "path";
9import { repoRoot } from "./helpers.js";
10
11const docsFolder = resolve(repoRoot, "docs");
12
13async function findMarkdownFiles(folder) {
14 const items = await readdir(folder, { withFileTypes: true });
15
16 return (
17 await Promise.all(
18 items.map(async (item) => {
19 if (item.isDirectory()) {
20 const files = await findMarkdownFiles(resolve(folder, item.name));
21 return files.map((x) => resolve(folder, x));
22 }
23
24 if (item.name.endsWith(".md")) {
25 return [resolve(folder, item.name)];
26 } else {
27 return [];
28 }
29 })
30 )
31 ).flat();
32}
33await main();
34
35async function main() {
36 const docs = await findMarkdownFiles(docsFolder);
37
38 const failure = [];
39 const regex = /^---.*title:.*---$/ms;
40 for (const doc of docs) {
41 const buffer = await readFile(doc, { encoding: "utf-8" });
42 const content = buffer.toString();
43 if (!regex.test(content)) {
44 failure.push(doc);
45 }
46 }
47
48 if (failure.length > 0) {
49 console.log("Files with missing title: frontmatter", failure);
50
51 console.log(
52 [
53 "Make sure to add front matter in the file with title, e.g.:",
54 "---",
55 "title: xyz",
56 "---",
57 ].join("\n")
58 );
59 process.exit(1);
60 } else {
61 console.log("Docs look good!");
62 }
63}
64