From c3dd914074dec2175282ce62cd6f033cdaed4212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= <42278642+schoero@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:03:46 +0100 Subject: [PATCH 1/3] fix: browser import --- package-lock.json | 4 ++-- package.json | 4 ++-- src/api/browser.entry.ts | 3 --- vite.config.ts | 10 ++++++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index cc0e8acc..c4b9b0dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unwritten", - "version": "0.1.4", + "version": "0.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "unwritten", - "version": "0.1.4", + "version": "0.2.5", "license": "MIT", "dependencies": { "cac": "^6.7.14", diff --git a/package.json b/package.json index 924694e2..79335da2 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "bugs": { "url": "https://github.com/schoero/unwritten/issues" }, - "main": "./lib/api/node.js", - "browser": "./lib/api/browser.js", + "main": "./lib/api/node.entry.js", + "browser": "./lib/api/browser.entry.js", "bin": "./lib/bin/index.js", "scripts": { "build": "vite build", diff --git a/src/api/browser.entry.ts b/src/api/browser.entry.ts index 53b9b017..04d6537e 100644 --- a/src/api/browser.entry.ts +++ b/src/api/browser.entry.ts @@ -30,18 +30,15 @@ export async function unwritten(code: string, options?: BrowserAPIOptions): Prom ts }); - // Compile const { checker, program } = compile(defaultContext, code, options?.tsconfig); - // Parse const config = await createConfig(defaultContext, options?.config); const interpreterContext = createInterpreterContext(defaultContext, checker, config); const entryFileSymbol = getEntryFileSymbolsFromProgram(interpreterContext, program); const parsedSymbols = interpret(interpreterContext, entryFileSymbol); - // Render const renderer = await getRenderer(options?.renderer); const renderContext = createRenderContext(defaultContext, renderer, config); diff --git a/vite.config.ts b/vite.config.ts index b6cd5d05..d6317311 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,4 +1,5 @@ import shebang from "rollup-plugin-preserve-shebang"; +import dts from "vite-plugin-dts"; import noBundlePlugin from "vite-plugin-no-bundle"; import { config, defineConfig } from "@schoero/vite-config"; @@ -9,7 +10,7 @@ export default defineConfig({ build: { emptyOutDir: true, lib: { - entry: "/src/bin/index.ts", + entry: ["/src/bin/index.ts", "/src/api/browser.entry.ts"], formats: ["es"] }, minify: false, @@ -25,6 +26,11 @@ export default defineConfig({ plugins: [ ...config.plugins ?? [], noBundlePlugin(), - shebang() + shebang(), + dts({ + entryRoot: "./src", + exclude: ["src/**/*.test.ts", "test/**"], + pathsToAliases: true + }) ] }); From ca33ef2ae68282058e6071a82e8d555c1fc4cdac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= <42278642+schoero@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:04:29 +0100 Subject: [PATCH 2/3] feat: make rendering of table of contents optional --- src/renderer/markup/config/default.ts | 1 + src/renderer/markup/html/index.ts | 11 +++++++++-- src/renderer/markup/markdown/index.ts | 11 +++++++++-- src/renderer/markup/types-definitions/config.ts | 3 +++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/renderer/markup/config/default.ts b/src/renderer/markup/config/default.ts index 4b51edc5..8dba2eb3 100644 --- a/src/renderer/markup/config/default.ts +++ b/src/renderer/markup/config/default.ts @@ -32,6 +32,7 @@ const defaultRenderConfig: Complete = { renderParentNames: "documentation", renderPrivateMembers: false, renderSourceCodeLinks: true, + renderTableOfContents: true, stringLiteralEncapsulation: ["\"", "\""], tagEncapsulation: ["`", "`"], translations: { diff --git a/src/renderer/markup/html/index.ts b/src/renderer/markup/html/index.ts index 23f30ac5..569c9c72 100644 --- a/src/renderer/markup/html/index.ts +++ b/src/renderer/markup/html/index.ts @@ -12,6 +12,7 @@ import { import { getDestinationFilePath } from "unwritten:renderer/markup/utils/file"; import { createSectionNode, createTitleNode } from "unwritten:renderer/markup/utils/nodes"; import { capitalize } from "unwritten:renderer/markup/utils/translations"; +import { getRenderConfig } from "unwritten:renderer/utils/config.js"; import { renderNewLine } from "unwritten:renderer/utils/new-line"; import { renderAnchorNode } from "unwritten:renderer:html/ast/anchor"; import { renderBoldNode } from "unwritten:renderer:html/ast/bold"; @@ -115,6 +116,8 @@ const htmlRenderer: HTMLRenderer = { htmlRenderer.initializeContext(ctx); + const renderConfig = getRenderConfig(ctx); + return sourceFileEntities.reduce<(SourceFileEntity & { documentation: ASTNode[]; tableOfContents: ASTNode; title: string; titleAnchor: AnchorTarget; })[]>((convertedSourceFileEntities, sourceFileEntity) => { const destination = getDestinationFilePath(ctx, sourceFileEntities, sourceFileEntity); @@ -143,11 +146,15 @@ const htmlRenderer: HTMLRenderer = { setCurrentSourceFile(ctx, convertedSourceFileEntity); + const tableOfContents = renderConfig.renderTableOfContents && + createSectionNode("table-of-contents", convertedSourceFileEntity.tableOfContents); + const documentation = createSectionNode("documentation", ...convertedSourceFileEntity.documentation); + const ast = createTitleNode( convertedSourceFileEntity.title, convertedSourceFileEntity.titleAnchor, - createSectionNode("table-of-contents", convertedSourceFileEntity.tableOfContents), - createSectionNode("documentation", ...convertedSourceFileEntity.documentation) + tableOfContents, + documentation ); const renderedNewLine = renderNewLine(ctx); diff --git a/src/renderer/markup/markdown/index.ts b/src/renderer/markup/markdown/index.ts index daa9566c..f255deda 100644 --- a/src/renderer/markup/markdown/index.ts +++ b/src/renderer/markup/markdown/index.ts @@ -15,6 +15,7 @@ import { import { getDestinationFilePath } from "unwritten:renderer/markup/utils/file"; import { createSectionNode, createTitleNode } from "unwritten:renderer/markup/utils/nodes"; import { capitalize } from "unwritten:renderer/markup/utils/translations"; +import { getRenderConfig } from "unwritten:renderer/utils/config.js"; import { renderWithIndentation } from "unwritten:renderer/utils/indentation"; import { renderNewLine } from "unwritten:renderer/utils/new-line"; import { renderAnchorNode } from "unwritten:renderer:markdown/ast/anchor"; @@ -118,6 +119,8 @@ const markdownRenderer: MarkdownRenderer = { const { getFileName } = ctx.dependencies.path; + const renderConfig = getRenderConfig(ctx); + const renderedNewLine = renderNewLine(ctx); const renderedEmptyLine = renderEmptyLine(ctx); @@ -151,11 +154,15 @@ const markdownRenderer: MarkdownRenderer = { setCurrentSourceFile(ctx, convertedSourceFileEntity); + const tableOfContents = renderConfig.renderTableOfContents && + createSectionNode("table-of-contents", convertedSourceFileEntity.tableOfContents); + const documentation = createSectionNode("documentation", ...convertedSourceFileEntity.documentation); + const ast = createTitleNode( convertedSourceFileEntity.title, convertedSourceFileEntity.titleAnchor, - createSectionNode("table-of-contents", convertedSourceFileEntity.tableOfContents), - createSectionNode("documentation", ...convertedSourceFileEntity.documentation) + tableOfContents, + documentation ); const renderedContent = renderNode(ctx, ast); diff --git a/src/renderer/markup/types-definitions/config.ts b/src/renderer/markup/types-definitions/config.ts index ea4c82e3..8e6f85c5 100644 --- a/src/renderer/markup/types-definitions/config.ts +++ b/src/renderer/markup/types-definitions/config.ts @@ -47,6 +47,9 @@ export interface MarkupRenderConfig { /** Defines whether the renderer should render links to the source code. */ renderSourceCodeLinks?: boolean; + /** Defines whether the renderer should render the table of contents. */ + renderTableOfContents?: boolean; + /** Defines how string literal type annotations should be encapsulated in the rendered output. */ stringLiteralEncapsulation?: Encapsulation | false; From c27f50bab804b7aaf4aa5d9cbd406033479d76a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= <42278642+schoero@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:08:22 +0100 Subject: [PATCH 3/3] chore(release): v0.2.6 --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- schemas/renderer/config.json | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 789f7c9c..eed6b178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## v0.2.6 + +[compare changes](https://github.com/schoero/unwritten/compare/v0.2.5...v0.2.6) + +### Features + +- Make rendering of table of contents optional ([ca33ef2](https://github.com/schoero/unwritten/commit/ca33ef2)) + +### Fixes + +- Browser import ([c3dd914](https://github.com/schoero/unwritten/commit/c3dd914)) + +### ❤️ Contributors + +- Roger Schönbächler + ## v0.2.5 [compare changes](https://github.com/schoero/unwritten/compare/v0.2.3...v0.2.5) diff --git a/package.json b/package.json index 79335da2..25734b21 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.2.5", + "version": "0.2.6", "type": "module", "name": "unwritten", "description": "unwritten is a cli tool that auto generates documentation from your JavaScript or TypeScript project by utilizing TSDoc or JSDoc comments.", diff --git a/schemas/renderer/config.json b/schemas/renderer/config.json index f204d4f2..46dd1d1e 100644 --- a/schemas/renderer/config.json +++ b/schemas/renderer/config.json @@ -199,6 +199,10 @@ "description": "Defines whether the renderer should render links to the source code.", "type": "boolean" }, + "renderTableOfContents": { + "description": "Defines whether the renderer should render the table of contents.", + "type": "boolean" + }, "sidebar": { "description": "Renders the table of contents in an aside element and the documentation in a main element.", "type": "boolean" @@ -669,6 +673,10 @@ "description": "Defines whether the renderer should render links to the source code.", "type": "boolean" }, + "renderTableOfContents": { + "description": "Defines whether the renderer should render the table of contents.", + "type": "boolean" + }, "sectionSeparator": { "anyOf": [ {