From 78114a955d6b2b94dd5f4443f4b7d478cbff6ad5 Mon Sep 17 00:00:00 2001 From: flakey5 <73616808+flakey5@users.noreply.github.com> Date: Mon, 3 Nov 2025 13:12:07 -0800 Subject: [PATCH] fix: add legacy-html-assets generator Move asset folder copying to its own generator that we can call separately from the legacy-html generator Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com> --- bin/commands/generate.mjs | 5 +- eslint.config.mjs | 2 +- src/generators/index.mjs | 2 + .../assets/api.js | 0 .../assets/js-flavor-cjs.svg | 0 .../assets/js-flavor-esm.svg | 0 .../assets/style.css | 0 src/generators/legacy-html-assets/index.mjs | 50 +++++++++++++++++++ src/generators/legacy-html/index.mjs | 20 +------- 9 files changed, 56 insertions(+), 23 deletions(-) rename src/generators/{legacy-html => legacy-html-assets}/assets/api.js (100%) rename src/generators/{legacy-html => legacy-html-assets}/assets/js-flavor-cjs.svg (100%) rename src/generators/{legacy-html => legacy-html-assets}/assets/js-flavor-esm.svg (100%) rename src/generators/{legacy-html => legacy-html-assets}/assets/style.css (100%) create mode 100644 src/generators/legacy-html-assets/index.mjs diff --git a/bin/commands/generate.mjs b/bin/commands/generate.mjs index e51fa2b7..024fcb76 100644 --- a/bin/commands/generate.mjs +++ b/bin/commands/generate.mjs @@ -18,7 +18,7 @@ const availableGenerators = Object.keys(publicGenerators); /** * @typedef {Object} Options - * @property {Array|string} input - Specifies the glob/path for input files. + * @property {Array|string} [input] - Specifies the glob/path for input files. * @property {Array|string} [ignore] - Specifies the glob/path for ignoring files. * @property {Array} target - Specifies the generator target mode. * @property {string} version - Specifies the target Node.js version. @@ -42,7 +42,6 @@ export default { type: 'text', message: 'Enter input glob patterns', variadic: true, - required: true, }, }, ignore: { @@ -131,7 +130,7 @@ export default { * @returns {Promise} */ 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); diff --git a/eslint.config.mjs b/eslint.config.mjs index 6076d288..2d5522c8 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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: { diff --git a/src/generators/index.mjs b/src/generators/index.mjs index cca7767e..a4d1b8eb 100644 --- a/src/generators/index.mjs +++ b/src/generators/index.mjs @@ -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'; @@ -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, diff --git a/src/generators/legacy-html/assets/api.js b/src/generators/legacy-html-assets/assets/api.js similarity index 100% rename from src/generators/legacy-html/assets/api.js rename to src/generators/legacy-html-assets/assets/api.js diff --git a/src/generators/legacy-html/assets/js-flavor-cjs.svg b/src/generators/legacy-html-assets/assets/js-flavor-cjs.svg similarity index 100% rename from src/generators/legacy-html/assets/js-flavor-cjs.svg rename to src/generators/legacy-html-assets/assets/js-flavor-cjs.svg diff --git a/src/generators/legacy-html/assets/js-flavor-esm.svg b/src/generators/legacy-html-assets/assets/js-flavor-esm.svg similarity index 100% rename from src/generators/legacy-html/assets/js-flavor-esm.svg rename to src/generators/legacy-html-assets/assets/js-flavor-esm.svg diff --git a/src/generators/legacy-html/assets/style.css b/src/generators/legacy-html-assets/assets/style.css similarity index 100% rename from src/generators/legacy-html/assets/style.css rename to src/generators/legacy-html-assets/assets/style.css diff --git a/src/generators/legacy-html-assets/index.mjs b/src/generators/legacy-html-assets/index.mjs new file mode 100644 index 00000000..da3e462d --- /dev/null +++ b/src/generators/legacy-html-assets/index.mjs @@ -0,0 +1,50 @@ +// @ts-check +'use strict'; + +import { cp, rm } from 'node:fs/promises'; +import { join } from 'node:path'; + +/** + * TODO docs + * + * @type {GeneratorMetadata>} + */ +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} 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, + }); + }, +}; diff --git a/src/generators/legacy-html/index.mjs b/src/generators/legacy-html/index.mjs index f8c1e58f..f99e8dc0 100644 --- a/src/generators/legacy-html/index.mjs +++ b/src/generators/legacy-html/index.mjs @@ -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'; @@ -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; }, };