Skip to content

Commit 335f60c

Browse files
Prepared a CLI package
1 parent bd85d47 commit 335f60c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+525
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/
44
/packages/demo/*/coverage/
55
/packages/*/coverage/
66
/coverage/
7+
yarn-error.log

packages/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/jest-coverage

packages/app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"dependencies": {
2020
"@lcov-viewer/components": "^1.1.0",
2121
"@lcov-viewer/core": "^1.1.0",
22-
"lcov-parse": "^1.0.0",
2322
"preact": "^10.5.15",
2423
"preact-router": "^3.2.1",
2524
"react-dropzone": "^11.4.2"

packages/app/src/components/LcovImport/LcovImport.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { buildCoverageTree, clsx } from '@lcov-viewer/core';
1+
import { buildCoverage, buildCoverageTree, clsx } from '@lcov-viewer/core';
22
import { route } from 'preact-router';
33
import React, { useCallback, useState } from 'react';
44
import { useDropzone } from 'react-dropzone';
5-
import buildCoverage from '../../utils/buildCoverage';
65
import readLcov from '../../utils/readLcov';
76
import useCoverageDataControl from '../CoverageDataProvider/useCoverageDataControl';
87
import classes from './LcovImport.module.less';

packages/app/src/utils/readLcov.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { source as parseLCOV } from 'lcov-parse';
1+
import { parseLCOV } from '@lcov-viewer/core';
22

33
const readLcov = (file) => new Promise((resolve, reject) => {
44
const date = new Date(file.lastModified || file.lastModifiedDate || new Date().getTime()).toString();
55
const reader = new FileReader();
6-
reader.onload = () => {
7-
const lcovContent = reader.result;
8-
parseLCOV(lcovContent, (error, data) => {
9-
if (error) {
10-
reject([error, 'Failed to parse file']);
11-
} else {
12-
resolve([date, data]);
13-
}
14-
});
6+
reader.onload = async () => {
7+
try {
8+
const data = await parseLCOV(reader.result);
9+
resolve([date, data]);
10+
} catch (error) {
11+
reject([error, 'Failed to parse file']);
12+
}
1513
};
1614
reader.onerror = () => reject([reader.error, 'Failed to read file']);
1715
reader.readAsText(file);

packages/cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/lib/

packages/cli/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License Copyright (c) 2021 Eugene Zinovyev <eugene.zinovyev@gmail.com>
2+
3+
Permission is hereby granted,
4+
free of charge, to any person obtaining a copy of this software and associated
5+
documentation files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use, copy, modify, merge,
7+
publish, distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to the
9+
following conditions:
10+
11+
The above copyright notice and this permission notice
12+
(including the next paragraph) shall be included in all copies or substantial
13+
portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

packages/cli/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
![build](https://github.com/eugenezinovyev/lcov-viewer/actions/workflows/main.yml/badge.svg)
2+
[![Known Vulnerabilities](https://snyk.io/test/github/eugenezinovyev/lcov-viewer/badge.svg?targetFile=packages%2Fcli%2Fpackage.json)](https://snyk.io/test/github/eugenezinovyev/lcov-viewer?targetFile=packages%2Fcli%2Fpackage.json)
3+
[![npm version](https://badge.fury.io/js/@lcov-viewer%2Fcli.svg)](https://www.npmjs.com/package/@lcov-viewer/cli)
4+
5+
# LCOV viewer CLI
6+
7+
CLI to convert coverage to grouped HTML report. Generates code coverage report grouped by directory.
8+
9+
## Installation
10+
11+
```
12+
npm install -g @lcov-viewer/cli
13+
yarn global add @lcov-viewer/cli
14+
```
15+
16+
## Usage
17+
```
18+
lcov-viewer lcov -o ./report-output-directory ./lcov.info
19+
```
20+
21+
# Other packages
22+
An Istanbul report package: [@lcov-viewer/istanbul-report](https://www.npmjs.com/package/@lcov-viewer/istanbul-report)
23+
24+
25+
## Demo
26+
![report](https://user-images.githubusercontent.com/1678896/160290486-4474bd0a-c3e5-4e0e-90dc-6ac72a1e76f7.gif)

packages/cli/commands/lcov.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { buildCoverage, parseLCOV } from '@lcov-viewer/core';
2+
import { promises as fs } from 'fs';
3+
import path from 'path';
4+
5+
async function lcov(src, { output }) {
6+
const [stats, lcovContent] = await Promise.all([fs.stat(src), fs.readFile(src, { encoding: 'utf8' })]);
7+
const date = stats.mtime.toString();
8+
const lcov = await parseLCOV(lcovContent);
9+
const coverage = buildCoverage(lcov);
10+
const assetsDirectory = path.resolve(__dirname, 'assets');
11+
await fs.mkdir(output, { recursive: true });
12+
const files = await fs.readdir(assetsDirectory);
13+
files.map(file => {
14+
const dest = path.resolve(output, file);
15+
return fs.copyFile(path.resolve(assetsDirectory, file), dest);
16+
});
17+
await fs.writeFile(
18+
path.resolve(output, 'report-data.js'),
19+
`window.REPORT_DATE = '${date.toString()}';window.COVERAGE_DATA = ${JSON.stringify(coverage)};`,
20+
{ encoding: 'utf8' },
21+
);
22+
}
23+
24+
export default lcov;

packages/cli/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@lcov-viewer/cli",
3+
"keywords": [
4+
"coverage",
5+
"code coverage",
6+
"cli",
7+
"lcov",
8+
"report"
9+
],
10+
"version": "1.1.0",
11+
"private": false,
12+
"author": "Eugene Zinovyev <eugene.zinovyev@gmail.com>",
13+
"main": "lib/index.js",
14+
"license": "MIT",
15+
"scripts": {
16+
"build": "rollup -c"
17+
},
18+
"dependencies": {
19+
"commander": "^9.1.0"
20+
},
21+
"bin": {
22+
"lcov-viewer": "lib/index.js"
23+
},
24+
"devDependencies": {
25+
"@lcov-viewer/core": "^1.1.0",
26+
"@lcov-viewer/report": "^1.1.0",
27+
"@lcov-viewer/rollup-copy": "^1.1.0",
28+
"@rollup/plugin-commonjs": "^21.0.2",
29+
"@rollup/plugin-node-resolve": "^13.1.3",
30+
"rollup": "^2.70.1",
31+
"rollup-plugin-preserve-shebang": "^1.0.1",
32+
"rollup-plugin-terser": "^7.0.2"
33+
},
34+
"files": [
35+
"lib/**/*.*"
36+
],
37+
"directories": {
38+
"lib": "lib"
39+
},
40+
"description": "LCOV viewer CLI to convert coverage to grouped HTML report. Generates code coverage report grouped by directory.",
41+
"repository": {
42+
"type": "git",
43+
"url": "https://github.com/eugenezinovyev/lcov-viewer.git",
44+
"directory": "packages/cli"
45+
}
46+
}

0 commit comments

Comments
 (0)