-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
40 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
import yargs from 'yargs'; | ||
import { hideBin } from 'yargs/helpers'; | ||
import { dedupe, updateToBranch } from './gitUtils'; | ||
|
||
async function main(argv) { | ||
await updateToBranch('@mui/monorepo', 'mui/material-ui', `refs/pull/${argv.pr}/head`); | ||
await dedupe(); | ||
} | ||
|
||
yargs(hideBin(process.argv)) | ||
.command({ | ||
command: '$0', | ||
description: 'transpile TypeScript demos', | ||
builder: (command) => { | ||
return command | ||
.option('pr', { | ||
description: 'PR number', | ||
}) | ||
.demandOption('pr'); | ||
}, | ||
handler: main, | ||
}) | ||
.help() | ||
.strict(true) | ||
.version(false) | ||
.parse(); |
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,40 @@ | ||
import * as execa from 'execa'; | ||
|
||
const $ = execa.$({ stdio: 'inherit' }); | ||
|
||
export async function updateToBranch(dependency: string, repo: string, branch: string = 'master') { | ||
// eslint-disable-next-line no-console | ||
console.log(`Updating "${repo}" to branch "${branch}"...`); | ||
|
||
await $`pnpm update -r ${dependency}@github:${repo}#${encodeURIComponent(branch)}`; | ||
} | ||
|
||
export async function dedupe() { | ||
// eslint-disable-next-line no-console | ||
console.log(`Deduping...`); | ||
|
||
await $({ stdio: 'inherit' })`pnpm dedupe`; | ||
} | ||
|
||
export async function updateToLatestCommit( | ||
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; | ||
|
||
await updateToBranch(dependency, repo, latestCommit); | ||
} |
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 |
---|---|---|
@@ -1,32 +1,7 @@ | ||
import * as execa from 'execa'; | ||
import { dedupe, updateToLatestCommit } from './gitUtils'; | ||
|
||
const $ = execa.$({ stdio: 'inherit' }); | ||
|
||
async function updateGithubDependency(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:${repo}#${latestCommit}`; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Deduping...`); | ||
|
||
await $({ stdio: 'inherit' })`pnpm dedupe`; | ||
async function main() { | ||
await updateToLatestCommit('@mui/monorepo', 'mui/material-ui'); | ||
await dedupe(); | ||
} | ||
|
||
updateGithubDependency('@mui/monorepo', 'mui/material-ui'); | ||
main(); |