Skip to content

Commit

Permalink
reorganize directory structure (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Jun 6, 2018
1 parent 88d9e1a commit b737181
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 55 deletions.
2 changes: 0 additions & 2 deletions addon_files/node-red/etc/npmrc

This file was deleted.

2 changes: 2 additions & 0 deletions addon_files/redmatic/etc/npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache = /usr/local/addons/redmatic/npm-cache
prefix = /usr/local/addons/redmatic
File renamed without changes.
29 changes: 16 additions & 13 deletions addon_files/node-red/node-red → addon_files/redmatic/redmatic
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

CONF_DIR=/usr/local/etc/config
ADDON_DIR=/usr/local/addons/node-red
ADDON_DIR=/usr/local/addons/redmatic
WWW_DIR=/usr/local/etc/config/addons/www/redmatic

NODE=$ADDON_DIR/bin/node
Expand Down Expand Up @@ -60,25 +60,28 @@ case "$1" in
echo "Info: <a href="https://github.com/hobbyquaker/RedMatic"><img src="/addons/redmatic/logo-w-200.png" align="right"/></a>"
echo "Info: <table><tr><td>Node.js</td><td>$NODE_VERSION</td></tr>"
echo "Info: <tr><td>npm</td><td>$VERSION_npm</td></tr>"
echo "Info: <tr><td>Node-RED</td><td>$VERSION_nodered</td></tr>"
echo "Info: <tr><td>Node-RED Dashboard</td><td>$VERSION_nodereddashboard</td></tr>"
echo "Info: <tr><td>node-red-contrib-ccu</td><td>$VERSION_noderedcontribccu</td></tr></table>"
echo "Info: <tr><td>Node-RED</td><td>$VERSION_nodered</td></tr></table>"
echo "Name: RedMatic"
echo "Version: $VERSION_ADDON"
echo "Update: /addons/redmatic/update_check.cgi"
echo "Operations: restart uninstall"
;;

uninstall)
Stop
$ADDON_DIR/update_addon node-red
$ADDON_DIR/update_addon node-red-dashboard
rm -r $ADDON_DIR
rm -r $WWW_DIR
rm $CONF_DIR/addons/www/check_update_node_red.cgi &> /dev/null || true
rm $CONF_DIR/lighttpd/node-red.conf
rm $CONF_DIR/rc.d/node-red
;;
Stop
$ADDON_DIR/update_addon node-red
$ADDON_DIR/update_addon node-red-dashboard
rm -r $ADDON_DIR
rm -r $WWW_DIR
rm $CONF_DIR/lighttpd/redmatic.conf
rm $CONF_DIR/rc.d/redmatic

# migration
if [ -f $CONF_DIR/addons/www/check_update_node_red.cgi ]; then
rm $CONF_DIR/addons/www/check_update_node_red.cgi
fi

;;

