Skip to content

Commit

Permalink
chore: fancy log for generate:api-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Apr 4, 2024
1 parent 5860783 commit ab29fa7
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@eslint-types/prettier": "5.1.3",
"@eslint-types/typescript-eslint": "7.2.0",
"@eslint-types/unicorn": "51.0.1",
"@poppinss/cliui": "~6.4.1",
"@types/markdown-it": "13.0.7",
"@types/node": "20.12.2",
"@types/sanitize-html": "2.11.0",
Expand Down
145 changes: 145 additions & 0 deletions pnpm-lock.yaml

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

53 changes: 36 additions & 17 deletions scripts/apidocs/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Project } from 'ts-morph';
import type { Task } from '../logger';
import { ui } from '../logger';
import { writeDiffIndex } from './output/diff-index';
import { writePages } from './output/page';
import { writePageIndex } from './output/page-index';
Expand All @@ -14,32 +16,49 @@ import {
import { getProject } from './project';

export async function generate(): Promise<void> {
console.log('Reading project');
const project = getProject();
console.log('Processing components');
const apiDocsPages = processComponents(project);
console.log('Writing files');
await writeFiles(apiDocsPages);
let project: Project;
let apiDocsPages: RawApiDocsPage[];
await ui
.tasks()
.add('Reading project', () => {
project = getProject();
return 'Project read successfully';
})
.add('Processing components', (task) => {
apiDocsPages = processComponents(task, project);
return 'Components processed successfully';
})
.add('Writing files', async (task) => {
await writeFiles(task, apiDocsPages);
return 'Files written successfully';
})
.run();
}

export function processComponents(project: Project): RawApiDocsPage[] {
export function processComponents(
task: Task,
project: Project
): RawApiDocsPage[] {
return [
...processProjectClasses(project),
...processProjectInterfaces(project),
processProjectUtilities(project),
...processModuleClasses(project),
...processProjectClasses(task, project),
...processProjectInterfaces(task, project),
processProjectUtilities(task, project),
...processModuleClasses(task, project),
];
}

async function writeFiles(apiDocsPages: RawApiDocsPage[]): Promise<void> {
console.log('- diff index');
async function writeFiles(
task: Task,
apiDocsPages: RawApiDocsPage[]
): Promise<void> {
task.update('diff index');
writeDiffIndex(apiDocsPages);
console.log('- page index');
task.update('page index');
await writePageIndex(apiDocsPages);
console.log('- pages');
task.update('pages');
await writePages(apiDocsPages);
console.log('- search index');
task.update('search index');
writeSearchIndex(apiDocsPages);
console.log('- source base url');
task.update('source base url');
await writeSourceBaseUrl();
}
Loading

0 comments on commit ab29fa7

Please sign in to comment.