Skip to content

Commit

Permalink
Merge pull request #22 from flowforge/multiple-nr-versions
Browse files Browse the repository at this point in the history
Use a specific NR version
  • Loading branch information
hardillb authored Mar 11, 2022
2 parents b87cb9d + 13598e4 commit 31a77e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Custom laucher to start Node-RED is a loadale set of settings and to capture log
- --port port to listen on for management interface
- --project FlowForge project id UUID
- --token Bearer Token to access Forge platfrom
- --nodeRedPath path to dir with a `node_modules` directory container a version of Node-RED

FORGE_URL, FORGE_PROJECT_ID & FORGE_PROJECT_TOKEN and be used as env vars instead of the cmd line args if not set (cmd line args take preceident)
FORGE_URL, FORGE_PROJECT_ID, FORGE_PROJECT_TOKEN & FORGE_NR_PATH and be used as env vars instead of the cmd line args if not set (cmd line args take preceident)
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const cmdLineOptions = [
{ name: 'forgeURL', type: String },
{ name: 'project', type: String },
{ name: 'token', type: String },
{ name: 'buffer', alias: 'b', type: Number }
{ name: 'buffer', alias: 'b', type: Number },
{ name: 'nodeRedPath', alias: 'n', type: String }
]

const options = commandLineArgs(cmdLineOptions)
Expand All @@ -21,15 +22,25 @@ options.forgeURL = options.forgeURL || process.env.FORGE_URL
options.project = options.project || process.env.FORGE_PROJECT_ID
options.token = options.token || process.env.FORGE_PROJECT_TOKEN
options.logBufferMax = options.logBufferMax || 1000
options.nodeRedPath = options.nodeRedPath || process.env.FORGE_NR_PATH

const ext = process.platform === 'win32' ? '.cmd' : ''

options.execPath = undefined
for (let i = 0; i < require.main.paths.length; i++) {
const execPath = path.join(require.main.paths[i], '.bin', `node-red${ext}`)
if (fs.existsSync(execPath)) {
options.execPath = execPath
break
if (options.nodeRedPath) {
options.execPath = path.join(options.nodeRedPath, 'node_modules', '.bin', `node-red${ext}`)
if (!fs.existsSync(options.execPath)) {
options.execPath = undefined
}
}
if (!options.execPath) {
// Find the bundled version
for (let i = 0; i < require.main.paths.length; i++) {
const execPath = path.join(require.main.paths[i], '.bin', `node-red${ext}`)
if (fs.existsSync(execPath)) {
options.execPath = execPath
break
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class Launcher {
]

if (this.settings.stack?.['memory'] && /^[1-9]\d*$/.test(this.settings.stack['memory'])) {
processArguments.push(`--max-old-space-size=${this.settings.stack['memory']}`)
const memLimit = Math.round(this.settings.stack['memory'] * 0.75)
processArguments.push(`--max-old-space-size=${memLimit}`)
}

this.proc = childProcess.spawn(
Expand Down

0 comments on commit 31a77e6

Please sign in to comment.