chore(script): more prompts during publish
This commit is contained in:
@@ -8,6 +8,7 @@ const git = simpleGit()
|
|||||||
const packagesDir = path.resolve(__dirname, '../../packages')
|
const packagesDir = path.resolve(__dirname, '../../packages')
|
||||||
|
|
||||||
export type PackageDetails = {
|
export type PackageDetails = {
|
||||||
|
commitMessage: string
|
||||||
name: string
|
name: string
|
||||||
newCommits: number
|
newCommits: number
|
||||||
shortName: string
|
shortName: string
|
||||||
@@ -43,6 +44,7 @@ export const getPackageDetails = async (): Promise<PackageDetails[]> => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
commitMessage: newCommits.latest?.message ?? '',
|
||||||
name: packageJson.name as string,
|
name: packageJson.name as string,
|
||||||
newCommits: newCommits.total,
|
newCommits: newCommits.total,
|
||||||
shortName: dirName,
|
shortName: dirName,
|
||||||
@@ -64,15 +66,20 @@ export const showPackageDetails = (details: PackageDetails[]) => {
|
|||||||
|
|
||||||
${details
|
${details
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const name = p?.newCommits ? chalk.bold.green(p?.shortName.padEnd(28)) : p?.shortName.padEnd(28)
|
const name = p?.newCommits
|
||||||
const publishData = `${p?.publishedVersion} at ${p?.publishDate
|
? chalk.bold.green(p?.shortName.padEnd(28))
|
||||||
.split(':')
|
: chalk.dim(p?.shortName.padEnd(28))
|
||||||
.slice(0, 2)
|
const publishData = `${p?.publishedVersion.padEnd(8)}${p?.publishDate.split('T')[0]}`
|
||||||
.join(':')
|
const newCommits = p?.newCommits ? chalk.bold.green(`⇡${p?.newCommits} `) : ' '
|
||||||
.replace('T', ' ')}`
|
const commitMessage = p?.commitMessage
|
||||||
const newCommits = `${p?.newCommits ? `${chalk.bold.green(p?.newCommits)} new commits` : ''}`
|
? chalk.dim(
|
||||||
|
p.commitMessage.length < 57
|
||||||
|
? p.commitMessage
|
||||||
|
: p.commitMessage.substring(0, 60).concat('...'),
|
||||||
|
)
|
||||||
|
: ''
|
||||||
|
|
||||||
return ` ${name}${publishData} ${newCommits}`
|
return ` ${name}${newCommits}${publishData} ${commitMessage}`
|
||||||
})
|
})
|
||||||
.join('\n')}
|
.join('\n')}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ async function main() {
|
|||||||
abort(`Invalid bump type: ${bump}.\n\nMust be one of: ${semver.RELEASE_TYPES.join(', ')}`)
|
abort(`Invalid bump type: ${bump}.\n\nMust be one of: ${semver.RELEASE_TYPES.join(', ')}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bump.startsWith('pre') && tag === 'latest') {
|
||||||
|
abort(`Prerelease bumps must have tag: beta or canary`)
|
||||||
|
}
|
||||||
|
|
||||||
const packageDetails = await getPackageDetails()
|
const packageDetails = await getPackageDetails()
|
||||||
showPackageDetails(packageDetails)
|
showPackageDetails(packageDetails)
|
||||||
|
|
||||||
@@ -63,7 +67,7 @@ async function main() {
|
|||||||
${packagesToRelease
|
${packagesToRelease
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const { shortName, version } = packageMap[p]
|
const { shortName, version } = packageMap[p]
|
||||||
return ` ${shortName.padEnd(24)} ${version} -> ${semver.inc(version, bump)}`
|
return ` ${shortName.padEnd(24)} ${version} -> ${semver.inc(version, bump, tag)}`
|
||||||
})
|
})
|
||||||
.join('\n')}
|
.join('\n')}
|
||||||
`)
|
`)
|
||||||
@@ -77,33 +81,43 @@ ${packagesToRelease
|
|||||||
const results: { name: string; success: boolean }[] = []
|
const results: { name: string; success: boolean }[] = []
|
||||||
|
|
||||||
for (const pkg of packagesToRelease) {
|
for (const pkg of packagesToRelease) {
|
||||||
const { packagePath, shortName } = packageMap[pkg]
|
const { packagePath, shortName, name: registryName } = packageMap[pkg]
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(chalk.bold(`\n\nPublishing ${shortName}...\n\n`))
|
console.log(chalk.bold(`\n\n🚀 Publishing ${shortName}...\n\n`))
|
||||||
let npmVersionCmd = `npm --no-git-tag-version --prefix ${packagePath} version ${bump}`
|
let npmVersionCmd = `npm --no-git-tag-version --prefix ${packagePath} version ${bump}`
|
||||||
if (tag !== 'latest') {
|
if (tag !== 'latest') {
|
||||||
npmVersionCmd += ` --preid ${tag}`
|
npmVersionCmd += ` --preid ${tag}`
|
||||||
}
|
}
|
||||||
execSync(npmVersionCmd, execOpts)
|
execSync(npmVersionCmd, execOpts)
|
||||||
execSync(`git add ${packagePath}/package.json`, execOpts)
|
|
||||||
|
|
||||||
const packageObj = await fse.readJson(`${packagePath}/package.json`)
|
const packageObj = await fse.readJson(`${packagePath}/package.json`)
|
||||||
const newVersion = packageObj.version
|
const newVersion = packageObj.version
|
||||||
|
|
||||||
const tagName = `${shortName}/${newVersion}`
|
const tagName = `${shortName}/${newVersion}`
|
||||||
execSync(`git commit -m "chore(release): ${tagName} [skip ci]" `, execOpts)
|
const shouldCommit = await confirm(`🧑💻 Commit Release?`)
|
||||||
execSync(`git tag -a ${tagName} -m "${tagName}"`, execOpts)
|
if (shouldCommit) {
|
||||||
|
execSync(`git add ${packagePath}/package.json`, execOpts)
|
||||||
|
execSync(`git commit -m "chore(release): ${tagName} [skip ci]" `, execOpts)
|
||||||
|
}
|
||||||
|
|
||||||
if (pkg === 'payload') {
|
const shouldTag = await confirm(`🏷️ Tag ${tagName}?`)
|
||||||
execSync(`git tag -a v${newVersion} -m "v${newVersion}"`, execOpts)
|
if (shouldTag) {
|
||||||
|
execSync(`git tag -a ${tagName} -m "${tagName}"`, execOpts)
|
||||||
|
|
||||||
|
if (pkg === 'payload') {
|
||||||
|
execSync(`git tag -a v${newVersion} -m "v${newVersion}"`, execOpts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let publishCmd = `pnpm publish -C ${packagePath} --no-git-checks`
|
let publishCmd = `pnpm publish -C ${packagePath} --no-git-checks`
|
||||||
if (tag !== 'latest') {
|
if (tag !== 'latest') {
|
||||||
publishCmd += ` --tag ${tag}`
|
publishCmd += ` --tag ${tag}`
|
||||||
}
|
}
|
||||||
execSync(publishCmd, execOpts)
|
const shouldPublish = await confirm(`🚢 Publish ${registryName}${chalk.yellow('@' + tag)}?`)
|
||||||
|
if (shouldPublish) {
|
||||||
|
execSync(publishCmd, execOpts)
|
||||||
|
}
|
||||||
|
|
||||||
results.push({ name: shortName, success: true })
|
results.push({ name: shortName, success: true })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user