Skip to content

Commit

Permalink
chore: Use @vitejs/release-scripts (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Jan 23, 2023
1 parent 105808c commit 545aa67
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 381 deletions.
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
},
"devDependencies": {
"@types/babel__core": "^7.20.0",
"@types/execa": "^2.0.0",
"@types/fs-extra": "^11.0.1",
"@types/minimist": "^1.2.2",
"@types/node": "^18.11.18",
"@types/picomatch": "^2.3.0",
"@types/prompts": "^2.4.2",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"@vitejs/release-scripts": "^1.0.4",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.32.0",
"eslint-define-config": "^1.14.0",
Expand All @@ -49,14 +47,11 @@
"execa": "^6.1.0",
"fs-extra": "^11.1.0",
"lint-staged": "^13.1.0",
"minimist": "^1.2.7",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.29.2",
"prettier": "2.8.3",
"prompts": "^2.4.2",
"rollup": "^3.7.0",
"semver": "^7.3.8",
"simple-git-hooks": "^2.8.1",
"tsx": "^3.12.2",
"typescript": "^4.6.4",
Expand Down
46 changes: 21 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 3 additions & 45 deletions scripts/publishCI.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,5 @@
import semver from 'semver'
import {
args,
getActiveVersion,
getPackageInfo,
publishPackage,
step,
} from './releaseUtils'
import { publish } from '@vitejs/release-scripts'

async function main() {
const tag = args._[0]

if (!tag) {
throw new Error('No tag specified')
}

let pkgName = 'plugin-react'
let version

if (tag.includes('@')) [pkgName, version] = tag.split('@')
else version = tag

if (version.startsWith('v')) version = version.slice(1)

const { currentVersion, pkgDir } = getPackageInfo(pkgName)
if (currentVersion !== version)
throw new Error(
`Package version from tag "${version}" mismatches with current version "${currentVersion}"`,
)

const activeVersion = await getActiveVersion(pkgName)

step('Publishing package...')
const releaseTag = version.includes('beta')
? 'beta'
: version.includes('alpha')
? 'alpha'
: semver.lt(currentVersion, activeVersion)
? 'previous'
: undefined
await publishPackage(pkgDir, releaseTag)
}

main().catch((err) => {
console.error(err)
process.exit(1)
publish({
defaultPackage: 'plugin-react',
})
154 changes: 27 additions & 127 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,129 +1,29 @@
import prompts from 'prompts'
import semver from 'semver'
import colors from 'picocolors'
import {
args,
getPackageInfo,
getVersionChoices,
isDryRun,
logRecentCommits,
packages,
run,
runIfNotDry,
step,
updateVersion,
} from './releaseUtils'

async function main(): Promise<void> {
let targetVersion: string | undefined

const { pkg }: { pkg: string } = await prompts({
type: 'select',
name: 'pkg',
message: 'Select package',
choices: packages.map((i) => ({ value: i, title: i })),
})

if (!pkg) return

await logRecentCommits(pkg)

const { currentVersion, pkgName, pkgPath, pkgDir } = getPackageInfo(pkg)

if (!targetVersion) {
const { release }: { release: string } = await prompts({
type: 'select',
name: 'release',
message: 'Select release type',
choices: getVersionChoices(currentVersion),
})

if (release === 'custom') {
const res: { version: string } = await prompts({
type: 'text',
name: 'version',
message: 'Input custom version',
initial: currentVersion,
})
targetVersion = res.version
} else {
targetVersion = release
}
}

if (!semver.valid(targetVersion)) {
throw new Error(`invalid target version: ${targetVersion}`)
}

const tag = `${pkgName}@${targetVersion}`

if (targetVersion.includes('beta') && !args.tag) {
args.tag = 'beta'
}
if (targetVersion.includes('alpha') && !args.tag) {
args.tag = 'alpha'
}

const { yes }: { yes: boolean } = await prompts({
type: 'confirm',
name: 'yes',
message: `Releasing ${colors.yellow(tag)} Confirm?`,
})

if (!yes) {
return
}

step('\nUpdating package version...')
updateVersion(pkgPath, targetVersion)

step('\nGenerating changelog...')
await run(
'npx',
[
'conventional-changelog',
'-p',
'angular',
'-i',
'CHANGELOG.md',
'-s',
'--commit-path',
'.',
'--lerna-package',
pkgName,
],
{ cwd: pkgDir },
)

const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
if (stdout) {
step('\nCommitting changes...')
await runIfNotDry('git', ['add', '-A'])
await runIfNotDry('git', ['commit', '-m', `release: ${tag}`])
await runIfNotDry('git', ['tag', tag])
} else {
console.log('No changes to commit.')
return
}

step('\nPushing to GitHub...')
await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`])
await runIfNotDry('git', ['push'])

if (isDryRun) {
console.log(`\nDry run finished - run git diff to see package changes.`)
} else {
console.log(
colors.green(
'\nPushed, publishing should starts shortly on CI.\nhttps://github.com/vitejs/vite-plugin-react/actions/workflows/publish.yml',
),
import { release } from '@vitejs/release-scripts'
import { logRecentCommits, run } from './releaseUtils'

release({
repo: 'vite-plugin-react',
packages: ['plugin-react'],
toTag: (pkg, version) => `${pkg}@${version}`,
logChangelog: async (pkgName) => {
await logRecentCommits(pkgName)
},
generateChangelog: async (pkgName) => {
await run(
'npx',
[
'conventional-changelog',
'-p',
'angular',
'-i',
'CHANGELOG.md',
'-s',
'--commit-path',
'.',
'--lerna-package',
pkgName,
],
{ cwd: `packages/${pkgName}` },
)
}

console.log()
}

main().catch((err) => {
console.error(err)
process.exit(1)
},
})

0 comments on commit 545aa67

Please sign in to comment.