clean up development config

This commit is contained in:
Eric Hulburd
2016-02-09 11:16:49 -06:00
parent 109ad432bb
commit a334afbc01
20 changed files with 170 additions and 111 deletions

View File

@@ -1,7 +1,11 @@
import React from 'react';
import layoutRt from './layout.rt.js'; import layoutRt from './layout.rt.js';
var Layout = React.createClass({ var Layout = React.createClass({
getInitialState: function() {
getInitialState: function(){
return {view: "????"};
}, },
handleResize: function(e) { handleResize: function(e) {
@@ -14,11 +18,12 @@ var Layout = React.createClass({
setView: function(event) { setView: function(event) {
var layout = this; var layout = this;
console.log(event.target.value)
layout.setState({view: event.target.value}); layout.setState({view: event.target.value});
}, },
render: function() { render: function() {
return layoutRt.bind(this); return layoutRt.call(this);
} }
}); });

View File

@@ -1,4 +1,6 @@
<div>
<div id="layout">
<h1>{this.state.view}</h1>
<select onChange="{this.setView}"> <select onChange="{this.setView}">
<option value="savings">Savings</option> <option value="savings">Savings</option>
<option value="production">Production</option> <option value="production">Production</option>

View File

@@ -1,5 +1,5 @@
import React from 'react/addons'; import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
export default function () { export default function () {
return React.createElement('div', {}, React.createElement('select', { 'onChange': this.setView }, React.createElement('option', { 'value': 'savings' }, 'Savings'), React.createElement('option', { 'value': 'production' }, 'Production'))); return React.createElement('div', { 'id': 'layout' }, React.createElement('h1', {}, this.state.view), React.createElement('select', { 'onChange': this.setView }, React.createElement('option', { 'value': 'savings' }, 'Savings'), React.createElement('option', { 'value': 'production' }, 'Production')));
}; };

View File

@@ -27,9 +27,9 @@ gulp.task('save_house_csv', function(done){
}); });
gulp.task('compile_react_templates', function() { gulp.task('compile_react_templates', function() {
gulp.src('./client/react/**/*.rt') gulp.src('./client/dashboard/**/*.rt')
.pipe(rtCompile(rt_config)) .pipe(rtCompile(rt_config))
.pipe(gulp.dest('./client/react')); .pipe(gulp.dest('./client/dashboard'));
}); });

45
npm-debug.log Normal file
View File

@@ -0,0 +1,45 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@3.5.3
3 info using node@v5.4.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle spike_proto@0.0.0~prestart: spike_proto@0.0.0
6 silly lifecycle spike_proto@0.0.0~prestart: no script for prestart, continuing
7 info lifecycle spike_proto@0.0.0~start: spike_proto@0.0.0
8 verbose lifecycle spike_proto@0.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle spike_proto@0.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/eric/Code/spike2/node_modules/.bin:/home/eric/.rvm/gems/ruby-1.9.3-p484@oroeco_dev/bin:/home/eric/.rvm/gems/ruby-1.9.3-p484@global/bin:/home/eric/.rvm/rubies/ruby-1.9.3-p484/bin:/home/eric/.rvm/bin:/home/eric/bin:/usr/local/heroku/bin:/home/eric/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/lampp/bin
10 verbose lifecycle spike_proto@0.0.0~start: CWD: /home/eric/Code/spike2
11 silly lifecycle spike_proto@0.0.0~start: Args: [ '-c', 'babel-node ./server/app.express.js' ]
12 silly lifecycle spike_proto@0.0.0~start: Returned: code: 1 signal: null
13 info lifecycle spike_proto@0.0.0~start: Failed to exec start script
14 verbose stack Error: spike_proto@0.0.0 start: `babel-node ./server/app.express.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at EventEmitter.emit (events.js:172:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at ChildProcess.emit (events.js:172:7)
14 verbose stack at maybeClose (internal/child_process.js:821:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid spike_proto@0.0.0
16 verbose cwd /home/eric/Code/spike2
17 error Linux 3.19.0-49-generic
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 error node v5.4.1
20 error npm v3.5.3
21 error code ELIFECYCLE
22 error spike_proto@0.0.0 start: `babel-node ./server/app.express.js`
22 error Exit status 1
23 error Failed at the spike_proto@0.0.0 start script 'babel-node ./server/app.express.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the spike_proto package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error babel-node ./server/app.express.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs spike_proto
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls spike_proto
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

View File

@@ -3,11 +3,10 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "babel-node ./app.express.js" "start": "babel-node ./server/app.express.js"
}, },
"dependencies": { "dependencies": {
"body-parser": "~1.12.0", "body-parser": "~1.12.0",
"cookie-parser": "~1.3.4",
"debug": "~2.1.1", "debug": "~2.1.1",
"jade": "~1.9.2", "jade": "~1.9.2",
"morgan": "~1.5.1", "morgan": "~1.5.1",

View File

@@ -6,46 +6,71 @@ import express from 'express';
import path from 'path'; import path from 'path';
import webpack from 'webpack'; import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server'; import WebpackDevServer from 'webpack-dev-server';
import schema from './config/graphql/schema'; import bodyParser from 'body-parser';
import DB from './config/database'; import DB from './config/database';
import routes from './routes'; import routes from './routes';
const API_PORT = 8080;
const APP_PORT = 3000; const APP_PORT = 3000;
const JS_PORT = 3000;
var app = express(); var api = express();
/*
* Serve API App
*/
DB.sync().then(()=>{ DB.sync().then(()=>{
routes(app); routes(api);
api.use(bodyParser.json());
api.use(bodyParser.urlencoded({ extended: false }));
api.listen(API_PORT, () => {
console.log(`API is now running on http://localhost:${API_PORT}`);
});
});
/* /*
* Logging, Cookie, JSON Parsing Middleware * Development Server
*/ */
import favicon from 'serve-favicon'; var config = require('./config/webpack/development'),
import logger from 'morgan'; dev_server = new WebpackDevServer(webpack(config), {
import cookieParser from 'cookie-parser'; contentBase: __dirname + '/../client/build/development',
import bodyParser from 'bodyParser'; publicPath: "/assets/",
proxy: {
// uncomment after placing your favicon in /public '/data': `http://localhost:${APP_PORT}`,
app.use(favicon(__dirname + '/public/favicon.ico')); },
app.use(logger('dev')); stats: {colors: true}
app.use(bodyParser.json()); }),
app.use(bodyParser.urlencoded({ extended: false })); app = dev_server.app;
/* /*
* Serve Vendor Scripts, CSS, and Templates * Serve Vendor Scripts, CSS, and Templates
*/ */
import favicon from 'serve-favicon';
import logger from 'morgan';
// uncomment after placing your favicon in /public
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
// serve fonts in /assets/fonts // serve fonts in /assets/fonts
import assets from "connect-assets"; import assets from "connect-assets";
app.use("/assets/fonts", express.static("node_modules/bootstrap/dist/fonts"));
app.use("/assets/fonts", express.static("node_modules/font-awesome/fonts")); // TODO: These routes need to match references in the bootstrap and font awesome files.
app.use("/assets/fonts", express.static("bootstrap/dist/fonts"));
app.use("/assets/fonts", express.static("font-awesome/fonts"));
// serve compiled vendor assets and application.css. // serve compiled vendor assets and application.css.
app.use(assets({ app.use(assets({
paths: ["./assets/js", "./assets/css", "./../node_modules"], paths: ["./../node_modules"],
build: true, build: true,
buildDir: false, buildDir: false,
//compile: false, //compile: false,
@@ -61,9 +86,6 @@ app.get("/", (req, res, next)=>{
res.render("index"); res.render("index");
}); });
app.listen(APP_PORT, () => {
console.log(`App is now running on http://localhost:${APP_PORT}`);
});
/* /*
* Handle Errors * Handle Errors
@@ -98,55 +120,8 @@ app.use(function(err, req, res, next) {
}); });
}); });
dev_server.listen(APP_PORT, () => {
console.log(`App is now running on http://localhost:${APP_PORT}`);
}); });
/*
* Development Server
*/
import ExtractTextPlugin from "extract-text-webpack-plugin";
var compiler = webpack({
entry: {
app: __dirname + '/../client/app.js',
style: __dirname + '/../client/style.scss'
},
output: {
filename: '[name].js',
path: __dirname + '/../client/build'
},
externals: {
jquery: "$",
d3: "d3"
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
}
]
},
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin("style.css", {
allChunks: true
})
]
});
var dev_server = new WebpackDevServer(compiler, {
contentBase: __dirname + '/../client/build',
publicPath: "/assets/",
proxy: {
'/data': `http://localhost:${APP_PORT}`
},
stats: {colors: true}
});
module.exports = app; module.exports = app;

View File

@@ -0,0 +1,17 @@
import fs from 'fs';
const CONTROLLER_DIR = __dirname + '/../controllers';
class Controllers {
static sync(){
fs.readdirSync(CONTROLLER_DIR).forEach(function(file) {
var controller = require(CONTROLLER_DIR + '/' + file);
Controllers[controller.NAME] = controller;
});
return true;
}
}
export default Controllers;

View File

@@ -10,15 +10,15 @@ var sequelize = new Sequelize("postgres://spikeuser:123456@localhost:5432/spike2
idle: 10000 idle: 10000
} }
}); });
const model_dir = __dirname + '/../models' const MODEL_DIR = __dirname + '/../models'
class Database { class Database {
static sync(){ static sync(){
console.log("syncing db") console.log("syncing db")
fs.readdirSync(model_dir).forEach(function(file) { fs.readdirSync(MODEL_DIR).forEach(function(file) {
var model = require(model_dir + '/' + file); var model = require(MODEL_DIR + '/' + file);
Database[model.name] = model; Database[model.NAME] = model;
Database.models.push(model); Database.models.push(model);
}); });

View File

@@ -1,5 +1,7 @@
export default { var config = {
modules: 'es6', modules: 'es6',
'target-version': '0.14.3', targetVersion: '0.14.0',
'suffix': '.rt' suffix: '.rt'
}; };
export default config;

View File

@@ -1,3 +1,5 @@
import webpack from 'webpack';
const ROOT = __dirname + '/../../../'; const ROOT = __dirname + '/../../../';
module.exports = { module.exports = {
@@ -17,21 +19,20 @@ module.exports = {
loaders: [ loaders: [
{ {
test: /\.scss$/, test: /\.scss$/,
loader: ['style', 'raw', 'sass'] loaders: ['style', 'raw', 'sass']
}, { }, {
test: /\.css$/, test: /\.css$/,
loader: ['style', 'raw'] loaders: ['style', 'raw']
}, {
test: /\.js$/,
loader: 'babel'
} }
] ]
}, },
sassLoader: { sassLoader: {
includePaths: [ROOT + 'client', ROOT + 'node_modules'] includePaths: [ROOT + 'client', ROOT + 'node_modules']
}, },
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [ plugins: [
new ExtractTextPlugin("style.css", {
allChunks: true
}),
new webpack.ProvidePlugin({ new webpack.ProvidePlugin({
$: "jquery", $: "jquery",
jQuery: "jquery", jQuery: "jquery",

View File

@@ -1,13 +1,18 @@
import DB from './../config/database.js'; import DB from './../config/database.js';
const NAME = 'EnergyController';
class EnergyController{ class EnergyController{
static index(req, res){ static index(req, res){
DB.House.findOne({where: {name: req.housename}}).then((house)=>{ DB.House.findOne({where: {name: req.housename}}).then((house)=>{
house.getEnergyDataByTime(req.params.start_time, req.params.end_time).then((energy_data){ house.getEnergyDataByTime(req.params.start_time, req.params.end_time).then((energy_data)=>{
req.json(energy_data); req.json(energy_data);
}); });
}); });
} }
} }
EnergyController.NAME = NAME;
module.exports = EnergyController;

View File

@@ -1,11 +1,16 @@
import DB from './../config/database.js'; import DB from './../config/database.js';
const NAME = HousesController;
class HousesController{ class HousesController{
static index(req, res){ static index(req, res){
DB.House.findAll({attributes: ['id', 'name']}).then((houses){ DB.House.findAll({attributes: ['id', 'name']}).then((houses)=>{
res.json(houses); res.json(houses);
}); });
} }
} }
HousesController.NAME = NAME;
module.exports = HousesController;

View File

@@ -1,13 +1,18 @@
import DB from './../config/database.js'; import DB from './../config/database.js';
const NAME = 'PowerController';
class PowerController{ class PowerController{
static index(req, res){ static index(req, res){
DB.House.findOne({where: {name: req.housename}}).then((house)=>{ DB.House.findOne({where: {name: req.housename}}).then((house)=>{
house.getPowerDataByTime(req.params.start_time, req.params.end_time).then((power_data){ house.getPowerDataByTime(req.params.start_time, req.params.end_time).then((power_data)=>{
res.json(power_data); res.json(power_data);
}); });
}); });
} }
} }
PowerController.NAME = NAME;
module.exports = PowerController;

View File

@@ -34,8 +34,7 @@ export default function (opt) {
var options = extend({ var options = extend({
filename: file.path, filename: file.path,
sourceFiles: [file.relative], sourceFiles: [file.relative],
generatedFile: replaceExtension(file.relative), generatedFile: replaceExtension(file.relative)
suffix: '.rt'
}, opt); }, opt);
if (options.suffix && !options.name) { if (options.suffix && !options.name) {

View File

@@ -32,5 +32,5 @@ var EnergyDatum = DB.sequelize.define(NAME, {
} }
}); });
EnergyDatum.name = NAME; EnergyDatum.NAME = NAME;
module.exports = EnergyDatum; module.exports = EnergyDatum;

View File

@@ -1,6 +1,5 @@
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import DB from "./../config/database"; import DB from "./../config/database";
import {nodeInterface} from './../config/graphql/node';
const NAME = 'House'; const NAME = 'House';
@@ -76,5 +75,5 @@ var House = DB.sequelize.define(NAME, {
} }
}); });
House.name = NAME; House.NAME = NAME;
module.exports = House; module.exports = House;

View File

@@ -1,6 +1,6 @@
import DB from "./../config/database"; import DB from "./../config/database";
const NAME = 'PowerDatum' const NAME = 'PowerDatum';
/** /**
* Define your own types here * Define your own types here
@@ -32,5 +32,5 @@ var PowerDatum = DB.sequelize.define(NAME, {
} }
}); });
PowerDatum.name = NAME; PowerDatum.NAME = NAME;
module.exports = PowerDatum; module.exports = PowerDatum;

View File

@@ -1,9 +1,11 @@
import Controllers from 'controllers' import Controllers from './config/controllers'
export default function(app){ export default function(app){
app.use('/data/v1/savings/:housename', Controllers.Energy.savings); Controllers.sync();
app.use('/data/v1/production/:housename', Controllers.Energy.production);
app.use('/data/v1/houses/:housename'); app.use('/data/v1/savings/:housename', Controllers.PowerController.index);
app.use('/data/v1/production/:housename', Controllers.EnergyController.index);
app.use('/data/v1/houses/', Controllers.EnergyController.index);
}; };

View File

@@ -4,8 +4,6 @@ html
meta(charset='utf-8') meta(charset='utf-8')
meta(http-equiv='content-type', content='text/html; charset=UTF-8') meta(http-equiv='content-type', content='text/html; charset=UTF-8')
meta(name='viewport', content='width=device-width, initial-scale=1') meta(name='viewport', content='width=device-width, initial-scale=1')
!= css("vendor")
!= css("application")
title Spike Prototype title Spike Prototype
body body
#spike_container #spike_container
@@ -23,7 +21,7 @@ html
ul.nav.navbar-nav.navbar-right ul.nav.navbar-nav.navbar-right
li li
a(href='/') Spike a(href='/') Spike
block content block content
#spike_footer #spike_footer
.container Footer .container Footer
script(type='text/javascript'). script(type='text/javascript').
@@ -31,5 +29,5 @@ html
// in developer tools for the native `fetch`. // in developer tools for the native `fetch`.
self.fetch = null; self.fetch = null;
script(src='http://localhost:3000/webpack-dev-server.js') script(src='http://localhost:3000/webpack-dev-server.js')
!= js("vendor") script(src='/assets/style.js')
script(src='/assets/js/application.js') script(src='/assets/app.js')