Skip to content

Commit

Permalink
feat(command): release command start and finish
Browse files Browse the repository at this point in the history
  • Loading branch information
msanguineti committed Apr 18, 2019
1 parent ee21230 commit c168ee2
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cmds/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2019 Mirco Sanguineti
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/

import start from './release_start'
import finish from './release_finish'

export default {
command: 'release <command>',
desc: 'Manage starting and finishing releases',
builder: function (yargs: any) {
return yargs.command(start).command(finish)
},
handler: function (argv: { [key: string]: any }) {}
}
83 changes: 83 additions & 0 deletions src/cmds/release_finish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { exec } from 'shelljs'
import { info } from '../utils/text'
import inquirer from 'inquirer'

/**
* Copyright (c) 2019 Mirco Sanguineti
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/

export default {
command: 'finish <releaseBranch>',
desc:
'Finishes a release. Release branch name should be something like `2.3.0` or some version convention',
builder: (yargs: any) => {},
handler: async (argv: { [key: string]: any }) => {
const mergeInto = argv.usedev ? argv.development : argv.main

exec(`git checkout ${argv.release}/${argv.releaseBranch}`)
exec(`git tag ${argv.releaseBranch}`)
exec(`git checkout ${mergeInto}`)
exec(`git merge ${argv.release}/${argv.releaseBranch}`)

switch (argv.push) {
case 'always':
exec(`git push --tags origin ${mergeInto}`)
break
case 'never':
console.log(
`Remember to ${info(
`git push --tags origin ${mergeInto}`
)} when you're done.`
)
break
case 'ask':
if (await ask(`Do you want to push to ${mergeInto}?`)) {
exec(`git push --tags origin ${mergeInto}`)
}
break
}

if (argv.usedev) {
exec(`git checkout master`)
exec(`git merge --ff-only ${argv.releaseBranch}`)
}

switch (argv.deleteBranch) {
case 'always':
deleteBranch(argv)
break
case 'never':
break
case 'ask':
if (
await ask(
`Do you want to delete branch ${argv.release}/${
argv.releaseBranch
}?`
)
) {
deleteBranch(argv)
}
break
}
}
}

function deleteBranch (argv: { [key: string]: any }) {
exec(`git branch -d ${argv.feature}/${argv.featureBranch}`)
exec(`git push origin :${argv.feature}/${argv.featureBranch}`)
}

async function ask (question: string) {
const answer: { accept: string } = await inquirer.prompt([
{
type: 'confirm',
name: 'accept',
message: question
}
])
return answer.accept
}
20 changes: 20 additions & 0 deletions src/cmds/release_start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isValidBranchName } from '../core'
import { exec } from 'shelljs'

/**
* Copyright (c) 2019 Mirco Sanguineti
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/

export default {
command: 'start <branchName> <from>',
desc: 'Start a new release',
builder: (yargs: any) => {},
handler: (argv: { [key: string]: any }) => {
if (isValidBranchName(argv.branchName)) {
exec(`git checkout -b ${argv.release}/${argv.branchName} ${argv.from}`)
}
}
}

0 comments on commit c168ee2

Please sign in to comment.