Skip to content

Commit

Permalink
chore: add generating docs/site/MONOREPO.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
spirAde authored and raymondfeng committed Jun 11, 2020
1 parent 3f14bfa commit 188faed
Show file tree
Hide file tree
Showing 42 changed files with 207 additions and 104 deletions.
2 changes: 1 addition & 1 deletion acceptance/extension-logging-fluentd/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/test-extension-logging-fluentd",
"version": "0.3.6",
"description": "Acceptance test for extension-logging with fluentd",
"description": "Acceptance test for `@loopback/extension-logging` with fluentd",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion acceptance/repository-cloudant/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/test-repository-cloudant",
"version": "2.2.2",
"description": "",
"description": "Acceptance tests for `@loopback/repository` + `loopback-connector-cloudant`",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion acceptance/repository-mongodb/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/test-repository-mongodb",
"version": "0.7.6",
"description": "",
"description": "Acceptance tests for `@loopback/repository` + `loopback-connector-mongodb`",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion acceptance/repository-mysql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/test-repository-mysql",
"version": "0.7.6",
"description": "",
"description": "Acceptance tests for `@loopback/repository` + `loopback-connector-mysql`",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion acceptance/repository-postgresql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/test-repository-postgresql",
"version": "2.1.6",
"description": "",
"description": "Acceptance tests for `@loopback/repository` + `loopback-connector-postgresql`",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
86 changes: 86 additions & 0 deletions bin/update-monorepo-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2020. All Rights Reserved.
// Node module: loopback-next
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/**
* This is an internal script to update docs/site MONOREPO.md file with filling
* up all packages with lexicographical order
*/
'use strict';

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

const MONOREPO_FILE_DIST = 'docs/site';
const MONOREPO_FILE_NAME = 'MONOREPO.md';

function getPackageRelativeUri(pkg) {
return path.relative(pkg.rootPath, pkg.location);
}

async function getSortedPackages() {
const project = new Project(process.cwd());
const packages = await project.getPackages();
packages.sort((p1, p2) =>
getPackageRelativeUri(p1).localeCompare(getPackageRelativeUri(p2)),
);
return packages;
}

function getPackageFields(pkg) {
const packageJson = fs.readJsonSync(path.join(pkg.location, 'package.json'));

const relativeUri = getPackageRelativeUri(pkg);
const pkgUrl = `https://github.com/strongloop/loopback-next/tree/master/${relativeUri}`;

return [
`[${relativeUri}](${pkgUrl})`,
pkg.private ? '_(private)_' : pkg.name,
packageJson.description,
];
}

function updateTable(packages) {
const header = ['Package', 'npm', 'Description'];
const rows = packages.map(getPackageFields);

return createMarkdownTable([header, ...rows]);
}

async function updateMonorepoFile() {
const packages = await getSortedPackages();
const markdownTable = updateTable(packages);
const monorepoFilePath = path.join(MONOREPO_FILE_DIST, MONOREPO_FILE_NAME);

const content = [
'<!-- Do not edit this file. It is automatically generated by update-monorepo-file script -->',
'',
'# Monorepo overview',
'',
'The [loopback-next](https://github.com/strongloop/loopback-next) repository uses',
'[lerna](https://lernajs.io/) to manage multiple packages for LoopBack 4.',
'',
'Please run the following command to update packages information after adding new',
'one in the monorepo: `npm run update-monorepo-file`',
'',
markdownTable,
'',
'We use npm scripts declared in',
'[package.json](https://github.com/strongloop/loopback-next/blob/master/package.json)',
'to work with the monorepo managed by lerna. See',
'[Developing LoopBack](./DEVELOPING.md) for more details.',
].join('\n');

fs.writeFileSync(monorepoFilePath, content + '\n', {encoding: 'utf-8'});
}

if (require.main === module) {
updateMonorepoFile().catch(err => {
console.error(err);
process.exit(1);
});
}
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/docs",
"version": "3.8.2",
"description": "Documentation for LoopBack 4",
"description": "Documentation files rendered at [https://loopback.io](https://loopback.io)",
"homepage": "https://github.com/strongloop/loopback-next/tree/master/docs",
"author": "IBM Corp.",
"copyright.owner": "IBM Corp.",
Expand Down
6 changes: 4 additions & 2 deletions docs/site/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,10 @@ and falls back to `extensions`.

6. Run `update-ts-project-refs` to update TypeScript project references

7. Remind to update `CODEOWNERS` and `docs/site/MONOREPO.md` If you would like
to do it manually, follow steps below:
7. Run `update-monorepo-file` to update `docs/site/MONOREPO.md`

8. Remind to update `CODEOWNERS`. If you would like to do it manually, follow
steps below:

To add a new package by hand, create a folder in
[`packages`](https://github.com/strongloop/loopback-next/tree/master/packages)
Expand Down
Loading

0 comments on commit 188faed

Please sign in to comment.