Skip to content

Commit

Permalink
chore(dev-utils): Updated release script to allow custom CHANGELOG up…
Browse files Browse the repository at this point in the history
…dates
  • Loading branch information
mlaursen committed Jul 3, 2021
1 parent 8646c28 commit dde151b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
19 changes: 5 additions & 14 deletions packages/dev-utils/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Octokit } from "@octokit/core";
import dotenv from "dotenv";
import log from "loglevel";
import { join } from "path";
import prompts from "prompts";

import { changelogData } from "./changelogData";
import { clean } from "./clean";
Expand All @@ -14,6 +13,7 @@ import {
replaceTag,
run,
uncommittedFiles,
verify,
} from "./utils";
import { initBlog } from "./utils/initBlog";
import { variables } from "./variables";
Expand Down Expand Up @@ -56,17 +56,8 @@ async function rollback(): Promise<never> {
return process.exit(1);
}

async function verify(autoConfirm: boolean): Promise<void> {
if (autoConfirm) {
return;
}

const { complete } = await prompts({
type: "confirm",
name: "complete",
message: "Continue the release?",
initial: false,
});
async function continueOrRollback(autoConfirm: boolean): Promise<void> {
const complete = await verify("Continue the release?", autoConfirm);

if (!complete) {
await rollback();
Expand Down Expand Up @@ -143,7 +134,7 @@ A token can be created at:

if (blog) {
log.info("Update the blog...");
await verify(autoYes);
await continueOrRollback(autoYes);
}

git("add -u");
Expand All @@ -155,7 +146,7 @@ A token can be created at:
}

run(`npx lerna publish from-package${distTag}${yes}`);
await verify(autoYes);
await continueOrRollback(autoYes);

git("push origin main");
git("push --tags");
Expand Down
1 change: 1 addition & 0 deletions packages/dev-utils/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from "./packages";
export * from "./run";
export * from "./styles";
export * from "./titles";
export * from "./verify";
41 changes: 27 additions & 14 deletions packages/dev-utils/src/utils/initBlog.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { readFile, writeFile } from "fs-extra";
import { join } from "path";
import log from "loglevel";
import { join } from "path";

import { documentationRoot, projectRoot, src } from "../constants";
import { getPackageJson } from "./packages";
import { format } from "./format";
import { getPackageJson } from "./packages";
import { verify } from "./verify";

const NEW_ENTRY = /^#{1,2}\s+\[\d/;

/**
*
* @returns the current release markdown that can be used to generate a github
* release for the current tag.
*/
export async function initBlog(): Promise<string> {
const blogPath = join(documentationRoot, src, "blogs", "index.md");
const version = (await getPackageJson("react-md")).version;
async function getCurrentReleaseNotes(): Promise<string> {
log.info("Update the root CHANGELOG.md with any additional changes.");
if (!(await verify("Continue with the release?"))) {
process.exit(1);
}

const changelog = await readFile(join(projectRoot, "CHANGELOG.md"), "utf8");
const blog = await readFile(blogPath, "utf-8");
const lines = changelog.split(/\r?\n/);
let lastEntryStart = -1;
let nextEntryStart = -1;

for (let i = 0; i < lines.length; i += 1) {
if (NEW_ENTRY.test(lines[i])) {
if (lastEntryStart === -1) {
Expand All @@ -36,8 +36,21 @@ export async function initBlog(): Promise<string> {
process.exit(1);
}

const currentRelease = lines.slice(lastEntryStart, nextEntryStart).join("\n");
const blogMarkdown = currentRelease
return lines.slice(lastEntryStart, nextEntryStart).join("\n");
}

/**
*
* @returns the current release markdown that can be used to generate a github
* release for the current tag.
*/
export async function initBlog(): Promise<string> {
const blogPath = join(documentationRoot, src, "blogs", "index.md");
const version = (await getPackageJson("react-md")).version;
const blog = await readFile(blogPath, "utf-8");

const currentReleaseNotes = await getCurrentReleaseNotes();
const blogMarkdown = currentReleaseNotes
// create smaller headings and remove margin
.replace(/^(###)\s+(.+)$/gm, "##### $2<!-- no-margin -->")
// replace issue/pr references with super-shorthand syntax. they can
Expand Down Expand Up @@ -65,5 +78,5 @@ ${blog}

await writeFile(blogPath, format(contents, "markdown"));

return currentRelease;
return currentReleaseNotes;
}
19 changes: 19 additions & 0 deletions packages/dev-utils/src/utils/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import prompts from "prompts";

export async function verify(
message: string,
autoConfirm = false
): Promise<boolean> {
if (autoConfirm) {
return true;
}

const { complete } = await prompts({
type: "confirm",
name: "complete",
message,
initial: false,
});

return complete;
}

0 comments on commit dde151b

Please sign in to comment.