1
1
const Handlebars = require ( 'handlebars' ) ;
2
2
const hljs = require ( 'highlight.js/lib/core' ) ;
3
- const asciidoc = require ( 'asciidoctor' ) ( )
4
- const cheerio = require ( 'cheerio' ) ;
5
3
hljs . registerLanguage ( 'cpp' , require ( 'highlight.js/lib/languages/cpp' ) ) ;
6
4
hljs . registerLanguage ( 'xml' , require ( 'highlight.js/lib/languages/xml' ) ) ;
7
5
const fs = require ( 'fs' ) ;
@@ -28,7 +26,6 @@ if (helpersDirExists) {
28
26
} ) ;
29
27
}
30
28
31
-
32
29
// Read the JSON data file
33
30
const dataFile = 'data.json' ;
34
31
const dataContents = fs . readFileSync ( dataFile , 'utf8' )
@@ -47,52 +44,57 @@ if (!fs.existsSync(mrdocsExecutable)) {
47
44
}
48
45
49
46
// Read panel snippet files and create documentation
47
+ const absSnippetsDir = path . join ( __dirname , 'snippets' )
50
48
for ( let panel of data . panels ) {
51
49
// Find source file
52
- const absSnippetsDir = path . join ( __dirname , 'snippets' )
53
50
const sourcePath = path . join ( absSnippetsDir , panel . source )
54
51
assert ( sourcePath . endsWith ( '.cpp' ) )
55
52
assert ( fs . existsSync ( sourcePath ) )
56
53
const sourceBasename = path . basename ( sourcePath , path . extname ( sourcePath ) )
57
54
58
55
// Create a CMakeLists.txt file for the snippet
59
56
const cmakeListsPath = path . join ( absSnippetsDir , 'CMakeLists.txt' )
60
- const cmakeListsContent = `cmake_minimum_required(VERSION 3.13)\nproject(${ sourceBasename } )\nadd_executable(${ sourceBasename } ${ panel . source } )\ntarget_compile_features(${ sourceBasename } PRIVATE cxx_std_23)\n`
57
+ const cmakeListsContent = `
58
+ cmake_minimum_required(VERSION 3.13)
59
+ project(${ sourceBasename } )
60
+ add_executable(${ sourceBasename } ${ panel . source } )
61
+ target_compile_features(${ sourceBasename } PRIVATE cxx_std_23)
62
+ ` ;
61
63
fs . writeFileSync ( cmakeListsPath , cmakeListsContent )
62
64
63
65
// Run mrdocs to generate documentation
64
66
const mrdocsConfig = path . join ( absSnippetsDir , 'mrdocs.yml' )
65
67
const mrdocsInput = cmakeListsPath
66
68
const mrdocsOutput = path . join ( absSnippetsDir , 'output' )
67
- const command = `${ mrdocsExecutable } --config=${ mrdocsConfig } ${ mrdocsInput } --output=${ mrdocsOutput } --multipage=true --generate=adoc`
69
+ const args = [
70
+ mrdocsExecutable ,
71
+ `--config=${ mrdocsConfig } ` ,
72
+ mrdocsInput ,
73
+ `--output=${ mrdocsOutput } ` ,
74
+ '--multipage=true' ,
75
+ '--generate=html' ,
76
+ '--embedded=true' ,
77
+ ] ;
78
+ const command = args . join ( ' ' ) ;
68
79
console . log ( `Running command: ${ command } ` )
69
- execSync ( command , { encoding : 'utf8' } ) ;
80
+ try {
81
+ execSync ( command , { stdio : 'inherit' } ) ;
82
+ } catch ( error ) {
83
+ console . error ( `Command failed with exit code ${ error . status } ` ) ;
84
+ process . exit ( error . status ) ;
85
+ }
70
86
71
- // Look for documentation file somewhere in the output directory
72
- const documentationFilename = `${ sourceBasename } .adoc `
87
+ // Look load symbol page in the output directory
88
+ const documentationFilename = `${ sourceBasename } .html `
73
89
const documentationPath = path . join ( mrdocsOutput , documentationFilename )
74
90
if ( ! fs . existsSync ( documentationPath ) ) {
75
91
console . log ( `Documentation file ${ documentationFilename } not found in ${ mrdocsOutput } ` )
76
- console . log ( 'mrdocs failed to generate documentation' )
92
+ console . log ( 'Failed to generate website panel documentation' )
77
93
process . exit ( 1 )
78
94
}
79
- const documentationContent = fs . readFileSync ( documentationPath , 'utf8' )
80
- const htmlDocumentation = asciidoc . convert ( documentationContent , {
81
- doctype : 'book' ,
82
- safe : 'safe' ,
83
- standalone : true
84
- } )
85
- const $ = cheerio . load ( htmlDocumentation )
86
- // Iterate 5, 4, 3, 2, 1
87
- for ( let i = 5 ; i >= 1 ; i -- ) {
88
- $ ( `h${ i } ` ) . replaceWith ( function ( ) {
89
- return $ ( `<h${ i + 1 } >` ) . html ( $ ( this ) . html ( ) ) ;
90
- } ) ;
91
- }
92
- $ ( '#footer' ) . remove ( ) ;
93
- panel . documentation = $ ( 'body' ) . html ( ) ;
95
+ panel . documentation = fs . readFileSync ( documentationPath , 'utf8' ) ;
94
96
95
- // Also inject the contents of the source file
97
+ // Also inject the contents of the source file as highlighted C++
96
98
const snippetContents = fs . readFileSync ( sourcePath , 'utf8' ) ;
97
99
const highlightedSnippet = hljs . highlight ( snippetContents , { language : 'cpp' } ) . value ;
98
100
panel . snippet = highlightedSnippet ;
@@ -102,10 +104,10 @@ for (let panel of data.panels) {
102
104
fs . unlinkSync ( cmakeListsPath ) ;
103
105
}
104
106
105
- // Render the template with the data
107
+ // Render the template with the data containing the snippet data
106
108
const result = template ( data ) ;
107
109
108
- // Write the output to an HTML file
110
+ // Write the rendered website template to an HTML file
109
111
assert ( templateFile . endsWith ( '.hbs' ) ) ;
110
112
const outputFile = templateFile . slice ( 0 , - 4 ) ;
111
113
fs . writeFileSync ( outputFile , result ) ;
0 commit comments