-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
7 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ dist/ | |
coverage/ | ||
/sandbox | ||
**/*.d.ts | ||
/docs/_preview | ||
/docs/_loopback.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const yaml = require('js-yaml'); | ||
|
||
const src = process.argv[2]; | ||
const dest = process.argv[3] || src; | ||
|
||
if (!src) { | ||
console.log(` | ||
Missing required argument: path to original Jekyll config'); | ||
Usage: | ||
node %s <source _config.yml> [dest path]', process.argv[1]); | ||
`); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Reading Jekyll config from %s', src); | ||
const config = yaml.safeLoad(fs.readFileSync(src, 'utf8')); | ||
|
||
config.sidebars = ['lb4_sidebar']; | ||
config.defaults[0].values.sidebar = 'lb4_sidebar'; | ||
config.plugins = config.plugins.filter(p => p !== 'jekyll-sitemap'); | ||
|
||
console.log('Writing Jekyll config to %s', dest); | ||
fs.writeFileSync(dest, yaml.dump(config), 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# This scripts builds a small Jekyll site to preview LB4 documentation changes. | ||
# The idea is to get as close to `strongloop/loopback.io` configuration as | ||
# possible, while removing as many non-LB4 pages as possible. | ||
|
||
# Set `-e` so that non-zero exit code from any step will be honored | ||
set -e | ||
|
||
# Make sure we use the correct repo root dir | ||
DIR=`dirname $0` | ||
DOCS_ROOT=$DIR/.. | ||
REPO_ROOT=$DIR/../.. | ||
|
||
pushd $DOCS_ROOT > /dev/null | ||
|
||
SOURCE_DIR=_loopback.io | ||
if [ ! -d $SOURCE_DIR ]; then | ||
echo "Shadow cloning the strongloop/loopback.io github repo" | ||
git clone --depth 1 https://github.com/strongloop/loopback.io.git $SOURCE_DIR | ||
else | ||
echo "Found existing loopback.io clone, pulling latest changes" | ||
(cd $SOURCE_DIR && git pull) | ||
fi | ||
|
||
echo "Installing setup dependencies" | ||
npm install --no-save js-yaml | ||
|
||
JEKYLL_DIR=_preview | ||
rm -rf $JEKYLL_DIR | ||
mkdir $JEKYLL_DIR | ||
|
||
node bin/build-jekyll-preview-config $SOURCE_DIR/_config.yml $JEKYLL_DIR/_config.yml | ||
|
||
echo "Copying LB4 readmes" | ||
node bin/copy-readmes | ||
|
||
echo "Copyping Gemfile, index.html and data files" | ||
rm -rf $JEKYLL_DIR/{_data,_includes,_layouts} | ||
cp -r $SOURCE_DIR/Gemfile* $JEKYLL_DIR/ | ||
cp -r $SOURCE_DIR/index.html $JEKYLL_DIR/ | ||
cp -r $SOURCE_DIR/_data $JEKYLL_DIR/ | ||
cp -r $SOURCE_DIR/_includes $JEKYLL_DIR/ | ||
cp -r $SOURCE_DIR/_layouts $JEKYLL_DIR/ | ||
|
||
echo "Copying static assets" | ||
cp -r $SOURCE_DIR/{css,images,dist,js,fonts} $JEKYLL_DIR/ | ||
rm -rf $JEKYLL_DIR/doc | ||
mkdir -p $JEKYLL_DIR/doc | ||
cp -r $SOURCE_DIR/doc/index.md $JEKYLL_DIR/doc | ||
|
||
echo "Setting up LB4 doc pages", | ||
rm -rf $JEKYLL_DIR/pages | ||
ln -s $PWD/site $JEKYLL_DIR/pages | ||
|
||
echo "Setting up sidebar(s)" | ||
rm -rf $JEKYLL_DIR/_data/sidebars | ||
ln -s $PWD/site/sidebars $JEKYLL_DIR/_data/sidebars | ||
|
||
echo "Installing Ruby dependencies" | ||
(cd $JEKYLL_DIR && bundle install) | ||
|
||
echo "Done. Run the following command to start the site:" | ||
echo "" | ||
echo " npm run docs:start" | ||
echo "" | ||
echo "NOTE: Watch mode is not supported yet." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters