Skip to content

Commit

Permalink
fix: 修复branhclear命令不加参数兜底值覆盖配置文件
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Oct 21, 2020
1 parent b06528c commit cfd5c06
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 64 deletions.
121 changes: 64 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
{
"name": "branchclear-cli",
"version": "0.0.0-development",
"description": "git分支清理cli工具",
"main": "src/index.js",
"name": "branchclear-cli",
"version": "0.0.0-development",
"description": "git分支清理cli工具",
"main": "src/index.js",
"author": "mengshagn918",
"keywords": ["branch","git","clearbranch","clear","branchclear"],
"license": "MIT",
"bin": {
"branchclear": "bin/index.js"
},
"scripts": {
"cz": "cz",
"semantic-release": "semantic-release"
},
"dependencies": {
"chalk": "^4.1.0",
"commander": "^6.1.0",
"execa": "^4.0.3",
"husky": "^4.3.0",
"inquirer": "^7.3.3",
"js-yaml": "^3.14.0",
"ora": "^5.1.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"commitizen": "^4.2.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^7.10.0",
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"semantic-release-cli": "^5.4.0",
"semantic-release": "^17.2.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.js": [
"eslint --fix",
"prettier --config .prettierrc.yml --write"
],
"*.md": [
"prettier --config .prettierrc.yml --write"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"repository": {
"type": "git",
"url": "https://github.com/mengshang918/branchclear-cli.git"
}
"keywords": [
"branch",
"git",
"clearbranch",
"clear",
"branchclear"
],
"license": "MIT",
"bin": {
"branchclear": "bin/index.js"
},
"scripts": {
"cz": "cz",
"semantic-release": "semantic-release"
},
"dependencies": {
"chalk": "^4.1.0",
"commander": "^6.1.0",
"execa": "^4.0.3",
"husky": "^4.3.0",
"inquirer": "^7.3.3",
"js-yaml": "^3.14.0",
"minimist": "^1.2.5",
"ora": "^5.1.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"commitizen": "^4.2.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^7.10.0",
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"semantic-release": "^17.2.1",
"semantic-release-cli": "^5.4.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.js": [
"eslint --fix",
"prettier --config .prettierrc.yml --write"
],
"*.md": [
"prettier --config .prettierrc.yml --write"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"repository": {
"type": "git",
"url": "https://github.com/mengshang918/branchclear-cli.git"
}
}
14 changes: 8 additions & 6 deletions src/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* @Author: jiangxiaowei
* @Date: 2020-10-10 11:54:44
* @Last Modified by: jiangxiaowei
* @Last Modified time: 2020-10-10 16:12:42
* @Last Modified time: 2020-10-21 19:05:30
*/
const { program } = require('commander')
const parseArgs = require('minimist')
const { version } = require('../package.json')
const { validateStrIsReg } = require('./utils')
const { validateStrIsReg, hasKey } = require('./utils')

/**
* @param {string} gitUser git用户
Expand Down Expand Up @@ -42,12 +43,13 @@ module.exports = (gitUser) => {
) {
program.help()
}
const args = parseArgs(process.argv.slice(2))
return {
answers: {
main,
user,
clearPosition: position,
remoteName: remotename,
...(hasKey(args, ['m', 'main']) && { main }),
...(hasKey(args, ['u', 'user']) && { user }),
...(hasKey(args, ['p', 'position']) && { clearPosition: position }),
...(hasKey(args, ['remote', 'remotename']) && { remoteName: remotename }),
isReg: !!branchreg,
...(!!branchreg && { branchRegStr: branchreg }),
isIgnore: !!ignorereg,
Expand Down
29 changes: 28 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: jiangxiaowei
* @Date: 2020-09-29 16:51:11
* @Last Modified by: jiangxiaowei
* @Last Modified time: 2020-10-10 14:05:32
* @Last Modified time: 2020-10-21 18:59:47
*/

/**
Expand Down Expand Up @@ -38,8 +38,35 @@ const validateReg = (item) => {
}
}

/**
* 基本数据类型检测
* @param {unknown} checkVar 待检测的变量
* @returns {string} 基本数据类型:Object | Array | String | Number | Boolean | Null | Undefined
*/
const typeCheck = (checkVar) => {
const typeClass = Object.prototype.toString.call(checkVar)

return typeClass.split(' ')[1].split(']')[0]
}

/**
* 判断obj中是否含有key这个属性
* @param {object} obj 需要判断的对象
* @param {string|Array} key 需要判断的key
*/
const hasKey = (obj, key) => {
if (typeCheck(key) === 'Array') {
return key.some((item) => Object.prototype.hasOwnProperty.call(obj, item))
} else if (typeCheck(key) === 'String') {
return Object.prototype.hasOwnProperty.call(obj, key)
}
return false
}

module.exports = {
getBrachList,
validateReg,
validateStrIsReg,
typeCheck,
hasKey,
}

0 comments on commit cfd5c06

Please sign in to comment.