Skip to content

Commit 006f2d1

Browse files
castastrophemwcz
authored andcommitted
Add dynamic indexing of elements for raw demo page (#253)
* Add dynamic doc listing * Remove index file from git project * rename file and create post-new npm script * --append * remove index from npm start
1 parent 7fb0b6a commit 006f2d1

File tree

6 files changed

+78
-34
lines changed

6 files changed

+78
-34
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
node_modules
33
tmp
44

5+
# Compiled index
6+
doc/index.html
7+
58
# Logs
69
lerna-debug.log
7-
npm-debug.log
10+
npm-debug.log*
811

912
# Local files
1013
*.local.umd.js

doc/index.html

Lines changed: 0 additions & 25 deletions
This file was deleted.

doc/wrapper.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width" />
6+
<title>RH Elements</title>
7+
8+
<link href="../elements/rhelement/rhelement.min.css" rel="stylesheet">
9+
</head>
10+
<body unresolved>
11+
<h1>Demos</h1>
12+
<ul id="demos"><!-- Inject list --></ul>
13+
</body>
14+
</html>

package-lock.json

Lines changed: 21 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
"bootstrap": "lerna bootstrap --hoist",
1010
"postinstall": "npm run bootstrap",
1111
"test-suite-inject": "node scripts/test-suite-inject.js",
12+
"doc-listing-inject": "node scripts/doc-listing-inject.js",
1213
"storybook": "start-storybook -c .storybook -p 9001 -s ./elements",
1314
"build-storybook": "build-storybook -c .storybook -o .storybook_out",
1415
"gh-pages-storybook": "storybook-to-ghpages",
1516
"deploy-storybook": "npm run build-storybook && npm run gh-pages-storybook",
16-
"new": "cd elements && yo --no-insight --no-update-notifier rhelement && npm run test-suite-inject && npm run bootstrap"
17+
"new": "cd elements && yo --no-insight --no-update-notifier rhelement && npm run post-new",
18+
"post-new": "npm run test-suite-inject && npm run doc-listing-inject && npm run bootstrap"
1719
},
1820
"husky": {
1921
"hooks": {

scripts/doc-listing-inject.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const elementsDir = path.join(__dirname, "../elements");
5+
6+
let elementNames = fs
7+
.readdirSync(elementsDir)
8+
.filter(file => fs.statSync(path.join(elementsDir, file)).isDirectory());
9+
10+
// Remove rhelement core from listing
11+
elementNames = elementNames.filter(folder => folder !== "rhelement");
12+
13+
// Remove themesets and sass helpers from the listings
14+
elementNames = elementNames.filter(
15+
folder => !folder.includes("themeset") && !folder.includes("sass")
16+
);
17+
18+
let markup = "";
19+
elementNames.forEach(
20+
element =>
21+
(markup += `\n\t\t\t\t\t<li><a href="../elements/${element}/demo">${element}</a></li>`)
22+
);
23+
24+
const wrapper = path.join(__dirname, "../doc/wrapper.html");
25+
const index = path.join(__dirname, "../doc/index.html");
26+
27+
// Read in the wrapper template
28+
fs.readFile(wrapper, (err, data) => {
29+
if (err) throw err;
30+
let content = data.toString();
31+
content = content.replace("<!-- Inject list -->", markup + "\n\t\t\t\t");
32+
// Output the updated index file
33+
fs.writeFile(index, content, function(err) {
34+
if (err) throw err;
35+
});
36+
});

0 commit comments

Comments
 (0)