Skip to content
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
5 changes: 2 additions & 3 deletions bin/commands/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const availableGenerators = Object.keys(publicGenerators);

/**
* @typedef {Object} Options
* @property {Array<string>|string} input - Specifies the glob/path for input files.
* @property {Array<string>|string} [input] - Specifies the glob/path for input files.
* @property {Array<string>|string} [ignore] - Specifies the glob/path for ignoring files.
* @property {Array<keyof publicGenerators>} target - Specifies the generator target mode.
* @property {string} version - Specifies the target Node.js version.
Expand All @@ -42,7 +42,6 @@ export default {
type: 'text',
message: 'Enter input glob patterns',
variadic: true,
required: true,
},
},
ignore: {
Expand Down Expand Up @@ -131,7 +130,7 @@ export default {
* @returns {Promise<void>}
*/
async action(opts) {
const docs = await loadAndParse(opts.input, opts.ignore);
const docs = await loadAndParse(opts.inpu ?? [], opts.ignore);
const releases = await parseChangelog(opts.changelog);

const rawTypeMap = await loadFromURL(opts.typeMap);
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default defineConfig([
},
{
files: [
'src/generators/legacy-html/assets/*.js',
'src/generators/legacy-html-assets/assets/*.js',
'src/generators/web/ui/**/*',
],
languageOptions: {
Expand Down
2 changes: 2 additions & 0 deletions src/generators/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jsonSimple from './json-simple/index.mjs';
import jsxAst from './jsx-ast/index.mjs';
import legacyHtml from './legacy-html/index.mjs';
import legacyHtmlAll from './legacy-html-all/index.mjs';
import legacyHtmlAssets from './legacy-html-assets/index.mjs';
import legacyJson from './legacy-json/index.mjs';
import legacyJsonAll from './legacy-json-all/index.mjs';
import llmsTxt from './llms-txt/index.mjs';
Expand All @@ -18,6 +19,7 @@ import web from './web/index.mjs';
export const publicGenerators = {
'json-simple': jsonSimple,
'legacy-html': legacyHtml,
'legacy-html-assets': legacyHtmlAssets,
'legacy-html-all': legacyHtmlAll,
'man-page': manPage,
'legacy-json': legacyJson,
Expand Down
50 changes: 50 additions & 0 deletions src/generators/legacy-html-assets/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @ts-check
'use strict';

import { cp, rm } from 'node:fs/promises';
import { join } from 'node:path';

/**
* TODO docs
*
* @type {GeneratorMetadata<Input, Array<TemplateValues>>}
*/
export default {
name: 'legacy-html-assets',

version: '1.0.0',

description: 'TODO',

dependsOn: 'metadata',

/**
* Generates the legacy version of the API docs in HTML
* @param {Input} _
* @param {Partial<GeneratorOptions>} options
*/
async generate(_, { output }) {
if (!output) {
return;
}

// Define the output folder for API docs assets
const assetsFolder = join(output, 'assets');

// Removes the current assets directory to copy the new assets
// and prevent stale assets from existing in the output directory
// If the path does not exists, it will simply ignore and continue
await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 });

// Current directory path relative to the `index.mjs` file
const baseDir = import.meta.dirname;

// We copy all the other assets to the output folder at the end of the process
// to ensure that all latest changes on the styles are applied to the output
// Note.: This is not meant to be used for DX/developer purposes.
await cp(join(baseDir, 'assets'), assetsFolder, {
recursive: true,
force: true,
});
},
};
20 changes: 1 addition & 19 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { cp, readFile, rm, writeFile } from 'node:fs/promises';
import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import HTMLMinifier from '@minify-html/node';
Expand Down Expand Up @@ -168,24 +168,6 @@ export default {
}
}

if (output) {
// Define the output folder for API docs assets
const assetsFolder = join(output, 'assets');

// Removes the current assets directory to copy the new assets
// and prevent stale assets from existing in the output directory
// If the path does not exists, it will simply ignore and continue
await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 });

// We copy all the other assets to the output folder at the end of the process
// to ensure that all latest changes on the styles are applied to the output
// Note.: This is not meant to be used for DX/developer purposes.
await cp(join(baseDir, 'assets'), assetsFolder, {
recursive: true,
force: true,
});
}

return generatedValues;
},
};
Loading