Skip to content

Pyu/afp 206 website crashes if top level docs folder is missing #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .changeset/8b2474fa/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "@brisk-docs/website", "type": "patch" }],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/8b2474fa/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Gracefully handle top-level docs directory being missing
9 changes: 7 additions & 2 deletions packages/website/bin/page-generator/get-docs-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
const path = require('path');
const fs = require('fs-extra');

const processDirectory = dirPath =>
fs
const processDirectory = dirPath => {
if (!fs.existsSync(dirPath) || !fs.statSync(dirPath).isDirectory()) {
return null;
}

return fs
.readdirSync(dirPath)
.map(fname => ({
id: path.parse(fname).name,
Expand All @@ -24,6 +28,7 @@ const processDirectory = dirPath =>
children: processDirectory(fullPath),
};
});
};

/**
* @param docsPath absolute path to where the docs are located
Expand Down
14 changes: 14 additions & 0 deletions packages/website/bin/page-generator/get-docs-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ describe('Get docs info utility', () => {
});
});
});

describe('Missing docs directory', () => {
let cwd;
let docsInfo;

beforeAll(async () => {
cwd = await copyFixtureIntoTempDir(__dirname, 'simple-mock-packages');
docsInfo = getDocsInfo(path.join(cwd, 'docs'));
});

it('should return null if the docs folder does not exist', () => {
expect(docsInfo).toBeNull();
});
});
4 changes: 3 additions & 1 deletion packages/website/bin/page-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ module.exports = async function generatePages(
};

const packageSitemap = generatePackagePages(packageInfo, generatorConfig);
const docsSitemap = generateProjectDocsPages(docsInfo, generatorConfig);
const docsSitemap = docsInfo
? generateProjectDocsPages(docsInfo, generatorConfig)
: undefined;

return {
packages: packageSitemap,
Expand Down
27 changes: 27 additions & 0 deletions packages/website/bin/page-generator/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,30 @@ describe('File modification tests', () => {
expect(fs.existsSync(firstDocsPage)).toEqual(false);
});
});

describe('Missing docs folder', () => {
let sitemap;

beforeAll(async () => {
const packagesCwd = await copyFixtureIntoTempDir(
__dirname,
'simple-mock-packages',
);

const packagesPaths = [path.join(packagesCwd, 'packages', '/*')];
const docsPath = 'path/that/does/not/exist';
const pagesPath = await createTempDir();
const componentsPath = await createTempDir();

sitemap = await generatePages(
packagesPaths,
docsPath,
pagesPath,
componentsPath,
);
});

it('should return the docs sitemap as undefined', () => {
expect(sitemap.docs).toBeUndefined();
});
});
10 changes: 6 additions & 4 deletions packages/website/components/navigation/docs-nav-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import TreeNavContent, { arrayToTreeItems } from './tree-nav-content';
const NavContent = () => {
const treeData = {
rootId: 'docs',
items: arrayToTreeItems(pageInfo.docs, {
parentId: 'docs',
parentTitle: 'Docs',
}),
items: pageInfo.docs
? arrayToTreeItems(pageInfo.docs, {
parentId: 'docs',
parentTitle: 'Docs',
})
: {},
};

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/website/pages-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Page, PackageInfo } from './types';

interface Info {
packages: PackageInfo[];
docs: Page[];
docs?: Page[];
}

const data: Info = pageInfo;
Expand Down
131 changes: 72 additions & 59 deletions packages/website/pages/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TableTree, {
Row,
Cell,
} from '@atlaskit/table-tree';
import SectionMessage from '@atlaskit/section-message';
import Link from 'next/link';
import titleCase from 'title-case';

Expand All @@ -15,73 +16,85 @@ import DocsNavContent from '../components/navigation/docs-nav-content';
import NavigationWrapper from '../components/navigation-wrapper';
import PageTitle from '../components/page-title';

const NoDocsMessage = () => (
<SectionMessage appearance="warning">
We couldn&apos;t find any docs pages in your provided docs directory
</SectionMessage>
);

type State = { expansionMap: { [s: string]: boolean } };

export default class Docs extends React.Component<{}, State> {
class DocsTable extends React.Component<{}, State> {
state: State = { expansionMap: {} };

render() {
const { expansionMap } = this.state;

return (
<>
<PageTitle title="Documents" />
<NavigationWrapper navContent={DocsNavContent}>
<Page>
<Title>Documents Overview</Title>
<Section>
<TableTree>
<Headers>
<Header width={300}>Name</Header>
<Header width={400}>Path</Header>
</Headers>
<Rows
items={pageInfo.docs}
render={({
id,
pagePath,
children,
}: {
id: string;
pagePath: string;
children: React.ReactChild[];
}) => (
<Row
itemId={id}
items={children}
hasChildren={children && children.length > 0}
isExpanded={Boolean(expansionMap[id])}
onExpand={() =>
this.setState({
expansionMap: {
...expansionMap,
[id]: true,
},
})
}
onCollapse={() =>
this.setState({
expansionMap: {
...expansionMap,
[id]: false,
},
})
}
>
<Cell singleLine>{titleCase(id)}</Cell>
<Cell>
<Link href={pagePath}>
<a>{pagePath}</a>
</Link>
</Cell>
</Row>
)}
/>
</TableTree>
</Section>
</Page>
</NavigationWrapper>
</>
<Section>
<TableTree>
<Headers>
<Header width={300}>Name</Header>
<Header width={400}>Path</Header>
</Headers>
<Rows
items={pageInfo.docs}
render={({
id,
pagePath,
children,
}: {
id: string;
pagePath: string;
children: React.ReactChild[];
}) => (
<Row
itemId={id}
items={children}
hasChildren={children && children.length > 0}
isExpanded={Boolean(expansionMap[id])}
onExpand={() =>
this.setState({
expansionMap: {
...expansionMap,
[id]: true,
},
})
}
onCollapse={() =>
this.setState({
expansionMap: {
...expansionMap,
[id]: false,
},
})
}
>
<Cell singleLine>{titleCase(id)}</Cell>
<Cell>
<Link href={pagePath}>
<a>{pagePath}</a>
</Link>
</Cell>
</Row>
)}
/>
</TableTree>
</Section>
);
}
}

const Docs = () => (
<>
<PageTitle title="Documents" />
<NavigationWrapper navContent={DocsNavContent}>
<Page>
<Title>Documents Overview</Title>
{pageInfo.docs ? <DocsTable /> : <NoDocsMessage />}
</Page>
</NavigationWrapper>
</>
);

export default Docs;
5 changes: 4 additions & 1 deletion packages/website/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import WidthDetector from '@atlaskit/width-detector';
import { Section } from '../components/page';
import Panel, { PanelGrid } from '../components/panel';
import Meta from '../components/meta-context';
import pageInfo from '../pages-list';

const WINDOW_BREAKPOINT = 800;

Expand Down Expand Up @@ -74,7 +75,9 @@ class HomePage extends React.Component {
<Section>
<PanelGrid displayAsColumn={displayAsColumn}>
<Panel href="/packages" {...this.packagesPanelProps} />
<Panel href="/docs" {...this.docsPanelProps} />
{pageInfo.docs && (
<Panel href="/docs" {...this.docsPanelProps} />
)}
</PanelGrid>
</Section>
</Page>
Expand Down
8 changes: 4 additions & 4 deletions scripts/micros_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
#!/bin/sh ofsifosdiflsdfisdf

# Build
(cd .. && bolt build:docs)
(cd .. && bolt build:docs)gfdgdflgk

# Copy files
cp ../packages/website/package.json ../deploy
cp ../packages/website/package.json ../deploy fsdifuosdfiusdlfsd
cp ../yarn.lock ../deploy

cp -r ../packages/website/.next ../deploy
cp -r ../packages/website/.next ../deploygdogiudfogiu
cp -r ../packages/website/static ../deploy

# Install dependencies
Expand Down
4 changes: 4 additions & 0 deletions typings/atlaskit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ declare module '@atlaskit/drawer' {
declare const Drawer: React.ComponentType<any, any>;
export default Drawer;
}
declare module '@atlaskit/section-message' {
declare const SectionMessage: React.ComponentType<any, any>;
export default SectionMessage;
}

declare module '@atlaskit/table-tree' {
declare const aDefault: React.ComponentType<any, any>;
Expand Down