forked from mui/toolpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[code-infra] Add monorepo update script (mui#3091)
- Loading branch information
1 parent
2af7023
commit 68c27a2
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as execa from 'execa'; | ||
|
||
const $ = execa.$({ stdio: 'inherit' }); | ||
|
||
async function updateToLatest(dependency: string, repo: string, branch: string = 'master') { | ||
const url = new URL(`https://api.github.com/repos/${repo}/commits`); | ||
url.searchParams.set('sha', branch); | ||
url.searchParams.set('per_page', '1'); | ||
const res = await fetch(url); | ||
if (!res.ok) { | ||
throw new Error(`HTTP ${res.status} while fetching "${url}"`); | ||
} | ||
const commits = await res.json(); | ||
|
||
if (commits.length <= 0) { | ||
throw new Error(`No commits found for "${branch}"`); | ||
} | ||
|
||
const latestCommit: string = commits[0].sha; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Updating "${repo}" to latest commit ${latestCommit}...`); | ||
|
||
await $`pnpm update -r ${dependency}@github:mui/material-ui#${latestCommit}`; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Deduping...`); | ||
|
||
await $({ stdio: 'inherit' })`pnpm dedupe`; | ||
} | ||
|
||
updateToLatest('@mui/monorepo', 'mui/material-ui'); |