systemview-plugin 1.0.0 → 1.1.1

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,13 +1,24 @@
1
1
  const fs = require("fs");
2
- const getAllTests = require("./getAllTest");
3
-
4
- module.exports = (specs, projectCode, serviceId, helperMethods = {}) => {
2
+ const {
3
+ deleteFile,
4
+ getFile,
5
+ ensureDir,
6
+ getName,
7
+ getFilesByNamespace,
8
+ } = require("./utils");
9
+ module.exports = ({ App, specs, projectCode, serviceId, module = {} }) => {
5
10
  specs = specs.substr(-1) === "/" ? specs.substr(0, specs.length - 1) : specs;
6
-
11
+ const system = {};
12
+ App.on("ready", (_system) => {
13
+ system.connectionData = _system.connectionData;
14
+ system.modules = _system.modules;
15
+ system.routing = _system.routing;
16
+ system.services = _system.services;
17
+ });
7
18
  return function SystemViewPlugin() {
8
19
  const { SystemView } = this.useService("SystemView");
9
- Object.assign(this, helperMethods);
10
20
 
21
+ Object.assign(this, module);
11
22
  this.saveDoc = ({ documentation, namespace }) => {
12
23
  const fileName = `${specs}/docs/${getName(namespace)}.md`;
13
24
  ensureDir(`${specs}/docs/`);
@@ -33,9 +44,9 @@ module.exports = (specs, projectCode, serviceId, helperMethods = {}) => {
33
44
  const tests = JSON.parse(getFile(fileName) || "[]");
34
45
  return tests;
35
46
  } else if (moduleName) {
36
- return getAllTests(`${specs}/tests/`, moduleName);
47
+ return getFilesByNamespace(`${specs}/tests/`, moduleName);
37
48
  } else {
38
- return getAllTests(`${specs}/tests/`);
49
+ return getFilesByNamespace(`${specs}/tests/`);
39
50
  }
40
51
  };
41
52
  this.saveTest = (test, index) => {
@@ -66,32 +77,9 @@ module.exports = (specs, projectCode, serviceId, helperMethods = {}) => {
66
77
  docs: fs.readdirSync(`${specs}/docs/`),
67
78
  tests: fs.readdirSync(`${specs}/tests/`),
68
79
  });
80
+ this.getConnection = () => {
81
+ const specList = this.getSpecList();
82
+ return { projectCode, serviceId, system, specList };
83
+ };
69
84
  };
70
-
71
- function deleteFile(fileName) {
72
- try {
73
- console.log(fileName);
74
- fs.unlinkSync(fileName);
75
- } catch (err) {
76
- // console.error(err);
77
- }
78
- }
79
- function getFile(fileName) {
80
- try {
81
- return fs.readFileSync(fileName, "utf8");
82
- } catch (error) {
83
- // console.log(error);
84
- }
85
- }
86
- function ensureDir(dir) {
87
- if (!fs.existsSync(dir)) {
88
- fs.mkdirSync(dir, { recursive: true });
89
- }
90
- }
91
-
92
- function getName({ serviceId, moduleName, methodName }) {
93
- if (methodName) return `${moduleName}.${methodName}`;
94
- else if (moduleName) return moduleName;
95
- else if (serviceId) return serviceId;
96
- }
97
85
  };
package/index.js CHANGED
@@ -1,40 +1,38 @@
1
1
  const SystemViewModule = require("./SystemViewModule");
2
- const fs = require("fs");
2
+ const { getSpecList } = require("./utils");
3
3
 
4
- function ensureDir(dir) {
5
- if (!fs.existsSync(dir)) {
6
- fs.mkdirSync(dir, { recursive: true });
7
- }
8
- }
9
-
10
- const getSpecList = (specs) => {
11
- ensureDir(`${specs}/docs/`);
12
- ensureDir(`${specs}/tests/`);
13
- return {
14
- docs: fs.readdirSync(`${specs}/docs/`),
15
- tests: fs.readdirSync(`${specs}/tests/`),
16
- };
17
- };
18
4
  module.exports = function ({
19
5
  connection = "http://localhost:3300/systemview/api",
20
6
  specs = "./specs",
21
7
  projectCode,
22
8
  serviceId,
23
- helperMethods,
9
+ module,
24
10
  }) {
25
11
  return function (App) {
26
12
  App.loadService("SystemView", connection)
27
- .module("Plugin", SystemViewModule(specs, projectCode, serviceId, helperMethods))
28
- .on("ready", async function connectSystemView(system) {
29
- try {
30
- const { SystemView } = this.useService("SystemView");
31
- const specList = getSpecList(specs);
32
- console.log("reconnection");
33
- await SystemView.connect({ system, projectCode, serviceId, specList });
34
- // SystemView.on("reconnect", connectSystemView.bind(this, system));
35
- } catch (error) {
36
- console.log("SystemView connection failed---->", error);
13
+ .module(
14
+ "Plugin",
15
+ SystemViewModule({
16
+ specs,
17
+ App,
18
+ projectCode,
19
+ serviceId,
20
+ module,
21
+ })
22
+ )
23
+ .on(
24
+ "ready",
25
+ async function connectSystemView({ connectionData, modules, routing, services }) {
26
+ const system = { connectionData, modules, routing, services };
27
+ try {
28
+ const { SystemView } = this.useService("SystemView");
29
+ const specList = getSpecList(specs);
30
+ await SystemView.connect({ system, projectCode, serviceId, specList });
31
+ console.log(`[SystemView]: ${projectCode}.${serviceId} connected!\n`);
32
+ } catch (error) {
33
+ console.log(`[SystemView]: ${projectCode}.${serviceId} connection failed\n`);
34
+ }
37
35
  }
38
- });
36
+ );
39
37
  };
40
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemview-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Connects your SystemLynx project to the SystemView UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,5 +18,13 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/Odion100/systemview-plugin/issues"
20
20
  },
21
- "homepage": "https://github.com/Odion100/systemview-plugin#readme"
21
+ "homepage": "https://github.com/Odion100/systemview-plugin#readme",
22
+ "devDependencies": {
23
+ "cz-conventional-changelog": "^3.3.0"
24
+ },
25
+ "config": {
26
+ "commitizen": {
27
+ "path": "./node_modules/cz-conventional-changelog"
28
+ }
29
+ }
22
30
  }
package/utils.js ADDED
@@ -0,0 +1,70 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ function deleteFile(fileName) {
5
+ try {
6
+ console.log(fileName);
7
+ fs.unlinkSync(fileName);
8
+ } catch (err) {
9
+ // console.error(err);
10
+ }
11
+ }
12
+ function getFile(fileName) {
13
+ try {
14
+ return fs.readFileSync(fileName, "utf8");
15
+ } catch (error) {
16
+ // console.log(error);
17
+ }
18
+ }
19
+ function ensureDir(dir) {
20
+ if (!fs.existsSync(dir)) {
21
+ fs.mkdirSync(dir, { recursive: true });
22
+ }
23
+ }
24
+
25
+ function getName({ serviceId, moduleName, methodName }) {
26
+ if (methodName) return `${moduleName}.${methodName}`;
27
+ else if (moduleName) return moduleName;
28
+ else if (serviceId) return serviceId;
29
+ }
30
+
31
+ function getFilesByNamespace(folder, namespace) {
32
+ const files = fs.readdirSync(folder); // read the contents of the current directory
33
+ const namespacePattern = namespace
34
+ ? new RegExp(`^${namespace}\\..+\\.json$`)
35
+ : /\.json$/;
36
+
37
+ return files
38
+ .filter((file) => namespacePattern.test(file))
39
+ .reduce((sum, file) => {
40
+ const filePath = path.join(folder, file);
41
+ const fileContents = fs.readFileSync(filePath, "utf-8");
42
+ const parsedData = JSON.parse(fileContents);
43
+
44
+ return sum.concat(parsedData);
45
+ }, []);
46
+ }
47
+
48
+ function ensureDir(dir) {
49
+ if (!fs.existsSync(dir)) {
50
+ fs.mkdirSync(dir, { recursive: true });
51
+ }
52
+ }
53
+
54
+ const getSpecList = (specs) => {
55
+ ensureDir(`${specs}/docs/`);
56
+ ensureDir(`${specs}/tests/`);
57
+ return {
58
+ docs: fs.readdirSync(`${specs}/docs/`),
59
+ tests: fs.readdirSync(`${specs}/tests/`),
60
+ };
61
+ };
62
+
63
+ module.exports = {
64
+ deleteFile,
65
+ getFile,
66
+ getName,
67
+ getFilesByNamespace,
68
+ getSpecList,
69
+ ensureDir,
70
+ };
package/getAllTest.js DELETED
@@ -1,21 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- module.exports = function getFilesByNamespace(folder, namespace) {
5
- const files = fs.readdirSync(folder); // read the contents of the current directory
6
- const namespacePattern = namespace
7
- ? new RegExp(`^${namespace}\\..+\\.json$`)
8
- : /\.json$/;
9
-
10
- return files
11
- .filter((file) => namespacePattern.test(file))
12
- .reduce((sum, file) => {
13
- const filePath = path.join(folder, file);
14
- const fileContents = fs.readFileSync(filePath, "utf-8");
15
- const parsedData = JSON.parse(fileContents);
16
-
17
- return sum.concat(parsedData);
18
- }, []);
19
- };
20
-
21
- // no namespace passed, return all files