2017-12-17 14:31:37 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
const { parseFromDirectory } = require( '../lib' );
|
|
|
|
|
2017-12-17 14:31:37 +00:00
|
|
|
const fs = require( 'fs' );
|
|
|
|
const path = require( 'path' );
|
2017-12-18 22:08:09 +00:00
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
// Accept an optional directory name where the content files live.
|
2017-12-29 10:40:05 +00:00
|
|
|
const contentPath = (
|
|
|
|
process.argv[ 2 ]
|
|
|
|
? path.resolve( process.argv[ 2 ] )
|
|
|
|
: path.join( __dirname, '..' )
|
|
|
|
);
|
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
// Parse the content from the directory.
|
|
|
|
const result = parseFromDirectory( contentPath );
|
2017-12-29 10:40:05 +00:00
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
// Report any errors.
|
|
|
|
const errorCount = result.errors ? result.errors.length : 0;
|
2018-04-24 10:20:07 +00:00
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
( result.errors || [] ).forEach( err => {
|
|
|
|
err.message.split( '\n' ).forEach( line => {
|
|
|
|
console.log( '%s: %s', err.filename, line );
|
2018-06-25 02:42:33 +00:00
|
|
|
} );
|
2017-12-17 14:31:37 +00:00
|
|
|
} );
|
|
|
|
|
2018-06-25 05:00:12 +00:00
|
|
|
// Count all profile headings, if requested.
|
2018-04-16 22:15:26 +00:00
|
|
|
if ( process.env.REPORT_PROFILE_HEADINGS ) {
|
|
|
|
console.log();
|
|
|
|
console.log(
|
|
|
|
'Profile headings by count (%d total profiles):',
|
2018-06-25 05:00:12 +00:00
|
|
|
result.profileFilenames.length
|
2018-04-16 22:15:26 +00:00
|
|
|
);
|
2018-06-25 05:00:12 +00:00
|
|
|
Object.keys( result.profileHeadingCounts ).forEach( heading => {
|
|
|
|
console.log(
|
|
|
|
'%s: %d',
|
|
|
|
heading,
|
|
|
|
result.profileHeadingCounts[ heading ]
|
|
|
|
);
|
2018-04-16 22:15:26 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:31:37 +00:00
|
|
|
console.log();
|
|
|
|
console.log(
|
|
|
|
'%d problem%s detected',
|
|
|
|
errorCount,
|
|
|
|
( errorCount === 1 ? '' : 's' )
|
|
|
|
);
|
|
|
|
|
2020-05-06 06:42:21 +00:00
|
|
|
process.exitCode = ( errorCount > 0 ? 3 : 0 );
|