-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Use @vitejs/release-scripts (#87)
- Loading branch information
1 parent
105808c
commit 545aa67
Showing
5 changed files
with
53 additions
and
381 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
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 |
---|---|---|
@@ -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', | ||
}) |
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,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) | ||
}, | ||
}) |
Oops, something went wrong.