Skip to content

Commit 86c5c02

Browse files
committed
chore(dev-utils): Update release for new major versions and legacy docs
1 parent 631d56c commit 86c5c02

8 files changed

Lines changed: 79 additions & 11 deletions

File tree

packages/dev-utils/src/release.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Octokit } from "@octokit/core";
22
import dotenv from "dotenv";
33
import log from "loglevel";
44
import { join } from "path";
5+
import prompts from "prompts";
56

67
import { changelogData } from "./changelogData";
78
import { clean } from "./clean";
@@ -13,6 +14,7 @@ import {
1314
replaceTag,
1415
run,
1516
uncommittedFiles,
17+
updateRmdMajorVersion,
1618
verify,
1719
} from "./utils";
1820
import { initBlog } from "./utils/initBlog";
@@ -66,6 +68,16 @@ async function continueOrRollback(autoConfirm: boolean): Promise<void> {
6668
log.info();
6769
}
6870

71+
async function getOneTimePassword(): Promise<string> {
72+
const { otp } = await prompts({
73+
type: "text",
74+
name: "otp",
75+
message: "Enter the one time password required to publishing to npm",
76+
});
77+
78+
return otp;
79+
}
80+
6981
interface Options {
7082
clean: boolean;
7183
type: ReleaseType;
@@ -139,6 +151,8 @@ A token can be created at:
139151
await continueOrRollback(autoYes);
140152
}
141153

154+
const version = await updateRmdMajorVersion();
155+
142156
git("add -u");
143157
await replaceTag();
144158

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

150-
run(`npx lerna publish from-package${distTag}${yes}`);
164+
const otp = await getOneTimePassword();
165+
166+
run(`npx lerna publish from-package${distTag}${yes} --otp=${otp}`);
151167
await continueOrRollback(autoYes);
152168

153169
if (!prerelease) {
@@ -167,7 +183,6 @@ A token can be created at:
167183
${percentChanged}
168184
\`\`\`
169185
`;
170-
const version = await getLernaVersion();
171186
const octokit = new Octokit({ auth: GITHUB_TOKEN });
172187
const response = await octokit.request(
173188
"POST /repos/{owner}/{repo}/releases",

packages/dev-utils/src/shared.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import { markdown } from "./markdown";
1515
import {
1616
copyFilesWithBanner,
1717
format,
18+
getAllVersions,
1819
getPackages,
1920
list,
20-
getAllVersions,
21+
updateRmdMajorVersion,
2122
} from "./utils";
2223

2324
const REPLACE_TOKEN = "<!-- rmd-readme-replace -->";
@@ -188,5 +189,6 @@ export async function shared(clean = false): Promise<void> {
188189
sharedSassdoc(),
189190
allPackages(),
190191
createVerions(),
192+
updateRmdMajorVersion(),
191193
]);
192194
}

packages/dev-utils/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from "./packages";
99
export * from "./run";
1010
export * from "./styles";
1111
export * from "./titles";
12+
export * from "./updateRmdMajorVersion";
1213
export * from "./verify";
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { promises as fs } from "fs";
2+
import log from "loglevel";
3+
import { join } from "path";
4+
5+
import { documentationRoot } from "../constants";
6+
import { getLernaVersion } from "./packages";
7+
8+
const rmdVersionFile = join(
9+
documentationRoot,
10+
"src",
11+
"constants",
12+
"rmdVersion.ts"
13+
);
14+
15+
const FILE_PREFIX = `// this is generated during the release process and should not be updated manually
16+
export const RMD_MAJOR_VERSION = `;
17+
18+
/**
19+
* @returns The full major.minor.patch version number
20+
*/
21+
export async function updateRmdMajorVersion(): Promise<string> {
22+
const version = await getLernaVersion();
23+
const nextMajor = parseInt(version.substring(0, version.indexOf(".")), 10);
24+
const versionFile = await fs.readFile(rmdVersionFile, "utf8");
25+
const prevMajor = parseInt(versionFile.replace(FILE_PREFIX, ""), 10);
26+
27+
if (Number.isNaN(nextMajor) || Number.isNaN(prevMajor)) {
28+
log.error("Unable to determine the react-md major version number.");
29+
process.exit(1);
30+
}
31+
32+
if (nextMajor !== prevMajor) {
33+
await fs.writeFile(rmdVersionFile, `${FILE_PREFIX}${nextMajor};`);
34+
35+
const docsBranch = `legacy-docs-v${prevMajor}`;
36+
log.info(`A new major version has been detected! Ensure the following steps have occurred:
37+
38+
- Update my domains to make sure there's a new A name for v${prevMajor}.react-md.dev
39+
- Create a new \`${docsBranch}\` from the last published tag and push it to origin
40+
- Update the Vercel domains to add a new v${prevMajor}.react-md.dev pointing to the \`${docsBranch}\`\`
41+
`);
42+
}
43+
44+
return version;
45+
}

