Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a script that concatenates changelog_unreleased into a blog post …
…draft
- Loading branch information
Showing
2 changed files
with
1,405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"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" | ||
); |
Oops, something went wrong.