44 */
55
66import { readFileSync , writeFileSync } from 'fs' ;
7+ import { join } from 'path' ;
78
89// These types lack type definitions.
910const marked = require ( 'marked' ) ;
1011const highlightJs = require ( 'highlight.js' ) ;
1112
13+ // Regular expression that matches the markdown extension of a given path.
14+ const markdownExtension = / .m d $ / ;
15+
1216// Setup the default options for converting markdown to HTML.
1317marked . setOptions ( {
1418 // Implement a highlight function that converts the code block into a highlighted
@@ -23,15 +27,14 @@ marked.setOptions({
2327} ) ;
2428
2529if ( require . main === module ) {
26- // The script expects the input files to be specified in the following format:
27- // {input_file_path}={output_file_path}
28- // We have to know the output paths because the input path and output path differ
29- // fundamentally within the Bazel sandbox.
30- const inputFiles = process . argv . slice ( 2 ) . map ( argument => argument . split ( '=' ) ) ;
30+ // The script expects the bazel-bin path as first argument. All remaining arguments will be
31+ // considered as markdown input files that need to be transformed.
32+ const [ bazelBinPath , ...inputFiles ] = process . argv . slice ( 2 ) ;
3133
3234 // Walk through each input file and write transformed markdown output to the specified
33- // output path.
34- inputFiles . forEach ( ( [ inputPath , outputPath ] ) => {
35+ // Bazel bin directory.
36+ inputFiles . forEach ( inputPath => {
37+ const outputPath = join ( bazelBinPath , inputPath . replace ( markdownExtension , '.html' ) ) ;
3538 writeFileSync ( outputPath , marked ( readFileSync ( inputPath , 'utf8' ) ) ) ;
3639 } ) ;
3740}
0 commit comments