Skip to content

Commit 6c72f80

Browse files
committed
try joined install first
1 parent d82282c commit 6c72f80

4 files changed

Lines changed: 58 additions & 29 deletions

File tree

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.1.168",
3+
"version": "1.1.169",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/node-red-contrib-openflow-storage.ts

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { WebSocketClient, NoderedUtil, Base } from "@openiap/openflow-api";
88
import * as nodered from "node-red";
99
import { FileSystemCache } from "@openiap/openflow-api";
1010
import { RestartService, servicename } from "./nodeclient/cliutil";
11+
const child_process = require("child_process");
1112
export class noderednpmrc {
1213
public _id: string;
1314
public _type: string = "npmrc";
@@ -135,6 +136,41 @@ export class noderedcontribopenflowstorage {
135136
}
136137
});
137138
}
139+
async GetMissingModules(settings: any) {
140+
const globaldir = await this.getGlobalModulesDir();
141+
let currentmodules = this.scanDirForNodesModules(path.resolve('.'));
142+
currentmodules = currentmodules.concat(this.scanDirForNodesModules(globaldir));
143+
// currentmodules.forEach(pck => {
144+
// console.log(pck.name + "@" + pck.version);
145+
// });
146+
const keys = Object.keys(settings.nodes);
147+
let modules = "";
148+
for (let i = 0; i < keys.length; i++) {
149+
const key = keys[i];
150+
if (key == "node-red" || key == "node-red-node-rbe" || key == "node-red-node-tail") continue;
151+
const val = settings.nodes[key];
152+
const version = (val.pending_version ? val.pending_version : val.version)
153+
const pcks = currentmodules.filter(x => x.name == key && x.version == version);
154+
if (pcks.length != 1) {
155+
modules += (" " + key + "@" + version);
156+
}
157+
}
158+
return modules.trim();
159+
}
160+
// key + "@" + version
161+
installNPMPackage(pck: string) {
162+
try {
163+
this._logger.info("Installing " + pck);
164+
child_process.execSync("npm install " + pck, { stdio: [0, 1, 2], cwd: this.settings.userDir });
165+
} catch (error) {
166+
this._logger.error("npm install error");
167+
if (error.status) this._logger.error("npm install status: " + error.status);
168+
if (error.message) this._logger.error("npm install message: " + error.message);
169+
if (error.stderr) this._logger.error("npm install stderr: " + error.stderr);
170+
if (error.stdout) this._logger.error("npm install stdout: " + error.stdout);
171+
}
172+
173+
}
138174
DiffObjects(o1, o2) {
139175
// choose a map() impl.
140176
// you may use $.map from jQuery if you wish
@@ -562,34 +598,27 @@ export class noderedcontribopenflowstorage {
562598
if (this._settings == null) {
563599
this._settings = settings;
564600
try {
565-
const child_process = require("child_process");
566-
const globaldir = await this.getGlobalModulesDir();
567-
let currentmodules = this.scanDirForNodesModules(path.resolve('.'));
568-
currentmodules = currentmodules.concat(this.scanDirForNodesModules(globaldir));
569-
// currentmodules.forEach(pck => {
570-
// console.log(pck.name + "@" + pck.version);
571-
// });
572-
const keys = Object.keys(settings.nodes);
573-
// let modules = "";
574-
for (let i = 0; i < keys.length; i++) {
575-
const key = keys[i];
576-
if (key == "node-red" || key == "node-red-node-rbe" || key == "node-red-node-tail") continue;
577-
const val = settings.nodes[key];
578-
const version = (val.pending_version ? val.pending_version : val.version)
579-
const pcks = currentmodules.filter(x => x.name == key && x.version == version);
580-
if (pcks.length != 1) {
581-
try {
582-
this._logger.info("Installing " + key + "@" + version);
583-
child_process.execSync("npm install " + key + "@" + version, { stdio: [0, 1, 2], cwd: this.settings.userDir });
584-
} catch (error) {
585-
this._logger.error("npm install error");
586-
if (error.status) this._logger.error("npm install status: " + error.status);
587-
if (error.message) this._logger.error("npm install message: " + error.message);
588-
if (error.stderr) this._logger.error("npm install stderr: " + error.stderr);
589-
if (error.stdout) this._logger.error("npm install stdout: " + error.stdout);
590-
}
601+
let modules = await this.GetMissingModules(settings);
602+
if (!NoderedUtil.IsNullEmpty(modules)) {
603+
let hadErrors: boolean = false;
604+
try {
605+
this.installNPMPackage(modules);
606+
hadErrors = false;
607+
} catch (error) {
608+
hadErrors = true;
609+
}
610+
if (hadErrors) {
611+
modules = await this.GetMissingModules(settings);
612+
var arr = modules.split(" ");
613+
arr.forEach(pck => {
614+
try {
615+
this.installNPMPackage(pck);
616+
} catch (error) {
617+
}
618+
});
591619

592620
}
621+
593622
}
594623
} catch (error) {
595624
this._logger.error(error);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.168
1+
1.1.169

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.1.168",
3+
"version": "1.1.169",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)