forked from enketo/enketo-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-readme-with-shield-badge.js
35 lines (31 loc) · 1.27 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
/* **************
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 coverageDir = path.resolve( __dirname, 'test-coverage' );
fs.readdirSync( coverageDir ).forEach( function( file ) {
if ( file.indexOf( 'cov' ) === 0 && file.indexOf( '.json' ) > 0 ) {
collector.add( JSON.parse( fs.readFileSync( path.resolve( coverageDir, file ), 'utf8' ) ) );
}
} );
report.on( 'done', function() {
console.log( 'The istanbul shield badge report has been generated' );
} );
report.writeReport( collector, true );
} catch ( err ) {
console.error( err.message );
process.exit( 1 );
}