-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: flakey5 <73616808+flakey5@users.noreply.github.com> Co-authored-by: Claudio W <cwunder@gnome.org>
- Loading branch information
1 parent
4963da2
commit 8f40d5c
Showing
21 changed files
with
1,136 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
import { writeFile } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
|
||
/** | ||
* This generator consolidates data from the `legacy-json` generator into a single | ||
* JSON file (`all.json`). | ||
* | ||
* @typedef {Array<import('../legacy-json/types.d.ts').Section>} Input | ||
* | ||
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').Output>} | ||
*/ | ||
export default { | ||
name: 'legacy-json-all', | ||
|
||
version: '1.0.0', | ||
|
||
description: | ||
'Generates the `all.json` file from the `legacy-json` generator, which includes all the modules in one single file.', | ||
|
||
dependsOn: 'legacy-json', | ||
|
||
/** | ||
* Generates the legacy JSON `all.json` file. | ||
* | ||
* @param {Input} input | ||
* @param {Partial<GeneratorOptions>} options | ||
*/ | ||
async generate(input, { output }) { | ||
/** | ||
* The consolidated output object that will contain | ||
* combined data from all sections in the input. | ||
* | ||
* @type {import('./types.d.ts').Output} | ||
*/ | ||
const generatedValue = { | ||
miscs: [], | ||
modules: [], | ||
classes: [], | ||
globals: [], | ||
methods: [], | ||
}; | ||
|
||
const propertiesToCopy = [ | ||
'miscs', | ||
'modules', | ||
'classes', | ||
'globals', | ||
'methods', | ||
]; | ||
|
||
input.forEach(section => { | ||
// Copy the relevant properties from each section into our output | ||
propertiesToCopy.forEach(property => { | ||
if (section[property]) { | ||
generatedValue[property].push(...section[property]); | ||
} | ||
}); | ||
}); | ||
|
||
if (output) { | ||
await writeFile(join(output, 'all.json'), JSON.stringify(generatedValue)); | ||
} | ||
|
||
return generatedValue; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
MiscSection, | ||
Section, | ||
SignatureSection, | ||
ModuleSection, | ||
} from '../legacy-json/types'; | ||
|
||
export interface Output { | ||
miscs: Array<MiscSection>; | ||
modules: Array<Section>; | ||
classes: Array<SignatureSection>; | ||
globals: Array<ModuleSection | { type: 'global' }>; | ||
methods: Array<SignatureSection>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Grabs a method's return value | ||
export const RETURN_EXPRESSION = /^returns?\s*:?\s*/i; | ||
|
||
// Grabs a method's name | ||
export const NAME_EXPRESSION = /^['`"]?([^'`": {]+)['`"]?\s*:?\s*/; | ||
|
||
// Denotes a method's type | ||
export const TYPE_EXPRESSION = /^\{([^}]+)\}\s*/; | ||
|
||
// Checks if there's a leading hyphen | ||
export const LEADING_HYPHEN = /^-\s*/; | ||
|
||
// Grabs the default value if present | ||
export const DEFAULT_EXPRESSION = /\s*\*\*Default:\*\*\s*([^]+)$/i; | ||
|
||
// Grabs the parameters from a method's signature | ||
// ex/ 'new buffer.Blob([sources[, options]])'.match(PARAM_EXPRESSION) === ['([sources[, options]])', '[sources[, options]]'] | ||
export const PARAM_EXPRESSION = /\((.+)\);?$/; | ||
|
||
// The plurals associated with each section type. | ||
export const SECTION_TYPE_PLURALS = { | ||
module: 'modules', | ||
misc: 'miscs', | ||
class: 'classes', | ||
method: 'methods', | ||
property: 'properties', | ||
global: 'globals', | ||
example: 'examples', | ||
ctor: 'signatures', | ||
classMethod: 'classMethods', | ||
event: 'events', | ||
var: 'vars', | ||
}; | ||
|
||
// The keys to not promote when promoting children. | ||
export const UNPROMOTED_KEYS = ['textRaw', 'name', 'type', 'desc', 'miscs']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
import { writeFile } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
import { groupNodesByModule } from '../../utils/generators.mjs'; | ||
import { createSectionBuilder } from './utils/buildSection.mjs'; | ||
|
||
/** | ||
* This generator is responsible for generating the legacy JSON files for the | ||
* legacy API docs for retro-compatibility. It is to be replaced while we work | ||
* on the new schema for this file. | ||
* | ||
* This is a top-level generator, intaking the raw AST tree of the api docs. | ||
* It generates JSON files to the specified output directory given by the | ||
* config. | ||
* | ||
* @typedef {Array<ApiDocMetadataEntry>} Input | ||
* | ||
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').Section[]>} | ||
*/ | ||
export default { | ||
name: 'legacy-json', | ||
|
||
version: '1.0.0', | ||
|
||
description: 'Generates the legacy version of the JSON API docs.', | ||
|
||
dependsOn: 'ast', | ||
|
||
/** | ||
* Generates a legacy JSON file. | ||
* | ||
* @param {Input} input | ||
* @param {Partial<GeneratorOptions>} options | ||
*/ | ||
async generate(input, { output }) { | ||
const buildSection = createSectionBuilder(); | ||
|
||
// This array holds all the generated values for each module | ||
const generatedValues = []; | ||
|
||
const groupedModules = groupNodesByModule(input); | ||
|
||
// Gets the first nodes of each module, which is considered the "head" | ||
const headNodes = input.filter(node => node.heading.depth === 1); | ||
|
||
/** | ||
* @param {ApiDocMetadataEntry} head | ||
* @returns {import('./types.d.ts').ModuleSection} | ||
*/ | ||
const processModuleNodes = head => { | ||
const nodes = groupedModules.get(head.api); | ||
|
||
const section = buildSection(head, nodes); | ||
generatedValues.push(section); | ||
|
||
return section; | ||
}; | ||
|
||
await Promise.all( | ||
headNodes.map(async node => { | ||
// Get the json for the node's section | ||
const section = processModuleNodes(node); | ||
|
||
// Write it to the output file | ||
if (output) { | ||
await writeFile( | ||
join(output, `${node.api}.json`), | ||
JSON.stringify(section) | ||
); | ||
} | ||
}) | ||
); | ||
|
||
return generatedValues; | ||
}, | ||
}; |
Oops, something went wrong.