Skip to content

Commit

Permalink
chore(dev-utils): Update release for new major versions and legacy docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Nov 24, 2021
1 parent 631d56c commit 86c5c02
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 11 deletions.
19 changes: 17 additions & 2 deletions packages/dev-utils/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -13,6 +14,7 @@ import {
replaceTag,
run,
uncommittedFiles,
updateRmdMajorVersion,
verify,
} from "./utils";
import { initBlog } from "./utils/initBlog";
Expand Down Expand Up @@ -66,6 +68,16 @@ async function continueOrRollback(autoConfirm: boolean): Promise<void> {
log.info();
}

async function getOneTimePassword(): Promise<string> {
const { otp } = await prompts({
type: "text",
name: "otp",
message: "Enter the one time password required to publishing to npm",
});

return otp;
}

interface Options {
clean: boolean;
type: ReleaseType;
Expand Down Expand Up @@ -139,6 +151,8 @@ A token can be created at:
await continueOrRollback(autoYes);
}

const version = await updateRmdMajorVersion();

git("add -u");
await replaceTag();

Expand All @@ -147,7 +161,9 @@ A token can be created at:
distTag = " --dist-tag next";
}

run(`npx lerna publish from-package${distTag}${yes}`);
const otp = await getOneTimePassword();

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

if (!prerelease) {
Expand All @@ -167,7 +183,6 @@ A token can be created at:
${percentChanged}
\`\`\`
`;
const version = await getLernaVersion();
const octokit = new Octokit({ auth: GITHUB_TOKEN });
const response = await octokit.request(
"POST /repos/{owner}/{repo}/releases",
Expand Down
4 changes: 3 additions & 1 deletion packages/dev-utils/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { markdown } from "./markdown";
import {
copyFilesWithBanner,
format,
getAllVersions,
getPackages,
list,
getAllVersions,
updateRmdMajorVersion,
} from "./utils";

const REPLACE_TOKEN = "<!-- rmd-readme-replace -->";
Expand Down Expand Up @@ -188,5 +189,6 @@ export async function shared(clean = false): Promise<void> {
sharedSassdoc(),
allPackages(),
createVerions(),
updateRmdMajorVersion(),
]);
}
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,4 +9,5 @@ export * from "./packages";
export * from "./run";
export * from "./styles";
export * from "./titles";
export * from "./updateRmdMajorVersion";
export * from "./verify";
45 changes: 45 additions & 0 deletions packages/dev-utils/src/utils/updateRmdMajorVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { promises as fs } from "fs";
import log from "loglevel";
import { join } from "path";

import { documentationRoot } from "../constants";
import { getLernaVersion } from "./packages";

const rmdVersionFile = join(
documentationRoot,
"src",
"constants",
"rmdVersion.ts"
);

const FILE_PREFIX = `// this is generated during the release process and should not be updated manually
export const RMD_MAJOR_VERSION = `;

/**
* @returns The full major.minor.patch version number
*/
export async function updateRmdMajorVersion(): Promise<string> {
const version = await getLernaVersion();
const nextMajor = parseInt(version.substring(0, version.indexOf(".")), 10);
const versionFile = await fs.readFile(rmdVersionFile, "utf8");
const prevMajor = parseInt(versionFile.replace(FILE_PREFIX, ""), 10);

if (Number.isNaN(nextMajor) || Number.isNaN(prevMajor)) {
log.error("Unable to determine the react-md major version number.");
process.exit(1);
}

if (nextMajor !== prevMajor) {
await fs.writeFile(rmdVersionFile, `${FILE_PREFIX}${nextMajor};`);

const docsBranch = `legacy-docs-v${prevMajor}`;
log.info(`A new major version has been detected! Ensure the following steps have occurred:
- Update my domains to make sure there's a new A name for v${prevMajor}.react-md.dev
- Create a new \`${docsBranch}\` from the last published tag and push it to origin
- Update the Vercel domains to add a new v${prevMajor}.react-md.dev pointing to the \`${docsBranch}\`\`
`);
}

return version;
}
6 changes: 4 additions & 2 deletions packages/documentation/src/components/Layout/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DropdownMenu } from "@react-md/menu";
import { unitToNumber } from "@react-md/utils";

import { CodePreferenceToggle } from "components/CodePreference";
import { RMD_MAJOR_VERSION } from "constants/rmdVersion";

import ToggleTheme from "./ToggleTheme";
import ToggleRTL from "./ToggleRTL";
Expand All @@ -31,8 +32,9 @@ export default function ActionMenu(): ReactElement {
<ToggleTheme as="menuitem" />,
<ToggleRTL as="menuitem" />,
<CodePreferenceToggle as="menuitem" />,
<VersionMenuItem version="v2" />,
<VersionMenuItem version="v1" />,
...Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => (
<VersionMenuItem version={`v${i + 1}`} />
)),
<GithubLink as="menuitem" />,
<TableOfContentsMenuItem />,
]}
Expand Down
11 changes: 6 additions & 5 deletions packages/documentation/src/components/Layout/NavHeaderTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ArrowDropDownSVGIcon } from "@react-md/material-icons";
import { DropdownMenu } from "@react-md/menu";
import { BELOW_INNER_RIGHT_ANCHOR } from "@react-md/utils";

import { RMD_MAJOR_VERSION } from "constants/rmdVersion";

import styles from "./NavHeaderTitle.module.scss";
import VersionMenuItem from "./VersionMenuItem";

Expand All @@ -17,15 +19,14 @@ export default function NavHeaderTitle(): ReactElement {
<AppBarTitle keyline={!isToggleableLayout(layout)}>react-md</AppBarTitle>
<DropdownMenu
id="version-picker"
items={[
<VersionMenuItem small version="v2" />,
<VersionMenuItem small version="v1" />,
]}
items={Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => (
<VersionMenuItem small version={`v${i + 1}`} />
))}
dropdownIcon={<ArrowDropDownSVGIcon />}
anchor={BELOW_INNER_RIGHT_ANCHOR}
className={styles.menu}
>
@v3
{`@v${RMD_MAJOR_VERSION}`}
</DropdownMenu>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EventName, sendAnalyticsEvent } from "utils/analytics";

export interface VersionMenuItemProps extends MenuItemLinkProps {
small?: boolean;
version: "v1" | "v2" | "latest";
version: "v1" | "latest" | string;
}

export default forwardRef<HTMLAnchorElement, VersionMenuItemProps>(
Expand Down
2 changes: 2 additions & 0 deletions packages/documentation/src/constants/rmdVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this is generated during the release process and should not be updated manually
export const RMD_MAJOR_VERSION = 3;

0 comments on commit 86c5c02

Please sign in to comment.