Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Add a Batfish demo site for testing components #169

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ src/components/*/index.js
packages/**/package-lock.json
pkg
src/test-cases-app/component-index.js
_site*
demo/vendor/*
demo/batfish.config.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
pkg
src/test-cases-app/component-index.js
src/components/syntax-highlighting/index.js
_site_*
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ cache:
- node_modules
git:
depth: 3

script:
- npm test
- npm run build-batfish
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ npm start
npm run start-legacy
```

Docs build process and automated testing coming soon.
The `demo/` directory contains a demo Batfish site to test components locally. You can add the component to the site and view it with:

When making changes to the build script, test that the module builds correctly by running `npm run build` and then linking the local package with another local repo. Make sure you are able to run the local repo without errors from dr-ui.
```bash
npm run start-batfish
```

Travis will also build the demo site to make sure there are no errors at build time. You can also test that the demo site will build with:

```bash
npm run build-batfish
```

## Tests

Expand Down
3 changes: 3 additions & 0 deletions demo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./conf/eslint-config-browser.json"
}
6 changes: 6 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# dr-ui demo site

Sample [Batfish](https://github.com/mapbox/batfish) site to test dr-ui components.

* Run: `npm run start`
* Build: `npm run build`
101 changes: 101 additions & 0 deletions demo/batfish.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const path = require('path');
const pageShellDir = path.join(__dirname, './vendor/docs-page-shell');
module.exports = () => {
const config = {
siteOrigin: 'https://docs.mapbox.com',
siteBasePath: '/demo',
productionDevtool: 'source-map',
pagesDirectory: path.join(__dirname, 'src/pages/'),
outputDirectory: path.join(__dirname, '_site/'),
temporaryDirectory: path.join(__dirname, '_site_tmp/'),
stylesheets: [
require.resolve('@mapbox/mbx-assembly/dist/assembly.css'),
path.join(pageShellDir, 'page-shell-styles.css'),
path.join(__dirname, './src/css/site.css'),
require.resolve('../pkg/css/docs-prose.css'),
require.resolve('../pkg/css/prism.css')
],
applicationWrapperPath: path.join(
__dirname,
'src/components/application-wrapper.js'
),
inlineJs: [{ filename: path.join(pageShellDir, 'page-shell-script.js') }],
jsxtremeMarkdownOptions: {
wrapper: path.join(__dirname, 'src/components/markdown-page-shell.js'),
rehypePlugins: [
require('rehype-slug'),
require('@mapbox/rehype-prism'),
require('../pkg/plugins/add-links-to-headings'),
require('../pkg/plugins/create-sections'),
require('../pkg/plugins/make-table-scroll')
]
},
devBrowserslist: false,
babelInclude: ['mimic-fn', 'debounce-fn'],
dataSelectors: {
listSubFolders: data => {
const folders = data.pages.filter(
file => file.path.split(path.sep).length === 4
);
return folders;
},
orderedPages: data => {
// get all pages and the meta we need to process
const pages = data.pages.map(p => ({
title: p.frontMatter.title,
description: p.frontMatter.description,
path: p.path,
order: p.frontMatter.order || undefined,
navOrder: p.frontMatter.navOrder || undefined,
layout: p.frontMatter.layout || undefined,
topic: p.frontMatter.topic || undefined,
thumbnail: p.frontMatter.thumbnail || undefined
}));
// get top level nav items
const navItems = pages
.filter(p => p.navOrder)
.sort((a, b) => parseFloat(a.navOrder) - parseFloat(b.navOrder));
// add second level items
const items = navItems.reduce((obj, parent) => {
const children = pages.filter(page =>
page.path.startsWith(parent.path)
);

const topics = [
...new Set(
children.reduce((arr, page) => {
if (page.topic) arr = arr.concat(page.topic);
return arr;
}, [])
)
];

obj[parent.path] = {
title: parent.title,
description: parent.description,
order: parent.order,
navOrder: parent.navOrder,
path: parent.path,
layout: parent.layout,
topics: topics,
pages: children
.reduce((arr, child) => {
// if parent layout is accordion, set childen layout to accordion
if (parent.layout === 'accordion') {
child.layout = parent.layout;
}
arr = arr.concat(child);
return arr;
}, [])
.sort((a, b) => parseFloat(a.order) - parseFloat(b.order))
};
return obj;
}, {});
return items;
}
}
};
return config;
};
7 changes: 7 additions & 0 deletions demo/conf/eslint-config-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true
}
}
22 changes: 22 additions & 0 deletions demo/conf/eslint-config-browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "./eslint-config-base.json",
"parser": "babel-eslint",
"env": {
"browser": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"globals": {
"MapboxPageShell": true
},
"plugins": ["react"],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"node/no-unsupported-features": "off"
}
}
1 change: 1 addition & 0 deletions demo/css/site.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* extra styles here */
Loading