@@ -7,6 +7,7 @@ const fs = require('fs');
77const path = require ( 'path' ) ;
88const SaxonJS = require ( 'saxon-js' ) ;
99const { marked } = require ( 'marked' ) ;
10+ const { elapsed} = require ( '../elapsed' ) ;
1011
1112/**
1213 * Recursively reads all .xmir files from a directory.
@@ -125,44 +126,46 @@ function wrapHtml(name, html, css) {
125126 * Command to generate documentation.
126127 * @param {Hash } opts - All options
127128 */
128- module . exports = async function ( opts ) {
129- try {
130- const input = path . resolve ( opts . target , '1-parse' ) ;
131- const output = path . resolve ( opts . target , 'docs' ) ;
132- fs . mkdirSync ( output , { recursive : true } ) ;
133- const css = path . join ( output , 'styles.css' ) ;
134- fs . writeFileSync ( css , '' ) ;
135- const packages_info = { } ;
136- const all_xmir_htmls = [ ] ;
137- const xmirs = readXmirsRecursively ( input ) ;
138- for ( const xmir of xmirs ) {
139- const relative = path . relative ( input , xmir ) ;
140- const name = path . parse ( xmir ) . name ;
141- const xmir_html = createXmirHtmlBlock ( xmir ) ;
142- const html_app = path . join ( output , path . dirname ( relative ) , `${ name } .html` ) ;
143- fs . mkdirSync ( path . dirname ( html_app ) , { recursive : true } ) ;
144- fs . writeFileSync ( html_app , wrapHtml ( name , xmir_html , css ) ) ;
145- const packages = path . dirname ( relative ) . split ( path . sep ) . join ( '.' ) ;
146- const html_package = path . join ( output , `package_${ packages } .html` ) ;
147- if ( ! ( packages in packages_info ) ) {
148- packages_info [ packages ] = {
149- xmir_htmls : [ ] ,
150- path : html_package
151- } ;
129+ module . exports = function ( opts ) {
130+ return elapsed ( async ( tracked ) => {
131+ try {
132+ const input = path . resolve ( opts . target , '1-parse' ) ;
133+ const output = path . resolve ( opts . target , 'docs' ) ;
134+ fs . mkdirSync ( output , { recursive : true } ) ;
135+ const css = path . join ( output , 'styles.css' ) ;
136+ fs . writeFileSync ( css , '' ) ;
137+ const packages_info = { } ;
138+ const all_xmir_htmls = [ ] ;
139+ const xmirs = readXmirsRecursively ( input ) ;
140+ for ( const xmir of xmirs ) {
141+ const relative = path . relative ( input , xmir ) ;
142+ const name = path . parse ( xmir ) . name ;
143+ const xmir_html = createXmirHtmlBlock ( xmir ) ;
144+ const html_app = path . join ( output , path . dirname ( relative ) , `${ name } .html` ) ;
145+ fs . mkdirSync ( path . dirname ( html_app ) , { recursive : true } ) ;
146+ fs . writeFileSync ( html_app , wrapHtml ( name , xmir_html , css ) ) ;
147+ const packages = path . dirname ( relative ) . split ( path . sep ) . join ( '.' ) ;
148+ const html_package = path . join ( output , `package_${ packages } .html` ) ;
149+ if ( ! ( packages in packages_info ) ) {
150+ packages_info [ packages ] = {
151+ xmir_htmls : [ ] ,
152+ path : html_package
153+ } ;
154+ }
155+ packages_info [ packages ] . xmir_htmls . push ( xmir_html ) ;
156+ all_xmir_htmls . push ( xmir_html ) ;
152157 }
153- packages_info [ packages ] . xmir_htmls . push ( xmir_html ) ;
154- all_xmir_htmls . push ( xmir_html ) ;
155- }
156- for ( const package_name of Object . keys ( packages_info ) ) {
157- fs . mkdirSync ( path . dirname ( packages_info [ package_name ] . path ) , { recursive : true } ) ;
158- fs . writeFileSync ( packages_info [ package_name ] . path ,
159- generatePackageHtml ( `${ package_name } package` , packages_info [ package_name ] . xmir_htmls , css ) ) ;
158+ for ( const package_name of Object . keys ( packages_info ) ) {
159+ fs . mkdirSync ( path . dirname ( packages_info [ package_name ] . path ) , { recursive : true } ) ;
160+ fs . writeFileSync ( packages_info [ package_name ] . path ,
161+ generatePackageHtml ( `${ package_name } package` , packages_info [ package_name ] . xmir_htmls , css ) ) ;
162+ }
163+ const packages = path . join ( output , 'packages.html' ) ;
164+ fs . writeFileSync ( packages , generatePackageHtml ( 'overall package' , all_xmir_htmls , css ) ) ;
165+ tracked . print ( `Documentation generation completed in the ${ output } directory` ) ;
166+ } catch ( error ) {
167+ console . error ( 'Error generating documentation:' , error ) ;
168+ throw error ;
160169 }
161- const packages = path . join ( output , 'packages.html' ) ;
162- fs . writeFileSync ( packages , generatePackageHtml ( 'overall package' , all_xmir_htmls , css ) ) ;
163- console . info ( 'Documentation generation completed in the %s directory' , output ) ;
164- } catch ( error ) {
165- console . error ( 'Error generating documentation:' , error ) ;
166- throw error ;
167- }
170+ } ) ;
168171} ;
0 commit comments