Skip to content

Commit

Permalink
[docs] Use found EOL in buildApi.js (mui#16167)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz authored and eps1lon committed Jun 13, 2019
1 parent 8953450 commit 37c2e8a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/scripts/buildApi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */

import { mkdir, readFileSync, writeFileSync } from 'fs';
import { EOL } from 'os';
import path from 'path';
import kebabCase from 'lodash/kebabCase';
import { defaultHandlers, parse as docgenParse } from 'react-docgen';
Expand Down Expand Up @@ -77,6 +78,14 @@ function getInheritance(testInfo, src) {
};
}

function getLineFeed(source) {
const match = source.match(/\r?\n/);
if (match === null) {
return EOL;
}
return match[0];
}

async function buildDocs(options) {
const { component: componentObject, pagesMarkdown } = options;
const src = readFileSync(componentObject.filename, 'utf8');
Expand Down Expand Up @@ -146,6 +155,7 @@ async function buildDocs(options) {
reactAPI.pagesMarkdown = pagesMarkdown;
reactAPI.src = src;
reactAPI.spread = spread;
reactAPI.EOL = getLineFeed(src);

const testInfo = await parseTest(componentObject.filename);
// no Object.assign to visually check for collisions
Expand Down Expand Up @@ -174,7 +184,10 @@ async function buildDocs(options) {
return;
}

writeFileSync(path.resolve(docsApiDirectory, `${kebabCase(reactAPI.name)}.md`), markdown);
writeFileSync(
path.resolve(docsApiDirectory, `${kebabCase(reactAPI.name)}.md`),
markdown.replace(/\r?\n/g, reactAPI.EOL),
);
writeFileSync(
path.resolve(docsApiDirectory, `${kebabCase(reactAPI.name)}.js`),
`import 'docs/src/modules/components/bootstrap';
Expand All @@ -188,7 +201,7 @@ function Page() {
}
export default Page;
`,
`.replace(/\r?\n/g, reactAPI.EOL),
);

console.log('Built markdown docs for', reactAPI.name);
Expand Down

0 comments on commit 37c2e8a

Please sign in to comment.