Skip to content

Commit

Permalink
update deps, use release it
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Jun 8, 2020
1 parent b88115e commit d1a7afc
Show file tree
Hide file tree
Showing 3 changed files with 2,032 additions and 30 deletions.
52 changes: 29 additions & 23 deletions index.js
Expand Up @@ -7,7 +7,7 @@ const Chalk = require('chalk')
const RandomColor = require('randomcolor')
const Program = require('commander')
const Fs = require('fs')
const git = require('simple-git/promise')(process.cwd())
const git = require('simple-git')(process.cwd())
const spawn = require('child_process').spawn

Program.description(
Expand All @@ -23,20 +23,14 @@ Program.description(
'How many times should the command be executed?',
parseInt
)
.option(
'-s --script <script>',
'Command to run in branches'
)
.option(
'-g --gitflow',
'Compare current with master branch'
)
.option('-s --script <script>', 'Command to run in branches')
.option('-g --gitflow', 'Compare current with master branch')
.option('-c --cli', 'Print the results in the console', true)
.parse(process.argv)

git
.branch()
.then(result => {
.then((result) => {
const originBranch = getCurrentBranch(result.branches)
const branches = result.all

Expand All @@ -48,10 +42,14 @@ git
}
}

console.log(Chalk.green(`Current Branch is ${originBranch.name} ${originBranch.commit}`))
console.log(
Chalk.green(
`Current Branch is ${originBranch.name} ${originBranch.commit}`
)
)

let defaultBranches = []
if(Program.gitflow) {
if (Program.gitflow) {
defaultBranches = ['master', originBranch.name]
}

Expand All @@ -62,15 +60,15 @@ git
default: defaultBranches,
message: "What's your branches to compare?",
choices: branches,
validate: input => {
validate: (input) => {
if (input.length < 2) {
return 'You have to select at least two branches!'
}
return true
}
}
])
.then(result => {
.then((result) => {
const choices = result.choice

return Inquirer.prompt([
Expand All @@ -81,25 +79,33 @@ git
message:
'Please enter the command you want to execute in all branches!'
}
]).then(result => {
]).then((result) => {
const cmd = result.cmd
return run(choices, cmd, Program.file, Program.rounds || 1)
})
})
.catch(() => {
// after we switch to specific commit we have to attach to the local branch
return git.checkout(originBranch.commit).then(git.checkout(originBranch.name))
return git
.checkout(originBranch.commit)
.then(git.checkout(originBranch.name))
})
.then(() => {
return git.checkout(originBranch.commit).then(git.checkout(originBranch.name))
return git
.checkout(originBranch.commit)
.then(git.checkout(originBranch.name))
})
.then(() => console.log(Chalk.green(`Back to ${originBranch.name} ${originBranch.commit}`)))
.then(() =>
console.log(
Chalk.green(`Back to ${originBranch.name} ${originBranch.commit}`)
)
)
})
.catch(console.error)

function run(branches, cmd, mode, rounds) {
return branches.reduce(function(p, branch) {
return p.then(function() {
return branches.reduce(function (p, branch) {
return p.then(function () {
console.log(Chalk.hex(RandomColor())(`Checking out "${branch}"`))
return git.checkout(branch).then(() => {
return execute(branch, cmd, mode, rounds)
Expand All @@ -114,8 +120,8 @@ function execute(branch, cmd, mode, rounds) {
iterations.push(branch)
}

return iterations.reduce(function(p, branch, round) {
return p.then(function() {
return iterations.reduce(function (p, branch, round) {
return p.then(function () {
console.log(Chalk.grey(`Execute "${cmd}"`))
return spawnAsync(branch, cmd, mode, round)
})
Expand All @@ -136,7 +142,7 @@ function spawnAsync(branch, cmd, mode, round) {
)
}

command.on('close', code => {
command.on('close', (code) => {
console.log(
Chalk.grey(`Executed: "${cmd}" and exited with code: ${code}`)
)
Expand Down
15 changes: 8 additions & 7 deletions package.json
Expand Up @@ -4,6 +4,7 @@
"description": "Checkout multiple git branches, execute scripts and return to the origin branch.",
"main": "index.js",
"scripts": {
"release": "release-it --github.release",
"format": "prettier ./*.js --write",
"test": "prettier ./*.js --debug-check",
"patch": "np patch --yolo",
Expand All @@ -22,14 +23,14 @@
"author": "Dustin Deus <deusdustin@gmail.com> (http://www.starptech.de)",
"license": "ISC",
"dependencies": {
"chalk": "^2.3.0",
"commander": "^2.11.0",
"inquirer": "^6.5.2",
"randomcolor": "^0.5.3",
"simple-git": "^1.80.1"
"chalk": "^4.0.0",
"commander": "^5.1.0",
"inquirer": "^7.1.0",
"randomcolor": "^0.5.4",
"simple-git": "^2.6.0"
},
"devDependencies": {
"np": "^2.16.1",
"prettier": "^1.7.4"
"release-it": "^13.6.2",
"prettier": "^2.0.5"
}
}

0 comments on commit d1a7afc

Please sign in to comment.