From 2a07d503a061a05881378a3e5e52410188a29d94 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 29 Jul 2021 13:34:43 -0700 Subject: [PATCH] Adds multiple api version support to docgen. --- docgen/content-sources/{ => v1}/HOME.md | 0 docgen/content-sources/{ => v1}/toc.yaml | 0 docgen/content-sources/v2/HOME.md | 8 +++++++ docgen/content-sources/v2/toc.yaml | 27 ++++++++++++++++++++++ docgen/generate-docs.js | 29 +++++++++++++++++++----- 5 files changed, 58 insertions(+), 6 deletions(-) rename docgen/content-sources/{ => v1}/HOME.md (100%) rename docgen/content-sources/{ => v1}/toc.yaml (100%) create mode 100644 docgen/content-sources/v2/HOME.md create mode 100644 docgen/content-sources/v2/toc.yaml diff --git a/docgen/content-sources/HOME.md b/docgen/content-sources/v1/HOME.md similarity index 100% rename from docgen/content-sources/HOME.md rename to docgen/content-sources/v1/HOME.md diff --git a/docgen/content-sources/toc.yaml b/docgen/content-sources/v1/toc.yaml similarity index 100% rename from docgen/content-sources/toc.yaml rename to docgen/content-sources/v1/toc.yaml diff --git a/docgen/content-sources/v2/HOME.md b/docgen/content-sources/v2/HOME.md new file mode 100644 index 000000000..d70db12a3 --- /dev/null +++ b/docgen/content-sources/v2/HOME.md @@ -0,0 +1,8 @@ +# Firebase Functions v2 SDK Reference + +The `firebase-functions` package provides an SDK for defining Cloud Functions for Firebase. + +To get started using Cloud Functions, see +[Get started: write, test, and deploy your first functions](/docs/functions/get-started). + +For source code, see the [Cloud Functions for Firebase GitHub repo](https://github.com/firebase/firebase-functions). diff --git a/docgen/content-sources/v2/toc.yaml b/docgen/content-sources/v2/toc.yaml new file mode 100644 index 000000000..04b95a495 --- /dev/null +++ b/docgen/content-sources/v2/toc.yaml @@ -0,0 +1,27 @@ +toc: + - title: globals.html + path: /docs/reference/functions/globals.html + - title: index.html + path: /docs/reference/functions/index.html + - title: logger_common_.html + path: /docs/reference/functions/logger_common_.html + - title: logger_compat_.html + path: /docs/reference/functions/logger_compat_.html + - title: logger_index_.html + path: /docs/reference/functions/logger_index_.html + - title: logger_index_.logentry.html + path: /docs/reference/functions/logger_index_.logentry.html + - title: v2_base_.html + path: /docs/reference/functions/v2_base_.html + - title: v2_index_.html + path: /docs/reference/functions/v2_index_.html + - title: v2_options_.eventhandleroptions.html + path: /docs/reference/functions/v2_options_.eventhandleroptions.html + - title: v2_options_.globaloptions.html + path: /docs/reference/functions/v2_options_.globaloptions.html + - title: v2_options_.html + path: /docs/reference/functions/v2_options_.html + - title: v2_providers_https_.html + path: /docs/reference/functions/v2_providers_https_.html + - title: v2_providers_https_.httpsoptions.html + path: /docs/reference/functions/v2_providers_https_.httpsoptions.html diff --git a/docgen/generate-docs.js b/docgen/generate-docs.js index 2f8b9abb0..5e66392cf 100644 --- a/docgen/generate-docs.js +++ b/docgen/generate-docs.js @@ -24,23 +24,38 @@ const yaml = require('js-yaml'); const repoPath = path.resolve(`${__dirname}/..`); // Command-line options. -const { source: sourceFile } = yargs - .option('source', { - default: `${repoPath}/src/{v1,logger}`, +const { api: apiVersion } = yargs + .option('api', { + default: 'v1', describe: 'Typescript source file(s)', type: 'string', }) .version(false) .help().argv; +let sourceFile; +switch (apiVersion) { + case 'v1': + sourceFile = `${repoPath}/src/{v1,logger}`; + break; + case 'v2': + sourceFile = `${repoPath}/src/{v2,logger}`; + break; + default: + throw new Error( + `Unrecognized version ${apiVersion}, must be one of v1 or v2` + ); +} + const docPath = path.resolve(`${__dirname}/html`); -const contentPath = path.resolve(`${__dirname}/content-sources`); +const contentPath = path.resolve(`${__dirname}/content-sources/${apiVersion}`); const tempHomePath = path.resolve(`${contentPath}/HOME_TEMP.md`); const devsitePath = `/docs/reference/functions/`; const { JSDOM } = require('jsdom'); const typeMap = require('./type-aliases.json'); +const { existsSync } = require('fs'); /** * Strips path prefix and returns only filename. @@ -72,8 +87,10 @@ function runTypedoc() { * @param {string} subdir Subdir to move files out of. */ async function moveFilesToRoot(subdir) { - await exec(`mv ${docPath}/${subdir}/* ${docPath}`); - await exec(`rmdir ${docPath}/${subdir}`); + if (existsSync(`${docPath}/${subdir}`)) { + await exec(`mv ${docPath}/${subdir}/* ${docPath}`); + await exec(`rmdir ${docPath}/${subdir}`); + } } /**