diff --git a/packages/dev-utils/src/release.ts b/packages/dev-utils/src/release.ts index f6f603169a..1da6071fb6 100644 --- a/packages/dev-utils/src/release.ts +++ b/packages/dev-utils/src/release.ts @@ -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"; @@ -13,6 +14,7 @@ import { replaceTag, run, uncommittedFiles, + updateRmdMajorVersion, verify, } from "./utils"; import { initBlog } from "./utils/initBlog"; @@ -66,6 +68,16 @@ async function continueOrRollback(autoConfirm: boolean): Promise { log.info(); } +async function getOneTimePassword(): Promise { + 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; @@ -139,6 +151,8 @@ A token can be created at: await continueOrRollback(autoYes); } + const version = await updateRmdMajorVersion(); + git("add -u"); await replaceTag(); @@ -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) { @@ -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", diff --git a/packages/dev-utils/src/shared.ts b/packages/dev-utils/src/shared.ts index 9a87fe2431..0b3ec4200d 100644 --- a/packages/dev-utils/src/shared.ts +++ b/packages/dev-utils/src/shared.ts @@ -15,9 +15,10 @@ import { markdown } from "./markdown"; import { copyFilesWithBanner, format, + getAllVersions, getPackages, list, - getAllVersions, + updateRmdMajorVersion, } from "./utils"; const REPLACE_TOKEN = ""; @@ -188,5 +189,6 @@ export async function shared(clean = false): Promise { sharedSassdoc(), allPackages(), createVerions(), + updateRmdMajorVersion(), ]); } diff --git a/packages/dev-utils/src/utils/index.ts b/packages/dev-utils/src/utils/index.ts index b1aeaf3c3e..1617c0ec5b 100644 --- a/packages/dev-utils/src/utils/index.ts +++ b/packages/dev-utils/src/utils/index.ts @@ -9,4 +9,5 @@ export * from "./packages"; export * from "./run"; export * from "./styles"; export * from "./titles"; +export * from "./updateRmdMajorVersion"; export * from "./verify"; diff --git a/packages/dev-utils/src/utils/updateRmdMajorVersion.ts b/packages/dev-utils/src/utils/updateRmdMajorVersion.ts new file mode 100644 index 0000000000..6e0b2ffe1f --- /dev/null +++ b/packages/dev-utils/src/utils/updateRmdMajorVersion.ts @@ -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 { + 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; +} diff --git a/packages/documentation/src/components/Layout/ActionMenu.tsx b/packages/documentation/src/components/Layout/ActionMenu.tsx index a13b636899..a6f9f30ffd 100644 --- a/packages/documentation/src/components/Layout/ActionMenu.tsx +++ b/packages/documentation/src/components/Layout/ActionMenu.tsx @@ -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"; @@ -31,8 +32,9 @@ export default function ActionMenu(): ReactElement { , , , - , - , + ...Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => ( + + )), , , ]} diff --git a/packages/documentation/src/components/Layout/NavHeaderTitle.tsx b/packages/documentation/src/components/Layout/NavHeaderTitle.tsx index 7952be7571..f9bb0aa53a 100644 --- a/packages/documentation/src/components/Layout/NavHeaderTitle.tsx +++ b/packages/documentation/src/components/Layout/NavHeaderTitle.tsx @@ -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"; @@ -17,15 +19,14 @@ export default function NavHeaderTitle(): ReactElement { react-md , - , - ]} + items={Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => ( + + ))} dropdownIcon={} anchor={BELOW_INNER_RIGHT_ANCHOR} className={styles.menu} > - @v3 + {`@v${RMD_MAJOR_VERSION}`} ); diff --git a/packages/documentation/src/components/Layout/VersionMenuItem.tsx b/packages/documentation/src/components/Layout/VersionMenuItem.tsx index d6e6372c0f..b664de6c7d 100644 --- a/packages/documentation/src/components/Layout/VersionMenuItem.tsx +++ b/packages/documentation/src/components/Layout/VersionMenuItem.tsx @@ -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( diff --git a/packages/documentation/src/constants/rmdVersion.ts b/packages/documentation/src/constants/rmdVersion.ts new file mode 100644 index 0000000000..7f7fb6b01a --- /dev/null +++ b/packages/documentation/src/constants/rmdVersion.ts @@ -0,0 +1,2 @@ +// this is generated during the release process and should not be updated manually +export const RMD_MAJOR_VERSION = 3;