diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..cdf0df0 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "optional": ["es7.classProperties"] +} diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 24b5e68..0000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "public/components" -} diff --git a/.gitignore b/.gitignore index 3a45ab3..926b2e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -pkg -*.DS_Store node_modules -public/components -config/Secret.js +Secret.md +npm-debug.log diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index b83df4a..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,144 +0,0 @@ -module.exports = function(grunt) { - require('time-grunt')(grunt); - - grunt.initConfig({ - // Dev tasks - concurrent: { - dev: ["nodemon", "watch"], - options: { - logConcurrentOutput: true - } - }, - - sass: { - dev: { - options: { - sourceMap: true, - update: true - }, - files: [{ - expand: true, - cwd: 'public/scss/', - src: ['*.scss'], - dest: 'public/css', - ext: '.css' - }] - }, - prod: { - options: { - style: 'compressed' - }, - files: [{ - expand: true, - cwd: 'public/scss/', - src: ['*.scss'], - dest: 'pkg/public/css', - ext: '.css' - }] - } - }, - - nodemon: { - dev: { - script: 'app.js', - options: { - env: { - "NODE_ENV": 'dev' - }, - watch: ['app.js', 'config', 'controllers', 'helpers', 'models'], - delay: 300, - } - } - }, - - watch: { - scss: { - files: ['public/scss/**/*.scss'], - tasks: ['sass:dev'] - }, - livereload: { - files: ['public/js/**/*.js', 'public/css/*.css'], - options: { - livereload: 35740 - } - } - }, - - // Build tasks - pkg: grunt.file.readJSON('package.json'), - - clean: { - css: ["public/css/*"], - pkg: ["pkg/"], - }, - - bump: { - options: { - commit: false, - createTag: false, - push: false - } - }, - - copy: { - main: { - files: [ - {src: [ - '.bowerrc', - 'app.js', - 'bower.json', - 'config/**', - 'controllers/**', - 'helpers/**', - 'models/**', - 'package.json', - 'public/**', - 'sh/**', - 'views/**' - ], dest: 'pkg/'} - ] - } - }, - - imagemin: { - full: { - files: [{ - expand: true, - cwd: 'public/', - src: ['img/**/*.{png,jpg,gif}'], - dest: 'pkg/public/' - }] - } - }, - - 'sftp-deploy': { - prod: { - auth: { - host: 'delirium.cloudapp.net', - port: 22, - authKey: 'prod' - }, - src: 'pkg', - dest: '/home/slack-bill-sharing-prod/slack-bill-sharing', - server_sep: '/' - } - } - }); - - // Dev tasks - grunt.loadNpmTasks("grunt-concurrent"); - grunt.loadNpmTasks('grunt-contrib-sass'); - grunt.loadNpmTasks('grunt-nodemon'); - grunt.loadNpmTasks('grunt-contrib-watch'); - - grunt.registerTask('default', ["clean:css", "sass:dev", 'concurrent']); - - // Build tasks - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-bump'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-imagemin'); - grunt.loadNpmTasks('grunt-sftp-deploy'); - - grunt.registerTask('prod', ['clean:pkg', 'sass:prod', 'copy:main', 'imagemin:full', 'sftp-deploy', 'bump']); -}; diff --git a/Procfile b/Procfile index 207d22f..4fb0a5e 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: node app.js \ No newline at end of file +web: node main.js \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..5d68e9f --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +// Register babel to have ES6 support on the server +require("babel-core/register"); + +// Start the server app +require("./src/server"); diff --git a/main.js b/main.js new file mode 100644 index 0000000..8bfc04a --- /dev/null +++ b/main.js @@ -0,0 +1,30 @@ +var pm2 = require('pm2'); + +var instances = process.env.WEB_CONCURRENCY || -1; +var maxMemory = process.env.WEB_MEMORY || 512; + +pm2.connect(function() { +  pm2.start({ +    script    : 'index.js', +    exec_mode : 'cluster', +    instances : instances, +    max_memory_restart : maxMemory + 'M'   // Auto restart if process taking more than XXmo +  }, function(err) { +    if (err) return console.error('Error while launching applications', err.stack || err); +    console.log('PM2 and application has been succesfully started'); + +    // Display logs in standard output +    pm2.launchBus(function(err, bus) { +      console.log('[PM2] Log streaming started'); + +      bus.on('log:out', function(packet) { +       console.log('[App:%s] %s', packet.process.name, packet.data); +      }); + +      bus.on('log:err', function(packet) { +        console.error('[App:%s][Err] %s', packet.process.name, packet.data); +      }); +    }); + +  }); +}); \ No newline at end of file diff --git a/package.json b/package.json index 844653b..24767bb 100644 --- a/package.json +++ b/package.json @@ -25,28 +25,20 @@ "dev": "DEBUG=hub node index" }, "dependencies": { + "babel": "^6.3.26", + "babel-core": "^5.8.33", "bcrypt": "^0.8.5", "body-parser": "^1.14.2", - "bower": "^1.7.7", "compression": "^1.6.1", + "debug": "^2.2.0", "ejs": "^2.4.1", "express": "^4.13.4", "grunt-contrib-sass": "^0.9.2", + "kerberos": "0.0.17", "mongoose": "^4.4.2", + "pm2": "^0.15.10", "q": "^1.4.1", + "serve-favicon": "^2.3.0", "slack-client": "^1.5.1" - }, - "devDependencies": { - "grunt": "^0.4.5", - "grunt-bump": "^0.7.0", - "grunt-concurrent": "^2.1.0", - "grunt-contrib-clean": "^0.7.0", - "grunt-contrib-copy": "^0.8.2", - "grunt-contrib-imagemin": "^1.0.0", - "grunt-contrib-watch": "^0.6.1", - "grunt-nodemon": "^0.4.1", - "grunt-sftp-deploy": "^0.2.4", - "open": "0.0.5", - "time-grunt": "^1.3.0" } } diff --git a/sh/prod/deploy.sh b/sh/prod/deploy.sh deleted file mode 100644 index 4a8cdc1..0000000 --- a/sh/prod/deploy.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/zsh - -# set user variables -#PATH='~.nvm/v0.10.36/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/X11/bin:/usr/local/git/bin' -PATH='/Users/adriengsell/.nvm/v0.10.36/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/X11/bin:/usr/local/git/bin' -SOURCEFOLDER='Sources' -USR='slack-bill-sharing' -VERSION='prod' -SERVER='delirium.cloudapp.net' - -# Deploy sources -cd ~/$SOURCEFOLDER/$USR -grunt $VERSION - -# Run the app -APPSCRIPT='cd /home/'$USR-$VERSION'/'$USR'/ ;\ -npm install --production ;\ -export NODE_ENV='$VERSION' ;\ -forever stop app.js ;\ -forever start app.js ;\ -sudo cp /home/'$USR-$VERSION'/'$USR'/sh/'$VERSION'/nginx.conf /etc/nginx/sites-available/'$USR-$VERSION' ;\ -sudo ln -s /etc/nginx/sites-available/'$USR-$VERSION' /etc/nginx/sites-enabled/ ;\ -sudo service nginx reload' -ssh -t $USR-$VERSION@$SERVER "$APPSCRIPT" \ No newline at end of file diff --git a/sh/prod/nginx.conf b/sh/prod/nginx.conf deleted file mode 100644 index 963111e..0000000 --- a/sh/prod/nginx.conf +++ /dev/null @@ -1,18 +0,0 @@ - upstream compta.dailydinities.fr { - server 127.0.0.1:3212; -} - -server { - listen 80; - server_name compta.dailydinities.fr; - - location / { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_set_header X-NginX-Proxy true; - - proxy_pass http://compta.dailydinities.fr/; - proxy_redirect off; - } -} \ No newline at end of file diff --git a/sh/prod/start.sh b/sh/prod/start.sh deleted file mode 100644 index d07d1c9..0000000 --- a/sh/prod/start.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# set user variables -PATH='~/.nvm/v0.10.36/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/X11/bin:/usr/local/git/bin' -USR='slack-bill-sharing' -VERSION='prod' -ROOT='dailydinities' -SERVER='delirium.cloudapp.net' - -# Create User -USRSCRIPT='sudo useradd '$USR-$VERSION'; \ -sudo passwd '$USR-$VERSION' \ -sudo mkdir /home/'$USR-$VERSION'; \ -sudo adduser '$USR-$VERSION' sudo; \ -cd /home/'$USR-$VERSION'/; \ -sudo chown -Rv '$USR-$VERSION' /home/'$USR-$VERSION'/; \ -sudo mkdir /home/'$USR-$VERSION'/'$USR'; \ -sudo chown -Rv '$USR-$VERSION' /home/'$USR-$VERSION/$USR'/' -#ssh $ROOT@$SERVER "$USRSCRIPT" - -# Sign the server -pbcopy < ~/.ssh/id_rsa.pub -SIGNSCRIPT='mkdir /home/'$USR'-'$VERSION'/.ssh ;\ -vi /home/'$USR'-'$VERSION'/.ssh/authorized_keys' -#ssh -t $USR-$VERSION@$SERVER "$SIGNSCRIPT" - -# Install a few stuff in the server -APPSCRIPT='npm install bower -g ;\ -npm install forever -g ;\ -npm install azure-cli -g' -#ssh -t $USR-$VERSION@$SERVER "$APPSCRIPT" \ No newline at end of file diff --git a/config/config.js b/src/config/config.js similarity index 100% rename from config/config.js rename to src/config/config.js diff --git a/controllers/admin.js b/src/controllers/admin.js similarity index 100% rename from controllers/admin.js rename to src/controllers/admin.js diff --git a/controllers/login.js b/src/controllers/login.js similarity index 100% rename from controllers/login.js rename to src/controllers/login.js diff --git a/helpers/auth.js b/src/helpers/auth.js similarity index 100% rename from helpers/auth.js rename to src/helpers/auth.js diff --git a/helpers/billSharing.js b/src/helpers/billSharing.js similarity index 100% rename from helpers/billSharing.js rename to src/helpers/billSharing.js diff --git a/helpers/expense.js b/src/helpers/expense.js similarity index 100% rename from helpers/expense.js rename to src/helpers/expense.js diff --git a/helpers/initializer.js b/src/helpers/initializer.js similarity index 100% rename from helpers/initializer.js rename to src/helpers/initializer.js diff --git a/helpers/member.js b/src/helpers/member.js similarity index 100% rename from helpers/member.js rename to src/helpers/member.js diff --git a/models/expense.js b/src/models/expense.js similarity index 100% rename from models/expense.js rename to src/models/expense.js diff --git a/models/member.js b/src/models/member.js similarity index 100% rename from models/member.js rename to src/models/member.js diff --git a/public/css/style.css b/src/public/css/style.css similarity index 100% rename from public/css/style.css rename to src/public/css/style.css diff --git a/public/css/style.css.map b/src/public/css/style.css.map similarity index 100% rename from public/css/style.css.map rename to src/public/css/style.css.map diff --git a/public/favicon.png b/src/public/favicon.png similarity index 100% rename from public/favicon.png rename to src/public/favicon.png diff --git a/public/img/example.png b/src/public/img/example.png similarity index 100% rename from public/img/example.png rename to src/public/img/example.png diff --git a/public/img/login-back.png b/src/public/img/login-back.png similarity index 100% rename from public/img/login-back.png rename to src/public/img/login-back.png diff --git a/public/img/logo.png b/src/public/img/logo.png similarity index 100% rename from public/img/logo.png rename to src/public/img/logo.png diff --git a/public/js/html5shiv.min.js b/src/public/js/html5shiv.min.js similarity index 100% rename from public/js/html5shiv.min.js rename to src/public/js/html5shiv.min.js diff --git a/public/js/script.js b/src/public/js/script.js similarity index 100% rename from public/js/script.js rename to src/public/js/script.js diff --git a/public/robots.tx b/src/public/robots.tx similarity index 100% rename from public/robots.tx rename to src/public/robots.tx diff --git a/public/scss/partials/_admin.scss b/src/public/scss/partials/_admin.scss similarity index 100% rename from public/scss/partials/_admin.scss rename to src/public/scss/partials/_admin.scss diff --git a/public/scss/partials/_btn.scss b/src/public/scss/partials/_btn.scss similarity index 100% rename from public/scss/partials/_btn.scss rename to src/public/scss/partials/_btn.scss diff --git a/public/scss/partials/_form.scss b/src/public/scss/partials/_form.scss similarity index 100% rename from public/scss/partials/_form.scss rename to src/public/scss/partials/_form.scss diff --git a/public/scss/partials/_header.scss b/src/public/scss/partials/_header.scss similarity index 100% rename from public/scss/partials/_header.scss rename to src/public/scss/partials/_header.scss diff --git a/public/scss/partials/_login.scss b/src/public/scss/partials/_login.scss similarity index 100% rename from public/scss/partials/_login.scss rename to src/public/scss/partials/_login.scss diff --git a/public/scss/partials/_reset.scss b/src/public/scss/partials/_reset.scss similarity index 100% rename from public/scss/partials/_reset.scss rename to src/public/scss/partials/_reset.scss diff --git a/public/scss/partials/_tab3.scss b/src/public/scss/partials/_tab3.scss similarity index 100% rename from public/scss/partials/_tab3.scss rename to src/public/scss/partials/_tab3.scss diff --git a/public/scss/style.scss b/src/public/scss/style.scss similarity index 100% rename from public/scss/style.scss rename to src/public/scss/style.scss diff --git a/public/sitemap.xml b/src/public/sitemap.xml similarity index 100% rename from public/sitemap.xml rename to src/public/sitemap.xml diff --git a/app.js b/src/server.js similarity index 77% rename from app.js rename to src/server.js index 337ec27..e3c6697 100644 --- a/app.js +++ b/src/server.js @@ -1,20 +1,26 @@ -var config = require('./config/config'), - auth = require('./helpers/auth'), - billSharing = require('./helpers/billSharing'), - expense = require('./helpers/expense'), - initializer = require('./helpers/initializer'), - member = require('./helpers/member'), - adminCtrl = require('./controllers/admin'), - loginCtrl = require('./controllers/login'); - -var express = require('express'), - bodyParser = require('body-parser'), - compression = require('compression'), - path = require('path'), - mongoose = require('mongoose'), - Slack = require('slack-client'), - fs = require('fs'), - q = require('q'); +import path from "path"; +import express from "express"; +import compression from "compression"; +import bodyParser from "body-parser"; +//import cookieParser from "cookie-parser"; +//import favicon from "serve-favicon"; +//import morgan from "morgan"; +import mongoose from "mongoose"; +import Slack from "Slack"; +import fs from "fs"; +import q from "q"; +import config from "./config/config"; + +import AppsCtrl from "./controllers/AppsCtrl"; +import auth from "./helpers/auth"; +import billSharing from "./helpers/billSharing"; +import expense from "./helpers/expense"; +import initializer from "./helpers/initializer"; +import member from "./helpers/member"; +import adminCtrl from "./controllers/admin"; +import loginCtrl from "./controllers/login"; + +const debug = require("debug")("bot"); var app = express(); diff --git a/views/admin.ejs b/src/views/admin.ejs similarity index 100% rename from views/admin.ejs rename to src/views/admin.ejs diff --git a/views/login.ejs b/src/views/login.ejs similarity index 100% rename from views/login.ejs rename to src/views/login.ejs diff --git a/views/partials/footer.ejs b/src/views/partials/footer.ejs similarity index 100% rename from views/partials/footer.ejs rename to src/views/partials/footer.ejs diff --git a/views/partials/head.ejs b/src/views/partials/head.ejs similarity index 100% rename from views/partials/head.ejs rename to src/views/partials/head.ejs diff --git a/views/partials/header.ejs b/src/views/partials/header.ejs similarity index 100% rename from views/partials/header.ejs rename to src/views/partials/header.ejs