@flink-app/api-docs-plugin 0.12.1-alpha.7 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BUILD.md +52 -0
- package/CHANGELOG.md +7 -0
- package/DEVELOPMENT.md +64 -0
- package/dist/dev-server.d.ts +1 -0
- package/dist/dev-server.js +46 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -14
- package/dist/react-app/api-docs-favicon.svg +14 -0
- package/dist/react-app/assets/index-DZQKCGSz.css +1 -0
- package/dist/react-app/assets/index-Ds6xtmfB.js +57 -0
- package/dist/react-app/assets/index-Ds6xtmfB.js.map +1 -0
- package/dist/react-app/index.html +14 -0
- package/dist/react-app/vite.svg +1 -0
- package/package.json +29 -29
- package/readme.md +111 -18
- package/dist/views/index.pug +0 -22
- package/nodemon.json +0 -6
- package/src/index.ts +0 -52
- package/src/views/index.pug +0 -22
- package/tsconfig.json +0 -23
package/BUILD.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Build Process for API Docs Plugin
|
|
2
|
+
|
|
3
|
+
This plugin consists of two main parts:
|
|
4
|
+
1. The TypeScript plugin code
|
|
5
|
+
2. A React application for the documentation UI
|
|
6
|
+
|
|
7
|
+
## Directory Structure
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
api-docs-plugin/
|
|
11
|
+
├── src/ # TypeScript plugin source
|
|
12
|
+
├── react-app/ # React application source
|
|
13
|
+
│ ├── src/ # React components
|
|
14
|
+
│ └── dist/ # Built React files (after build)
|
|
15
|
+
└── dist/ # Compiled plugin output
|
|
16
|
+
├── index.js # Compiled plugin
|
|
17
|
+
└── react-app/ # Copied React build files
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Build Process
|
|
21
|
+
|
|
22
|
+
The build process follows these steps:
|
|
23
|
+
|
|
24
|
+
1. **Build React App**:
|
|
25
|
+
- Runs `npm run build` in the `react-app` directory
|
|
26
|
+
- Outputs files to `react-app/dist`
|
|
27
|
+
|
|
28
|
+
2. **Compile TypeScript**:
|
|
29
|
+
- Compiles all TypeScript files from `src/` to `dist/`
|
|
30
|
+
|
|
31
|
+
3. **Copy Assets**:
|
|
32
|
+
- Copies the built React app from `react-app/dist` to `dist/react-app`
|
|
33
|
+
|
|
34
|
+
## Commands
|
|
35
|
+
|
|
36
|
+
- `npm run prepare`: Runs the full build process (React + TypeScript + copy)
|
|
37
|
+
- `npm run build:react`: Builds only the React app
|
|
38
|
+
- `npm run clean`: Removes the dist directory
|
|
39
|
+
|
|
40
|
+
## How It Works
|
|
41
|
+
|
|
42
|
+
1. The plugin serves the React app from `dist/react-app` at the `/docs` endpoint
|
|
43
|
+
2. The React app fetches API data from `/docs/api`
|
|
44
|
+
3. The plugin provides the API data based on registered Flink handlers
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
For development, you can run:
|
|
49
|
+
- `npm run dev`: Starts a development server
|
|
50
|
+
- `npm run watch`: Watches for TypeScript changes
|
|
51
|
+
|
|
52
|
+
Make sure to build the React app before testing the full plugin.
|
package/CHANGELOG.md
ADDED
package/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Development Guide for API Docs Plugin
|
|
2
|
+
|
|
3
|
+
This guide explains how to develop the API Docs Plugin React app.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js installed (see root .nvmrc for version)
|
|
8
|
+
- Dependencies installed in both the plugin root and react-app directories:
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
cd react-app && npm install
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Development Setup
|
|
15
|
+
|
|
16
|
+
The development setup consists of two servers:
|
|
17
|
+
|
|
18
|
+
1. **Mock API Server** (port 3001): Serves sample API data
|
|
19
|
+
2. **Vite Dev Server** (port 5173): Serves the React app with hot-reloading
|
|
20
|
+
|
|
21
|
+
## Running the Development Environment
|
|
22
|
+
|
|
23
|
+
1. Start the mock API server:
|
|
24
|
+
```bash
|
|
25
|
+
npm run dev:mock-api
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
2. In another terminal, start the React dev server:
|
|
29
|
+
```bash
|
|
30
|
+
npm run dev:react
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. Open http://localhost:5173 in your browser
|
|
34
|
+
|
|
35
|
+
The React app will fetch data from the mock API server through Vite's proxy configuration.
|
|
36
|
+
|
|
37
|
+
## Available Scripts
|
|
38
|
+
|
|
39
|
+
| Command | Description |
|
|
40
|
+
|---------|-------------|
|
|
41
|
+
| `npm run dev:mock-api` | Start the mock API server |
|
|
42
|
+
| `npm run dev:react` | Start the React development server |
|
|
43
|
+
| `npm run build:react` | Build the React app for production |
|
|
44
|
+
| `npm run prepare` | Build everything for production |
|
|
45
|
+
| `npm run clean` | Remove all build artifacts |
|
|
46
|
+
|
|
47
|
+
## Modifying Sample Data
|
|
48
|
+
|
|
49
|
+
To test different API structures, edit `sample.json` and restart the mock API server.
|
|
50
|
+
|
|
51
|
+
## Building for Production
|
|
52
|
+
|
|
53
|
+
To build the complete plugin:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm run prepare
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This will:
|
|
60
|
+
1. Build the React app
|
|
61
|
+
2. Compile TypeScript
|
|
62
|
+
3. Copy assets to the dist directory
|
|
63
|
+
|
|
64
|
+
The built plugin will serve the React app statically in production.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var flink_1 = require("@flink-app/flink");
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
var fs_1 = __importDefault(require("fs"));
|
|
9
|
+
var app = (0, flink_1.expressFn)();
|
|
10
|
+
var port = 3001;
|
|
11
|
+
// Configure development options
|
|
12
|
+
var options = {
|
|
13
|
+
apiPath: "/docs/api",
|
|
14
|
+
};
|
|
15
|
+
// Load sample data
|
|
16
|
+
var sampleData;
|
|
17
|
+
try {
|
|
18
|
+
sampleData = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, "../sample.json"), "utf-8"));
|
|
19
|
+
console.log("Sample data loaded successfully");
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error("Failed to load sample.json:", error);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
// Enable CORS for development
|
|
26
|
+
app.use(function (req, res, next) {
|
|
27
|
+
res.header("Access-Control-Allow-Origin", "*");
|
|
28
|
+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
29
|
+
next();
|
|
30
|
+
});
|
|
31
|
+
// Serve API endpoint
|
|
32
|
+
app.get(options.apiPath, function (req, res) {
|
|
33
|
+
console.log("API request received at ".concat(options.apiPath));
|
|
34
|
+
res.json({
|
|
35
|
+
routes: Array.isArray(sampleData) ? sampleData : [sampleData],
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
// Start the server
|
|
39
|
+
app.listen(port, function () {
|
|
40
|
+
console.log("Mock API server running at http://localhost:".concat(port));
|
|
41
|
+
console.log("API endpoint available at http://localhost:".concat(port).concat(options.apiPath));
|
|
42
|
+
console.log("\nTo develop the React app:");
|
|
43
|
+
console.log("1. Keep this server running");
|
|
44
|
+
console.log("2. In another terminal, cd to react-app and run 'npm run dev'");
|
|
45
|
+
console.log("3. Open http://localhost:5173 to see the app");
|
|
46
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,14 @@ import { FlinkPlugin } from "@flink-app/flink";
|
|
|
2
2
|
export type ApiDocOptions = {
|
|
3
3
|
/**
|
|
4
4
|
* Path to where api docs can be accessed
|
|
5
|
+
* Defaults to "/docs"
|
|
5
6
|
*/
|
|
6
7
|
path?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Path to where route and schemas are fetched from.
|
|
10
|
+
* Defaults to "/docs/api"
|
|
11
|
+
*/
|
|
12
|
+
apiPath?: string;
|
|
7
13
|
/**
|
|
8
14
|
* Name of plugin
|
|
9
15
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.apiDocPlugin = void 0;
|
|
4
|
-
var path_1 = require("path");
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
5
8
|
var apiDocPlugin = function (options) {
|
|
6
9
|
if (options === void 0) { options = {}; }
|
|
7
10
|
return {
|
|
@@ -11,23 +14,15 @@ var apiDocPlugin = function (options) {
|
|
|
11
14
|
};
|
|
12
15
|
exports.apiDocPlugin = apiDocPlugin;
|
|
13
16
|
function init(app, options) {
|
|
14
|
-
// TODO: Use parsedHandlerConfig
|
|
15
17
|
var expressApp = app.expressApp, handlers = app.handlers;
|
|
16
18
|
if (!expressApp) {
|
|
17
19
|
// should not happen
|
|
18
20
|
throw new Error("Express app not initialized");
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
expressApp.
|
|
22
|
-
expressApp.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var sortedHandlers = handlers.sort(function (routeA, routeB) {
|
|
26
|
-
return routeA.routeProps.path.localeCompare(routeB.routeProps.path);
|
|
27
|
-
});
|
|
28
|
-
res.render("index", {
|
|
29
|
-
title: options.title || "API Docs",
|
|
30
|
-
handlers: sortedHandlers,
|
|
31
|
-
});
|
|
22
|
+
var staticPath = path_1.default.resolve(__dirname, "react-app");
|
|
23
|
+
expressApp === null || expressApp === void 0 ? void 0 : expressApp.use(options.path || "/docs", expressApp.static(staticPath));
|
|
24
|
+
expressApp === null || expressApp === void 0 ? void 0 : expressApp.get(options.apiPath || "/docs/api", function (req, res) {
|
|
25
|
+
var sortedHandlers = handlers.sort(function (routeA, routeB) { return routeA.routeProps.path.localeCompare(routeB.routeProps.path); });
|
|
26
|
+
res.json({ routes: sortedHandlers });
|
|
32
27
|
});
|
|
33
28
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<title>API Docs Favicon</title>
|
|
4
|
+
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
5
|
+
<!-- Document outline -->
|
|
6
|
+
<path d="M6,2 L20,2 L26,8 L26,28 L6,28 Z" fill="#FFFFFF" stroke="#2563EB" stroke-width="2" />
|
|
7
|
+
<!-- Folded corner -->
|
|
8
|
+
<path d="M20,2 L20,8 L26,8 Z" fill="#E5E7EB" stroke="#2563EB" stroke-width="2" />
|
|
9
|
+
<!-- Document lines -->
|
|
10
|
+
<line x1="10" y1="14" x2="22" y2="14" stroke="#2563EB" stroke-width="2" />
|
|
11
|
+
<line x1="10" y1="18" x2="22" y2="18" stroke="#2563EB" stroke-width="2" />
|
|
12
|
+
<line x1="10" y1="22" x2="18" y2="22" stroke="#2563EB" stroke-width="2" />
|
|
13
|
+
</g>
|
|
14
|
+
</svg>
|