-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ViES
committed
Jun 29, 2020
0 parents
commit f36aafe
Showing
7 changed files
with
507 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ts-coverage | ||
|
||
When you migrate your project to TypeScript it's useful to track the progress. | ||
ts-coverage print simple histogram so you can always know how close to the goal you are. | ||
|
||
## Example | ||
|
||
`npx ts-coverage ./src` | ||
|
||
*Output* | ||
|
||
``` | ||
.js(x) | ############################################################ | 1933 (97.9%) | ||
.ts(x) | # | 41 (2.1%) | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path'); | ||
const lib = require('./lib'); | ||
const { argv } = require('yargs') | ||
.usage("$0 <path>"); | ||
|
||
if (module.parent) throw new Error(`Can't be imported`); | ||
|
||
process.on('unhandledRejection', error => { | ||
throw error; | ||
}); | ||
|
||
const [dir] = argv._; | ||
|
||
lib(dir); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
const globby = require('globby'); | ||
const chalk = require('chalk'); | ||
const histogram = require('ascii-histogram'); | ||
|
||
const percent = (n, total) => (n && (n / total * 100).toFixed(1)) + '%'; | ||
|
||
const formatter = total => n => `${n} (${percent(n, total)})`; | ||
|
||
const printOutput = data => { | ||
const total = Object.values(data) | ||
.reduce((acc, v) => acc + v, 0); | ||
|
||
const output = histogram(data, { map: formatter(total) }) | ||
.split('\n') | ||
.map((v, i) => { | ||
switch (i) { | ||
case 0: | ||
return chalk.yellowBright(v); | ||
case 1: | ||
return chalk.blueBright(v); | ||
default: | ||
return v; | ||
} | ||
}) | ||
.join('\n'); | ||
|
||
console.log(total | ||
? output | ||
: 'No sources found ¯\\_(ツ)_/¯.' | ||
); | ||
}; | ||
|
||
/** | ||
* @param {string} directory | ||
*/ | ||
module.exports = async (directory = process.cwd()) => { | ||
const extensions = {}; | ||
|
||
directory = path.resolve(directory); | ||
|
||
await fs.access(directory); | ||
|
||
for await (const p of globby.stream(`${directory}/**/*.{js,jsx,ts,tsx}`)) { | ||
const extension = path.extname(p); | ||
extensions[extension] = (extensions[extension] || 0) + 1; | ||
} | ||
|
||
const jsx = extensions['.js'] + extensions['.jsx']; | ||
const tsx = extensions['.ts'] + extensions['.tsx']; | ||
|
||
const data = { | ||
'.js(x)': jsx || 0, | ||
'.ts(x)': tsx || 0, | ||
}; | ||
|
||
printOutput(data); | ||
}; |
Oops, something went wrong.