-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
draft-blog-post.js
89 lines (74 loc) · 2.34 KB
/
draft-blog-post.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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const path = require("path");
const changelogUnreleasedDir = path.join(__dirname, "../changelog_unreleased");
const blogDir = path.join(__dirname, "../website/blog");
const version = require("../package.json").version.replace(/-.+/, "");
const versionShort = version.replace(/\.0$/, "");
const categories = [
{ dir: "javascript", title: "JavaScript" },
{ dir: "typescript", title: "TypeScript" },
{ dir: "flow", title: "Flow" },
{ dir: "json", title: "JSON" },
{ dir: "css", title: "CSS" },
{ dir: "scss", title: "SCSS" },
{ dir: "less", title: "Less" },
{ dir: "html", title: "HTML" },
{ dir: "vue", title: "Vue" },
{ dir: "angular", title: "Angular" },
{ dir: "lwc", title: "LWC" },
{ dir: "handlebars", title: "Handlebars" },
{ dir: "graphql", title: "GraphQL" },
{ dir: "markdown", title: "Markdown" },
{ dir: "mdx", title: "MDX" },
{ dir: "yaml", title: "YAML" },
{ dir: "api", title: "API" },
{ dir: "cli", title: "CLI" }
];
const categoriesByDir = categories.reduce((result, category) => {
result[category.dir] = category;
return result;
}, {});
const dirs = fs
.readdirSync(changelogUnreleasedDir, { withFileTypes: true })
.filter(entry => entry.isDirectory());
for (const dir of dirs) {
const dirPath = path.join(changelogUnreleasedDir, dir.name);
const category = categoriesByDir[dir.name];
if (!category) {
throw new Error("Unknown category: " + dir.name);
}
category.entries = fs
.readdirSync(path.join(changelogUnreleasedDir, dir.name))
.filter(fileName => /^pr-\d+\.md$/.test(fileName))
.map(fileName =>
fs
.readFileSync(path.join(dirPath, fileName), "utf8")
.trim()
.replace(/^#### [a-z]/, s => s.toUpperCase())
);
}
const result = [
`---
author: "🚧"
authorURL: "https://github.com/🚧"
title: "Prettier ${versionShort}: 🚧"
---`,
"🚧 Write an introduction here.",
"<!--truncate-->",
"## Highlights",
"🚧 Move the most interesting changes here.",
"## Other changes"
];
for (const category of categories) {
if (!category.entries || category.entries.length === 0) {
continue;
}
result.push("### " + category.title);
result.push(...category.entries);
}
fs.writeFileSync(
path.join(blogDir, `${new Date().getFullYear()}-00-00-${version}.md`),
result.join("\n\n") + "\n"
);