2019-04-03 21:06:20 +00:00
#!/usr/bin/env node
2023-03-15 16:00:52 +00:00
/ * *
* Copyright ( c ) HashiCorp , Inc .
* SPDX - License - Identifier : MPL - 2.0
* /
2019-04-03 21:06:20 +00:00
/* eslint-disable */
2019-08-01 21:04:59 +00:00
// run this script via yarn in the ui directory:
// yarn gen-story-md some-component
//
// or if the story is for a component in an in-repo-addon or an engine:
// yarn gen-story-md some-component name-of-engine
2019-04-03 21:06:20 +00:00
const fs = require ( 'fs' ) ;
const jsdoc2md = require ( 'jsdoc-to-markdown' ) ;
var args = process . argv . slice ( 2 ) ;
const name = args [ 0 ] ;
2019-05-13 19:05:25 +00:00
const addonOrEngine = args [ 1 ] ;
const inputFile = addonOrEngine
? ` lib/ ${ addonOrEngine } /addon/components/ ${ name } .js `
: ` app/components/ ${ name } .js ` ;
2019-08-01 21:04:59 +00:00
const outputFile = addonOrEngine ? ` lib/ ${ addonOrEngine } /stories/ ${ name } .md ` : ` stories/ ${ name } .md ` ;
2019-04-03 21:06:20 +00:00
const component = name
. split ( '-' )
2022-02-17 19:30:56 +00:00
. map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
2019-04-03 21:06:20 +00:00
. join ( '' ) ;
const options = {
files : inputFile ,
template : fs . readFileSync ( './lib/story-md.hbs' , 'utf8' ) ,
2019-06-03 20:25:59 +00:00
'example-lang' : 'js' ,
2019-04-03 21:06:20 +00:00
} ;
let md = jsdoc2md . renderSync ( options ) ;
const pageBreakIndex = md . lastIndexOf ( '---' ) ; //this is our last page break
const seeLinks = ` **See**
2019-05-13 19:05:25 +00:00
- [ Uses of $ { component } ] ( https : //github.com/hashicorp/vault/search?l=Handlebars&q=${component}+OR+${name})
2022-02-17 19:30:56 +00:00
- [ $ { component } Source Code ] ( https : //github.com/hashicorp/vault/blob/main/ui/${inputFile})
2019-04-03 21:06:20 +00:00
` ;
const generatedWarning = ` <!--THIS FILE IS AUTO GENERATED. This file is generated from JSDoc comments in ${ inputFile } . To make changes, first edit that file and run "yarn gen-story-md ${ name } " to re-generate the content.-->
` ;
md = generatedWarning + md . slice ( 0 , pageBreakIndex ) + seeLinks + md . slice ( pageBreakIndex ) ;
fs . writeFileSync ( outputFile , md ) ;