Skip to content

Commit 483bbd8

Browse files
committed
build(docs): add scripts for fast previews of LB4 doc changes
Add a script `docs/bin/build-preview-site.sh` that creates a subset of loopback.io site with just enough content to support fast previews of LB4 documentation. Add monorepo-level npm scripts to simplify usage of the new build script. Usage: 1. Run the script to create a new Jekyll site in `docs/_preview` dir: $ npm run docs:prepare 2. Follow the instructions printed by the script to start Jekyll: $ npm run docs:start 3. View the documentation. 4. Make changes to documentation files in `docs/site`. 5. Restart Jekyll (stop the running process and go to step 2). The good parts: - Initial build of LB4-only docs takes about 6 seconds. (Compare to ~4 minutes for the entire docs site!) - Incremental rebuild after changing a single file takes less than a second. Downsides: - Watch mode does not work. AFAICT, Jekyll cannot watch symlinked files stored outside of `source` directory. Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent bd60fb1 commit 483bbd8

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ dist/
33
coverage/
44
/sandbox
55
**/*.d.ts
6+
/docs/_preview
7+
/docs/_loopback.io

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ packages/tsdocs/fixtures/monorepo/packages/pkg1/docs
3232
# ESLint cache
3333
.eslintcache
3434

35+
# Docs preview
36+
docs/_loopback.io/
37+
docs/_preview/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/coverage
33
/docs/apidocs
44
/docs/site/apidocs
5+
/docs/_loopback.io/
6+
/docs/_preview/
57
packages/cli/generators/*/templates
68
packages/cli/snapshots/
79
packages/tsdocs/fixtures/monorepo/docs
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const fs = require('fs');
6+
const yaml = require('js-yaml');
7+
8+
const src = process.argv[2];
9+
const dest = process.argv[3] || src;
10+
11+
if (!src) {
12+
console.log(`
13+
Missing required argument: path to original Jekyll config');
14+
15+
Usage:
16+
17+
node %s <source _config.yml> [dest path]', process.argv[1]);
18+
19+
`);
20+
process.exit(1);
21+
}
22+
23+
console.log('Reading Jekyll config from %s', src);
24+
const config = yaml.safeLoad(fs.readFileSync(src, 'utf8'));
25+
26+
config.sidebars = ['lb4_sidebar'];
27+
config.defaults[0].values.sidebar = 'lb4_sidebar';
28+
config.plugins = config.plugins.filter(p => p !== 'jekyll-sitemap');
29+
30+
console.log('Writing Jekyll config to %s', dest);
31+
fs.writeFileSync(dest, yaml.dump(config), 'utf8');

docs/bin/build-preview-site.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# This scripts builds a small Jekyll site to preview LB4 documentation changes.
4+
# The idea is to get as close to `strongloop/loopback.io` configuration as
5+
# possible, while removing as many non-LB4 pages as possible.
6+
7+
# Set `-e` so that non-zero exit code from any step will be honored
8+
set -e
9+
10+
# Make sure we use the correct repo root dir
11+
DIR=`dirname $0`
12+
DOCS_ROOT=$DIR/..
13+
REPO_ROOT=$DIR/../..
14+
15+
pushd $DOCS_ROOT > /dev/null
16+
17+
SOURCE_DIR=_loopback.io
18+
if [ ! -d $SOURCE_DIR ]; then
19+
echo "Shadow cloning the strongloop/loopback.io github repo"
20+
git clone --depth 1 https://github.com/strongloop/loopback.io.git $SOURCE_DIR
21+
else
22+
echo "Found existing loopback.io clone, pulling latest changes"
23+
(cd $SOURCE_DIR && git pull)
24+
fi
25+
26+
echo "Installing setup dependencies"
27+
npm install --no-save js-yaml
28+
29+
JEKYLL_DIR=_preview
30+
rm -rf $JEKYLL_DIR
31+
mkdir $JEKYLL_DIR
32+
33+
node bin/build-jekyll-preview-config $SOURCE_DIR/_config.yml $JEKYLL_DIR/_config.yml
34+
35+
echo "Copying LB4 readmes"
36+
node bin/copy-readmes
37+
38+
echo "Copyping Gemfile, index.html and data files"
39+
rm -rf $JEKYLL_DIR/{_data,_includes,_layouts}
40+
cp -r $SOURCE_DIR/Gemfile* $JEKYLL_DIR/
41+
cp -r $SOURCE_DIR/index.html $JEKYLL_DIR/
42+
cp -r $SOURCE_DIR/_data $JEKYLL_DIR/
43+
cp -r $SOURCE_DIR/_includes $JEKYLL_DIR/
44+
cp -r $SOURCE_DIR/_layouts $JEKYLL_DIR/
45+
46+
echo "Copying static assets"
47+
cp -r $SOURCE_DIR/{css,images,dist,js,fonts} $JEKYLL_DIR/
48+
rm -rf $JEKYLL_DIR/doc
49+
mkdir -p $JEKYLL_DIR/doc
50+
cp -r $SOURCE_DIR/doc/index.md $JEKYLL_DIR/doc
51+
52+
echo "Setting up LB4 doc pages",
53+
rm -rf $JEKYLL_DIR/pages
54+
ln -s $PWD/site $JEKYLL_DIR/pages
55+
56+
echo "Setting up sidebar(s)"
57+
rm -rf $JEKYLL_DIR/_data/sidebars
58+
ln -s $PWD/site/sidebars $JEKYLL_DIR/_data/sidebars
59+
60+
echo "Installing Ruby dependencies"
61+
(cd $JEKYLL_DIR && bundle install)
62+
63+
echo "Done. Run the following command to start the site:"
64+
echo ""
65+
echo " npm run docs:start"
66+
echo ""
67+
echo "NOTE: Watch mode is not supported yet."

