Skip to content

Commit

Permalink
fix: decouple from @scaleds/components, transpile @scaleds/docs (#239)
Browse files Browse the repository at this point in the history
feat: dynamic whitelist aka featuredComponents config property
  • Loading branch information
nowseemee authored Jun 5, 2020
1 parent c1f16dc commit 4339f7a
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/components/.monument.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ const config = {
outputDirName: 'monument',
docsFilePath: '/dist/scale-components.json',
namespace: 'scale-components',
featuredComponents: ["button", "card", "link", "icon", "tag", "table"],
themeFilePath: '/dist/theme.iife.js'
};
module.exports = config;
3 changes: 2 additions & 1 deletion packages/docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ yarn-error.log
.yarn-integrity

# Stencil files
components.json
components.json
loader/
51 changes: 40 additions & 11 deletions packages/docs/cli/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,59 @@ const findUserConfig = require("./find-user-config")
const { logger } = require("./logger")
const path = require("path")
const fs = require("fs-extra")
const spawn = require("child_process").spawn

const copy = async argv => {
try {
const config = require(await findUserConfig(argv))
const monumentRootPath = path.join(__dirname, "..")
const stencilRootPath = process.env.CWD

return Promise.all([
fs.copy(
`${stencilRootPath}${config.docsFilePath}`,
`${monumentRootPath}/components.json`
),
const psClean = spawn(
"cd",
[
path.join(__dirname, "../"),
"&&",
"yarn",
"gatsby",
"clean",
],
{
shell: true,
}
)

fs.copy(
`${stencilRootPath}/dist/${config.namespace}`,
`${monumentRootPath}/public/components/`
),

config.themeFilePath &&
psClean.on("close", () => {
return Promise.all([
fs.copy(
`${stencilRootPath}${config.docsFilePath}`,
`${monumentRootPath}/components.json`
),

fs.copy(
`${stencilRootPath}/dist/${config.namespace}`,
`${monumentRootPath}/public/components/`
),

fs.copy(
`${stencilRootPath}/dist`,
`${monumentRootPath}/dist`
),

fs.copy(
`${stencilRootPath}/loader`,
`${monumentRootPath}/loader`
),

fs.copy(
`${stencilRootPath}${config.themeFilePath}`,
`${monumentRootPath}/public/theme.js`
),
])
])
})


} catch (error) {
logger.error(error)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "prismjs/themes/prism.css"
import {
defineCustomElements,
applyPolyfills,
} from "@scaleds/components/loader"
} from "./loader"

applyPolyfills().then(() => {
defineCustomElements(window)
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module.exports = {
author: `@telekom`,
},
plugins: [
{
resolve: `gatsby-plugin-compile-es6-packages`,
options: {
modules: [`@scaleds/docs`]
}
},
{
resolve: "@scaleds/gatsby-plugin",
options: {
Expand Down
3 changes: 2 additions & 1 deletion packages/docs/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const { GraphQLObjectType, GraphQLString } = require("graphql")
const { GraphQLObjectType, GraphQLString, GraphQLList } = require("graphql")
const config = require(process.env.MONUMENT_CONFIG_FILE)
const { createFilePath } = require(`gatsby-source-filesystem`)

Expand All @@ -18,6 +18,7 @@ exports.setFieldsOnGraphQLNodeType = ({ type }) => {
docsFilePath: { type: GraphQLString },
themeFilePath: { type: GraphQLString },
namespace: { type: GraphQLString },
featuredComponents: { type: GraphQLList(GraphQLString) },
}),
}),
resolve: () => config,
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"version": "0.1.4",
"author": "eeegor",
"dependencies": {
"@scaleds/components": "^0.1.4",
"@scaleds/gatsby-plugin": "^0.1.4",
"@textlint/markdown-to-ast": "^6.1.7",
"fs-extra": "^9.0.0",
"gatsby": "^2.17.11",
"gatsby-image": "^2.2.31",
"gatsby-plugin-compile-es6-packages": "^2.1.0",
"gatsby-plugin-manifest": "^2.2.27",
"gatsby-plugin-offline": "^3.0.19",
"gatsby-plugin-react-helmet": "^3.1.14",
Expand Down
5 changes: 2 additions & 3 deletions packages/docs/src/components/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from "react"
import { Link } from "gatsby"

const whiteList = ["button", "card", "link", "icon", "tag", "table"]

const Sidebar = ({ components, currentPage }) => {
const Sidebar = ({ components, currentPage, featuredComponents }) => {
const sortedComponents = components.sort((a, b) => {
if (a.node.fields.filename < b.node.fields.filename) {
return -1
Expand All @@ -15,7 +14,7 @@ const Sidebar = ({ components, currentPage }) => {
})

const filtered = sortedComponents.filter((c) => {
if (whiteList.includes(c.node.fields.filename.replace("/", ""))) {
if (featuredComponents.includes(c.node.fields.filename.replace("/", ""))) {
return true
} else if (c.node.fields.section !== "components") {
return true
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/src/layouts/documentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export default ({ children, location }) => {
title
}
}
site {
config {
featuredComponents
}
}
}
`)
return (
Expand All @@ -37,6 +42,7 @@ export default ({ children, location }) => {
<Sidebar
currentPage={location.pathname}
components={data.sidebar.edges}
featuredComponents={data.site.config.featuredComponents}
/>
</div>
<section className="main__content">
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@
core-js-pure "^3.0.0"
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.0.0":
version "7.10.2"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.2.tgz#d103f21f2602497d38348a32e008637d506db839"
integrity sha512-6sF3uQw2ivImfVIl62RZ7MXhO2tap69WeWK57vAaimT6AZbE4FbqjdEJIN1UqoD6wI6B+1n9UiagafH1sxjOtg==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.1.2", "@babel/runtime@^7.3.1", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2", "@babel/runtime@^7.9.6":
version "7.9.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.6.tgz#a9102eb5cadedf3f31d08a9ecf294af7827ea29f"
Expand Down Expand Up @@ -7660,6 +7667,14 @@ gatsby-page-utils@^0.2.1:
lodash "^4.17.15"
micromatch "^3.1.10"

gatsby-plugin-compile-es6-packages@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/gatsby-plugin-compile-es6-packages/-/gatsby-plugin-compile-es6-packages-2.1.0.tgz#eb6068d8936fd8b404716e47b821d09bf0656af7"
integrity sha512-yrYAAjabHWJr3ARi8xzDm01dbBfyOxEWTwGkL3BMdgL/opfLvTrwLmfium4kSelnLs70DYY3rYDwyHjqyFsnFQ==
dependencies:
"@babel/runtime" "^7.0.0"
regex-escape "^3.4.8"

gatsby-plugin-manifest@^2.2.27:
version "2.4.2"
resolved "https://registry.yarnpkg.com/gatsby-plugin-manifest/-/gatsby-plugin-manifest-2.4.2.tgz#0a9605a778a8e30ce047b9b3701031b9bde61d6b"
Expand Down Expand Up @@ -14623,6 +14638,11 @@ regenerator-transform@^0.14.2:
"@babel/runtime" "^7.8.4"
private "^0.1.8"

regex-escape@^3.4.8:
version "3.4.9"
resolved "https://registry.yarnpkg.com/regex-escape/-/regex-escape-3.4.9.tgz#407b413562e2373d56994ff213e693658ea4f8f7"
integrity sha512-Cv9rjwyQwVhn3L097ysanWsEElurmxDj6Cc4Ut23z7e6hzRbrNvF3Le7yAciMfuzyb0sZwSr0ZHunMNCIoy2/g==

regex-not@^1.0.0, regex-not@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
Expand Down

0 comments on commit 4339f7a

Please sign in to comment.