git-branch-description
Advanced tools
| const os = require('os'); | ||
| const parser = require('../util/parser'); | ||
| const git = require('../util/git'); | ||
| const output = require('../util/out'); | ||
| module.exports = function(re) { | ||
| const descConfig = parser.read(); | ||
| const branches = git.allBranches(true); | ||
| let out = [], br, regex = new RegExp(re); | ||
| for(let name of branches) { | ||
| br = {}; | ||
| br.name = name; | ||
| br.desc = descConfig[name] || git.branchDescription(name); | ||
| if (br.desc.match(regex) || br.name.match(regex)) { | ||
| br.desc = br.desc.replace(regex, function(str) { | ||
| return `\x1B[31m${str}\x1B[39m`; | ||
| }); | ||
| br.name = br.name.replace(regex, function(str) { | ||
| return `\x1B[31m${str}\x1B[39m`; | ||
| }); | ||
| out.push(br); | ||
| } | ||
| } | ||
| output.outputDescription(out); | ||
| } |
+36
| var os = require('os'); | ||
| var git = require('./git'); | ||
| function renderPrefix(isCurrent) { | ||
| return isCurrent ? '*' : ' '; | ||
| } | ||
| function colorName(name, isCurrent) { | ||
| if (isCurrent) { | ||
| return `\x1B[32m${name.replace('\x1B[39m', '\x1B[39m\x1B[32m')}\x1B[39m`; | ||
| } else { | ||
| return name; | ||
| } | ||
| } | ||
| function colorDesc(desc) { | ||
| if (desc) { | ||
| return ` \x1B[36m${desc.replace('\x1B[39m', '\x1B[39m\x1B[36m')}\x1B[39m`; | ||
| } else { | ||
| return ''; | ||
| } | ||
| } | ||
| function isCurrentBranch(name) { | ||
| const currentBranch = git.currentHead(); | ||
| name = name.replace(/\x1B\[\d+m/g, ''); | ||
| return name === currentBranch; | ||
| } | ||
| exports.outputDescription = function (descs) { | ||
| let out = descs.map(({name, desc}) => { | ||
| var isCurrent = isCurrentBranch(name); | ||
| return `${renderPrefix(isCurrent)} ${colorName(name, isCurrent)} ${colorDesc(desc)}`; | ||
| }); | ||
| console.log(out.join(os.EOL).toString()); | ||
| } |
+11
-2
@@ -16,2 +16,3 @@ #!/usr/bin/env node | ||
| var edit = require('../command/edit'); | ||
| var find = require('../command/find'); | ||
@@ -24,3 +25,4 @@ var check = require('../util/check'); | ||
| check.gitDir(); | ||
| check.invariantGitDir(check.isGitDir()); | ||
| program.command('init') | ||
@@ -85,4 +87,11 @@ .description('initialize a git repository with a branch-description.properties') | ||
| }) | ||
| }) | ||
| }); | ||
| program.command('find <regex>') | ||
| .description('find branch which name or descrition matches regex') | ||
| .action(function(regex) { | ||
| find(regex); | ||
| }); | ||
| program.parse(process.argv); |
| var check = require('../util/check'); | ||
| if (check.gitDir(true)) { | ||
| if (check.isGitDir()) { | ||
| try { | ||
| require('./init')(); | ||
| require('./init')(); | ||
| } catch (e) { | ||
@@ -7,0 +7,0 @@ |
+3
-37
@@ -1,40 +0,6 @@ | ||
| var os = require('os'); | ||
| var parser = require('../util/parser'); | ||
| var git = require('../util/git'); | ||
| var output = require('../util/out'); | ||
| var currentBranch = git.currentHead(); | ||
| function renderPrefix(isCurrent) { | ||
| return isCurrent ? '*' : ' '; | ||
| } | ||
| function colorName(name, isCurrent) { | ||
| if (isCurrent) { | ||
| return `\x1B[32m${name}\x1B[39m`; | ||
| } else { | ||
| return name; | ||
| } | ||
| } | ||
| function colorDesc(desc) { | ||
| if (desc) { | ||
| return ` \x1B[36m${desc}\x1B[39m`; | ||
| } else { | ||
| return ''; | ||
| } | ||
| } | ||
| function isCurrentBranch(name) { | ||
| return name === currentBranch; | ||
| } | ||
| function outputDescription(descs) { | ||
| let out = descs.map(({name, desc}) => { | ||
| var isCurrent = isCurrentBranch(name); | ||
| return `${renderPrefix(isCurrent)} ${colorName(name, isCurrent)} ${colorDesc(desc)}`; | ||
| }); | ||
| console.log(out.join(os.EOL).toString()); | ||
| } | ||
| module.exports = function(specifyBranch, mode, clean) { | ||
@@ -50,3 +16,3 @@ | ||
| }; | ||
| return outputDescription([sbr]); | ||
| return output.outputDescription([sbr]); | ||
| } | ||
@@ -73,3 +39,3 @@ | ||
| outputDescription(out); | ||
| output.outputDescription(out); | ||
| } |
+1
-1
| { | ||
| "name": "git-branch-description", | ||
| "version": "1.1.8", | ||
| "version": "1.1.9", | ||
| "description": "manage branch description via branch-description.properties", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+16
-7
@@ -5,12 +5,21 @@ var fs = require('fs'); | ||
| var pwd = parser.getRootDir(); | ||
| var pwd = parser.getRootDir(); | ||
| exports.gitDir = function(rv) { | ||
| var isGitDir = fs.existsSync(path.resolve(pwd, '.git')); | ||
| if (!rv && !isGitDir) { | ||
| console.error('\x1B[31mNot a git repository.\x1B[39m'); | ||
| exports.isGitDir = function() { | ||
| return fs.existsSync(path.resolve(pwd, '.git')); | ||
| } | ||
| exports.invariant = function(val, message) { | ||
| if (!val) { | ||
| console.log(`\x1B[31m${message}\x1B[39m`); | ||
| process.exit(1); | ||
| } else { | ||
| return isGitDir; | ||
| } | ||
| } | ||
| exports.invariantGitDir = function(val) { | ||
| if (!val) { | ||
| this.invariant(false, 'Not a git repository'); | ||
| } | ||
| } | ||
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
12407
12.58%14
16.67%307
13.28%