Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ updates:
- '@eslint/*'
- 'globals'
- 'stylelint-*'
orama:
patterns:
- '@orama/*'
open-pull-requests-limit: 10
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ Options:
-o, --output <path> Specify the relative or absolute output directory
-v, --version <semver> Specify the target version of Node.js, semver compliant (default: "v22.6.0")
-c, --changelog <url> Specify the path (file: or https://) to the CHANGELOG.md file (default: "https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md")
-t, --target [mode...] Set the processing target modes (choices: "json-simple", "legacy-html", "legacy-html-all", "man-page", "legacy-json", "legacy-json-all", "addon-verify", "api-links")
-t, --target [mode...] Set the processing target modes (choices: "json-simple", "legacy-html", "legacy-html-all", "man-page", "legacy-json", "legacy-json-all", "addon-verify", "api-links", "orama-db")
-h, --help display help for command
```
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
"prettier": "3.5.2"
},
"dependencies": {
"acorn": "^8.14.0",
"@actions/core": "^1.11.1",
"@orama/orama": "^3.1.3",
"@orama/plugin-data-persistence": "^3.1.3",
"acorn": "^8.14.0",
"commander": "^13.1.0",
"estree-util-visit": "^2.0.0",
"dedent": "^1.5.3",
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"glob": "^11.0.1",
"hast-util-to-string": "^3.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import publicGenerators from './generators/index.mjs';
import astJs from './generators/ast-js/index.mjs';
import oramaDb from './generators/orama-db/index.mjs';

const availableGenerators = {
...publicGenerators,
// This one is a little special since we don't want it to run unless we need
// it and we also don't want it to be publicly accessible through the CLI.
'ast-js': astJs,
'orama-db': oramaDb,
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/generators/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import legacyJson from './legacy-json/index.mjs';
import legacyJsonAll from './legacy-json-all/index.mjs';
import addonVerify from './addon-verify/index.mjs';
import apiLinks from './api-links/index.mjs';
import oramaDb from './orama-db/index.mjs';

export default {
'json-simple': jsonSimple,
Expand All @@ -18,4 +19,5 @@ export default {
'legacy-json-all': legacyJsonAll,
'addon-verify': addonVerify,
'api-links': apiLinks,
'orama-db': oramaDb,
};
95 changes: 95 additions & 0 deletions src/generators/orama-db/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

import { create } from '@orama/orama';
import { persistToFile } from '@orama/plugin-data-persistence/server';
import { groupNodesByModule } from '../../utils/generators.mjs';
Comment thread
AugustinMauroy marked this conversation as resolved.
import { createSectionBuilder } from '../legacy-json/utils/buildSection.mjs';

/**
* This generator is responsible for generating the Orama database for the
* API docs. It is based on the legacy-json generator.
*
* @typedef {Array<ApiDocMetadataEntry>} Input
*
* @type {import('../types.d.ts').GeneratorMetadata<Input, import('./types.d.ts').OramaDb>}
Comment thread
AugustinMauroy marked this conversation as resolved.
*/
export default {
name: 'orama-db',

version: '1.0.0',

description: 'Generates the Orama database for the API docs.',

dependsOn: 'ast',

/**
* Generates the Orama database.
*
* @param {Input} input
* @param {Partial<GeneratorOptions>} options
*/
async generate(input, { output, version }) {
const buildSection = createSectionBuilder();

// Create the Orama instance with the schema
const db = create({
schema: {
name: 'string',
type: 'string',
desc: 'string',
stability: 'number',
stabilityText: 'string',
meta: {
changes: 'string[]',
added: 'string[]',
napiVersion: 'string[]',
deprecated: 'string[]',
removed: 'string[]',
},
},
});

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').OramaDbEntry}
Comment thread
AugustinMauroy marked this conversation as resolved.
Outdated
*/
const processModuleNodes = head => {
const nodes = groupedModules.get(head.api);

const section = buildSection(head, nodes);

// Insert data into the Orama instance
db.insert({
name: section.name,
type: section.type,
desc: section.desc,
stability: section.stability,
stabilityText: section.stabilityText,
meta: {
changes: section.meta.changes,
added: section.meta.added,
napiVersion: section.meta.napiVersion,
deprecated: section.meta.deprecated,
removed: section.meta.removed,
},
});

return section;
};

headNodes.map(processModuleNodes);

await persistToFile(
db,
'json',
`${output}/${version.raw.replaceAll('.', '-')}-orama-db.json`
);

return db;
},
};