Skip to content

Commit ffe741c

Browse files
Drakeoonlukewalczakandrewtsar0wyamankatby
authored
docs: migrate to Docusaurus (callstack#3614)
Co-authored-by: lukewalczak <[email protected]> Co-authored-by: Andriy Tsaryov <[email protected]> Co-authored-by: Yaman KATBY <[email protected]>
1 parent 1074ab2 commit ffe741c

File tree

986 files changed

+32591
-6434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

986 files changed

+32591
-6434
lines changed

Diff for: .circleci/config.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
executors:
44
default:
55
docker:
6-
- image: circleci/node:16
6+
- image: cimg/node:16.18.0
77
working_directory: ~/react-native-paper
88

99
commands:
@@ -104,10 +104,11 @@ jobs:
104104
- run:
105105
name: Build docs
106106
command: |
107+
export DOCUSAURUS_BASE_URL="/output/job/$CIRCLE_WORKFLOW_JOB_ID/artifacts/$CIRCLE_NODE_INDEX/docs/"
107108
cd docs && yarn build && cd ..
108109
bash .circleci/comment-artifacts.sh
109110
- store_artifacts:
110-
path: docs/dist
111+
path: docs/build
111112
destination: docs
112113

113114
deploy-docs:
@@ -148,4 +149,5 @@ workflows:
148149
- deploy-docs:
149150
filters:
150151
branches:
151-
only: main
152+
only:
153+
- main

Diff for: .circleci/deploy-docs.sh

+13-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
99
SOURCE_BRANCH="main"
1010
TARGET_BRANCH="gh-pages"
1111

12-
cd $DIR/../docs
12+
git checkout $SOURCE_BRANCH
13+
14+
cd $DIR/..
15+
16+
# Install React Native Paper dependencies for examples
17+
yarn
18+
19+
cd docs
1320

1421
# Save some useful information
1522
REPO=`git config remote.origin.url`
@@ -25,34 +32,19 @@ cd ..
2532

2633
# Clean existing dist/ contents
2734
rm -rf dist/**/* || :
28-
rm -f dist/*.{html,css,js,json,map} || :
35+
rm -f dist/*.{html,css,js,json,map,xml} || :
2936
rmdir dist/* || :
3037

3138
# Run our build script.
3239
yarn
3340
yarn build
3441

35-
# Build the docs for 1.0
36-
git checkout 1.0
37-
yarn
38-
yarn build
42+
# Move the built docs to cloned `gh-pages` directory
43+
cp -R build/. dist
3944

40-
# Build the docs for 2.0
41-
git checkout 2.0
42-
yarn
43-
yarn build
44-
45-
# Build the docs for 3.0
46-
git checkout 3.0
47-
yarn
48-
yarn build
49-
50-
# Build the docs for 4.0
51-
git checkout 4.0
52-
yarn
53-
yarn build
45+
rm -rf build
5446

55-
# Push the built docs
47+
# Change directory to the one using `gh-pages` branch
5648
cd dist
5749

5850
# Configure git.

Diff for: .eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ node_modules/
22
flow-typed/
33
coverage/
44
docs/dist/
5+
docs/build/
6+
docs/public/
7+
docs/static/
58
web-build/
69
testSetup.js
710

Diff for: docs/.babelrc

-3
This file was deleted.

Diff for: docs/.eslintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../.eslintrc",
3+
4+
"settings": {
5+
"import/core-modules": ["react-native-paper"]
6+
},
7+
8+
"rules": {
9+
"react/prop-types": "off",
10+
"import/no-unresolved": [
11+
2,
12+
{"ignore": ["^@docusaurus"]}
13+
]
14+
}
15+
}

Diff for: docs/.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
22+
# component-docs-plugin
23+
docs/components
24+
25+
# legacy
126
dist/
227
.linaria-cache/

Diff for: docs/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
4+
5+
### Installation
6+
7+
```
8+
$ yarn
9+
```
10+
11+
### Local Development
12+
13+
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
### Build
20+
21+
```
22+
$ yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
### Deployment
28+
29+
Using SSH:
30+
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

Diff for: docs/assets/screenshots/list-image.png

-62.2 KB
Binary file not shown.

Diff for: docs/assets/showcase/kurogahome.png

-248 KB
Binary file not shown.

Diff for: docs/assets/showcase/pharmaciesondutyturkey.png

-579 KB
Binary file not shown.

Diff for: docs/assets/showcase/prodigyiot.png

-145 KB
Binary file not shown.

Diff for: docs/assets/styles.css

-76
This file was deleted.

Diff for: docs/babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['@docusaurus/core/lib/babel/preset'],
3+
};

Diff for: docs/component-docs-plugin/generatePageMDX.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const config = require('../docusaurus.config');
2+
3+
const { baseUrl } = config;
4+
5+
function generatePageMDX(doc, link) {
6+
const description = doc.description
7+
.replace(/<\/br>/g, '')
8+
.replace(/style="[a-zA-Z0-9:;.\s()\-,]*"/gi, '')
9+
.replace(/src="screenshots/g, `src="${baseUrl}screenshots`);
10+
11+
const mdx = `
12+
---
13+
title: ${doc.title}
14+
---
15+
16+
import PropTable from '@site/src/components/PropTable.tsx';
17+
18+
${description}
19+
20+
## Props
21+
22+
<PropTable link="${link}" />
23+
`;
24+
25+
return mdx.slice(1);
26+
}
27+
28+
module.exports = generatePageMDX;

Diff for: docs/component-docs-plugin/index.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const {
2+
default: parseComponentDocs,
3+
} = require('component-docs/dist/parsers/component');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const generatePageMDX = require('./generatePageMDX');
8+
9+
const pluginName = 'component-docs-plugin';
10+
11+
async function componentsPlugin(_, options) {
12+
const { docsRootDir, libsRootDir, pages } = options;
13+
14+
function clean() {
15+
fs.rmSync(docsRootDir, { recursive: true, force: true });
16+
}
17+
18+
function createCategory(label, dir = '.') {
19+
const categoryJSON = JSON.stringify({ label }, undefined, 2);
20+
const docsCategoryDir = path.join(docsRootDir, dir);
21+
if (!fs.existsSync(docsCategoryDir)) {
22+
fs.mkdirSync(docsCategoryDir);
23+
}
24+
fs.writeFileSync(
25+
path.join(docsCategoryDir, `_category_.json`),
26+
categoryJSON
27+
);
28+
}
29+
30+
function createPageForComponent(targetArray, source) {
31+
const [item, subitem] = targetArray;
32+
const target = subitem ? `${item}/${subitem}` : item;
33+
const targetPath = target + '.mdx';
34+
const sourcePath = source + '.tsx';
35+
36+
// Parse component using component-docs.
37+
const doc = parseComponentDocs(path.join(libsRootDir, sourcePath), {
38+
root: libsRootDir,
39+
});
40+
41+
// Create directory for the output mdx file.
42+
fs.mkdirSync(
43+
path.join(docsRootDir, targetPath).split('/').slice(0, -1).join('/'),
44+
{ recursive: true }
45+
);
46+
47+
// Generate and write mdx file.
48+
fs.writeFileSync(
49+
path.join(docsRootDir, targetPath),
50+
generatePageMDX(doc, source)
51+
);
52+
53+
return doc;
54+
}
55+
56+
return {
57+
name: pluginName,
58+
async loadContent() {
59+
// Clean up docs directory.
60+
clean();
61+
// Create root components category.
62+
createCategory('Components', '.');
63+
64+
const docs = {};
65+
66+
for (const item in pages) {
67+
if (typeof pages[item] === 'string') {
68+
const doc = createPageForComponent([item], pages[item]);
69+
docs[pages[item]] = doc;
70+
} else {
71+
for (const subitem in pages[item]) {
72+
const doc = createPageForComponent(
73+
[item, subitem],
74+
pages[item][subitem]
75+
);
76+
docs[pages[item][subitem]] = doc;
77+
}
78+
}
79+
}
80+
81+
return docs;
82+
},
83+
async contentLoaded({ content: docs, actions }) {
84+
// Store component docs global data so it can be used in `PropsTable` component.
85+
actions.setGlobalData({
86+
docs,
87+
});
88+
},
89+
};
90+
}
91+
92+
module.exports = componentsPlugin;

0 commit comments

Comments
 (0)