Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a central script instead of one per package to generate docs #14216

Merged
merged 7 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Proper exit code and stderr status for docgen package
  • Loading branch information
oandregal committed Mar 4, 2019
commit b15166ca9efb61ec5421ad462d8836528c5bb023
2 changes: 1 addition & 1 deletion packages/docgen/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ const optionator = require( 'optionator' )( {
} );

const options = optionator.parseArgv( process.argv );
docgen( options._[ 0 ], options );
process.exit( docgen( options._[ 0 ], options ) );
26 changes: 14 additions & 12 deletions packages/docgen/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const relativeToAbsolute = ( basePath, relativePath ) => {
if ( fs.existsSync( targetFile ) ) {
return targetFile;
}
process.stdout.write( '\nRelative path does not exists.' );
process.stdout.write( '\n' );
process.stdout.write( `\nBase: ${ basePath }` );
process.stdout.write( `\nRelative: ${ relativePath }` );
process.stdout.write( '\n\n' );
process.stderr.write( '\nRelative path does not exists.' );
process.stderr.write( '\n' );
process.stderr.write( `\nBase: ${ basePath }` );
process.stderr.write( `\nRelative: ${ relativePath }` );
process.stderr.write( '\n\n' );
process.exit( 1 );
};

Expand All @@ -54,8 +54,8 @@ const processFile = ( rootDir, inputFile ) => {
currentFileStack.pop( inputFile );
return result;
} catch ( e ) {
process.stdout.write( `\n${ e }` );
process.stdout.write( '\n\n' );
process.stderr.write( `\n${ e }` );
process.stderr.write( '\n\n' );
process.exit( 1 );
}
};
Expand All @@ -66,8 +66,8 @@ const runCustomFormatter = ( customFormatterFile, rootDir, doc, symbols, heading
const output = customFormatter( rootDir, doc, symbols, headingTitle );
fs.writeFileSync( doc, output );
} catch ( e ) {
process.stdout.write( `\n${ e }` );
process.stdout.write( '\n\n' );
process.stderr.write( `\n${ e }` );
process.stderr.write( '\n\n' );
process.exit( 1 );
}
return 'custom formatter';
Expand All @@ -80,9 +80,9 @@ module.exports = function( sourceFile, options ) {
// Input: process CLI args, prepare files, etc
const processDir = process.cwd();
if ( sourceFile === undefined ) {
process.stdout.write( '\n' );
process.stdout.write( 'No source file provided' );
process.stdout.write( '\n\n' );
process.stderr.write( '\n' );
process.stderr.write( 'No source file provided' );
process.stderr.write( '\n\n' );
process.exit( 1 );
}
sourceFile = path.join( processDir, sourceFile );
Expand Down Expand Up @@ -123,4 +123,6 @@ module.exports = function( sourceFile, options ) {
fs.writeFileSync( tokens, JSON.stringify( result.tokens ) );
fs.writeFileSync( ast, JSON.stringify( result.ast ) );
}

process.exit( 0 );
};