Skip to content

Commit

Permalink
CLI: manage errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 17, 2019
1 parent fce4079 commit e6ff045
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/docgen/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ const formatter = require( './formatter' );

const packageName = process.argv[ 2 ];
if ( packageName === undefined ) {
process.stdout.write( '\nUsage: <path-to-docgen> <gutenberg-package-name>\n' );
process.stdout.write( '\nUsage: <path-to-docgen> <gutenberg-package-name>\n\n\n' );
process.exit( 1 );
}

const root = path.resolve( __dirname, '../../../' );
const input = path.resolve( root, `packages/${ packageName }/src/index.js` );
const output = path.resolve( root, `packages/${ packageName }/src/doc-api.md` );
const root = path.join( __dirname, '../../../' );
// TODO:
// - take input file from package.json?
// - make CLI take input file instead of package?
const input = path.join( root, `packages/${ packageName }/src/index.js` );
const output = path.join( root, `packages/${ packageName }/api.md` );

const code = fs.readFileSync( input, 'utf8' );
const json = engine( code );
const docs = formatter( json );
fs.readFile( input, 'utf8', ( err, data ) => {
if ( err ) {
process.stdout.write( `\n${ input } does not exists.\n\n\n` );
process.exit( 1 );
}

fs.writeFileSync( output, docs );
const json = engine( data );
const docs = formatter( json );
fs.writeFileSync( output, docs );
} );

0 comments on commit e6ff045

Please sign in to comment.