From f044558d9a0a28151707be9f5f916a94f3e53dc7 Mon Sep 17 00:00:00 2001 From: Thore Caspersen Date: Mon, 10 Jun 2019 18:11:25 +0200 Subject: [PATCH] fix(component name): by default use the filename as the component name --- lib/flotFyrTransformer.js | 32 ++++++++++++++++++++------------ lib/toComponentModule.js | 2 +- output/testmarkdown.js | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/flotFyrTransformer.js b/lib/flotFyrTransformer.js index eb7249a..bd982bb 100644 --- a/lib/flotFyrTransformer.js +++ b/lib/flotFyrTransformer.js @@ -6,18 +6,17 @@ var through = require("through2"); var replaceExt = require("replace-ext"); module.exports = function(src, dest, markdownOptions) { - // markdownOptions = Object.assign( - // { - // name: "MarkdownReact", - // prependJs: [], - // precompile: false, - // headings: false, - // remarkPlugins: [], - // defualtImport: false, - // importer: false - // }, - // markdownOptions - // ); + markdownOptions = Object.assign( + { + prependJs: [], + precompile: false, + headings: false, + remarkPlugins: [], + defualtImport: false, + importer: false + }, + markdownOptions + ); prettierOption = { printWidth: 80, @@ -41,10 +40,19 @@ module.exports = function(src, dest, markdownOptions) { if (path.extname(src) !== ".md") { return null; } + // get filename without extention ( forxsampel .js) + let filename = path.basename(src, path.extname(src)); return through(function(chunk, enc, done) { var output = chunk.toString(); + // add name to the markdown option if its not set + markdownOptions = Object.assign( + { + name: filename + }, + markdownOptions + ); const jsx = toComponentModule(output, markdownOptions); const beautifulJsx = prettier.format(jsx, prettierOption); diff --git a/lib/toComponentModule.js b/lib/toComponentModule.js index ca92560..8c0b2ea 100644 --- a/lib/toComponentModule.js +++ b/lib/toComponentModule.js @@ -13,7 +13,7 @@ const defaultTemplate = require("./templates/default"); module.exports = (input, options) => { options = Object.assign( { - name: "MarkdownReact", + name: "defualtNameSetByFlotFyrToComponentModuleFunc", prependJs: [], precompile: false, headings: false, diff --git a/output/testmarkdown.js b/output/testmarkdown.js index 3d09a8f..e5a5a3f 100644 --- a/output/testmarkdown.js +++ b/output/testmarkdown.js @@ -14,7 +14,7 @@ const frontMatter = { quantity: 834 }; -export default class MarkdownReact extends React.PureComponent { +export default class Testmarkdown extends React.PureComponent { render() { const props = this.props; return (