Skip to content

Commit

Permalink
feat(detail view): add detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
janechu committed May 23, 2018
1 parent 4b1ed8a commit 387b9c7
Show file tree
Hide file tree
Showing 93 changed files with 26,425 additions and 25,875 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ www/
#Ignore VSCode
.vscode/
.vs/

# tmp directories
.tmp/
70 changes: 70 additions & 0 deletions build/convert-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Utility for converting README files to .tsx files.
* Usage: node build/convert-readme.js %path%
*/
const path = require("path");
const glob = require("glob");
const fs = require("fs");
const argv = require("yargs").argv;
const MarkdownIt = require("markdown-it");

const srcDir = argv.src || "./src/**/README.md";

/**
* Start and end file strings
*/
const startFile = `// Generated file from ../../build
/* tslint:disable */
import * as React from "react";\n`;
const startFileExport = `export default class Documentation extends React.Component<{}, {}> {
public render(): JSX.Element {
return (
<div style={{padding: "14px"}}>\n `;

const startFilePlain = `${startFile}${startFileExport}`;
const endFile = `\n </div>
);
}
}\n`;

const mdPlain = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
xhtmlOut: true
});

/**
* All paths passed to the convert script
*/
const paths = argv._;

/**
* Function to create string exports of a given path
*/
function exportReadme(readmePath) {
const readmePaths = path.resolve(process.cwd(), srcDir);

glob(readmePaths, void(0), function(error, files) {
files.forEach((filePath) => {
let documentation = startFilePlain;
const markdown = fs.readFileSync(filePath, "utf8");
const exportPath = filePath.replace(/README\.md/, readmePath);
documentation += mdPlain.render(markdown);
documentation += endFile;

if (!fs.existsSync(exportPath)){
fs.mkdirSync(exportPath);
}

fs.writeFileSync(path.resolve(exportPath, "documentation.tsx"), documentation);
});
});
}

/**
* Convert all paths
*/
if (Array.isArray(paths)) {
paths.forEach(exportReadme);
}
30 changes: 30 additions & 0 deletions build/copy-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Utility for copying readme to their dist folders.
* Usage: node build/copy-readme.js
*/
const path = require("path");
const fs = require("fs");
const glob = require("glob");

const rootDir = path.resolve(process.cwd());
const srcReadmePaths = "src/**/README.md";
const destDir = "dist";

/**
* Function to copy readme files to their dist folder
*/
function copyReadmeFiles() {
const resolvedSrcReadmePaths = path.resolve(rootDir, srcReadmePaths);

glob(resolvedSrcReadmePaths, void(0), function(error, files) {
files.forEach((filePath) => {
const destReadmePath = filePath.replace(/(\bsrc\b)(?!.*\1)/, destDir);
fs.copyFileSync(filePath, destReadmePath);
});
});
}

/**
* Copy all files
*/
copyReadmeFiles();
Loading

0 comments on commit 387b9c7

Please sign in to comment.