@sprocketbot/listodo
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,5 +0,85 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lib_1 = require("./lib"); | ||
(0, lib_1.listodo)({ | ||
#!/usr/bin/env node | ||
import { execSync } from 'child_process'; | ||
import chalk from 'chalk'; | ||
const getGrepOptions = (options) => { | ||
let opts = " --full-name"; | ||
if (options.searchUntracked) | ||
opts += " --untracked"; | ||
if (options.searchIgnored) | ||
opts += " --untracked --no-exclude-standard"; | ||
if (options.lineNumbers) | ||
opts += " -n"; | ||
if (options.columnNumbers) | ||
opts += " --column"; | ||
if (options.ignoreCase) | ||
opts += " --ignore-case"; | ||
return opts; | ||
}; | ||
const parseGrep = (grep) => { | ||
const tokens = grep.split(":"); | ||
return { | ||
file: tokens[0], | ||
line: parseInt(tokens[1]), | ||
column: parseInt(tokens[2]), | ||
content: tokens[3].trim(), | ||
}; | ||
}; | ||
const BLAME_REGEX = /(.*) \d+ \d+ \d+\nauthor (.*)\nauthor-mail <(.*)>\nauthor-time (.*)\nauthor-tz (.*)\ncommitter (.*)\ncommitter-mail (.*)\ncommitter-time (.*)\ncommitter-tz (.*)\nsummary (.*)\nfilename (.*)\n\t(.*)\n/; | ||
const parseBlame = (blame) => { | ||
const match = blame.match(BLAME_REGEX); | ||
if (!match) { | ||
console.log(`Unable to parse blame ${blame}`); | ||
return {}; | ||
} | ||
const isCommitted = match[1] !== "0000000000000000000000000000000000000000" && match[1] !== "00000000"; | ||
return { | ||
isCommitted: isCommitted, | ||
rev: match[1], | ||
author: match[2], | ||
authorEmail: match[3], | ||
timestamp: parseInt(match[4]), | ||
timezone: parseInt(match[5]), | ||
commitMessage: match[10], | ||
}; | ||
}; | ||
const getTodos = (options) => { | ||
const gitGrep = `git grep ${getGrepOptions(options)} TODO ${options.files.join(" ")}`; | ||
let grepLines; | ||
try { | ||
grepLines = execSync(gitGrep).toString().split("\n").filter(l => l.length); | ||
} | ||
catch (err) { | ||
// console.log("Grep Error: ", err); | ||
throw err; // TODO handle | ||
} | ||
const todos = grepLines.map(parseGrep); | ||
for (let todo of todos) { | ||
const gitBlame = `git blame -L ${todo.line},${todo.line} -p ${todo.file}`; | ||
try { | ||
const blame = execSync(gitBlame, { stdio: "pipe" }).toString(); | ||
Object.assign(todo, parseBlame(blame)); | ||
} | ||
catch (err) { | ||
// console.error(`Blame error: Unable to find blame for ${todo.file} ${todo.line}:${todo.column}`); | ||
continue; | ||
} | ||
} | ||
return todos; | ||
}; | ||
const todoToStr = (todo) => { | ||
let datetime = ""; | ||
if (todo.isCommitted) | ||
datetime = new Date(todo.timestamp * 1000).toLocaleString(); | ||
const l1 = chalk.bold.yellowBright(`${todo.file}:${todo.line}:${todo.column}`); | ||
const l2 = todo.isCommitted ? chalk.gray(`\n ${todo.author} @ ${datetime}`) : ""; | ||
const l3 = chalk.italic.yellowBright(`\n ${todo.content}`); | ||
return l1 + l2 + l3; | ||
}; | ||
const listodo = (options) => { | ||
const todos = getTodos(options); | ||
todos.map(todoToStr).forEach(t => console.log(t + "\n")); | ||
}; | ||
listodo({ | ||
files: ["test"], | ||
@@ -6,0 +86,0 @@ searchUntracked: true, |
{ | ||
"name": "@sprocketbot/listodo", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -9,3 +9,3 @@ "bin": "bin/index.js", | ||
"dev": "nodemon src/index.ts", | ||
"build": "rimraf bin && tsc" | ||
"build": "rimraf bin && rollup -c" | ||
}, | ||
@@ -24,4 +24,7 @@ "repository": { | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^8.3.0", | ||
"nodemon": "^2.0.15", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.60.2", | ||
"rollup-plugin-preserve-shebang": "^1.0.1", | ||
"ts-node": "^10.4.0", | ||
@@ -28,0 +31,0 @@ "typescript": "^4.5.2" |
@@ -0,1 +1,3 @@ | ||
#!/usr/bin/env node | ||
import { listodo } from "./lib"; | ||
@@ -2,0 +4,0 @@ |
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
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
18993
7
9
298