Skip to content
Permalink
Browse files

Implement Module System

  • Loading branch information...
Florian Wendelborn
Florian Wendelborn committed Feb 22, 2017
1 parent dedef4a commit 7ef4254fa466da0152673ab65f70f20fa603b80b
@@ -1,3 +1,4 @@
/node_modules/
/build/
/npm-debug.log
/modules/
@@ -14,17 +14,21 @@
]
},
"dependencies": {
"hyperapp": "^0.4.2",
"bulma": "^0.3.1",
"hyperapp": "^0.5.0",
"robogen": "^0.0.2",
"spirit": "^0.4.0",
"spirit-body": "^0.0.3",
"spirit-router": "^0.4.0"
"spirit-router": "^0.4.0",
"superagent": "^3.4.4"
},
"description": "Modular real-time home automation server.",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-plugin-transform-react-jsx": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.1.8",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-3": "^6.22.0",
@@ -40,10 +44,11 @@
"main": "build",
"name": "smartflat",
"scripts": {
"build": "yarn run copy && webpack --config source/build/webpack.js && babel source/server -d build/server",
"copy": "rm -rf build && mkdir -p build/client && cp source/client/index.html build/client/index.html",
"start": "node build/server",
"watch": "nodemon --watch source --watch package.json -e js,jsx,html,css,png,svg,jpg,json,sass --exec \"yarn run build && yarn run start\""
"build": "yarn run build-clear && yarn run build-transpile",
"build-clear": "rm -rf build",
"start": "node build",
"build-transpile": "babel source -d build",
"watch": "nodemon --delay 0.5s --watch source --watch package.json --watch modules -e js,jsx,html,css,png,svg,jpg,json,sass --exec \"yarn run build && yarn run start\""
},
"repository": "https://dodekeract@github.com/smartflat/smartflat.git",
"version": "1.0.0"
@@ -18,6 +18,10 @@ Devices are just extensions.
- Real-time
- Scriptable

### Modular



## Extensions

- [WebHook](https://github.com/smartflat/smartflat-webhooks)

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

No changes.
@@ -2,6 +2,9 @@ export default {
cache: {
static: 'public, max-age=600'
},
routes: {
default: '/m/web-ui/'
},
listen: {
host: '0.0.0.0',
port: 8080
BIN -44.4 KB source/images/logo.png
Binary file not shown.

This file was deleted.

@@ -6,12 +6,13 @@ import spirit from 'spirit'

// internal

import config from './config'
import * as httpError from './utilities/http-error.js'
import config from './config'
import modules from './utilities/modules'

// routes

import {html, js} from './routes/client'
import {images, robots} from './routes/static'

// endregion

@@ -25,11 +26,19 @@ const {host, port} = config.listen

const app = route.define([
// client
route.get('/', html),
route.get('/bundle.js', js),
route.get('/', {
status: 307,
body: `<a href="${config.routes.default}">Redirect</a>`,
headers: {
Location: config.routes.default
}
}),

// modules
...modules(),

// other
route.get('/robots.txt', () => ''),
route.get('/robots.txt', robots),
route.get('/favicon.ico', () => ''),
route.any('*', httpError.notFound)
])
@@ -0,0 +1,13 @@
// region sign-in

export const signIn = async () => {
return {
status: 200,
body: JSON.stringify({
user: 'something'
}),
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
}
@@ -0,0 +1,24 @@
// region import

import fs from 'fs'
import robogen from 'robogen'

// utilities

import * as httpError from '../utilities/http-error'

// endregion

// region static

export const robots = {
status: 200,
body: robogen([{
disallow: '/'
}]),
headers: {
'Content-Type': 'text/plain; charset=utf-8'
}
}

// endregion

This file was deleted.

@@ -0,0 +1,2 @@
const foo = 'bar'
export default {foo}
File renamed without changes.
@@ -0,0 +1,34 @@
// region import

import fs from 'fs'
import path from 'path'
import route from 'spirit-router'

// internal

import api from './api'

// endregion

// region routes

const modules = fs
.readdirSync(`${__dirname}/../../modules`)
.map(name => path.join(`${__dirname}/../../modules`, name))
.filter(name => fs
.statSync(name)
.isDirectory()
)
.map(name => require(`${name}/build/info.js`).default({api}))

// endregion

// region serve

export default () => modules
.map(({name, routes}) => routes
.map(([method, path, dependencies, handler]) => route[method](`/m/${name}/${path}`, dependencies, handler))
)
.reduce((a, b) => [...a, ...b], [])

// endregion

0 comments on commit 7ef4254

Please sign in to comment.
You can’t perform that action at this time.