11const fs = require ( 'fs' )
2+ const os = require ( 'os' )
23const path = require ( 'path' )
34
45const parse = require ( './parse' )
6+ const compile = require ( './compile' )
57
68//
79// Find all header files except in ./deps or hidden dirs
@@ -16,9 +18,13 @@ const read = d => {
1618 const p = paths [ i ]
1719 const base = path . basename ( p )
1820
19- if ( base [ 0 ] === '.' || ( base === 'deps' ) ) {
20- continue
21- }
21+ const dontParse = (
22+ ( base [ 0 ] === '.' ) ||
23+ ( base === 'deps' ) ||
24+ ( base === 'hyper-docs' )
25+ )
26+
27+ if ( dontParse ) continue
2228
2329 const stat = fs . statSync ( p )
2430
@@ -52,13 +58,31 @@ const parseUrl = s => {
5258 let url = s . split ( '//' ) [ 1 ]
5359 if ( ! url ) url = s . split ( '@' ) [ 1 ]
5460
55- return url . replace ( ':' , '/' ) . replace ( '.git' , '' )
61+ return 'https://' + url . replace ( ':' , '/' ) . replace ( '.git' , '' )
5662}
5763
5864//
5965// Read all files from a path and parse their headers for docs
6066//
6167function main ( argv ) {
68+ if ( argv [ 0 ] === '--md' || argv [ 0 ] === '--html' ) {
69+ let buffers = fs
70+ . readFileSync ( 0 , 'utf8' )
71+ . split ( os . EOL )
72+ . filter ( Boolean )
73+
74+ try {
75+ buffers = buffers . map ( JSON . parse )
76+ } catch ( err ) {
77+ console . error ( err . message )
78+ process . exit ( 1 )
79+ }
80+
81+ const type = argv [ 0 ] . slice ( 2 )
82+ compile ( buffers , type )
83+ return
84+ }
85+
6286 const files = read ( argv [ 0 ] )
6387
6488 for ( const file of files ) {
@@ -73,7 +97,7 @@ function main (argv) {
7397 const output = parse ( s )
7498
7599 output . repo = parseUrl ( pkg . repository . url )
76- console . log ( JSON . stringify ( output , 2 , 2 ) )
100+ process . stdout . write ( JSON . stringify ( output ) + '\n' )
77101 }
78102}
79103
0 commit comments