Skip to content

Commit 3609804

Browse files
authored
Adds multiple api version support to docgen. (#924)
1 parent b6e22ea commit 3609804

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed
File renamed without changes.
File renamed without changes.

docgen/content-sources/v2/HOME.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Firebase Functions v2 SDK Reference
2+
3+
The `firebase-functions` package provides an SDK for defining Cloud Functions for Firebase.
4+
5+
To get started using Cloud Functions, see
6+
[Get started: write, test, and deploy your first functions](/docs/functions/get-started).
7+
8+
For source code, see the [Cloud Functions for Firebase GitHub repo](https://github.com/firebase/firebase-functions).

docgen/content-sources/v2/toc.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
toc:
2+
- title: globals.html
3+
path: /docs/reference/functions/globals.html
4+
- title: index.html
5+
path: /docs/reference/functions/index.html
6+
- title: logger_common_.html
7+
path: /docs/reference/functions/logger_common_.html
8+
- title: logger_compat_.html
9+
path: /docs/reference/functions/logger_compat_.html
10+
- title: logger_index_.html
11+
path: /docs/reference/functions/logger_index_.html
12+
- title: logger_index_.logentry.html
13+
path: /docs/reference/functions/logger_index_.logentry.html
14+
- title: v2_base_.html
15+
path: /docs/reference/functions/v2_base_.html
16+
- title: v2_index_.html
17+
path: /docs/reference/functions/v2_index_.html
18+
- title: v2_options_.eventhandleroptions.html
19+
path: /docs/reference/functions/v2_options_.eventhandleroptions.html
20+
- title: v2_options_.globaloptions.html
21+
path: /docs/reference/functions/v2_options_.globaloptions.html
22+
- title: v2_options_.html
23+
path: /docs/reference/functions/v2_options_.html
24+
- title: v2_providers_https_.html
25+
path: /docs/reference/functions/v2_providers_https_.html
26+
- title: v2_providers_https_.httpsoptions.html
27+
path: /docs/reference/functions/v2_providers_https_.httpsoptions.html

docgen/generate-docs.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,38 @@ const yaml = require('js-yaml');
2424
const repoPath = path.resolve(`${__dirname}/..`);
2525

2626
// Command-line options.
27-
const { source: sourceFile } = yargs
28-
.option('source', {
29-
default: `${repoPath}/src/{v1,logger}`,
27+
const { api: apiVersion } = yargs
28+
.option('api', {
29+
default: 'v1',
3030
describe: 'Typescript source file(s)',
3131
type: 'string',
3232
})
3333
.version(false)
3434
.help().argv;
3535

36+
let sourceFile;
37+
switch (apiVersion) {
38+
case 'v1':
39+
sourceFile = `${repoPath}/src/{v1,logger}`;
40+
break;
41+
case 'v2':
42+
sourceFile = `${repoPath}/src/{v2,logger}`;
43+
break;
44+
default:
45+
throw new Error(
46+
`Unrecognized version ${apiVersion}, must be one of v1 or v2`
47+
);
48+
}
49+
3650
const docPath = path.resolve(`${__dirname}/html`);
37-
const contentPath = path.resolve(`${__dirname}/content-sources`);
51+
const contentPath = path.resolve(`${__dirname}/content-sources/${apiVersion}`);
3852
const tempHomePath = path.resolve(`${contentPath}/HOME_TEMP.md`);
3953
const devsitePath = `/docs/reference/functions/`;
4054

4155
const { JSDOM } = require('jsdom');
4256

4357
const typeMap = require('./type-aliases.json');
58+
const { existsSync } = require('fs');
4459

4560
/**
4661
* Strips path prefix and returns only filename.
@@ -72,8 +87,10 @@ function runTypedoc() {
7287
* @param {string} subdir Subdir to move files out of.
7388
*/
7489
async function moveFilesToRoot(subdir) {
75-
await exec(`mv ${docPath}/${subdir}/* ${docPath}`);
76-
await exec(`rmdir ${docPath}/${subdir}`);
90+
if (existsSync(`${docPath}/${subdir}`)) {
91+
await exec(`mv ${docPath}/${subdir}/* ${docPath}`);
92+
await exec(`rmdir ${docPath}/${subdir}`);
93+
}
7794
}
7895

7996
/**

0 commit comments

Comments
 (0)