Skip to content

Commit

Permalink
fix: if NodeJS is installed in the system, NodeJS steps are by defaul…
Browse files Browse the repository at this point in the history
…t executed with it
  • Loading branch information
kasp1 committed Oct 15, 2022
1 parent 538ad42 commit 5ce9443
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [4.0.1](https://github.com/kasp1/Dozer/compare/v4.0.0...v4.0.1) (2022-10-13)


### Bug Fixes

* windows taskbar title of Dozer window ([236d403](https://github.com/kasp1/Dozer/commit/236d4038bcad67852f9660bbbd856d46265b197f))

# [4.0.0](https://github.com/kasp1/Dozer/compare/v3.1.0...v4.0.0) (2022-10-13)


Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> Dozer, a simple continuous integration / deployment / delivery / task runner (CI/CD).
Useful if:
- You don't have your own server existing cloud CI/CD options seem like overkill.
- You don't have your own server and/or existing cloud CI/CD options seem like overkill.
- Existing cloud CI/CD options are not suitable for some reason (e.g. too hardware demanding runs).
- You want to use command line tools that are hard to install on cloud runners.
- Your environment is already set up and you want to save time installing all tools on each CI/CD run.
Expand All @@ -21,6 +21,8 @@ The GUI is optional. Dozer can also just run as a CLI command.

# Quick Start

[Instructions for Dozer v3](https://github.com/kasp1/Dozer/tree/afe1b6220bae3603dfc1e4ff99cdc45f6a5d32ec) and earlier.

## Install

0. If you have Dozer 3 or earlier installed, uninstall it first (find Dozer in the *Apps & Features* settings dialog, click it and select Uninstall).
Expand Down Expand Up @@ -263,7 +265,15 @@ Before packaging for distribution, the development and build requirements for ea

The `DOZER_VC_DLLS` environment variable needs to be set to the path where `msvcp140.dll`, `vcruntime140.dll`, `vcruntime140_1.dll` are located, e.g. `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.32.31326\x64\Microsoft.VC143.CRT`.

Run `build-dist-win.bat`. When finished, the Dozer distributable should be present as `dist/Windows64.zip`.
Run `build-dist-win.bat`. When finished, the Dozer distributable should be present as `dist/Dozer_<version>_Windows_x64.zip`.

### Linux

Run `build-dist-linux.bat`. When finished, the Dozer distributable should be present as `dist/Dozer_<version>_Linux_x64.zip`.

### MacOS

Run `build-dist-mac.bat`. When finished, the Dozer distributable should be present as `dist/Dozer_<version>_MacOS.zip`.


## Websockets API
Expand Down
2 changes: 2 additions & 0 deletions examples/dev/dev-short.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
steps:
- title: Print Node Path
command: where node
- title: 10 Second Step
command: node examples/dev/delayed.js 10
- title: Instant Step
Expand Down
35 changes: 34 additions & 1 deletion runner/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Axios = require('axios')
const fs = require('fs')
const open = require('open')
const express = require('express')
const execSync = require('child_process').execSync

let helpers = {
log (...args) {
Expand Down Expand Up @@ -132,14 +133,46 @@ let helpers = {

helpers.log('Serving WebUI from', process.env['DOZER_DEV_WEBUI_DIR'])
} else {
server.use(express.static(path.join(__dirname, 'webui')))
server.use(express.static('webui'))
}

server.listen(port)

helpers.log('Serving WebUI on', port)

open(`http://localhost:${port}/#localhost:${helpers.getApiPort()}`)
},

node: '',
findNodeExecutable() {
let systemNodeJS = 'node'

switch (process.platform) {
case 'linux': systemNodeJS = execSync('whereis node', { econding: 'utf8' }).toString().trim(); break
case 'win32': systemNodeJS = execSync('where node', { econding: 'utf8' }).toString().trim(); break
case 'darwin': systemNodeJS = execSync('which node', { econding: 'utf8' }).toString().trim(); break
}

if (!fs.existsSync(systemNodeJS)) {
systemNodeJS = 'node'
} else {
systemNodeJS = `"${systemNodeJS}"`
}

helpers.node = systemNodeJS
},

replaceNodeInCommand(command) {
if (helpers.node == '') {
helpers.findNodeExecutable()
}

// replaces "node" at the beginning of the command
command = command.replace(/^node/gm, helpers.node)
// replaces "node" after each & or &&
command = command.replace(/(?<=&\W*)node/gm, helpers.node)

return command
}
}

Expand Down
10 changes: 10 additions & 0 deletions runner/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const open = require('open')

const h = require('./helpers.js')
const api = require('./api.js')
const helpers = require('./helpers.js')

let runner = {
yaml: null,
Expand Down Expand Up @@ -143,6 +144,15 @@ let runner = {
command = command.replace(new RegExp('\\${' + v + '}', 'gm'), runner.addedVars[v])
}

// if the command contains a "node" (NodeJS) call to a script, by default the script would be
// executed by the NodeJS version embedded with Dozer, which doesn't support ES6 "import",
// it does support only CommonJS "require". This can be worked-around by specifying direct
// path to the system's NodeJS binary in the command, which is done automatically by
// the following line. https://github.com/vercel/pkg/issues/1291
//
// Note: this has only effect in shipped builds where NodeJS is embedded by `pkg`
command = helpers.replaceNodeInCommand(command)

// run the exec
h.log('Executing step', h.getTitle(step) + ':', command)

Expand Down

0 comments on commit 5ce9443

Please sign in to comment.