code-complexity
Advanced tools
Comparing version
@@ -21,8 +21,8 @@ "use strict"; | ||
console.log(); | ||
console.log(" Examples:"); | ||
console.log(" Examples (using the source code instead of npm published versions):"); | ||
console.log(); | ||
console.log(" $ index.ts /path/to/git/directory"); | ||
console.log(" $ index.ts /path/to/git/directory --limit 3"); | ||
console.log(" $ index.ts /path/to/git/directory --details"); | ||
console.log(" $ index.ts /path/to/git/directory --min 10 --max 50"); | ||
console.log(" $ npm run build && node dist/index.js /path/to/git/directory"); | ||
console.log(" $ npm run build && node dist/index.js /path/to/git/directory --limit 3"); | ||
console.log(" $ npm run build && node dist/index.js /path/to/git/directory --details"); | ||
console.log(" $ npx code-complexity /path/to/git/directory --min 10 --max 50"); | ||
console.log(); | ||
@@ -29,0 +29,0 @@ }) |
@@ -42,2 +42,13 @@ "use strict"; | ||
var path_1 = require("path"); | ||
var PER_LINE = "\n"; | ||
var COMMITS_PER_FILE = /(?<commitCount>[0-9]+) (?<relativePathToFile>.+)/; | ||
var CommitCountPerFile = /** @class */ (function () { | ||
function CommitCountPerFile(relativePathToFile, absolutePathToFile, commitCount) { | ||
this.relativePathToFile = relativePathToFile; | ||
this.absolutePathToFile = absolutePathToFile; | ||
this.commitCount = commitCount; | ||
} | ||
return CommitCountPerFile; | ||
}()); | ||
exports.CommitCountPerFile = CommitCountPerFile; | ||
function countCommitsPerFile(directory, options) { | ||
@@ -55,7 +66,4 @@ return __awaiter(this, void 0, void 0, function () { | ||
.map(trim) | ||
.filter(jsOrTsOnly) | ||
.map(function (line) { | ||
var groups = line.match(COMMITS_PER_FILE).groups; | ||
return new CommitCountPerFile(groups.relativePathToFile, path_1.resolve(directory, groups.relativePathToFile), parseInt(groups.commitCount, 10)); | ||
}) | ||
.filter(removeEmptyLines) | ||
.map(toCommitCountPerFile(directory)) | ||
.filter(ignoreFilesThatNoLongerExist)]; | ||
@@ -66,16 +74,2 @@ }); | ||
exports.countCommitsPerFile = countCommitsPerFile; | ||
var PER_LINE = "\n"; | ||
var trim = function (s) { return s.trim(); }; | ||
var jsOrTsOnly = function (s) { return s.endsWith(".js") || s.endsWith(".ts"); }; | ||
var COMMITS_PER_FILE = /(?<commitCount>[0-9]+) (?<relativePathToFile>.+)/; | ||
var ignoreFilesThatNoLongerExist = function (commitCountPerFile) { return fs_1.existsSync(commitCountPerFile.absolutePathToFile); }; | ||
var CommitCountPerFile = /** @class */ (function () { | ||
function CommitCountPerFile(relativePathToFile, absolutePathToFile, commitCount) { | ||
this.relativePathToFile = relativePathToFile; | ||
this.absolutePathToFile = absolutePathToFile; | ||
this.commitCount = commitCount; | ||
} | ||
return CommitCountPerFile; | ||
}()); | ||
exports.CommitCountPerFile = CommitCountPerFile; | ||
function assertGitIsInstalled() { | ||
@@ -101,9 +95,32 @@ try { | ||
var firstParent = _a.firstParent, since = _a.since; | ||
var firstParentFlag = firstParent ? "--first-parent" : ""; | ||
var sinceParameter = since ? "--since=\"" + since + "\"" : ""; | ||
return [ | ||
"git -C " + directory + " log " + sinceParameter + " " + firstParentFlag + " --name-only --format=''", | ||
[ | ||
"git", | ||
"-C " + directory, | ||
"log", | ||
"--follow", | ||
"--name-only", | ||
"--format=''", | ||
since ? "--since=\"" + since + "\"" : "", | ||
firstParent ? "--first-parent" : "", | ||
"'*.[tj]s'" | ||
].join(" "), | ||
"sort", | ||
"uniq -c" | ||
"uniq --count" | ||
].join(" | "); | ||
} | ||
function trim(s) { | ||
return s.trim(); | ||
} | ||
function removeEmptyLines(s) { | ||
return s.length !== 0; | ||
} | ||
function toCommitCountPerFile(directory) { | ||
return function (line) { | ||
var groups = line.match(COMMITS_PER_FILE).groups; | ||
return new CommitCountPerFile(groups.relativePathToFile, path_1.resolve(directory, groups.relativePathToFile), parseInt(groups.commitCount, 10)); | ||
}; | ||
} | ||
function ignoreFilesThatNoLongerExist(commitCountPerFile) { | ||
return fs_1.existsSync(commitCountPerFile.absolutePathToFile); | ||
} |
{ | ||
"name": "code-complexity", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Measure projects complexity based on files sloc and commit count.", | ||
@@ -23,6 +23,6 @@ "main": "src/index.ts", | ||
"lint": "eslint --ext .ts .", | ||
"prepare": "npm run build", | ||
"pretest": "npm run lint", | ||
"prepare": "npm run lint && npm run build", | ||
"postversion": "git push --tags", | ||
"test": "NODE_ENV=test nyc mocha test/**/*.test.js" | ||
"test": "mocha --require ts-node/register test/*.ts", | ||
"test:watch": "mocha --require ts-node/register --watch --watch-files src/*.ts, test/*.ts" | ||
}, | ||
@@ -43,5 +43,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/chai": "^4.2.10", | ||
"@types/chai": "^4.2.11", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^13.9.0", | ||
"@types/node": "^13.9.1", | ||
"@types/proxyquire": "^1.3.28", | ||
@@ -62,4 +62,5 @@ "@typescript-eslint/eslint-plugin": "^2.23.0", | ||
"proxyquire": "^2.1.3", | ||
"ts-node": "^8.6.2", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
23503
1.53%394
4.51%20
5.26%