Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
/ homey-dev Public archive

Homey (docker) development environment

License

Notifications You must be signed in to change notification settings

cgHome/homey-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Homey-Dev

Homey (docker) development environment

â›” [DEPRECATED] Active at https://github.com/cghome/create-homey-app

Intro

After my old MacMini had died (RIP), I decided that my new computer (MacBook Pro) should no longer be a "Node.js Versions Messi". Because different server applications need different configurations and versions to load and manage. For example, if a Node.js app has not been used for a while, there is a good chance that it won't work properly anymore and you have to adapt the whole environment first. Only to find out afterwards, that there are new problems with another server app.

For this reason, I no longer install a server (Nodejs app, DB, etc.) directly on the computer, but create a separate docker image/container for all of them.

What is Homey-Dev ???

Homey-Dev is a development environment consisting of the normal Homey-App and a runtime environment (via athom-cli) in a (Homey-Dev) docker container. The container is controlled by various commands (see Bash commands), which are defined as "bash-functions" during installation.

Furthermore, different Build-Tools commands are integrated, which are implemented as npm-scripts and can be used with "homey-run ..." or "npm run ..." (If node.js is installed on host). In addition, a remote debugger can be defined for the Homey-App in development mode.

Pre-requisites

  • Bash compatible OS (Tested with macOS Mojave)
  • Docker installed
  • Git installed
  • Github account
  • Athom developer account

[Optional]

Installation

Install Homey-Dev

curl -s https://github.com/raw/cgHome/homey-dev/master/install.sh | bash && source ~/.bashrc

Configure git on host-os

git config --global hub.protocol https

git config --global credential.helper store
git config --global credential.helper 'cache --timeout 7200'

git config --global user.name ["GITUSER_NAME"]
git config --global user.email ["name@example.com"]

Optional:

git config --global color.ui auto
git config --global format.pretty oneline

Uninstall

unset -f homey-dev homey-run homey-start homey-createApp && rm ~/.bashrc

# OR remove the homey bash-functions on ~/.bashrc

unset -f homey-dev homey-run homey-start homey-createApp && nano ~/.bashrc

Upgrade

# Reinstall docker-image
[app-root] docker container rm -f ${PWD##*/}
[app-root] docker rmi cghome/homey-dev

# Reinstall the Homey-Dev bash-functions (if needed)
unset -f homey-dev homey-run homey-start homey-createApp && nano ~/.bashrc
curl -s https://github.com/raw/cgHome/homey-dev/master/install.sh | bash && source ~/.bashrc

# Start new Homey-Dev app-container
[app-root] homey-start

Attention:

After the bashrc-file modification, you have to reload the file (source ~/.bashrc) or restart the terminal-session.

Usage

Bash commands

homey-dev <command>         Run a bash command inside your homey-dev container
homey-run <npm-script>  Run a npm-script inside homey-dev container

homey-start             Start a homey-dev container for your homey-app
homey-createApp         Create a new homey-app & homey-dev container

Homey-Dev Build-Tools

info                    Homey-App (container) information
test                    Run a Homey-App in development/debug mode
setup                   Setup (install) a Homey-App
build                   Build a Homey-App for publishing
deploy:xxx              Workflow: build, push & relase on github and publish them to the Homey Apps Store.
deploy:major            - MAJOR version when you make incompatible API changes.
deploy:minor            - MINOR version when you add functionality in a backwards-compatible manner, and
deploy:patch            - PATCH version when you make backwards-compatible bug fixes. (see semver.org)
init:app                (Re)Initialize package.json based on homey-app/app.json (see .npm-init.js)

[User-Scripts]          User defined npm-scripts.

Define npm-scripts

# Format
"[Name]": "npm run -s _homeyRun -- [Name] && exit; [App-Container commands]"

# Sample
"foo": "npm run -s _homeyRun -- foo && exit; echo \">> bar on: (${HOSTNAME})\" "

Working with

(There is also a sample app see: org.cflat-inc.homey-app)

Step 1: Install Homey-Dev

curl -s https://github.com/raw/cgHome/homey-dev/master/install.sh | bash && source ~/.bashrc

Step 2: Create a Homey-App

[repo] homey-createApp

Step 2a: Or (if app exist) start Homey-Dev app-container

[app-root] homey-start

Step 2b: Migration of the <package.json> file into the Homey-Dev environment

[app-root] homey-dev npm init -y

Step 3: Add Remote (node.js) debuger

Replace app.js

'use strict';

const Homey = require('homey');

const DEBUG = process.env.DEBUG === '1';

class App extends Homey.App {
    constructor(...args) {
        super(...args);
    };

    onInit() {
        this.log(`${ this.id } is running...(debug mode ${ DEBUG ? 'on' : 'off' })`);
        if (DEBUG) {
            require('inspector').open(9229, '0.0.0.0');
        };
    };
}

module.exports = App;

Add to (VS Code) launch.json

{
    "type": "node",
    "request": "attach",
    "name": "Attach to Homey",
    "address": "xxx.xxx.xxx.xxx",         <- Homey IpAdr
    "port": 9229,
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/",
}

Step 4: Happy coding & testing

[app-root] homey-run test

[app-root] npm run test                 <- (*1)

Step 5: Deploy/Relase the Homey App on github and publish them to the Homey Apps Store

[app-root] homey-run deploy:minor

[app-root] npm run deploy:minor         <- (*1)

Step 5a: Or setup/install App on your homey

[app-root] homey-run setup

[app-root] npm run setup              <- (*1)

(*1 = If node.js is installed on host)

Changelog

v0.3.0

  • Some changes for the new Homey-App Store
  • Rename homey bash-cmd to homey-dev
  • Change npm-package athom-cli to homey

v0.2.2

  • npm-script 'install' to 'setup' renamed

v0.2.1

  • _homeyRun dedection fixed

v0.2.0

  • Homey-Dev Build-Tools added

v0.1.0

  • Initial release

ToDo

Copyright and license

Copyright 2018, 2018 cflat-inc.org under MIT License