@@ -4,7 +4,7 @@ import { execFile, fork, spawn } from 'child_process'
44import pathlib from 'path'
55import fs from 'fs/promises'
66import process from 'process'
7- import { Command } from 'commander'
7+ import { Command } from '@ commander-js/extra-typings '
88import autocomplete from './autocomplete.mjs'
99
1010const configs = {
@@ -164,7 +164,11 @@ const jsdoc = 'node_modules/jsdoc/jsdoc.js'
164164const template_location = 'docs/jsdoc/templates/template'
165165const specs_dir = 'docs/specs'
166166
167- async function run ( ) {
167+ /**
168+ * Build the documentations using JSDOC
169+ * @param {boolean | undefined } silent
170+ */
171+ async function run ( silent ) {
168172 await fs . mkdir ( out_dir , { recursive : true } )
169173
170174 const promises = Object . entries ( configs ) . map ( ( [ name , config ] ) => {
@@ -183,11 +187,14 @@ async function run() {
183187 ...config . libs . map ( each => pathlib . join ( libraries , each ) )
184188 ] )
185189
186- proc . on ( 'spawn' , ( ) => console . log ( `Building ${ name } ` ) )
190+ if ( ! silent ) {
191+ proc . on ( 'spawn' , ( ) => console . log ( `Building ${ name } ` ) )
192+ }
193+
187194 return new Promise ( resolve => {
188195 proc . on ( 'exit' , c => {
189196 if ( c === 0 ) {
190- console . log ( `Finished ${ name } ` )
197+ if ( ! silent ) console . log ( `Finished ${ name } ` )
191198 } else {
192199 console . error ( `Error occurred with ${ name } : jsdoc exited with code ${ c } ` )
193200 }
@@ -209,8 +216,12 @@ async function run() {
209216 if ( nonzeroRetcode !== undefined ) process . exit ( nonzeroRetcode )
210217}
211218
212- async function prepare ( { silent } ) {
213- await run ( )
219+ /**
220+ * Runs JSDOC, then `make`
221+ * @param {boolean | undefined } silent
222+ */
223+ async function prepare ( silent ) {
224+ await run ( silent )
214225
215226 // Copy images in images directory to out_dir
216227 await fs . readdir ( 'docs/images' ) . then ( images =>
@@ -219,7 +230,7 @@ async function prepare({ silent }) {
219230 const srcPath = pathlib . join ( 'docs/images' , img )
220231 const dstPath = pathlib . join ( out_dir , img )
221232 await fs . copyFile ( srcPath , dstPath )
222- console . debug ( `Copied ${ srcPath } to ${ dstPath } ` )
233+ if ( ! silent ) console . log ( `Copied ${ srcPath } to ${ dstPath } ` )
223234 } )
224235 )
225236 )
@@ -238,7 +249,7 @@ async function prepare({ silent }) {
238249 } )
239250
240251 if ( makeretcode !== 0 ) process . exit ( makeretcode )
241- console . log ( 'Finished running make' )
252+ if ( ! silent ) console . log ( 'Finished running make' )
242253
243254 // Copy pdf files that make produced to out_dir
244255 await fs . readdir ( specs_dir ) . then ( files =>
@@ -249,7 +260,7 @@ async function prepare({ silent }) {
249260 const srcPath = pathlib . join ( specs_dir , file )
250261 const dstPath = pathlib . join ( out_dir , file )
251262 await fs . copyFile ( srcPath , dstPath )
252- console . debug ( `Copied ${ srcPath } to ${ dstPath } ` )
263+ if ( ! silent ) console . debug ( `Copied ${ srcPath } to ${ dstPath } ` )
253264 } )
254265 )
255266 )
@@ -285,13 +296,16 @@ async function checkGitRoot() {
285296
286297await new Command ( )
287298 . hook ( 'preAction' , checkGitRoot )
288- . addCommand ( new Command ( 'run' ) . description ( 'Run JSDOC and build documentation' ) . action ( run ) , {
289- isDefault : true
290- } )
299+ . addCommand (
300+ new Command ( 'run' )
301+ . description ( 'Run JSDOC and build documentation' )
302+ . option ( '--silent' , 'Run without outputting to stdout' )
303+ . action ( args => run ( args . silent ) ) , { isDefault : true }
304+ )
291305 . addCommand (
292306 new Command ( 'prepare' )
293307 . option ( '--silent' , 'Run make without outputting to stdout' )
294- . action ( prepare )
308+ . action ( args => prepare ( args . silent ) )
295309 )
296310 . addCommand ( new Command ( 'clean' ) . description ( 'Clear the output directory' ) . action ( clean ) )
297311 . addCommand (
@@ -302,6 +316,7 @@ await new Command()
302316 . addCommand (
303317 new Command ( 'docs' )
304318 . description ( "Execute the 'run' command and then the 'autocomplete' command" )
305- . action ( ( ) => run ( ) . then ( autocomplete ) )
319+ . option ( '--silent' , 'Run without outputting to stdout' )
320+ . action ( args => run ( args . silent ) . then ( autocomplete ) )
306321 )
307322 . parseAsync ( )
0 commit comments