Skip to content

Commit

Permalink
Merge pull request #4 from jeroenouw/classes
Browse files Browse the repository at this point in the history
feat: Made classes, splitted files, updated readme and depedencies, added i…
  • Loading branch information
jeroenouw authored Feb 2, 2019
2 parents ad01048 + 420dbad commit a3442db
Show file tree
Hide file tree
Showing 31 changed files with 2,773 additions and 5,031 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TSCOV - Calculate your type coverage within seconds with this TypeScript CLI
# TSCOV - Check the type coverage of any TypeScript project with this easy npm package

[![tscov](https://img.shields.io/badge/dynamic/json.svg?label=tscov&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fjeroenouw%2Ftscov%2Fmaster%2Fpackage.json)](https://github.com/jeroenouw/tscov)
[![tscov](https://img.shields.io/badge/dynamic/json.svg?label=tscov&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.minCoverage&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fjeroenouw%2Ftscov%2Fmaster%2Fpackage.json)](https://github.com/jeroenouw/tscov)
[![npmversion](https://img.shields.io/npm/v/tscov.svg)](https://github.com/jeroenouw/tscov)
[![npmlicense](https://img.shields.io/npm/l/tscov.svg)](https://github.com/jeroenouw/AngularMaterialFirebase/blob/master/LICENSE/)
[![downloads](https://img.shields.io/npm/dy/tscov.svg)](https://github.com/jeroenouw/tscov)
Expand Down Expand Up @@ -61,9 +61,11 @@ tscov --details

# Test specific folder
tscov -p PATH_TO_FOLDER/FOLDERNAME
tscov --project PATH_TO_FOLDER/FOLDERNAME

# Testing specific files
tscov -p PATH_TO_FOLDER/FOLDERNAME -f FILENAME.ts
tscov --project PATH_TO_FOLDER/FOLDERNAME --file FILENAME.ts

# Start debugging
tscov --debug
Expand Down Expand Up @@ -121,10 +123,9 @@ Lastly, open a pull request on Github.

The following npm script are available

- `npm start` - watch files
- `npm run create` - create build, install globally and run tscov
- `npm start` - create build, install globally and run tscov
- `npm run build` - create build
- `npm test` - install globally and run tscov
- `npm run global` - install globally and run tscov
- `npm run link-upstream` - add remote
- `npm run sync` - fetch, checkout, merge and push
- `npm run reset` - removes node modules, package-lock.json, lib and re-installs everything.
Expand Down
3 changes: 2 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {};
import { Tscov } from './tscov/tscov';
export declare function index(): Tscov;
156 changes: 16 additions & 140 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,143 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var minimist_1 = tslib_1.__importDefault(require("minimist"));
var fs = tslib_1.__importStar(require("fs"));
var util = tslib_1.__importStar(require("util"));
var path = tslib_1.__importStar(require("path"));
var packageJson = tslib_1.__importStar(require("../package.json"));
var kleur_1 = require("kleur");
var tscov_1 = require("./tscov");
var figlet = require('figlet');
var program = require('commander');
var suppressError = false;
var existsAsync = util.promisify(fs.exists);
var readFileAsync = util.promisify(fs.readFile);
program
.version(showToolVersion())
.description(kleur_1.cyan('TypeScript CLI to calculate type coverage'))
.option('-m NUMBER, --min-coverage NUMBER', 'define your minimum wanted coverage % by replacing NUMBER (0-100) with 95 for example')
.option('-p FOLDERNAME, --project FOLDERNAME', 'Test folder')
.option('-p FOLDERNAME -f FILENAME, --project FOLDERNAME --file FILENAME', 'Test specific file')
.option('-d, --details', 'Show uncovered types')
.option('--debug', 'Show debug info');
function showToolVersion() {
console.log("Version: " + packageJson.version);
var inversify_1 = require("inversify");
var ts_config_1 = require("./tscov/ts-config");
var tscov_1 = require("./tscov/tscov");
var options_1 = require("./tscov/options");
var check_types_1 = require("./tscov/check-types");
var min_coverage_1 = require("./tscov/min-coverage");
function index() {
var container = new inversify_1.Container();
container.bind('TsConfig').to(ts_config_1.TsConfig).inSingletonScope();
container.bind('Tscov').to(tscov_1.Tscov).inSingletonScope();
container.bind('Options').to(options_1.Options).inSingletonScope();
container.bind('CheckTypes').to(check_types_1.CheckTypes).inSingletonScope();
container.bind('MinCoverage').to(min_coverage_1.MinCoverage).inSingletonScope();
return container.get('Tscov');
}
function showHelpLog() {
program.outputHelp();
}
function showIntroLog() {
console.log(figlet.textSync('TSCOV', { horizontalLayout: 'full' }));
console.log(kleur_1.cyan("The TypeScript CLI to calculate type coverage"));
}
// tslint:disable-next-line:cognitive-complexity no-big-function
function executeCommandLine() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var e_1, _a, argv, showVersion, showHelp, _b, correctCount, totalCount, anys, openCount, percent, minCoverage, failed, success, anys_1, anys_1_1, _c, file, line, character, text;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
showIntroLog();
argv = minimist_1.default(process.argv.slice(2), { '--': true });
showVersion = argv.v || argv.version;
if (showVersion) {
showToolVersion();
return [2 /*return*/];
}
showHelp = argv.h || argv.help;
if (showHelp) {
showHelpLog();
return [2 /*return*/];
}
suppressError = argv.suppressError;
return [4 /*yield*/, tscov_1.lint(argv.p || argv.project || '.', true, argv.debug, argv.f || argv.file)];
case 1:
_b = _d.sent(), correctCount = _b.correctCount, totalCount = _b.totalCount, anys = _b.anys;
openCount = totalCount - correctCount;
percent = Math.round(10000 * correctCount / totalCount) / 100;
return [4 /*yield*/, getMinCoverage(argv)];
case 2:
minCoverage = _d.sent();
failed = minCoverage && percent < minCoverage;
success = minCoverage && percent > minCoverage;
if (argv.d || argv.details || failed) {
console.log('');
console.log('------------- uncovered types ---------------');
try {
for (anys_1 = tslib_1.__values(anys), anys_1_1 = anys_1.next(); !anys_1_1.done; anys_1_1 = anys_1.next()) {
_c = anys_1_1.value, file = _c.file, line = _c.line, character = _c.character, text = _c.text;
console.log(path.resolve(process.cwd(), file) + ": " + kleur_1.cyan(line + 1 + ":" + (character + 1)) + (" - " + text));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (anys_1_1 && !anys_1_1.done && (_a = anys_1.return)) _a.call(anys_1);
}
finally { if (e_1) throw e_1.error; }
}
}
console.log('');
console.log('');
console.log('----------------- coverage ------------------');
console.log(kleur_1.cyan("" + totalCount) + " - max reachable type coverage");
console.log(kleur_1.cyan("" + correctCount) + " - types covered");
console.log(kleur_1.cyan("" + openCount) + " - types uncovered");
console.log('');
if (success) {
console.log(kleur_1.green(percent.toFixed(2) + "%") + " - coverage percentage" + kleur_1.white("\nYou can run " + kleur_1.cyan('"tscov --details"') + " to show all uncovered types."));
}
if (failed) {
console.log((kleur_1.red(percent.toFixed(2) + "%") + kleur_1.white(" - the type coverage rate is lower than your target: ") + kleur_1.cyan(minCoverage + "%.")));
}
;
return [2 /*return*/];
}
});
});
}
;
function getMinCoverage(argv) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var minCoverage, packageJsonPath, currentPackageJson, _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
packageJsonPath = path.resolve(process.cwd(), 'package.json');
return [4 /*yield*/, existsAsync(packageJsonPath)];
case 1:
if (!_c.sent()) return [3 /*break*/, 3];
_b = (_a = JSON).parse;
return [4 /*yield*/, readFileAsync(packageJsonPath)];
case 2:
currentPackageJson = _b.apply(_a, [(_c.sent()).toString()]);
if (currentPackageJson.typeCoverage && currentPackageJson.typeCoverage.minCoverage) {
minCoverage = currentPackageJson.typeCoverage.minCoverage;
}
_c.label = 3;
case 3:
if (argv['m'] || argv['min-coverage']) {
minCoverage = argv['m'] || argv['min-coverage'];
}
return [2 /*return*/, minCoverage];
}
});
});
}
;
executeCommandLine().then(function () {
console.log('');
console.log('');
console.log('');
}, function (error) {
if (error instanceof Error) {
console.log(kleur_1.red(error.message));
}
else {
console.log(kleur_1.red(error));
}
if (!suppressError) {
process.exit(1);
}
});
exports.index = index;
index();
13 changes: 0 additions & 13 deletions lib/tsconfig.d.ts

This file was deleted.

132 changes: 0 additions & 132 deletions lib/tsconfig.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/tscov.d.ts

This file was deleted.

Loading

0 comments on commit a3442db

Please sign in to comment.