Skip to content

Commit 6853ab5

Browse files
authored
Merge pull request #178 from NodeSecure/refactor-monorepo
refactor: transform to NPM monorepo
2 parents 4b4e22f + d375e54 commit 6853ab5

40 files changed

Lines changed: 38108 additions & 0 deletions

.github/workflows/vis-network.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: vis-network CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- workspaces/vis-network/**
9+
pull_request:
10+
paths:
11+
- workspaces/vis-network/**
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node-version: [16.x, 18.x]
19+
fail-fast: false
20+
steps:
21+
- name: Harden Runner
22+
uses: step-security/harden-runner@c8454efe5d0bdefd25384362fe217428ca277d57 # v2.2.0
23+
with:
24+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
25+
26+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- name: Install dependencies
32+
run: npm i
33+
- name: Run tests
34+
run: npm run test

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ $ npm test
208208

209209
> **Note** If you add a feature, try adding tests for it along.
210210
211+
## Workspaces
212+
213+
Click on one of the links to access the documentation of the workspace:
214+
215+
| name | package and link |
216+
| --- | --- |
217+
| documentation-ui | [@nodesecure/documentation-ui](./workspaces/documentation-ui) |
218+
| vis-network | [@nodesecure/vis-network ](./workspaces/vis-network) |
219+
220+
These packages are 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).
221+
```bash
222+
$ npm i @nodesecure/documentation-ui
223+
# or
224+
$ yarn add @nodesecure/documentation-ui
225+
```
226+
211227
## Contributors ✨
212228

213229
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"src",
2727
"views"
2828
],
29+
"workspaces": [
30+
"workspaces/documentation-ui",
31+
"workspaces/vis-network"
32+
],
2933
"repository": {
3034
"type": "git",
3135
"url": "git+https://github.com/NodeSecure/cli.git"
@@ -67,6 +71,7 @@
6771
"esbuild": "^0.17.3",
6872
"eslint": "^8.27.0",
6973
"esmock": "^2.1.0",
74+
"http-server": "^14.1.1",
7075
"pkg-ok": "^3.0.0",
7176
"pretty-bytes": "^5.6.0",
7277
"strip-ansi": "^7.0.1",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 NodeSecure
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Import Node.js Dependencies
2+
import path from "path";
3+
import fs from "fs";
4+
import { fileURLToPath } from "url";
5+
6+
// Import Third-party Dependencies
7+
import esbuild from "esbuild";
8+
9+
// CONSTANTS
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
11+
12+
const kMainDir = path.join(__dirname, "example");
13+
const kOutDir = path.join(__dirname, "dist");
14+
15+
await esbuild.build({
16+
entryPoints: [
17+
path.join(kMainDir, "master.js"),
18+
path.join(__dirname, "src", "css", "main.css")
19+
],
20+
platform: "browser",
21+
bundle: true,
22+
sourcemap: true,
23+
treeShaking: true,
24+
outdir: kOutDir
25+
});
26+
27+
fs.copyFileSync(path.join(kMainDir, "demo.html"), path.join(kOutDir, "index.html"));

0 commit comments

Comments
 (0)