Comparing version 0.1.2 to 0.1.3
@@ -6,4 +6,6 @@ #!/usr/bin/env node | ||
const { yellow, magenta } = require('chalk'); | ||
const nodeVersion = require('node-version'); | ||
const checkUpdate = require('../lib/check-update'); | ||
const checkNodeVersion = require('../lib/check-node-version'); | ||
const handleEsc = require('../lib/handle-esc'); | ||
const { info, success, error } = require('../lib/message-prefix'); | ||
@@ -17,16 +19,5 @@ const { | ||
if (nodeVersion.major < 6) { | ||
console.error( | ||
`${error} Now requires at least version 6 of Node. Please upgrade!` | ||
); | ||
process.exit(1); | ||
} | ||
checkNodeVersion(); | ||
process.stdin.setEncoding('utf8'); | ||
process.stdin.on('data', chunk => { | ||
if (chunk === '\u001b') { | ||
// ESC | ||
process.exit(0); | ||
} | ||
}); | ||
handleEsc(); | ||
@@ -37,5 +28,3 @@ args.option('d', 'Select branches which you want to delete'); | ||
const startCheckout = async () => { | ||
const choices = await getBranches(); | ||
const startCheckout = async branches => { | ||
const { branch } = await inquirer.prompt([ | ||
@@ -46,3 +35,3 @@ { | ||
message: 'Which branch do you want to checkout?', | ||
choices, | ||
choices: branches, | ||
}, | ||
@@ -56,6 +45,4 @@ ]); | ||
const startDeleteBranches = async () => { | ||
const choices = await getBranches(); | ||
const { branches } = await inquirer.prompt([ | ||
const startDeleteBranches = async branches => { | ||
const { branches: selectedBranches } = await inquirer.prompt([ | ||
{ | ||
@@ -65,7 +52,7 @@ type: 'checkbox', | ||
message: 'Which branches do you want to delete?', | ||
choices, | ||
choices: branches, | ||
}, | ||
]); | ||
if (branches.length === 0) { | ||
if (selectedBranches.length === 0) { | ||
console.log('No branch selected, exit.'); | ||
@@ -76,5 +63,5 @@ process.exit(1); | ||
const messageSuffix = | ||
branches.length === 1 | ||
selectedBranches.length === 1 | ||
? 'this branch?' | ||
: `those ${yellow.bold(branches.length)} branches?`; | ||
: `those ${yellow.bold(selectedBranches.length)} branches?`; | ||
@@ -86,3 +73,3 @@ const { confirm } = await inquirer.prompt([ | ||
message: `Are you want to ${yellow.bold('DELETE')} ${messageSuffix} | ||
${branches.join(', ')}`, | ||
${selectedBranches.join(', ')}`, | ||
}, | ||
@@ -100,3 +87,3 @@ ]); | ||
const main = async () => { | ||
const checkGitRepository = async () => { | ||
const currentBranch = await checkGit(); | ||
@@ -112,7 +99,26 @@ | ||
console.log(`${info} Current branch is ${magenta(currentBranch)}`); | ||
}; | ||
const getGitBranches = async () => { | ||
const branches = await getBranches(); | ||
if (branches.length === 0) { | ||
console.error(`${error} No other branches in the repository`); | ||
process.exit(1); | ||
} | ||
return branches; | ||
}; | ||
const main = async () => { | ||
checkUpdate(); | ||
await checkGitRepository(); | ||
const branches = await getGitBranches(); | ||
if (flags.d) { | ||
await startDeleteBranches(); | ||
await startDeleteBranches(branches); | ||
} else { | ||
await startCheckout(); | ||
await startCheckout(branches); | ||
} | ||
@@ -119,0 +125,0 @@ }; |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"bin": { | ||
@@ -32,3 +32,4 @@ "sg": "./bin/swagit.js", | ||
"node-version": "^1.1.3", | ||
"simple-git": "^1.95.1" | ||
"simple-git": "^1.95.1", | ||
"update-check": "^1.5.2" | ||
}, | ||
@@ -35,0 +36,0 @@ "devDependencies": { |
@@ -1,4 +0,4 @@ | ||
# Swagit | ||
![Swagit](https://i.imgur.com/kYSEMFD.png) | ||
![Swagit](https://i.imgur.com/QBNMDxU.png) | ||
[![Build Status](https://travis-ci.com/jigsawye/swagit.svg?branch=master)](https://travis-ci.com/jigsawye/swagit) | ||
@@ -39,2 +39,3 @@ ## Usage | ||
MIT © [jigsawye](https://jigsawye.com) | ||
MIT © [Evan Ye](https://github.com/jigsawye) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7606
9
155
41
6
+ Addedupdate-check@^1.5.2
+ Addeddeep-extend@0.6.0(transitive)
+ Addedini@1.3.8(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedregistry-auth-token@3.3.2(transitive)
+ Addedregistry-url@3.1.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedupdate-check@1.5.4(transitive)