packages/documentation/src/components/Layout/ActionMenu.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DropdownMenu } from "@react-md/menu";
77
import { unitToNumber } from "@react-md/utils";
88

99
import { CodePreferenceToggle } from "components/CodePreference";
10+
import { RMD_MAJOR_VERSION } from "constants/rmdVersion";
1011

1112
import ToggleTheme from "./ToggleTheme";
1213
import ToggleRTL from "./ToggleRTL";
@@ -31,8 +32,9 @@ export default function ActionMenu(): ReactElement {
3132
<ToggleTheme as="menuitem" />,
3233
<ToggleRTL as="menuitem" />,
3334
<CodePreferenceToggle as="menuitem" />,
34-
<VersionMenuItem version="v2" />,
35-
<VersionMenuItem version="v1" />,
35+
...Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => (
36+
<VersionMenuItem version={`v${i + 1}`} />
37+
)),
3638
<GithubLink as="menuitem" />,
3739
<TableOfContentsMenuItem />,
3840
]}

packages/documentation/src/components/Layout/NavHeaderTitle.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ArrowDropDownSVGIcon } from "@react-md/material-icons";
77
import { DropdownMenu } from "@react-md/menu";
88
import { BELOW_INNER_RIGHT_ANCHOR } from "@react-md/utils";
99

10+
import { RMD_MAJOR_VERSION } from "constants/rmdVersion";
11+
1012
import styles from "./NavHeaderTitle.module.scss";
1113
import VersionMenuItem from "./VersionMenuItem";
1214

@@ -17,15 +19,14 @@ export default function NavHeaderTitle(): ReactElement {
1719
<AppBarTitle keyline={!isToggleableLayout(layout)}>react-md</AppBarTitle>
1820
<DropdownMenu
1921
id="version-picker"
20-
items={[
21-
<VersionMenuItem small version="v2" />,
22-
<VersionMenuItem small version="v1" />,
23-
]}
22+
items={Array.from({ length: RMD_MAJOR_VERSION - 1 }, (_, i) => (
23+
<VersionMenuItem small version={`v${i + 1}`} />
24+
))}
2425
dropdownIcon={<ArrowDropDownSVGIcon />}
2526
anchor={BELOW_INNER_RIGHT_ANCHOR}
2627
className={styles.menu}
2728
>
28-
@v3
29+
{`@v${RMD_MAJOR_VERSION}`}
2930
</DropdownMenu>
3031
</>
3132
);

packages/documentation/src/components/Layout/VersionMenuItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EventName, sendAnalyticsEvent } from "utils/analytics";
66

77
export interface VersionMenuItemProps extends MenuItemLinkProps {
88
small?: boolean;
9-
version: "v1" | "v2" | "latest";
9+
version: "v1" | "latest" | string;
1010
}
1111

1212
export default forwardRef<HTMLAnchorElement, VersionMenuItemProps>(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// this is generated during the release process and should not be updated manually
2+
export const RMD_MAJOR_VERSION = 3;

0 commit comments

Comments
 (0)