Skip to content

Commit 78114a9

Browse files
committed
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 <[email protected]>
1 parent dca59d6 commit 78114a9

File tree

9 files changed

+56
-23
lines changed

9 files changed

+56
-23
lines changed

bin/commands/generate.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const availableGenerators = Object.keys(publicGenerators);
1818

1919
/**
2020
* @typedef {Object} Options
21-
* @property {Array<string>|string} input - Specifies the glob/path for input files.
21+
* @property {Array<string>|string} [input] - Specifies the glob/path for input files.
2222
* @property {Array<string>|string} [ignore] - Specifies the glob/path for ignoring files.
2323
* @property {Array<keyof publicGenerators>} target - Specifies the generator target mode.
2424
* @property {string} version - Specifies the target Node.js version.
@@ -42,7 +42,6 @@ export default {
4242
type: 'text',
4343
message: 'Enter input glob patterns',
4444
variadic: true,
45-
required: true,
4645
},
4746
},
4847
ignore: {
@@ -131,7 +130,7 @@ export default {
131130
* @returns {Promise<void>}
132131
*/
133132
async action(opts) {
134-
const docs = await loadAndParse(opts.input, opts.ignore);
133+
const docs = await loadAndParse(opts.inpu ?? [], opts.ignore);
135134
const releases = await parseChangelog(opts.changelog);
136135

137136
const rawTypeMap = await loadFromURL(opts.typeMap);

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default defineConfig([
9292
},
9393
{
9494
files: [
95-
'src/generators/legacy-html/assets/*.js',
95+
'src/generators/legacy-html-assets/assets/*.js',
9696
'src/generators/web/ui/**/*',
9797
],
9898
languageOptions: {

src/generators/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import jsonSimple from './json-simple/index.mjs';
77
import jsxAst from './jsx-ast/index.mjs';
88
import legacyHtml from './legacy-html/index.mjs';
99
import legacyHtmlAll from './legacy-html-all/index.mjs';
10+
import legacyHtmlAssets from './legacy-html-assets/index.mjs';
1011
import legacyJson from './legacy-json/index.mjs';
1112
import legacyJsonAll from './legacy-json-all/index.mjs';
1213
import llmsTxt from './llms-txt/index.mjs';
@@ -18,6 +19,7 @@ import web from './web/index.mjs';
1819
export const publicGenerators = {
1920
'json-simple': jsonSimple,
2021
'legacy-html': legacyHtml,
22+
'legacy-html-assets': legacyHtmlAssets,
2123
'legacy-html-all': legacyHtmlAll,
2224
'man-page': manPage,
2325
'legacy-json': legacyJson,
File renamed without changes.

src/generators/legacy-html/assets/js-flavor-cjs.svg renamed to src/generators/legacy-html-assets/assets/js-flavor-cjs.svg

File renamed without changes.

src/generators/legacy-html/assets/js-flavor-esm.svg renamed to src/generators/legacy-html-assets/assets/js-flavor-esm.svg

File renamed without changes.
File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { cp, rm } from 'node:fs/promises';
5+
import { join } from 'node:path';
6+
7+
/**
8+
* TODO docs
9+
*
10+
* @type {GeneratorMetadata<Input, Array<TemplateValues>>}
11+
*/
12+
export default {
13+
name: 'legacy-html-assets',
14+
15+
version: '1.0.0',
16+
17+
description: 'TODO',
18+
19+
dependsOn: 'metadata',
20+
21+
/**
22+
* Generates the legacy version of the API docs in HTML
23+
* @param {Input} _
24+
* @param {Partial<GeneratorOptions>} options
25+
*/
26+
async generate(_, { output }) {
27+
if (!output) {
28+
return;
29+
}
30+
31+
// Define the output folder for API docs assets
32+
const assetsFolder = join(output, 'assets');
33+
34+
// Removes the current assets directory to copy the new assets
35+
// and prevent stale assets from existing in the output directory
36+
// If the path does not exists, it will simply ignore and continue
37+
await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 });
38+
39+
// Current directory path relative to the `index.mjs` file
40+
const baseDir = import.meta.dirname;
41+
42+
// We copy all the other assets to the output folder at the end of the process
43+
// to ensure that all latest changes on the styles are applied to the output
44+
// Note.: This is not meant to be used for DX/developer purposes.
45+
await cp(join(baseDir, 'assets'), assetsFolder, {
46+
recursive: true,
47+
force: true,
48+
});
49+
},
50+
};

src/generators/legacy-html/index.mjs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { cp, readFile, rm, writeFile } from 'node:fs/promises';
3+
import { readFile, writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

66
import HTMLMinifier from '@minify-html/node';
@@ -168,24 +168,6 @@ export default {
168168
}
169169
}
170170

171-
if (output) {
172-
// Define the output folder for API docs assets
173-
const assetsFolder = join(output, 'assets');
174-
175-
// Removes the current assets directory to copy the new assets
176-
// and prevent stale assets from existing in the output directory
177-
// If the path does not exists, it will simply ignore and continue
178-
await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 });
179-
180-
// We copy all the other assets to the output folder at the end of the process
181-
// to ensure that all latest changes on the styles are applied to the output
182-
// Note.: This is not meant to be used for DX/developer purposes.
183-
await cp(join(baseDir, 'assets'), assetsFolder, {
184-
recursive: true,
185-
force: true,
186-
});
187-
}
188-
189171
return generatedValues;
190172
},
191173
};

0 commit comments

Comments
 (0)