systemview-plugin 1.1.1 → 1.3.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/README.md +97 -1
- package/SystemViewModule.js +13 -0
- package/index.js +35 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,98 @@
|
|
|
1
1
|
# systemview-plugin
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Connects a [SystemLynx](https://github.com/Odion100/SystemLynx) service to [SystemView](https://github.com/Odion100/systemview) — the documentation and testing suite for SystemLynx.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install systemview-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const { App } = require("systemlynx");
|
|
19
|
+
|
|
20
|
+
App.startService({ route, port })
|
|
21
|
+
.module("Users", Users)
|
|
22
|
+
.module("Orders", Orders);
|
|
23
|
+
|
|
24
|
+
if (process.env.SYSTEMVIEW_HOST) {
|
|
25
|
+
const SystemViewPlugin = require("systemview-plugin")({
|
|
26
|
+
connection: process.env.SYSTEMVIEW_HOST, // SystemView API URL
|
|
27
|
+
specs: "./specs", // local path for docs and test files
|
|
28
|
+
projectCode: "myProject", // groups services together in SystemView
|
|
29
|
+
serviceId: "MyService", // name for this service
|
|
30
|
+
});
|
|
31
|
+
App.use(SystemViewPlugin);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Set `SYSTEMVIEW_HOST` to your SystemView instance, e.g.:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
SYSTEMVIEW_HOST=http://localhost:3000/systemview/api node index.js
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## What it does on startup
|
|
44
|
+
|
|
45
|
+
1. **Registers with SystemView** — sends connection data to the SystemView server so the service appears in the UI under `projectCode > serviceId`
|
|
46
|
+
2. **Writes `systemview.manifest.json`** — saves connection data and spec file locations to the project root so the SystemView CLI can run tests without the SystemView server running
|
|
47
|
+
|
|
48
|
+
If multiple services in the same project use the plugin, each one merges its own entry into the manifest rather than overwriting it.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## `systemview.manifest.json`
|
|
53
|
+
|
|
54
|
+
Written automatically to the root of your service project on each startup:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"projectCode": "myProject",
|
|
59
|
+
"services": [
|
|
60
|
+
{
|
|
61
|
+
"serviceId": "MyService",
|
|
62
|
+
"system": {
|
|
63
|
+
"connectionData": {
|
|
64
|
+
"serviceUrl": "http://localhost:4100/my/api",
|
|
65
|
+
"modules": [ ... ],
|
|
66
|
+
"routing": { ... }
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"specList": {
|
|
70
|
+
"docs": ["Users.md"],
|
|
71
|
+
"tests": ["Users.signUp.json"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Add it to `.gitignore` — it's a local artifact that regenerates on each startup.
|
|
79
|
+
|
|
80
|
+
With the manifest in place, the CLI can run tests directly against your live service without needing the SystemView server:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
systemview test myProject
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Specs folder
|
|
89
|
+
|
|
90
|
+
The plugin reads and writes documentation and test files from the `specs` path you configure:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
specs/
|
|
94
|
+
docs/ # markdown files, one per method
|
|
95
|
+
tests/ # JSON test files, one per method
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
These files are committed to your repo. The SystemView UI saves to them via the plugin's `saveDoc` and `saveTest` methods.
|
package/SystemViewModule.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
2
3
|
const {
|
|
3
4
|
deleteFile,
|
|
4
5
|
getFile,
|
|
@@ -81,5 +82,17 @@ module.exports = ({ App, specs, projectCode, serviceId, module = {} }) => {
|
|
|
81
82
|
const specList = this.getSpecList();
|
|
82
83
|
return { projectCode, serviceId, system, specList };
|
|
83
84
|
};
|
|
85
|
+
this.getLog = ({ limit } = {}) => {
|
|
86
|
+
const logsFile = path.join(process.cwd(), "systemview.logs");
|
|
87
|
+
try {
|
|
88
|
+
const lines = fs.readFileSync(logsFile, "utf8")
|
|
89
|
+
.split("\n")
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.map(JSON.parse);
|
|
92
|
+
return limit ? lines.slice(-limit) : lines;
|
|
93
|
+
} catch {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
};
|
|
84
97
|
};
|
|
85
98
|
};
|
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
1
3
|
const SystemViewModule = require("./SystemViewModule");
|
|
2
4
|
const { getSpecList } = require("./utils");
|
|
3
5
|
|
|
@@ -8,7 +10,9 @@ module.exports = function ({
|
|
|
8
10
|
serviceId,
|
|
9
11
|
module,
|
|
10
12
|
}) {
|
|
11
|
-
|
|
13
|
+
const LOGS_FILE = path.join(process.cwd(), "systemview.logs");
|
|
14
|
+
|
|
15
|
+
function install(App) {
|
|
12
16
|
App.loadService("SystemView", connection)
|
|
13
17
|
.module(
|
|
14
18
|
"Plugin",
|
|
@@ -24,15 +28,44 @@ module.exports = function ({
|
|
|
24
28
|
"ready",
|
|
25
29
|
async function connectSystemView({ connectionData, modules, routing, services }) {
|
|
26
30
|
const system = { connectionData, modules, routing, services };
|
|
31
|
+
const specList = getSpecList(specs);
|
|
27
32
|
try {
|
|
28
33
|
const { SystemView } = this.useService("SystemView");
|
|
29
|
-
const specList = getSpecList(specs);
|
|
30
34
|
await SystemView.connect({ system, projectCode, serviceId, specList });
|
|
31
35
|
console.log(`[SystemView]: ${projectCode}.${serviceId} connected!\n`);
|
|
32
36
|
} catch (error) {
|
|
33
37
|
console.log(`[SystemView]: ${projectCode}.${serviceId} connection failed\n`);
|
|
34
38
|
}
|
|
39
|
+
// Write manifest so CLI can run tests without the SystemView server
|
|
40
|
+
try {
|
|
41
|
+
const manifestPath = path.join(process.cwd(), "systemview.manifest.json");
|
|
42
|
+
let manifest = { projectCode, services: [] };
|
|
43
|
+
if (fs.existsSync(manifestPath)) {
|
|
44
|
+
try { manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); } catch {}
|
|
45
|
+
if (!manifest.services) manifest.services = [];
|
|
46
|
+
}
|
|
47
|
+
const entry = { serviceId, system, specList };
|
|
48
|
+
const idx = manifest.services.findIndex((s) => s.serviceId === serviceId);
|
|
49
|
+
if (idx > -1) manifest.services[idx] = entry;
|
|
50
|
+
else manifest.services.push(entry);
|
|
51
|
+
manifest.projectCode = projectCode;
|
|
52
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.log(`[SystemView]: failed to write manifest: ${err.message}\n`);
|
|
55
|
+
}
|
|
35
56
|
}
|
|
36
57
|
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
install.log = function (...args) {
|
|
61
|
+
console.log(...args);
|
|
62
|
+
const entry = JSON.stringify({
|
|
63
|
+
ts: new Date().toISOString(),
|
|
64
|
+
service: `${projectCode}.${serviceId}`,
|
|
65
|
+
message: args.length === 1 ? args[0] : args,
|
|
66
|
+
});
|
|
67
|
+
fs.appendFileSync(LOGS_FILE, entry + "\n");
|
|
37
68
|
};
|
|
69
|
+
|
|
70
|
+
return install;
|
|
38
71
|
};
|