*)
echo "Usage: node-red {start|stop|restart|info|uninstall}" >&2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {

// By default, all user data is stored in the Node-RED install directory. To
// use a different location, the following property can be used
userDir: '/usr/local/addons/node-red/var',
userDir: '/usr/local/addons/redmatic/var',

// Node-RED scans the `nodes` directory in the install directory to find nodes.
// The following property can be used to specify an additional directory to scan.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env tclsh

set checkURL "https://api.github.com/repos/hobbyquaker/ccu-addon-node-red/releases/latest"
set downloadURL "https://github.com/hobbyquaker/ccu-addon-node-red/releases/latest"
set checkURL "https://api.github.com/repos/hobbyquaker/RedMatic/releases/latest"
set downloadURL "https://github.com/hobbyquaker/RedMatic/releases/latest"

catch {
set input $env(QUERY_STRING)
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions addon_files/redmatic/var/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "node-red-project",
"description": "A Node-RED Project",
"version": "0.0.1",
"dependencies": {
"node-red-dashboard": "2.9.4",
"node-red-contrib-ccu": "0.5.0",
"node-red-contrib-combine": "1.2.0",
"node-red-contrib-mqtt-json": "1.0.1"
}
}
2 changes: 1 addition & 1 deletion addon_files/update_addon
34 changes: 28 additions & 6 deletions addon_files/update_script
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

ADDONS_DIR=/usr/local/addons
RED_DIR=$ADDONS_DIR/node-red
RED_DIR=$ADDONS_DIR/redmatic
CONF_DIR=/usr/local/etc/config
WWW_DIR=$CONF_DIR/addons/www/redmatic

Expand All @@ -13,21 +13,43 @@ fi
mkdir -p $ADDONS_DIR && chmod 755 $ADDONS_DIR
mkdir -p $WWW_DIR && chmod 755 $WWW_DIR

if [ -f $CONF_DIR/rc.d/node-red ]; then
$CONF_DIR/rc.d/node-red stop
if [ -f $CONF_DIR/rc.d/redmatic ]; then
$CONF_DIR/rc.d/redmatic stop
fi

if [ -f $RED_DIR/settings.js ]; then
cp $RED_DIR/settings.js $RED_DIR/settings.js.old
fi

cp -af node-red $ADDONS_DIR/
cp -af redmatic $ADDONS_DIR/


# migration
if [ -d $ADDONS_DIR/node-red ]; then

if [ -f $CONF_DIR/rc.d/node-red ]; then
$CONF_DIR/rc.d/node-red stop
fi
if [ -f $CONF_DIR/addons/www/check_update_node_red.cgi ]; then
rm $CONF_DIR/addons/www/check_update_node_red.cgi
fi
if [ -f $CONF_DIR/lighttpd/node-red.conf ]; then
rm $CONF_DIR/lighttpd/node-red.conf
fi

cp $ADDONS_DIR/node-red/var/flows.json $RED_DIR/var/flows.json
cp $ADDONS_DIR/node-red/settings.js $RED_DIR/var/settings.js.old

rm -rf $ADDONS_DIR/node-red
fi


mkdir -p $CONF_DIR/lighttpd
ln -sf $RED_DIR/lighttpd.conf $CONF_DIR/lighttpd/node-red.conf
ln -sf $RED_DIR/lighttpd.conf $CONF_DIR/lighttpd/redmatic.conf


chmod a+x $RED_DIR/node-red
ln -sf $RED_DIR/node-red $CONF_DIR/rc.d/node-red
ln -sf $RED_DIR/redmatic $CONF_DIR/rc.d/redmatic

if [ ! -f $RED_DIR/var/flows.json ]; then
mv $RED_DIR/var/example-flows.json $RED_DIR/var/flows.json
Expand Down
47 changes: 23 additions & 24 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,43 @@ mkdir $ADDON_TMP 2> /dev/null || rm -r $ADDON_TMP/*

echo "download and extract Node.js $NODE_URL ..."
curl --silent $NODE_URL | tar -xJf - -C $ADDON_TMP
mv $ADDON_TMP/$NODE_NAME $ADDON_TMP/node-red
rm $ADDON_TMP/node-red/README.md
rm $ADDON_TMP/node-red/CHANGELOG.md
mv $ADDON_TMP/node-red/LICENSE $ADDON_TMP/node-red/LICENSE_Nodejs
mv $ADDON_TMP/$NODE_NAME $ADDON_TMP/redmatic
rm $ADDON_TMP/redmatic/README.md
rm $ADDON_TMP/redmatic/CHANGELOG.md
mv $ADDON_TMP/redmatic/LICENSE $ADDON_TMP/redmatic/LICENSE_Nodejs


echo "copying files to tmp dir..."
cp -r $ADDON_FILES/* $ADDON_TMP/
cp $BUILD_DIR/assets/logo-w-200.png $ADDON_TMP/node-red/
cp $BUILD_DIR/assets/logo-w-200.png $ADDON_TMP/redmatic/


echo "installing node modules..."
cp package.json $ADDON_TMP/node-red/lib/
cd $ADDON_TMP/node-red/lib
cp package.json $ADDON_TMP/redmatic/lib/
cd $ADDON_TMP/redmatic/lib
npm install --silent --no-package-lock --production --no-optional --global-style
rm $ADDON_TMP/node-red/lib/package.json
rm $ADDON_TMP/redmatic/lib/package.json


echo "installing additional Node-RED nodes..."
cd $ADDON_TMP/redmatic/var
npm install --silent --no-package-lock --production --no-optional


echo "adapt Node-RED..."
rm -r $ADDON_TMP/node-red/lib/node_modules/node-red/nodes/core/hardware
#mv $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js.orig
#sed "s/var npmCommand =.*/var npmCommand = '\/usr\/local\/addons\/node-red\/bin\/npm';/" $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js.orig > $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js
mv $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/log.js $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/log.js.orig
sed "s/util\.log/console.log/g" $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/log.js.orig > $ADDON_TMP/node-red/lib/node_modules/node-red/red/runtime/log.js
rm -r $ADDON_TMP/redmatic/lib/node_modules/node-red/nodes/core/hardware
#mv $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js.orig
#sed "s/var npmCommand =.*/var npmCommand = '\/usr\/local\/addons\/node-red\/bin\/npm';/" $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js.orig > $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/nodes/registry/installer.js
mv $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/log.js $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/log.js.orig
sed "s/util\.log/console.log/g" $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/log.js.orig > $ADDON_TMP/redmatic/lib/node_modules/node-red/red/runtime/log.js


cd $BUILD_DIR


echo "creating version files"
MODULES_DIR=$ADDON_TMP/node-red/lib/node_modules
VERSION_FILE=$ADDON_TMP/node-red/versions
MODULES_DIR=$ADDON_TMP/redmatic/lib/node_modules
VERSION_FILE=$ADDON_TMP/redmatic/versions
VERSION_ADDON=`jq -r '.version' package.json`

cat > $VERSION_FILE <<EOL
Expand All @@ -69,12 +76,6 @@ links() {
'node-red')
URL=https://nodered.org/
;;
'node-red-dashboard')
URL=https://github.com/node-red/node-red-dashboard/releases
;;
'node-red-contrib-ccu')
URL=https://github.com/hobbyquaker/node-red-contrib-ccu
;;
*)
URL=
esac
Expand All @@ -94,9 +95,7 @@ do
links $DIR $VERSION
done

RED_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red/package.json`
DASHBOARD_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-dashboard/package.json`
RED_CCU_VERSION=`jq -r '.version' $ADDON_TMP/node-red/lib/node_modules/node-red-contrib-ccu/package.json`
RED_VERSION=`jq -r '.version' $ADDON_TMP/redmatic/lib/node_modules/node-red/package.json`


echo "creating changelog file"
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"name": "redmatic",
"version": "1.0.0-beta.7",
"version": "1.0.0-beta.8",
"description": "Node-RED packaged as Homematic CCU addon",
"repository": "github:hobbyquaker/redmatic",
"private": true,
"main": "none",
"dependencies": {
"npm": "6.1.0",
"node-red": "0.18.7",
"node-red-admin": "0.1.3",
"node-red-dashboard": "2.9.4",
"node-red-contrib-ccu": "0.5.0",
"node-red-contrib-combine": "1.2.0",
"node-red-contrib-mqtt-json": "1.0.1"
"node-red-admin": "0.1.3"
},
"scripts": {
"test": "exit 0"
Expand Down

0 comments on commit b737181

Please sign in to comment.