Skip to content

Commit

Permalink
add a script that concatenates changelog_unreleased into a blog post …
Browse files Browse the repository at this point in the history
…draft
  • Loading branch information
thorn0 committed Jan 22, 2020
1 parent e7f3cfd commit 8cffb4e
Show file tree
Hide file tree
Showing 2 changed files with 1,405 additions and 0 deletions.
87 changes: 87 additions & 0 deletions scripts/draft-blog-post.js
@@ -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"
);

0 comments on commit 8cffb4e

Please sign in to comment.