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: split API into Operations and Functions list #613

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions tools/build/src/commands/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const build = async (lang: string) => {
'no-cache': true,
});

// Identify Operations
// TODO we can later add a supporting @operation tag, but this heuristic will go a long way
templateData.forEach(doclet => {
if (
doclet.returns
?.at(0)
?.type?.names.at(0)
.match(/operation/i)
) {
doclet.kind = 'operation';
}
});

// sort template data
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
templateData.sort(function (a, b) {
Expand Down Expand Up @@ -148,6 +161,10 @@ const build = async (lang: string) => {
const destination = `${destinationDir}/index.md`;
await mkdir(destinationDir, { recursive: true });
await writeFile(destination, docs);
await writeFile(
`${destinationDir}/raw.json`,
JSON.stringify(templateData, null, 2)
);
await writeFile(`${destinationDir}/${lang}.json`, JSON.stringify(docsJson));

await writeFile(
Expand Down
65 changes: 56 additions & 9 deletions tools/build/src/util/docs-template.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{{#if (showMainIndex)~}}

{{#globals kind="function" ~}}
{{#if @first~}}{{>heading-indent}}Functions
{{#globals kind="operation" ~}}
{{#if @first}}

#### Operations

<dl>
{{/if~}}
Expand All @@ -12,15 +14,37 @@
{{#if @prefix}}{{@prefix}} {{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{~#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}~}}
{{@codeClose~}}
</a>
{{~/sig}}{{/if~}}
</dt>
{{!-- <dd>{{{md (inlineLinks description)}}}</dd> --}}
{{#if @last~}}</dl>
{{/if~}}
{{/globals~}}
{{!-- {{>global-index-kinds kind="typedef" title="Typedefs" ~}} --}}

{{#globals kind="function"}}
{{#if @first}}

#### Functions

<dl>
{{/if~}}
<dt>
{{#if name}}{{#sig no-gfm=true ~}}
<a href="#{{toLowerCase (anchorName)}}">
{{~{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{@accessSymbol}}{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{~#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{@codeClose~}}
</a>
{{~/sig}}{{/if~}}
</dt>
{{#if @last~}}</dl>
{{/if~}}
{{/globals~}}

{{/if~}}

{{#commonFns}}
Expand All @@ -35,14 +59,37 @@ The following functions are exported from the common adaptor:
{{/if}}
{{/commonFns}}

{{#orphans ~}}
{{>separator~}}

{{#globals kind="operation" ~}}
{{#if @first~}}## Operations

Operations are used at the top level of your job code. You can nest Operations, but you cannot use an Operation within a callback.
{{/if~}}

### {{anchorName}}

{{! operations should list parameters but not returns }}
{{>sig-name}}

{{>body}}
{{>separator~}}

{{/globals~}}

{{#globals kind="function" ~}}
{{#if @first~}}

## Functions

{{>heading-indent}}{{anchorName}}
Functions are regular Javascript functions. They are not state aware, they do not neccessarily take state and they usually don't return state. Functions can only be used inside callback functions.
{{/if~}}

### {{anchorName}}

{{>sig-name}}

{{>body}}
{{>member-index~}}
{{>separator~}}
{{>members~}}
{{/orphans~}}

{{/globals~}}
Loading