Skip to content

Commit

Permalink
Merge pull request #571 from flowforge/fix-stack-installer
Browse files Browse the repository at this point in the history
Fix stack installer
  • Loading branch information
knolleary authored May 11, 2022
2 parents 0a07998 + 8a9d94a commit 0f00cc9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
27 changes: 26 additions & 1 deletion docs/install/local/stacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,32 @@ FlowForge is installed.
As new versions of Node-RED are released, the following steps can be used to
make them available within FlowForge.

For example, to add Node-RED 2.2.2:
### Development

If you are developing FlowForge having checked it out from GitHub then you can run
the following command in the project root

```bash
npm run install-stack --vers=2.2.2
```

### Production

If you are running a version from the installer then you can run the following
commands where `bin` is in the FlowForge Home directory
(e.g. `/opt/flowforge`)

Linux/Mac
```
bin/install-stack.sh 2.2.2
```

Windows:
```
bin\install-stack.bat 2.2.2
```

These scripts will automate the following steps

1. In the `var` directory in your FlowForge home directory, create a directory
called `stacks`
Expand Down
21 changes: 0 additions & 21 deletions forge/install-stack.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"cover:system": "nyc --silent --no-clean npm run test:system",
"cover:report": "nyc report --reporter=text --reporter html",
"dev:local": "cd ../flowforge-nr-launcher && npm install ../flowforge-nr-storage ../flowforge-nr-auth ../flowforge-nr-audit-logger && cd ../flowforge-driver-localfs && npm install ../flowforge-nr-launcher && cd ../flowforge && npm install ../flowforge-driver-localfs ../forge-ui-components",
"install-stack": "node forge/install-stack.js --"
"install-stack": "node scripts/install-stack.js --"
},
"bin": {
"flowforge": "./forge/app.js"
"flowforge": "./forge/app.js",
"ff-install-stack": "./scripts/install-stack.js"
},
"repository": {
"type": "git",
Expand Down
35 changes: 35 additions & 0 deletions scripts/install-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { exec } = require('child_process')
const { log, error } = require('console')
const fs = require('fs')
const path = require('path')

const flowforgeHome = process.env.FLOWFORGE_HOME

let vers = process.env.npm_config_vers
if (!vers) {
vers = process.argv[process.argv.length - 1]
if (!vers) {
throw new Error('command line arg vars is missing')
}
}

if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/.test(vers)) {
throw new Error('version not valid semantic version')
}

const p = path.join('var', 'stacks', vers)
if (flowforgeHome) {
path.join(flowforgeHome, p)
}
fs.mkdirSync(p, { recursive: true })

log(`installing stack node-red@${vers}`)
const npmCmd = `npm install --prefix ${p} node-red@${vers}`

exec(npmCmd, (err, stdout, stderr) => {
if (err) {
error(err)
} else {
log(`installed stack node-red@${vers}`)
}
})

0 comments on commit 0f00cc9

Please sign in to comment.