Skip to content

Commit

Permalink
fix(cli/release): add remote option
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Jan 6, 2022
1 parent dfd5587 commit 8c9ed7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 5 additions & 1 deletion packages/varlet-cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ program
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(changelog_1.changelog);
program.command('release').description('Release all packages and generate changelogs').action(release_1.release);
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(release_1.release);
program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint_1.commitLint);
program.on('command:*', function (_a) {
var _b = __read(_a, 1), cmd = _b[0];
Expand Down
17 changes: 9 additions & 8 deletions packages/varlet-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ async function publish(preRelease: boolean) {
}
}

async function pushGit(version: string) {
async function pushGit(version: string, remote = 'origin') {
const s = ora().start('Pushing to remote git repository')
await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', `v${version}`])
await execa('git', ['tag', `v${version}`])
await execa('git', ['push', 'origin', `v${version}`])
await execa('git', ['push', remote, `v${version}`])
const ret = await execa('git', ['push'])
s.succeed('Push remote repository successfully')

Expand All @@ -55,7 +55,7 @@ function updateVersion(version: string) {
})
}

export async function release() {
export async function release(cmd: { remote?: string }) {
try {
const currentVersion = require(resolve(CWD, 'package.json')).version

Expand Down Expand Up @@ -99,20 +99,21 @@ export async function release() {

if (!isPreRelease) {
await changelog()
await pushGit(expectVersion)
await pushGit(expectVersion, cmd.remote)
}

await publish(isPreRelease)

logger.success(`Release version ${expectVersion} successfully!`)

if (isPreRelease) {
try {
await execa('git', ['restore', '**/package.json'])
await execa('git', ['restore', 'package.json'])
// eslint-disable-next-line no-empty
} catch (e) {}
} catch {
logger.error('Restore package.json has failed, please restore manually')
}
}

logger.success(`Release version ${expectVersion} successfully!`)
} catch (error: any) {
logger.error(error.toString())
process.exit(1)
Expand Down
6 changes: 5 additions & 1 deletion packages/varlet-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ program
.description('Generate changelog')
.action(changelog)

program.command('release').description('Release all packages and generate changelogs').action(release)
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(release)

program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint)

Expand Down

0 comments on commit 8c9ed7c

Please sign in to comment.