Skip to content

[apidocs] Improve file detection and updates toc.yaml #936

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

Merged
merged 2 commits into from
Aug 11, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions docgen/content-sources/v2/toc.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
toc:
- title: globals.html
path: /docs/reference/functions/modules.html
- title: index.html
path: /docs/reference/functions/index.html
- title: logger_common.html
path: /docs/reference/functions/logger_common.html
- title: logger.LogEntry.html
path: /docs/reference/functions/logger.LogEntry.html
- title: v2_core.html
path: /docs/reference/functions/v2_core.html
- title: v2.html
path: /docs/reference/functions/v2.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
- title: functions
path: /docs/functions/alpha/v2.html
- title: functions.core
path: /docs/functions/alpha/v2_core.html
section:
- title: functions.CloudEvent
path: /docs/functions/alpha/v2_core.cloudevent.html
- title: functions.CloudFunction
path: /docs/functions/alpha/v2_core.cloudfunction.html
- title: functions.https
path: /docs/functions/alpha/v2_providers_https.html
section:
- title: functions.https.options
path: /docs/functions/alpha/v2_providers_https.httpsoptions.html
- title: 'functions.logger'
path: /docs/functions/alpha/logger.html
section:
- title: 'LogEntry'
path: /docs/functions/alpha/logger.LogEntry.html
- title: functions.options
path: /docs/functions/alpha/v2_options.html
section:
- title: functions.options.GlobalOptions
path: /docs/functions/alpha/v2_options.globaloptions.html
- title: functions.options.EventHandlerOptions
path: /docs/functions/alpha/v2_options.eventhandleroptions.html
- title: functions.params
path: /docs/functions/alpha/v2_params.html
- title: 'functions.pubsub'
path: /docs/functions/v2_providers_pubsub.html
section:
- title: 'Message'
path: /docs/functions/alpha/v2_providers_pubsub.Message.html
- title: 'TopicBuilder'
path: /docs/functions/alpha/v2_providers_pubsub.MessagePublishedData.html
- title: 'PubSubOptions'
path: /docs/functions/alpha/v2_providers_pubsub.PubSubOptions.html
10 changes: 7 additions & 3 deletions docgen/generate-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ const { api: apiVersion } = yargs
.version(false)
.help().argv;

let sourceFile;
let sourceFile, devsitePath;
switch (apiVersion) {
case 'v1':
sourceFile = `${repoPath}/src/{v1,logger}`;
devsitePath = '/docs/reference/functions/';
break;
case 'v2':
sourceFile = `${repoPath}/src/{v2,logger}`;
devsitePath = '/docs/functions/alpha/';
break;
default:
throw new Error(
Expand All @@ -50,7 +52,6 @@ switch (apiVersion) {
const docPath = path.resolve(`${__dirname}/html`);
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');

Expand Down Expand Up @@ -198,7 +199,10 @@ async function checkForMissingFilesAndFixFilenameCase(tocText) {
const filenames = tocText
.split('\n')
.filter((line) => line.includes('path:'))
.map((line) => line.split(devsitePath)[1].replace(/#.*$/, ''));
.map((line) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I would have had no idea how to refactor that.

Do we need to update the value for 'const devsitePath' as well? Or does this basically override that and extrapolate it from the toc.yaml file (which makes a lot of sense, since that is in a versioned directory that can be updated as we go)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other thing devsitePath feeds is _toc_autogenerated.yaml which I'm not sure if you use. That being said, I now fork devsitePath based on version.

parts = line.split('/');
return parts[parts.length - 1].replace(/#.*$/, '');
});
// Logs warning to console if a file from TOC is not found.
const fileCheckPromises = filenames.map(async (filename) => {
// Warns if file does not exist, fixes filename case if it does.
Expand Down