Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pv-stylemark): use same folder structure in stlyeguide/ output as in components/ #239

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/pv-stylemark/tasks/lsg/buildLsgExamples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolve } = require("path");
const { resolve, dirname } = require("path");
const { readFile } = require("fs-extra");
const hbsInstance = require("handlebars").create();

Expand Down Expand Up @@ -49,7 +49,9 @@ const buildComponentExample = async (config, lsgData, exampleData, template) =>
lsgConfig: config,
});
}
await writeFile(destPath, "styleguide", `${lsgData.componentName}-${exampleData.exampleName}`, markup);
// path to the directory where the referenced example's markup file is, relative to the `componentPath`
const exampleDir = exampleData.exampleMarkup.examplePath ? dirname(exampleData.exampleMarkup.examplePath) : "";
await writeFile(destPath, `styleguide/${lsgData.componentPath}/${exampleDir}`, `${lsgData.componentName}-${exampleData.exampleName}`, markup);
} catch (error) {
console.warn(error);
}
Expand Down
7 changes: 5 additions & 2 deletions packages/pv-stylemark/tasks/lsg/getLsgData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { readFile } = require("fs-extra");
const { resolve, parse: pathParse, normalize, relative: relPath, join } = require("path");
const { resolve, parse: pathParse, normalize, relative: relPath, join, dirname } = require("path");
const { marked } = require("marked");
const frontmatter = require("front-matter");
const { glob } = require("glob");
Expand Down Expand Up @@ -242,7 +242,10 @@ function cleanMarkdownFromExecutableCodeBlocks(markdownContent, name, componentP
// html file will be generated for html code blocks without a referenced file
const examplePath = groups.examplePath ? groups.examplePath : `${groups.exampleName}.html`;
const markupUrl = join("../components", componentPath, examplePath);
replacement += `<dds-example name="${groups.exampleName}" path="${name}-${groups.exampleName}.html${groups.search ?? ""}${groups.hash ?? ""}" ${groups.examplePath && !groups.params.hidden ? `markup-url="${markupUrl}"`: ""}></dds-example>`
// relative to `componentPath`
const exampleDir = groups.examplePath ? dirname(groups.examplePath) : "";
const htmlPath = join(componentPath, exampleDir, `${name}-${groups.exampleName}.html`);
replacement += `<dds-example name="${groups.exampleName}" path="${htmlPath}${groups.search ?? ""}${groups.hash ?? ""}" ${groups.examplePath && !groups.params.hidden ? `markup-url="${markupUrl}"`: ""}></dds-example>`
}
if (groups.content && !groups.params.hidden) {
// add the css/js code blocks for the example. make sure it is indented the way `marked` can handle it
Expand Down
Loading