Last active
April 27, 2017 15:00
-
-
Save maximpn/5958e99471c19b77f53e6b89b9f5622f to your computer and use it in GitHub Desktop.
Get statistic about total count of ts files and files which is implemented by using Angular 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const path = require("path"); | |
const walk = require("walk"); | |
const PROJECT_PATH = path.resolve(path.dirname(__dirname), 'src'), | |
checkRegExp = new RegExp("(^\\@[^@\\(]+\\()", "m"), | |
filesCountToSkip = 0; // Some magic number of files which aren't related to the Angular at all | |
let totalTSFiles = 0, | |
angular2TSFiles = 0; | |
const walker = walk.walk(PROJECT_PATH); | |
walker.on("file", (root, fileStats, next) => { | |
const extension = fileStats.name.substr(-8); | |
if (extension === ".spec.ts" || extension.substr(-5) === ".d.ts" || root.match(/helpers/) !== null || extension.substr(-3) !== ".ts") { | |
next(); | |
return; | |
} | |
fs.readFile(root + "/" + fileStats.name, "utf-8", (err, contents) => { | |
if (err) { | |
throw err; | |
} | |
totalTSFiles++; | |
if (checkRegExp.test(contents)) { | |
angular2TSFiles++; | |
} | |
}); | |
next(); | |
}); | |
walker.on("end", () => { | |
totalTSFiles -= filesCountToSkip; | |
if (totalTSFiles < angular2TSFiles) { | |
totalTSFiles = angular2TSFiles; | |
} | |
console.info( | |
"total files:", totalTSFiles, | |
"; Angular 2 files:", angular2TSFiles, | |
"Percentage:", Math.round(angular2TSFiles / totalTSFiles * 1000) / 10 + '%' | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment