This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from hipstersmoothie/index
Generate `index.html` for Monorepos
- Loading branch information
Showing
5 changed files
with
260 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const shell = require('shelljs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const colors = ['purple', 'pink', 'orange', 'green', 'blue', 'red']; | ||
|
||
function generateHTML(packages) { | ||
const packageRows = packages.map( | ||
(package, index) => ` | ||
<a href="${path.join(package.name, 'index.html')}" class="package-row"> | ||
<span class="title is-${colors[index % colors.length]}"> | ||
${package.name} | ||
</span> | ||
<span class="description">${package.description}</span> | ||
</a> | ||
` | ||
); | ||
const index = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Storybooks</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" type="text/css" href="monorepo-index.css"> | ||
</head> | ||
<body> | ||
<img class="banner" src="storybook.svg" alt="Storybook"/> | ||
<div class="content"> | ||
${packageRows.join('')} | ||
</div> | ||
</body> | ||
</html> | ||
`; | ||
|
||
return index; | ||
} | ||
|
||
module.exports = function buildMonorepoIndex( | ||
packages, | ||
customHTMLGenerate, | ||
outputDir | ||
) { | ||
let index; | ||
|
||
console.log(`=> Building index.html for monorepo`); | ||
|
||
if (customHTMLGenerate) { | ||
const fn = require(path.join(process.cwd(), customHTMLGenerate)); | ||
|
||
if (typeof fn === 'function') { | ||
index = fn(packages, outputDir); | ||
} | ||
} else { | ||
index = generateHTML(packages); | ||
|
||
shell.cp( | ||
path.join(__dirname, 'storybook.svg'), | ||
path.join(outputDir, 'storybook.svg') | ||
); | ||
shell.cp( | ||
path.join(__dirname, 'monorepo-index.css'), | ||
path.join(outputDir, 'monorepo-index.css') | ||
); | ||
} | ||
|
||
fs.writeFileSync(path.join(outputDir, 'index.html'), index); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
html { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
min-height: 60%; | ||
margin: 2rem; | ||
} | ||
|
||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
width: fit-content; | ||
justify-content: center; | ||
margin: 3rem auto; | ||
} | ||
|
||
.banner { | ||
max-width: 600px; | ||
width: 100%; | ||
margin: 3rem auto; | ||
} | ||
|
||
.package-row { | ||
margin-bottom: 2rem; | ||
color: #666; | ||
display: flex; | ||
align-items: stretch; | ||
text-decoration: none; | ||
transition: 0.3s; | ||
} | ||
|
||
.package-row:hover { | ||
box-shadow: 0 15px 20px #bbb; | ||
} | ||
|
||
.package-row .title { | ||
padding: 2rem; | ||
color: white; | ||
border-top-left-radius: 5%; | ||
border-bottom-left-radius: 5%; | ||
font-weight: bold; | ||
} | ||
|
||
.package-row .description { | ||
padding: 2rem 2rem 2rem 1rem; | ||
border-top-right-radius: 5%; | ||
border-bottom-right-radius: 5%; | ||
background: #f1f1f1; | ||
flex-grow: 1; | ||
box-shadow: 0px 10px 0 #d8d8d8; | ||
text-align: center; | ||
} | ||
|
||
.package-row:active .description { | ||
background: #d8d8d8; | ||
box-shadow: 0px 10px 0 #bebebe; | ||
} | ||
|
||
.is-purple { | ||
background: #b57ee5; | ||
box-shadow: 0px 10px 0 #9c65cc; | ||
} | ||
|
||
.package-row:active .is-purple { | ||
background: #9c65cc; | ||
box-shadow: 0px 10px 0 #824bb2; | ||
} | ||
|
||
.is-pink { | ||
background: #f1618c; | ||
box-shadow: 0px 10px 0 #d84873; | ||
} | ||
|
||
.package-row:active .is-pink { | ||
background: #d84873; | ||
box-shadow: 0px 10px 0 #be2e59; | ||
} | ||
|
||
.is-orange { | ||
background: #f3ad38; | ||
box-shadow: 0px 10px 0 #da941f; | ||
} | ||
|
||
.package-row:active .is-orange { | ||
background: #da941f; | ||
box-shadow: 0px 10px 0 #c07a05; | ||
} | ||
|
||
.is-green { | ||
background: #a2e05e; | ||
box-shadow: 0px 10px 0 #89c745; | ||
} | ||
|
||
.package-row:active .is-green { | ||
background: #89c745; | ||
box-shadow: 0px 10px 0 #6fad2b; | ||
} | ||
|
||
.is-blue { | ||
background: #6dabf5; | ||
box-shadow: 0px 10px 0 #5492dc; | ||
} | ||
|
||
.package-row:active .is-blue { | ||
background: #5492dc; | ||
box-shadow: 0px 10px 0 #3a78c2; | ||
} | ||
|
||
.is-red { | ||
background: #f16161; | ||
box-shadow: 0px 10px 0 #d84848; | ||
} | ||
|
||
.package-row:active .is-red { | ||
background: #d84848; | ||
box-shadow: 0px 10px 0 #be2e2e; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.