@sprocketbot/listodo
Advanced tools
Comparing version 0.0.16 to 0.0.17
#!/usr/bin/env node | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lib_1 = require("./lib"); | ||
console.log(process.argv); | ||
const root = (0, lib_1.getGitRoot)(); | ||
console.log(process.cwd()); | ||
(0, lib_1.listodo)({ | ||
files: [`${root}/src`], | ||
searchUntracked: true, | ||
searchIgnored: true, | ||
lineNumbers: true, | ||
columnNumbers: true, | ||
ignoreCase: true, | ||
}); | ||
// @ts-ignore | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
console.log(`Running listodo v${package_json_1.default.version}`); | ||
(0, lib_1.listodo)(); |
@@ -6,9 +6,20 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.listodo = exports.todoToStr = exports.getTodos = exports.parseBlame = exports.parseGrep = exports.getGitRoot = void 0; | ||
exports.listodo = exports.todoToStr = exports.getTodos = exports.getGrepIgnores = exports.getGrepInputs = exports.parseBlame = exports.parseGrep = exports.loadOptions = exports.getGitRoot = void 0; | ||
const child_process_1 = require("child_process"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const getGitRoot = () => { | ||
return (0, child_process_1.execSync)("git rev-parse --show-toplevel").toString().trim(); | ||
const default_config_json_1 = __importDefault(require("./default.config.json")); | ||
const fs_1 = require("fs"); | ||
const getGitRoot = () => (0, child_process_1.execSync)("git rev-parse --show-toplevel").toString().trim(); | ||
exports.getGitRoot = getGitRoot; | ||
const loadOptions = () => { | ||
const optionsPath = `${(0, exports.getGitRoot)()}/listodo.config.json`; | ||
if ((0, fs_1.existsSync)(optionsPath)) { | ||
const options = JSON.parse((0, fs_1.readFileSync)(optionsPath).toString()); | ||
return Object.assign(Object.assign({}, default_config_json_1.default), options); | ||
} | ||
else { | ||
return default_config_json_1.default; | ||
} | ||
}; | ||
exports.getGitRoot = getGitRoot; | ||
exports.loadOptions = loadOptions; | ||
const getGrepOptions = (options) => { | ||
@@ -34,11 +45,12 @@ let opts = " --full-name"; | ||
column: parseInt(tokens[2]), | ||
content: tokens[3].trim(), | ||
content: tokens.slice(3).join(":").trim(), | ||
rawGrep: grep, | ||
}; | ||
}; | ||
exports.parseGrep = parseGrep; | ||
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 BLAME_REGEX = /^(.*) \d+ \d+ \d+\nauthor (.*)\nauthor-mail <(.*)>\nauthor-time (.*)\nauthor-tz (.*)\ncommitter (.*)\ncommitter-mail (.*)\ncommitter-time (.*)\ncommitter-tz (.*)\nsummary (.*)(\nprevious (.*))?\nfilename (.*)\n\t(.*)\n$/; | ||
const parseBlame = (blame) => { | ||
const match = blame.match(BLAME_REGEX); | ||
if (!match) { | ||
console.log(`Unable to parse blame ${blame}`); | ||
// console.log(`Unable to parse blame ${blame}`); | ||
return {}; | ||
@@ -54,8 +66,16 @@ } | ||
timezone: parseInt(match[5]), | ||
commitMessage: match[10], | ||
commitMessage: match[10].trim(), | ||
}; | ||
}; | ||
exports.parseBlame = parseBlame; | ||
const getGrepInputs = (options) => { | ||
return options.inputs.map(i => `"${i}"`).join(" "); | ||
}; | ||
exports.getGrepInputs = getGrepInputs; | ||
const getGrepIgnores = (options) => { | ||
return options.ignore.map(i => `":!${i}"`).join(" "); | ||
}; | ||
exports.getGrepIgnores = getGrepIgnores; | ||
const getTodos = (options) => { | ||
const gitGrep = `git grep ${getGrepOptions(options)} TODO ${options.files.join(" ")}`; | ||
const gitGrep = `git grep ${getGrepOptions(options)} TODO ${(0, exports.getGrepInputs)(options)} ${(0, exports.getGrepIgnores)(options)}`; | ||
let grepLines; | ||
@@ -74,2 +94,3 @@ try { | ||
const blame = (0, child_process_1.execSync)(gitBlame, { stdio: "pipe" }).toString(); | ||
todo.rawBlame = blame; | ||
Object.assign(todo, (0, exports.parseBlame)(blame)); | ||
@@ -91,7 +112,11 @@ } | ||
const l2 = todo.isCommitted ? chalk_1.default.gray(`\n ${todo.author} @ ${datetime}`) : ""; | ||
const l3 = chalk_1.default.italic.yellowBright(`\n ${todo.content}`); | ||
return l1 + l2 + l3; | ||
const l3 = todo.isCommitted ? chalk_1.default.gray(`\n ${todo.commitMessage}`) : ""; | ||
const l4 = chalk_1.default.italic.yellowBright(`\n ${todo.content}`); | ||
const l5 = "\n" + todo.rawGrep; | ||
const l6 = "\n" + todo.rawBlame; | ||
return l1 + l4 + l2 + l3; | ||
}; | ||
exports.todoToStr = todoToStr; | ||
const listodo = (options) => { | ||
const listodo = () => { | ||
const options = (0, exports.loadOptions)(); | ||
const todos = (0, exports.getTodos)(options); | ||
@@ -98,0 +123,0 @@ todos.map(exports.todoToStr).forEach(t => console.log(t + "\n")); |
{ | ||
"name": "@sprocketbot/listodo", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "bin": "bin/index.js", |
@@ -48,4 +48,7 @@ # listodo | ||
## Future plans | ||
- Expose options through configuration file | ||
- Make sure ignoring works | ||
- Ignore package.json and package-lock.json by default | ||
- Error handling, error logging | ||
- Testing | ||
- Open for community contribution | ||
- Open for community contribution (eslint, commitlint) | ||
- More config options (colors, show email/show name/both) |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
8901
8
143
54
1