-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): release command start and finish
- Loading branch information
1 parent
ee21230
commit c168ee2
Showing
3 changed files
with
121 additions
and
0 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
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 }) {} | ||
} |
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 |
---|---|---|
@@ -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 | ||
} |
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 |
---|---|---|
@@ -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}`) | ||
} | ||
} | ||
} |