Skip to content

Commit 3d20b64

Browse files
committed
feat: initial
0 parents  commit 3d20b64

14 files changed

+2035
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.github/FUNDING.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: evillt
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: evillt
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
custom: https://donate.evila.me

.gitignore

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# parcel-bundler cache (https://parceljs.org/)
61+
.cache
62+
63+
# next.js build output
64+
.next
65+
66+
# nuxt.js build output
67+
.nuxt
68+
69+
# vuepress build output
70+
.vuepress/dist
71+
72+
# Serverless directories
73+
.serverless
74+
75+
# MacOS
76+
.DS_Store
77+
78+
# Universal output
79+
dist

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"bracketSpacing": true
5+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) evillt <ijoec123@gmail.com> (https://evila.me)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# git-delete-branch
2+
3+
> 🔌Tooling for delete git branches
4+
5+
Please consider starring the project to show your ❤️ and support.
6+
7+
[![NPM version](https://badgen.net/npm/v/git-delete-branch?icon=npm)](https://npmjs.com/package/git-delete-branch)
8+
[![NPM download](https://badgen.net/npm/dm/git-delete-branch?icon=npm)](https://npmjs.com/package/git-delete-branch)
9+
[![CircleCI](https://badgen.net/circleci/github/evillt/git-delete-branch?icon=circleci)](https://circleci.com/gh/evillt/git-delete-branch/tree/master)
10+
[![License](https://badgen.net/npm/license/git-delete-branch)](./LICENSE)
11+
[![donate](https://badgen.net/badge/support%20me/donate/f2a)](https://donate.evila.me)
12+
13+
## Features
14+
15+
- Support delete matched branches. e.g.`fix/*`
16+
17+
## Prerequires
18+
19+
- git
20+
- node.js
21+
22+
## Install
23+
24+
```console
25+
yarn global add git-delete-branch
26+
```
27+
28+
## Usage
29+
30+
Basically:
31+
32+
```console
33+
git-delete-branch [...branches]
34+
```
35+
36+
Or using git external commands:
37+
38+
```console
39+
git delete-branch [...branches]
40+
```
41+
42+
## CLI
43+
44+
`git-delete-branch [...branches] [options]`
45+
46+
### `branches`
47+
48+
Delete branches
49+
50+
### `options`
51+
52+
#### `-r, --remote` (WIP)
53+
54+
Delete remote branches
55+
56+
## Contributing
57+
58+
1. Fork it!
59+
2. Create your feature branch: `git checkout -b my-new-feature`
60+
3. Commit your changes: `git commit -am 'Add some feature'`
61+
4. Push to the branch: `git push origin my-new-feature`
62+
5. Submit a pull request :D
63+
64+
## Author
65+
66+
**git-delete-branch** © [evillt](https://github.com/evillt), Released under the [MIT](./LICENSE) License.
67+
68+
Authored and maintained by **EVILLT** with help from contributors ([list](https://github.com/evillt/git-delete-branch/contributors)).
69+
70+
> [evila.me](https://evila.me) · GitHub [@evillt](https://github.com/evillt) · Twitter [@evillt](https://twitter.com/evillt)

bin/cli.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
const GitDeleteBranch = require('..')
3+
4+
const app = new GitDeleteBranch()
5+
6+
app.run()

circle.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/node:latest
6+
branches:
7+
ignore:
8+
- gh-pages
9+
- /release\/.*/
10+
steps:
11+
- checkout
12+
- restore_cache:
13+
key: dependency-cache-{{ checksum "yarn.lock" }}
14+
- run:
15+
name: Install dependencies
16+
command: yarn
17+
- save_cache:
18+
key: dependency-cache-{{ checksum "yarn.lock" }}
19+
paths:
20+
- ./node_modules
21+
- run:
22+
name: Release
23+
command: npx semantic-release

lib/index.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const cac = require('cac')
2+
const path = require('path')
3+
const fs = require('fs')
4+
const spawn = require('cross-spawn')
5+
const parseArgs = require('../utils/parseArgs')
6+
const logger = require('../utils/logger')
7+
8+
module.exports = class Core {
9+
constructor() {
10+
this.cwd = process.cwd()
11+
this.rawArgs = process.argv
12+
this.args = parseArgs(this.rawArgs.slice(2))
13+
14+
this.isGitProject()
15+
16+
this.initCli()
17+
}
18+
19+
initCli() {
20+
const cli = (this.cli = cac())
21+
this.command = cli
22+
.command('[...branches]')
23+
.usage('[option]')
24+
.action(branches => {
25+
this.deleteBranch(branches)
26+
})
27+
28+
cli.version(require('../package.json').version).help()
29+
30+
this.cli.parse(this.rawArgs, { run: false })
31+
}
32+
33+
isGitProject() {
34+
if (!fs.existsSync(path.join(this.cwd, '.git'))) {
35+
logger.error('Current working directory is not a git project!')
36+
process.exit(1)
37+
}
38+
return true
39+
}
40+
41+
getBranch() {
42+
const { stdout } = spawn.sync('git', ['branch'])
43+
const branch = stdout
44+
.toString()
45+
.trimRight()
46+
.split('\n')
47+
.map(b => {
48+
if (!b.includes('*')) {
49+
return b.trim()
50+
}
51+
})
52+
.filter(Boolean)
53+
54+
return branch
55+
}
56+
57+
deleteBranch(branches) {
58+
const match = require('multimatch')
59+
const matched = match(this.getBranch(), branches)
60+
61+
matched.forEach(branch => {
62+
const ps = spawn.sync('git', ['branch', branch, '-D'])
63+
if (ps.status === 0) {
64+
logger.success('Deleted branch', `\`${branch}\``)
65+
}
66+
})
67+
}
68+
69+
run() {
70+
this.cli.runMatchedCommand()
71+
}
72+
}

package.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "git-delete-branch",
3+
"description": "🔌Tooling for delete git branches",
4+
"version": "0.0.1",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "evillt/git-delete-branch"
9+
},
10+
"bin": "bin/cli.js",
11+
"author": "evillt <ijoec123@gmail.com> (https://evila.me)",
12+
"main": "lib/index.js",
13+
"scripts": {},
14+
"dependencies": {
15+
"cac": "^6.5.2",
16+
"cross-spawn": "^6.0.5",
17+
"kleur": "^3.0.3",
18+
"mri": "^1.1.4",
19+
"multimatch": "^4.0.0"
20+
},
21+
"devDependencies": {
22+
"husky": "^1.0.0-rc.13",
23+
"lint-staged": "^7.2.0",
24+
"prettier": "^1.17.0"
25+
},
26+
"husky": {
27+
"hooks": {
28+
"pre-commit": "lint-staged"
29+
}
30+
},
31+
"lint-staged": {
32+
"linters": {
33+
"*.{js,json,md}": [
34+
"prettier --write",
35+
"git add"
36+
]
37+
}
38+
}
39+
}

utils/logger.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const kleur = require('kleur')
2+
const path = require('path')
3+
4+
class Logger {
5+
log(...args) {
6+
console.log(...args)
7+
}
8+
9+
success(...args) {
10+
this.log(kleur.green('success'), ...args)
11+
}
12+
13+
error(...args) {
14+
this.log(kleur.red('error'), ...args)
15+
}
16+
17+
warn(...args) {
18+
this.log(kleur.yellow('warning'), ...args)
19+
}
20+
21+
done(...args) {
22+
this.log(kleur.green(process.platform === 'win32' ? '√' : '✔'), ...args)
23+
}
24+
25+
tip(...args) {
26+
this.log(kleur.blue('tip'), ...args)
27+
}
28+
29+
info(...args) {
30+
this.log(kleur.cyan('info'), ...args)
31+
}
32+
}
33+
34+
module.exports = new Logger()

0 commit comments

Comments
 (0)