|
| 1 | +<p align="center"><h1 align="center"> |
| 2 | + 🐤 Documentation and Wiki UI 👀 |
| 3 | +</h1> |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <a href="https://www.npmjs.com/package/nsecure"> |
| 7 | + <img src="https://img.shields.io/github/package-json/v/NodeSecure/documentation-ui?style=for-the-badge" alt="npm version"> |
| 8 | + </a> |
| 9 | + <a href="https://www.npmjs.com/package/nsecure"> |
| 10 | + <img src="https://img.shields.io/github/license/NodeSecure/documentation-ui?style=for-the-badge" alt="license"> |
| 11 | + </a> |
| 12 | + <a href="https://api.securityscorecards.dev/projects/github.com/NodeSecure/documentation-ui"> |
| 13 | + <img src="https://api.securityscorecards.dev/projects/github.com/NodeSecure/documentation-ui/badge?style=for-the-badge" alt="ossf scorecard"> |
| 14 | + </a> |
| 15 | +</p> |
| 16 | + |
| 17 | +<p align="center"> |
| 18 | +<img src="https://i.imgur.com/Bo21VnK.png"> |
| 19 | +</p> |
| 20 | + |
| 21 | +## 📢 About |
| 22 | + |
| 23 | +Portable documentation/wiki UI for NodeSecure tools like [CLI](https://github.com/NodeSecure/cli) or [Preview](https://github.com/NodeSecure/preview). This package has been designed with the objective of rendering the same documentation to all developers whatever the tool they use. |
| 24 | + |
| 25 | +## 📜 Features |
| 26 | + |
| 27 | +- Render [NodeSecure flags](https://github.com/NodeSecure/flags/blob/main/FLAGS.md) using the package `@nodesecure/flags`. |
| 28 | +- Render [NodeSecure JS-X-RAY SAST Warnings](https://github.com/NodeSecure/js-x-ray). |
| 29 | +- Written in vanilla.js for maximum performance. |
| 30 | + |
| 31 | +> **Note** The content is retrieved from the github API (and sometimes it transform raw markdown response to HTML, that's why we use [markdown-it](https://github.com/markdown-it/markdown-it#readme) as dependency). |
| 32 | +
|
| 33 | +## 💃 Getting Started |
| 34 | + |
| 35 | +This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com). |
| 36 | + |
| 37 | +```bash |
| 38 | +$ npm i @nodesecure/documentation-ui |
| 39 | +# or |
| 40 | +$ yarn add @nodesecure/documentation-ui |
| 41 | +``` |
| 42 | + |
| 43 | +## 👀 Usage example |
| 44 | + |
| 45 | +```js |
| 46 | +// Import Third-party Dependencies |
| 47 | +import * as documentationUI from "@nodesecure/documentation-ui"; |
| 48 | + |
| 49 | +document.addEventListener("DOMContentLoaded", async () => { |
| 50 | + const documentRootElement = document.getElementById("whatever-you-want"); |
| 51 | + |
| 52 | + const wiki = documentationUI.render(documentRootElement, { |
| 53 | + prefetch: true, |
| 54 | + }); |
| 55 | + |
| 56 | + console.log(`Available views: ${[...wiki.header.views.keys()].join(",")}`); |
| 57 | + wiki.header.setNewActiveView("warnings"); |
| 58 | + |
| 59 | + // Note: you can also enumerate menus with `wiki.navigation.warnings.menus.keys()` |
| 60 | + wiki.navigation.warnings.setNewActiveMenu("unsafe-stmt"); |
| 61 | +}); |
| 62 | +``` |
| 63 | + |
| 64 | +The `render` API take an options payload describe by the following TS interface: |
| 65 | + |
| 66 | +```ts |
| 67 | +export interface RenderDocumentationUIOptions { |
| 68 | + /** |
| 69 | + * Prefetch all flags and cache them |
| 70 | + * |
| 71 | + * @default true |
| 72 | + */ |
| 73 | + prefetch?: boolean; |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### Fetch assets required for the bundler |
| 78 | + |
| 79 | +An incomplete example for esbuild. |
| 80 | + |
| 81 | +```js |
| 82 | +// Import Third-party Dependencies |
| 83 | +import { getBuildConfiguration } from "@nodesecure/documentation-ui/node"; |
| 84 | +import esbuild from "esbuild"; |
| 85 | + |
| 86 | +// Note: all entry points for assets (css etc..). |
| 87 | +const { entryPoints } = getBuildConfiguration(); |
| 88 | + |
| 89 | +await esbuild.build({ |
| 90 | + entryPoints: [...entryPoints], |
| 91 | +}); |
| 92 | +``` |
| 93 | + |
| 94 | +## API |
| 95 | + |
| 96 | +### render(rootElement: HTMLElement, options: RenderDocumentationUIOptions): RenderResult; |
| 97 | + |
| 98 | +Render the documentation in the given root element. |
| 99 | + |
| 100 | +```ts |
| 101 | +export interface RenderResult { |
| 102 | + header: Header; |
| 103 | + navigation: { |
| 104 | + flags: Navigation; |
| 105 | + warnings: Navigation; |
| 106 | + }; |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +<details><summary>Header & Navigation definition</summary> |
| 111 | + |
| 112 | +```ts |
| 113 | +class Header { |
| 114 | + active: HTMLElement; |
| 115 | + views: Map<string, HTMLElement>; |
| 116 | + defaultName: string | null; |
| 117 | + |
| 118 | + setNewActiveView(name: string): void; |
| 119 | +} |
| 120 | + |
| 121 | +class Navigation { |
| 122 | + active: HTMLElement; |
| 123 | + menus: Map<string, HTMLElement>; |
| 124 | + defaultName: string | null; |
| 125 | + prefetch: boolean; |
| 126 | + fetchCallback: (name: string, menu: HTMLElement) => any; |
| 127 | + |
| 128 | + setNewActiveMenu(name: string): void; |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +</details> |
| 133 | + |
| 134 | +## How to contribute/work on this project |
| 135 | + |
| 136 | +You can use the local `example/` to work on any updates. Just use the `example` npm script: |
| 137 | + |
| 138 | +```bash |
| 139 | +$ npm ci |
| 140 | +$ npm run example |
| 141 | +``` |
| 142 | + |
| 143 | +```json |
| 144 | +"scripts": { |
| 145 | + "example": "npm run example:build && http-server ./dist", |
| 146 | + "example:build": "node esbuild.config.js" |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +## License |
| 151 | + |
| 152 | +MIT |
0 commit comments