Skip to content

Commit

Permalink
Added development / building script and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fcktrmp authored and Hypfer committed Nov 20, 2018
1 parent 9396182 commit 5dfcafa
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ignore node_modules if installed here (e.g. by npm install)
/node_modules/

# ignore configuration files for local development
/develop/local/

# log and map files for local development (could/should become obsolete
# when more control over file location is possible)
/map
/log

# binary compilation output
/valetudo

# IntelliJ Idea project files
/.idea/
3 changes: 2 additions & 1 deletion Testing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
For local testing use the following environment variables:

* VALETUDO_CONFIG
* VAC_ADDRESS
* VAC_TOKEN
* VAC_WEBPORT
* VAC_MAP_TEST
* VAC_MAP_TEST
73 changes: 73 additions & 0 deletions develop/HOWTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Building and Modifying Valetudo

This file provides instructions for quickly setting up an environment where you can build
and modify Valetudo according to your needs.

It shows a complete setup from scratch, on a freshly installed Ubuntu 18.04 system.

Your mileage may vary if you're using a different OS, or if you start from a different setup.
However, it should be rather easy to understand the steps, and to adapt them to your situation.

### 1. Install prerequisites

Install git and npm:

`sudo apt install git npm`

### 2. Clone the repository

```
cd ~
git clone https://github.com/Hypfer/Valetudo.git
```

### 3. Install dependencies

```
cd Valetudo
npm install
```

### 4. Create configuration

```
./develop/run
```

On the first invocation, this script will create the files that you'll need for your local setup, and
it will tell you to to edit them. It is expected behavior for the script to fail on first run, and
you **must** edit at least the `develop/local/env` file.

Once you finished editing the files, you should be all set.

### 5. Verify configuration and run
```
./develop/run
```

If your configuration is correct, Valetudo should now be working on your development host.

### 6. Code!

Modify the source code according to your needs, and restart the server as needed -- you can always run it as:

```
./develop/run
```

### 7. Build and install on the device

When you're done with your modifications, here's how to build the executable for the robot:

```
./node_modules/.bin/pkg --targets latest-linux-armv7 --no-bytecode --options max-old-space-size=72 --public-packages=exif-parser,omggif,trim,prettycron .
```

The output file `valetudo` is a binary file that you can copy to the device:

```
scp ./valetudo [email protected]:/usr/local/bin/
```

Once you're that far, you hopefully don't need any further advice.

2 changes: 2 additions & 0 deletions develop/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"spots":[],"areas":[]}

13 changes: 13 additions & 0 deletions develop/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This is a sample environment for developing valetudo locally.
# This will not work for you out of the box. Please do not edit
# this file directly, but edit the file in local/env instead.

export VALETUDO_CONFIG=./develop/local/config.json
export VAC_WEBPORT=8080
export VAC_ADDRESS=192.168.1.42
export VAC_TOKEN=11223344556677889900aabbccddeeff
#export VAC_MAP_TEST=true

# In case your system uses a different command than "nodejs" for running node.js,
# please specify it below as VALETUDO_NODE_JS. Here's the default:
# VALETUDO_NODE_JS="nodejs"
86 changes: 86 additions & 0 deletions develop/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash -e

####################################################################################
#
# This file provides a simple way to run a development version of valetudo on your
# local computer. It should be invoked from the main directory as ./develop/run.sh
#
# Environment settings and configuration are read from the directory develop/local/.
# If that directory doesn't exist, it will be created on the first invocation of
# the script.
#
# For more information, see the file HOWTO.md in this directory.
#
####################################################################################


# check if we're in the right (main) directory
if [ "$0" != "./develop/run" ]; then
echo "Please run this script from the main Valetudo directory, i.e. as ./develop/run"
exit 1
fi

# check if necessary files exist
if [ ! -f "./develop/config.json.example" ]; then
echo "Example configuration not found, bailing out"
exit 1
fi

if [ ! -f "./develop/env.example" ]; then
echo "Example environment not found, bailing out"
exit 1
fi

# check if local configuration exists, else create
if [ ! -d "./develop/local" ]; then
echo "Local configuration not found, initializing ..."
echo ""

mkdir ./develop/local
cp ./develop/config.json.example ./develop/local/config.json

echo "# This file contains environment settings for your local valetudo development." > ./develop/local/env
echo "# Edit it according to your individual setup." >> ./develop/local/env
echo "" >> ./develop/local/env

# IMPORTANT: adjust the number of lines to be copied in case the example environment changes.
tail -n 9 ./develop/env.example >> ./develop/local/env

echo "Local configuration created. Please edit the files in ./develop/local/"
echo "to suit your needs, then start this script again."
echo ""

echo "Initializing local (development) maps and paths ..."
# Create empty map files for initial run, to prevent errors.
# This should be revisited when the map testing logic is adapted.
if [ ! -f "./map" ]; then
echo "Creating empty map file"
touch ./map
fi

if [ ! -f "./log" ]; then
echo "Creating empty path log file"
touch ./log
fi

exit 1
fi

if [ ! -f "./develop/local/env" ]; then
echo "Environment settings not found, bailing out"
exit 1
fi

# default command to run
VALETUDO_NODE_JS=nodejs

# load environment
. ./develop/local/env

echo "Starting Valetudo locally with the following settings:"
echo ""
grep -v '#' ./develop/local/env | grep '=' | cat
echo ""

$VALETUDO_NODE_JS ./index.js

0 comments on commit 5dfcafa

Please sign in to comment.