This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-readme-with-shield-badge.js
46 lines (42 loc) · 1.9 KB
/
update-readme-with-shield-badge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* **************
The only purpose of this script is to be used by the npm test script to write the shield badge within the README.md file
************** */
var fs = require( 'fs' );
var path = require( 'path' );
var istanbul = require( 'istanbul' );
var collector = new istanbul.Collector();
var Report = istanbul.Report;
var shieldBadgeReporter = require( 'istanbul-reporter-shield-badge' );
istanbul.Report.register( shieldBadgeReporter );
var report = Report.create( 'shield-badge', {
readmeFilename: 'README.md',
readmeDir: path.resolve( __dirname, '.' ),
subject: 'coverage'
} );
try {
console.log( '\n====================== Adding the badge to the ' + report.readmeFilename + ' =======================' );
var serverCoverageDir = path.resolve( __dirname, 'test-coverage/server' );
var clientCoverageDir = path.resolve( __dirname, 'test-coverage/client' );
fs.readdirSync( serverCoverageDir ).forEach( function( file ) {
if ( file.indexOf( 'coverage-final.json' ) === 0 ) {
collector.add( JSON.parse( fs.readFileSync( path.resolve( serverCoverageDir, file ), 'utf8' ) ) );
}
} );
fs.readdirSync( clientCoverageDir ).forEach( function( browserDir ) {
if ( browserDir.indexOf( 'HeadlessChrome' ) === 0 ) {
var browserDirPath = path.resolve( clientCoverageDir, browserDir );
fs.readdirSync( browserDirPath ).forEach( function( file ) {
if ( file.indexOf( 'coverage-final.json' ) === 0 ) {
collector.add( JSON.parse( fs.readFileSync( path.resolve( browserDirPath, file ), 'utf8' ) ) );
}
} );
}
} );
report.on( 'done', function() {
console.log( 'The istanbul shield badge report has been generated (from both sources)' );
} );
report.writeReport( collector, true );
} catch ( err ) {
console.error( err.message );
process.exit( 1 );
}