Skip to content

Commit

Permalink
build(docs): include package READMEs at publish time
Browse files Browse the repository at this point in the history
Add a script to copy per-package README files `docs/site/readmes`,
run it as part of the release process.
  • Loading branch information
bajtos committed Nov 14, 2018
1 parent 8d2b9bc commit b7be5c9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ benchmark/dist
**/package
.sandbox
packages/cli/generators/datasource/connectors.json
docs/site/readmes

# Exclude all files under sandbox except README.md and example
/sandbox/*
Expand Down
3 changes: 3 additions & 0 deletions bin/build-docs-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ DIR=`dirname $0`
REPO_ROOT=$DIR/..
pushd $REPO_ROOT >/dev/null

# Update README duplicates inside docs/site/readmes
node docs/bin/copy-readmes.js

# Clean up sandbox/loopback.io directory
rm -rf sandbox/loopback.io/

Expand Down
52 changes: 52 additions & 0 deletions docs/bin/copy-readmes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: loopback-next
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

/*
* This is an internal script to gather READMEs of all packages
* in our monorepo and copy them to `site/readmes` for consumption
* from the docs.
*/

const Project = require('@lerna/project');
const fs = require('fs-extra');
const path = require('path');

const REPO_ROOT = path.resolve(__dirname, '../..');
const DEST_ROOT = path.resolve(__dirname, '../site/readmes/loopback-next');

copyReadmes().catch(err => {
console.error('Unhandled error.', err);
process.exit(1);
});

async function copyReadmes() {
// Remove the original folder so we remove files from deleted packages
fs.removeSync(DEST_ROOT);

const project = new Project(REPO_ROOT);
const allPackages = await project.getPackages();

const packages = allPackages.filter(isDocumented).map(pkg => ({
name: pkg.name,
location: path.relative(REPO_ROOT, pkg.location),
}));

for (const {location} of packages) {
const src = path.join(REPO_ROOT, location, 'README.md');
const dest = path.join(DEST_ROOT, location, 'README.md');
await fs.copy(src, dest, {overwrite: true});
}
}

function isDocumented(pkg) {
return (
!pkg.name.startsWith('@loopback/sandbox-') &&
pkg.name !== '@loopback/docs' &&
pkg.name !== '@loopback/benchmark'
);
}
8 changes: 6 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
"scripts": {
"build:apidocs": "lb-apidocs --html-file=index.html",
"clean": "lb-clean loopback-docs*.tgz package api-docs"
"prepublishOnly": "node ./bin/copy-readmes",
"clean": "lb-clean loopback-docs*.tgz package api-docs site/readmes"
},
"devDependencies": {
"@loopback/build": "^1.0.1"
Expand All @@ -31,5 +32,8 @@
"url": "https://github.com/strongloop/loopback-next"
},
"copyright.owner": "IBM Corp.",
"license": "MIT"
"license": "MIT",
"dependencies": {
"fs-extra": "^7.0.1"
}
}

0 comments on commit b7be5c9

Please sign in to comment.