Skip to content

Commit

Permalink
feat(detail view): add detail view (microsoft#470)
Browse files Browse the repository at this point in the history
* feat(detail view): add detail view

* update tests

* fix some complexity issues

* fix a permutator test value

* re-order imports

* re-case readme markdown file names
  • Loading branch information
janechu authored May 25, 2018
1 parent 4b1ed8a commit 665b871
Show file tree
Hide file tree
Showing 93 changed files with 26,445 additions and 25,876 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/
69 changes: 69 additions & 0 deletions build/convert-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 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";
export default class Documentation extends React.Component<{}, {}> {
public render(): JSX.Element {
return (
<div style={{padding: "14px"}}>\n `;

const endFile = `\n </div>
);
}
}\n`;

const md = 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 = startFile;
const markdown = fs.readFileSync(filePath, "utf8");
const exportPath = filePath.replace(/README\.md/, readmePath);
documentation += md.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 665b871

Please sign in to comment.