systemview-plugin 1.2.0 → 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.
@@ -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
@@ -10,7 +10,9 @@ module.exports = function ({
10
10
  serviceId,
11
11
  module,
12
12
  }) {
13
- return function (App) {
13
+ const LOGS_FILE = path.join(process.cwd(), "systemview.logs");
14
+
15
+ function install(App) {
14
16
  App.loadService("SystemView", connection)
15
17
  .module(
16
18
  "Plugin",
@@ -53,5 +55,17 @@ module.exports = function ({
53
55
  }
54
56
  }
55
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");
56
68
  };
69
+
70
+ return install;
57
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemview-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Connects your SystemLynx project to the SystemView UI",
5
5
  "main": "index.js",
6
6
  "scripts": {