diff --git a/scripts/generate-readme/src/index.js b/scripts/generate-readme/src/index.js index a71ed7a16..cd5fce6b3 100644 --- a/scripts/generate-readme/src/index.js +++ b/scripts/generate-readme/src/index.js @@ -8,45 +8,22 @@ const { GetMonoDepTree, PrintTreeTrim } = require( 'pkg-dep-tree' ); // Local Dependencies const { GetFolders } = require( './helper' ); const Config = require( './config' ); -const { Render, RenderExample } = require( './renderer' ); +const { RenderHTML } = require( './renderer' ); /** * - * @param {filePath} reactSource + * @param {object} reactSource - Object of file paths */ -const RenderReactDocs = async ( reactSource ) => { +const GenerateReactProps = async ( reactSource ) => { let templateData = await JSDoc.getTemplateData( reactSource ); - - return templateData + + templateData = templateData .map( item => { - return { name } = item; + return { 'name': item.name, 'description': item.description }; }) - - // console.log( templateData ); - // console.log( await JSDoc.getJsdocData( reactSource ) ); - // return await JSDoc.getTemplateData( reactSource ); -} - -const GenerateReactProps = async( reactSourceFile ) => { - return await RenderReactDocs( { files: reactSourceFile } ); -} - -const GenerateDocPage = async () => { - let components = await GetFolders( Config.workspace ); - - let markdown = '' - - // Append React component comments to OVERVIEW.md file - markdown += await RenderReactDocs( { files: `${components[ 0 ]}/src/react/react.js` }, 'utf-8' ); - - // let html = Render( markdown ); - // html += `` - - // console.log( html ); - return markdown - // Fsp.writeFile( `index.html`, html ); + return JSON.stringify( templateData, null, 4 ); } @@ -58,6 +35,8 @@ const GenerateDocPage = async () => { let packageNamePlain = packageMeta.name.split('/')[1] let sourceFiles = { "files": `${ components[ 0 ] }/src/react/react.js` } + let sourceFileContent = await Fsp.readFile( sourceFiles.files, `utf-8` ); + let readme = `${packageMeta.name} --- @@ -73,9 +52,20 @@ npm i ${packageMeta.name} \`\`\` ## Usage +### HTML +\`\`\`html +${ RenderHTML( sourceFileContent ) } +\`\`\` + +### React +\`\`\`jsx +todo +\`\`\` ## Props -${ await RenderReactDocs( sourceFiles ) } +\`\`\`json +${ await GenerateReactProps( sourceFiles ) } +\`\`\` ## Dependency Graph \`\`\`bash diff --git a/scripts/generate-readme/src/renderer.js b/scripts/generate-readme/src/renderer.js index b0783d25d..03b878487 100644 --- a/scripts/generate-readme/src/renderer.js +++ b/scripts/generate-readme/src/renderer.js @@ -14,6 +14,8 @@ const PrismLanguage = require( 'prismjs/components/'); const TransformCode = ( code ) => { return Babel.transform( code, { presets: [ '@babel/preset-react', '@babel/preset-env' ], + minified: true, + comments: false }).code; } @@ -38,15 +40,19 @@ const FormatHTML = ( html, react ) => { /** * - * @param {string} react + * @param {string} react - The react source file contents */ const RenderHTML = ( react ) => { // Parse React code to commonJS let commonJS = TransformCode( react ); + // Extract HTML from common react code let html = ReactDOMServer.renderToStaticMarkup( eval( commonJS ) ); + + return html; + // Add styling and escaping to HTML - return FormatHTML( html, react ); + // return FormatHTML( html, react ); } /** @@ -94,5 +100,7 @@ const RenderMarkdownCode = ( markdown ) => { return Marked( markdown, { renderer: MarkdownRenderer, breaks: true } ); } -module.exports.Render = RenderMarkdownCode; -module.exports.RenderExample = RenderExample; \ No newline at end of file +// module.exports.Render = RenderMarkdownCode; +// module.exports.RenderExample = RenderExample; +module.exports.RenderHTML = RenderHTML; +// module.exports.RenderJSX = RenderJSX; \ No newline at end of file