Skip to content
Merged
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
24 changes: 17 additions & 7 deletions packages/patternfly-4/react-docs/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const path = require(`path`);
const fs = require('fs-extra'); //eslint-disable-line
const packageDirs = ['react-core', 'react-charts', 'react-styled-system', 'react-table'];

// Escape single quotes and backslashes in a file path
const escapeFilePath = filePath => filePath.replace(/[\\']/g, '\\$&');

exports.onCreateWebpackConfig = ({ stage, loaders, actions, plugins, getConfig }) => {
// Enable hot reloading on source code changes
const pfStylesTest = /patternfly-next.*(components|layouts|utilities).*\.css$/;
Expand Down Expand Up @@ -116,13 +119,20 @@ exports.createPages = async ({ graphql, actions }) => {

const rawExamples = [];
const packageDir = packageDirs.find(pkg => doc.absolutePath.indexOf(pkg) !== -1);

// In Windows environments, paths use backslashes to separate directories;
// Ensure that forward slashes are used to make it comparable
const docIdentifier = doc.relativeDirectory.replace(/\\/g, '/');

examples.edges.forEach(({ node: example }) => {
if (
example.relativeDirectory
.split('/')
.slice(0, 2)
.join('/') === doc.relativeDirectory
) {
// Replace backslashes with forward slashes as for `docIdentifier` above,
// and remove `/example` postfix
const exampleIdentifier = example.relativeDirectory
.split(/[/\\]/)
.slice(0, 2)
.join('/');

if (exampleIdentifier === docIdentifier) {
const examplePath = `../../${packageDir}/src/${example.relativePath}`;
rawExamples.push(
`{name: '${example.name}', path: '${examplePath}', file: require('!!raw-loader!${examplePath}')}`
Expand Down Expand Up @@ -159,7 +169,7 @@ exports.createPages = async ({ graphql, actions }) => {
const content = `
import React from 'react';
import docs from '${doc.absolutePath}';
import ComponentDocs from '${docsComponentPath}';
import ComponentDocs from '${escapeFilePath(docsComponentPath)}';

const rawExamples = [${rawExamples}];
const images = [${allImages}];
Expand Down
10 changes: 6 additions & 4 deletions packages/react-icons/build/generatorConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const templatesDir = path.resolve(__dirname, './templates');
const srcDir = path.resolve(__dirname, '../src');
const iconsDir = path.join(srcDir, './icons');

const escapeFilePath = filePath => filePath.replace(/\\/g, '\\$&');

module.exports = plop => {
plop.setGenerator('icons', {
prompts: [],
Expand All @@ -14,30 +16,30 @@ module.exports = plop => {
type: 'add',
force: true,
data: icon,
path: path.join(iconsDir, './{{id}}.js'),
path: escapeFilePath(path.join(iconsDir, './{{id}}.js')),
templateFile: path.join(templatesDir, 'iconFile.hbs')
});

actions.push({
type: 'add',
force: true,
data: icon,
path: path.join(iconsDir, './{{id}}.d.ts'),
path: escapeFilePath(path.join(iconsDir, './{{id}}.d.ts')),
templateFile: path.join(templatesDir, 'iconFileTS.hbs')
});
});

actions.push({
type: 'add',
force: true,
path: path.join(srcDir, './index.js'),
path: escapeFilePath(path.join(srcDir, './index.js')),
templateFile: path.join(templatesDir, 'mainBarrelFile.hbs')
});

actions.push({
type: 'add',
force: true,
path: path.join(srcDir, './index.d.ts'),
path: escapeFilePath(path.join(srcDir, './index.d.ts')),
templateFile: path.join(templatesDir, 'mainBarrelFileTS.hbs')
});

Expand Down