From 7f63f6aa41afd03269e03da7037331ce56a16eeb Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Tue, 27 Feb 2024 11:22:02 -0800 Subject: [PATCH] general style changes and fixes --- lib/cwd.ts | 5 ++--- lib/error.ts | 1 + lib/git.ts | 5 +---- lib/github.ts | 23 ++++++++++++++--------- lib/prompts.ts | 1 - lib/zx_helpers.ts | 2 +- release/lib/x.ts | 4 ++-- scripts/reset_next.ts | 3 ++- triage/run.ts | 2 +- 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/cwd.ts b/lib/cwd.ts index 40f34cc..f619b8a 100755 --- a/lib/cwd.ts +++ b/lib/cwd.ts @@ -6,13 +6,12 @@ export async function setCwd() { let RWFW_PATH = process.env.RWFW_PATH; if (!RWFW_PATH) { - throw new CustomError("`RWFW_PATH` isn't set. Set it to the path of the Redwood monorepo."); + throw new CustomError("The `RWFW_PATH` environment variable isn't set. Set it to the path of the Redwood monorepo."); } - try { RWFW_PATH = await fs.realpath(RWFW_PATH) } catch (error) { - throw new CustomError(`\`RWFW_PATH\` is set to "${RWFW_PATH}" but it doesn't exist at that path.`) + throw new CustomError(`\`RWFW_PATH\` environment variable is set to "${RWFW_PATH}" but it doesn't exist at that path.`) } const originalCwd = process.cwd() diff --git a/lib/error.ts b/lib/error.ts index 10cbdf7..56c6d56 100755 --- a/lib/error.ts +++ b/lib/error.ts @@ -1,4 +1,5 @@ export class CustomError extends Error { + name title constructor(message: string, title: string = '👷 Heads up') { diff --git a/lib/git.ts b/lib/git.ts index 2ef0afc..5c19ef3 100755 --- a/lib/git.ts +++ b/lib/git.ts @@ -7,7 +7,6 @@ import { unwrap } from './zx_helpers.js' /** Gets release branches (e.g. `release/major/v7.0.0`, etc.) */ export async function getReleaseBranches() { const releaseBranchesStdout = unwrap(await $`git branch --list release/*`) - if (releaseBranchesStdout === '') { return [] } @@ -18,7 +17,6 @@ export async function getReleaseBranches() { .sort((releaseBranchA, releaseBranchB) => { const [, , versionA] = releaseBranchA.split('/') const [, , versionB] = releaseBranchB.split('/') - return semver.compare(versionA, versionB) }) @@ -27,7 +25,6 @@ export async function getReleaseBranches() { export async function assertWorkTreeIsClean() { const workTreeIsClean = unwrap(await $`git status -s`) === '' - if (!workTreeIsClean) { throw new CustomError( "Your working tree isn't clean. Commit or stash your changes." @@ -41,6 +38,6 @@ export async function branchExists(branch: string) { export async function assertBranchExists(branch: string) { if (!(await branchExists(branch))) { - throw new CustomError(`The branch ${branch} does not exist. Check it out from the Redwood remote.`) + throw new CustomError(`The branch ${branch} doesn't exist. Check it out from the Redwood remote.`) } } diff --git a/lib/github.ts b/lib/github.ts index 87bf11e..f358dcf 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -4,20 +4,12 @@ import { CustomError } from './error.js' export const REMOTE = 'https://github.com/redwoodjs/redwood.git' -// See https://stackoverflow.com/questions/18268986/git-how-to-push-messages-added-by-git-notes-to-the-central-git-server. -export async function fetchNotes() { - await $`git fetch ${REMOTE} 'refs/notes/*:refs/notes/*'` -} -export async function pushNotes() { - await $`git push ${REMOTE} 'refs/notes/*'` -} - /** Get the GitHub token from REDWOOD_GITHUB_TOKEN */ export function getGitHubToken() { const gitHubToken = process.env.REDWOOD_GITHUB_TOKEN if (!gitHubToken) { - throw new CustomError("REDWOOD_GITHUB_TOKEN isn't set") + throw new CustomError("The `REDWOOD_GITHUB_TOKEN` environment variable isn't set") } return gitHubToken @@ -56,3 +48,16 @@ export async function pullBranch(branch: string) { export async function pushBranch(branch: string) { await $`git push ${REMOTE} ${branch}` } + +/** + * Fetches notes from the remote. + * + * See https://stackoverflow.com/questions/18268986/git-how-to-push-messages-added-by-git-notes-to-the-central-git-server. + */ +export async function fetchNotes() { + await $`git fetch ${REMOTE} 'refs/notes/*:refs/notes/*'` +} + +export async function pushNotes() { + await $`git push ${REMOTE} 'refs/notes/*'` +} diff --git a/lib/prompts.ts b/lib/prompts.ts index ad49bb3..d1c8f42 100755 --- a/lib/prompts.ts +++ b/lib/prompts.ts @@ -14,7 +14,6 @@ export function prompts( export function resolveRes(res: string) { const isYes = resIsYes(res) - if (isYes) { return 'yes' } diff --git a/lib/zx_helpers.ts b/lib/zx_helpers.ts index 9b933e3..60e258e 100755 --- a/lib/zx_helpers.ts +++ b/lib/zx_helpers.ts @@ -4,7 +4,7 @@ import type { ProcessOutput } from 'zx' * Helper for getting the trimmed stdout from `zx`'s `ProcessOutput`: * * ```ts - * unwrap(await $`git branch --list release/*`) + * unwrap(await $`...`) * ``` */ export function unwrap(processOutput: ProcessOutput) { diff --git a/release/lib/x.ts b/release/lib/x.ts index 6e31349..4b4cb70 100644 --- a/release/lib/x.ts +++ b/release/lib/x.ts @@ -15,7 +15,7 @@ export async function getLatestReleaseOrThrow() { `The latest release is ${chalk.magenta(latestRelease)}? [Y/n] > ` )) if (!ok) { - throw new CustomError('The latest release is not correct') + throw new CustomError("The latest release isn't correct") } return latestRelease } @@ -28,7 +28,7 @@ export async function getNextReleaseOrThrow({ latestRelease, desiredSemver }: Pi ) ) if (!ok) { - throw new CustomError('The next release is not correct') + throw new CustomError("The next release isn't correct") } return nextRelease } diff --git a/scripts/reset_next.ts b/scripts/reset_next.ts index 50da470..ba5b5fe 100644 --- a/scripts/reset_next.ts +++ b/scripts/reset_next.ts @@ -1,6 +1,7 @@ +// Don't use this unless you know what you're doing! +// // This script resets the next branch to the ${REMOTE}/next branch. // It's useful for testing the triage script, but it's destructive. -// Don't use it unless you know what you're doing! import { question, $ } from 'zx' diff --git a/triage/run.ts b/triage/run.ts index ff1191b..9bd3f55 100755 --- a/triage/run.ts +++ b/triage/run.ts @@ -23,7 +23,7 @@ try { process.exitCode = 1; if (error instanceof CustomError) { - consoleBoxen("👷 Heads up", error.message); + consoleBoxen(error.title, error.message); } else { throw error; }