Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix the doc generator #1489

Merged
merged 4 commits into from Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .compodocrc
@@ -0,0 +1,10 @@
---
tsconfig: ./tsconfig.json
output: ./docs
theme: material
hideGenerator: true
disablePrivate: true
disableProtected: true
disableInternal: true
disableCoverage: true
disableGraph: true
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@
* [Installation](#installation)
* [First example](#first-example)
* [Samples](#samples)
* [Reference API](#reference-api)
* [API Reference](#api-reference)
* [Authentication and authorization](#authentication-and-authorization)
* [OAuth2 client](#oauth2-client)
* [Using API keys](#using-api-keys)
Expand Down Expand Up @@ -108,6 +108,9 @@ runSample().catch(console.error);
### Samples
There are a lot of [samples](https://github.com/googleapis/google-api-nodejs-client/tree/master/samples) 🤗 If you're trying to figure out how to use an API ... look there first! If there's a sample you need missing, feel free to file an [issue][bugs].

### API Reference
This library has a full set of [API Reference Documenation](https://apis-nodejs.firebaseapp.com/). This documentation is auto-generated, and the location may change.

## Authentication and authorization
The are three primary ways to authenticate to Google APIs. Some service support all authentication methods, other may only support one or two.

Expand Down
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -25,7 +25,9 @@
"pretest": "npm run compile",
"prepare": "npm run compile",
"test": "nyc mocha build/test",
"docs": "echo no docs 👻",
"docs": "echo your docs are in another castle 🏰",
"pregenerate-docs": "npm run build-tools",
"generate-docs": "node build/src/generator/docs",
"system-test": "mocha build/system-test",
"samples-test": "cd samples && npm link ../ && pwd && npm test",
"lint": "gts check && eslint 'samples/**/*.js'",
Expand Down Expand Up @@ -53,6 +55,8 @@
"node": ">=6.0"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.7",
"@types/execa": "^0.9.0",
"@types/minimist": "^1.2.0",
"@types/mkdirp": "^0.5.2",
"@types/mocha": "^5.2.0",
Expand All @@ -75,6 +79,7 @@
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"execa": "^1.0.0",
"gts": "^0.9.0",
"hard-rejection": "^1.0.0",
"intelli-espower-loader": "^1.0.1",
Expand Down
58 changes: 58 additions & 0 deletions src/generator/docs.ts
@@ -0,0 +1,58 @@
/**
* Copyright 2018 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as execa from 'execa';
import * as fs from 'fs';
import * as nunjucks from 'nunjucks';
import * as Q from 'p-queue';
import * as path from 'path';
import {promisify} from 'util';

const readdir = promisify(fs.readdir);
const writeFile = promisify(fs.writeFile);
const srcPath = path.join(__dirname, '../../../src');
const apiPath = path.join(srcPath, 'apis');
const templatePath = path.join(srcPath, 'generator/templates/index.html.njk');
const indexPath = path.join(__dirname, '../../../docs/index.html');

/**
* Iterate over each API directory, and use the `compodoc` tool to generate
* reference API documentation in the `docs` folder. This folder is ignored
* in git, so a publish must be done with `npm run publish-docs`.
*
* To use this, run `npm run generate-docs`.
*/
async function main() {
const children = await readdir(apiPath);
const dirs = children.filter(x => !x.endsWith('.ts'));
const contents = nunjucks.render(templatePath, {apis: dirs});
await writeFile(indexPath, contents);
const q = new Q({concurrency: 10});
console.log(`Generating docs for ${dirs.length} APIs...`);
let i = 0;
const promises = dirs.map(dir => {
return q
.add(
() => execa(
'npx', ['compodoc', `src/apis/${dir}`, '-d', `./docs/${dir}`]))
.then(() => {
i++;
console.log(`[${i}/${dirs.length}] ${dir}`);
});
});
await Promise.all(promises);
}
main().catch(console.error);
41 changes: 41 additions & 0 deletions src/generator/templates/index.html.njk
@@ -0,0 +1,41 @@
<html>
<head>
<style type="text/css">
html, body {
font-family: roboto, sans-serif;
margin: 0px;
}
header {
background-color: #EEE;
padding: 10px;
font-size: 20px;
color: #666;
}
header img {
width: 50px;
vertical-align: middle;
padding-right: 10px;
}
ul {
list-style-type: none;
column-count: 3;
}
a {
text-decoration: none;
color: #337ab7;
}

</style>
</head>
<body>
<header>
<img src="https://avatars0.githubusercontent.com/u/1342004?v=3&s=96">
<span>Google API Node.js Client</span>
</header>
<ul>
{% for api in apis %}
<li><a href='{{api}}/index.html'>{{api}}</a></li>
{% endfor %}
</ul>
</body>
</html>