feat(cli): support gitTag option for release command (#12134)

* feat(cli): support gitTag option for release command

* chore: exclude temp file

* release: vant v4.6.4-beta.1
This commit is contained in:
neverland 2023-07-30 11:50:56 +08:00 committed by GitHub
parent e6a0694807
commit b6d35cd268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 5 deletions

3
.gitignore vendored
View File

@ -17,3 +17,6 @@ lib
dist
**/site-dist
changelog.generated.md
# temp file
packages/vant/README.md

View File

@ -75,6 +75,7 @@ program
.command('release')
.description('Compile components and release it')
.option('--tag <tag>', 'Release tag')
.option('--gitTag', 'Generate git tag')
.action(async (options) => {
const { release } = await import('./commands/release.js');
return release(options);

View File

@ -75,12 +75,30 @@ function publishPackage(packageManager: string, tag: string) {
execSync(command, { stdio: 'inherit' });
}
function commitChanges(pkgName: string, version: string) {
function commitChanges(pkgName: string, version: string, gitTag?: boolean) {
const message = `release: ${pkgName} v${version}`;
execSync(`git add -A && git commit -m "${message}"`, { stdio: 'inherit' });
if (gitTag) {
execSync(`git tag -a v${version} -m "${message}"`, { stdio: 'inherit' });
}
}
export async function release(command: { tag?: string }) {
function getCurrentBranch() {
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
return branch;
}
function pushChanges(gitTag?: boolean) {
const branch = getCurrentBranch();
execSync(`git push origin ${branch}`, { stdio: 'inherit' });
if (gitTag) {
execSync(`git push origin ${branch} --tags`, { stdio: 'inherit' });
}
}
export async function release(command: { tag?: string; gitTag?: boolean }) {
const cwd = process.cwd();
const { pkgName, currentVersion } = logCurrentVersion(cwd);
const version = await getNewVersion();
@ -99,5 +117,6 @@ export async function release(command: { tag?: string }) {
}
publishPackage(packageManager, tag);
commitChanges(pkgName, version);
commitChanges(pkgName, version, command.gitTag);
pushChanges(command.gitTag);
}

View File

@ -1,6 +1,6 @@
{
"name": "vant",
"version": "4.6.3",
"version": "4.6.4-beta.1",
"description": "Mobile UI Components built on Vue",
"main": "lib/vant.cjs.js",
"module": "es/index.mjs",
@ -18,7 +18,7 @@
"test": "vant-cli test",
"build": "vant-cli build",
"build:site": "vant-cli build-site",
"release": "cp ../../README.md ./ && vant-cli release && rm ./README.md",
"release": "cp ../../README.md ./ && vant-cli release --gitTag && rm ./README.md",
"release:site": "pnpm build:site && npx gh-pages -d site-dist --add",
"test:update": "vant-cli test --updateSnapshot",
"test:watch": "vant-cli test --watch",