docs/site/DEVELOPING.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See [Monorepo overview](./MONOREPO.md) for a list of all packages.
1818
- [Coding rules](#coding-rules)
1919
- [Working with dependencies](#working-with-dependencies)
2020
- [File naming convention](#file-naming-convention)
21+
- [Documentation](#documentation)
2122
- [API documentation](#api-documentation)
2223
- [Commit message guidelines](#commit-message-guidelines)
2324
- [Making breaking changes](#making-breaking-changes)
@@ -213,6 +214,85 @@ src/__tests__/integration/user.controller.integration.ts
213214
src/__tests__/unit/application.unit.ts
214215
```
215216

217+
## Documentation
218+
219+
The documentation available at [http://loopback.io/doc/en/lb4](loopback.io)
220+
website is powered by Jekyll and Markdown. The main site content and Jekyll
221+
configuration is hosted in
222+
[loopback.io](https://github.com/strongloop/loopback.io) repository on GitHub.
223+
224+
LoopBack 4 documentation is hosted inside this monorepo in the
225+
[/docs](https://github.com/strongloop/loopback-next/tree/master/docs) directory.
226+
This allows us to change both implementation and the documentation in a single
227+
pull request.
228+
229+
### Publishing changes
230+
231+
To prevent documentation changes going live before the changes in the
232+
implementation have been published, we have set up the following build pipeline:
233+
234+
1. As part of the LoopBack 4 release process, the content of `docs` directory is
235+
bundled and published to npmjs.org as `@loopback/docs` package.
236+
237+
2. We have a CI/CD pipeline to pick a new `@loopback/docs` version and commit
238+
the updated content to `loopback.io` repository. The job is run every night.
239+
240+
### Previewing loopback-next docs only
241+
242+
> This workflow is not available on Windows (unless you use Windows Subsystem
243+
> for Linux).
244+
245+
When making change to our documentation, it's useful to quickly check how is the
246+
updated markdown content going to be rendered on the website. To make this flow
247+
as fast as possible, we have a script to prepare a subset of our website with
248+
LoopBack 4 content only. This provides the fastest feedback loop possible, at
249+
the cost of occasional breakage when the script is not updated to accommodate
250+
changes made in the `loopback.io` repository.
251+
252+
As the initial setup, run the following command once, before you start making
253+
documentation changes:
254+
255+
```sh
256+
$ npm run docs:prepare
257+
```
258+
259+
This command will create `docs/_preview` directory with a Jekyll project and
260+
configure symlinks to let Jekyll automatically pick any changes made in
261+
`docs/site` files.
262+
263+
Whenever you want to (re)render documentation, just (re)start the following
264+
command:
265+
266+
```sh
267+
$ npm run docs:start
268+
```
269+
270+
The first run will be slightly longer because Jekyll has to render all doc
271+
pages. Subsequent runs should be very fast because only changed files are
272+
re-rendered thanks to Jekyll `incremental` mode.
273+
274+
### Viewing the full website
275+
276+
> This workflow is not available on Windows (unless you use Windows Subsystem
277+
> for Linux).
278+
279+
It is also possible to verify the full build setup, including validation of
280+
Markdown & Jekyll (liquid) syntax.
281+
282+
Run the following command to clone `loopback.io` repository to
283+
`sandbox/loopback.io` and get the current documentation from loopback-next
284+
copied in the right places in the Jekyll project:
285+
286+
```sh
287+
npm run build:site
288+
```
289+
290+
You can also run the documentation tests exactly as our CI pipeline does:
291+
292+
```sh
293+
npm run verify:docs
294+
```
295+
216296
## API Documentation
217297

218298
We use

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"test:ci": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",
6060
"verify:docs": "npm run build:site -- --verify",
6161
"build:site": "./bin/build-docs-site.sh",
62+
"docs:prepare": "./docs/bin/build-preview-site.sh",
63+
"docs:start": "cd docs/_preview && bundle exec jekyll serve --no-w --i",
6264
"mocha": "node packages/build/bin/run-mocha \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"",
6365
"posttest": "npm run lint"
6466
},

0 commit comments

Comments
 (0)