diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0bccbe5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: node_js +node_js: + - "4.2" + - "4.3" +before_script: + - mv .env_test .env +services: + - "mongodb" +env: + - CXX=g++-4.8 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 +notifications: + slack: evr-arch-europe:1UCLAzIauC94wHuy2W2VLD1F diff --git a/README.md b/README.md index 0264b74..4e0f1e1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # keystonejs-portal +[![Build Status](https://travis-ci.org/everisARQ/keystonejs-portal.svg?branch=master)](https://travis-ci.org/everisARQ/keystonejs-portal) + ## PRE-REQUISITES - mongodb diff --git a/gulpfile.js b/gulpfile.js index 4ac443e..d0b56e0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,7 @@ var shell = require('gulp-shell'); var open = require('gulp-open'); var sass = require('gulp-sass'); var jasmine = require('gulp-jasmine'); +var util = require('gulp-util'); var runSequence = require('run-sequence'); var paths = { @@ -51,9 +52,21 @@ gulp.task('start', 'Run keystonejs-portal.', shell.task('node keystone.js')); gulp.task('start-dev', 'Run keystonejs-portal with nodemon watching changes in js files.', shell.task('nodemon --watch ./routes --watch ./models keystone.js')); -gulp.task('test', 'Run all project tests', ['test:routes']); +gulp.task('test', 'Run all project tests', function (done) { + runSequence(['test:routes'], function (err) { + if (err) { + var exitCode = 2; + util.log(util.colors.red('[ERROR]'), 'gulp test task failed:', util.colors.red(err)); + util.log(util.colors.red('[FAIL]'), 'gulp test task failed - exiting with code', util.colors.red(exitCode)); + return process.exit(exitCode); + } else { + util.log(util.colors.green('[OK]'), 'gulp test task finished without errors'); + return done(); + } + }); +}); -gulp.task('test:routes', 'Runs routes tests', function () { +gulp.task('test:routes', 'Runs routes tests', function (done) { return gulp.src(paths.test.routes) .pipe(jasmine({ timeout: 15000 diff --git a/keystone.js b/keystone.js index 7097b5d..420e7ca 100644 --- a/keystone.js +++ b/keystone.js @@ -1,10 +1,11 @@ // Simulate config options from your production environment by // customising the .env file in your project's root folder. require('dotenv').load(); - -var keystone = require('keystone'), - i18n = require('i18n'), - path = require('path'); +var keystone = require('keystone'), + i18n = require('i18n'), + fs = require('fs'), + FileStreamRotator = require('file-stream-rotator'), + path = require('path'); // Initialise Keystone with your project's configuration. // See http://keystonejs.com/guide/config for available options @@ -26,7 +27,7 @@ keystone.init({ 'auto update': true, 'session': true, 'auth': true, - 'user model': 'User' + 'user model': 'User', }); @@ -79,6 +80,22 @@ keystone.set('language options', { // Load your project's Routes keystone.set('routes', require('./routes')); +// HTTP LOGGER +keystone.set('logger', 'common'); + +var logDirectory = __dirname + '/log' +// ensure log directory exists +fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory) + +// create a rotating write stream +var accessLogStream = FileStreamRotator.getStream({ + date_format: 'YYYYMMDD', + filename: logDirectory + '/access-%DATE%.log', + frequency: 'daily', + verbose: false +}); + +keystone.set('logger options', {stream: accessLogStream}); // Setup common locals for your emails. The following are required by Keystone's // default email templates, you may remove them if you're using your own. @@ -125,8 +142,16 @@ keystone.set('nav', { 'users': 'users' }); -// Start Keystone to connect to your database and initialise the web server +keystone.set('Logger options', { + level: 'info'/*, + formatter: '', + timestamp: '', + logstash: '', + json: ''*/ + +}); +// Start Keystone to connect to your database and initialise the web server keystone.start(); module.exports = keystone; diff --git a/package.json b/package.json index 00da983..aa9988b 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "dependencies": { "async": "^1.5.0", "dotenv": "^1.1.0", + "file-stream-rotator": "0.0.6", "i18n": "^0.7.0", - "keystone": "https://github.com/everisARQ/keystone.git#master", + "keystone": "file:../keystone", "node-sass": "^3.4.2", "node-sass-middleware": "^0.9.7", "semver": "^5.1.0", @@ -21,20 +22,22 @@ "gulp-open": "^1.0.0", "gulp-sass": "^2.1.1", "gulp-shell": "^0.5.0", + "gulp-util": "^3.0.7", "gulp-wait": "0.0.2", "gulp-watch": "^4.3.5", "jasmine": "^2.4.1", + "jshint": "^2.9.1", "jshint-stylish": "^0.1.3", "nodemon": "^1.8.1", "run-sequence": "^1.1.5", "supertest": "^1.2.0" }, "engines": { - "node": "^4.2.0", + "node": "^4.3.0", "npm": "^2.14.0" }, "scripts": { - "preinstall": "npm install semver && node -e \"require('./utils/startup-check.js').nodeVersion()\"", + "preinstall": "./preinstall.sh", "start": "node keystone.js", "start-dev": "nodemon --watch ./routes --watch ./models keystone.js", "test": "gulp test" diff --git a/preinstall.sh b/preinstall.sh new file mode 100755 index 0000000..ad7a04c --- /dev/null +++ b/preinstall.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +file="./node_modules/keystone" + +if [ -d "$file" ] +then + echo "pre-install validations run" + npm install semver && node -e "require('./node_modules/keystone/lib/archjs/utils/startup-check.js').nodeVersion(require('path').resolve('./package.json'))" +else + echo "First install. Doesn't execute validations" +fi diff --git a/routes/index.js b/routes/index.js index 75dbafb..9fe080f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -24,6 +24,8 @@ var keystone = require('keystone'), var importRoutes = keystone.importer(__dirname); +var logger = keystone.Logger; + // Add i18n API implementation keystone.pre('routes', i18n.init); keystone.set('i18n', i18n); @@ -41,6 +43,7 @@ var routes = { exports = module.exports = function(app) { // Views + logger.debug('Creates principal routes.'); app.get('/', routes.views.index); app.get('/blog/:category?', routes.views.blog); app.get('/blog/post/:post', routes.views.post); diff --git a/templates/layouts/default.jade b/templates/layouts/default.jade index 357f046..f36b991 100644 --- a/templates/layouts/default.jade +++ b/templates/layouts/default.jade @@ -121,7 +121,7 @@ html(lang="#{language}") li a.grey-text.text-lighten-3(href='#') Bug report hr.hidden-lg.hidden-md - .col-md-4.text-center + .col-md-6.text-center p.white-text.text-center SOCIAL MEDIA a.btn-floating.btn-large.fb-bg.waves-effect.waves-light(href='#') i.fa.fa-facebook diff --git a/test/helpers/keystone/index.js b/test/helpers/keystone/index.js index 1de024c..6ccbea1 100644 --- a/test/helpers/keystone/index.js +++ b/test/helpers/keystone/index.js @@ -3,6 +3,7 @@ var keystone = require('../../../keystone.js'); const port = process.env.TEST_PORT || 5150; +keystone.set('auto update', false); keystone.set('port', port); /** @@ -11,6 +12,9 @@ keystone.set('port', port); keystone.closeConnections = () => { keystone.httpServer.close(); keystone.mongoose.connection.close(); + keystone.app.close((err) => { + return (err) ? false : true; + }); }; module.exports = keystone;