diff --git a/.gitignore b/.gitignore index e59dbeddb45046ddd20d254045bac7239e59b25a..3578f038c7e6dc9d83f0352331c22145c7adc576 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.log *.out *.pid -*.js -*.js.map +*.map /.trash /pids /logs diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index f862cd6de8cda7d7d2357daf02931a5b3be17a21..0000000000000000000000000000000000000000 --- a/.jscsrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "preset": "airbnb", - "validateIndentation": 4, - "requireTrailingComma": false, - "disallowTrailingComma": true, - "requireSpacesInAnonymousFunctionExpression": false, - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties", - "disallowKeywordsOnNewLine": [], - "maximumLineLength": 80, - "requirePaddingNewLinesAfterBlocks": { - "allExcept": ["inCallExpressions", "inNewExpressions", "inArrayExpressions", "inProperties"] - } -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 97da9af5020e2de44ee806fe894f5a88a165e777..0000000000000000000000000000000000000000 --- a/.jshintrc +++ /dev/null @@ -1,25 +0,0 @@ -{ - "browser": false, - "node": true, - "esnext": true, - "eqeqeq": true, - "indent": 4, - "latedef": false, - "newcap": true, - "quotmark": "single", - "undef": true, - "unused": "vars", - "eqnull": true, - "globals": { - "describe": false, - "xdescribe": false, - "ddescribe": false, - "it": false, - "xit": false, - "iit": false, - "beforeEach": false, - "afterEach": false, - "before": false, - "after": false - } -} diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 32f291387eeef1a8fa35ff49cfb0a58f8fc93077..0000000000000000000000000000000000000000 --- a/gulpfile.js +++ /dev/null @@ -1,191 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); -var gutil = require('gulp-util'); -var raml = require('gulp-raml'); -var rename = require('gulp-rename'); -var jshint = require('gulp-jshint'); -var size = require('gulp-size'); -var jscs = require('gulp-jscs'); -var stylish = require('gulp-jscs-stylish'); -var mocha = require('gulp-mocha'); -var istanbul = require('gulp-istanbul'); -var nodemon = require('gulp-nodemon'); - -var path = require('path'); -var raml2html = require('raml2html'); -var through = require('through2'); -var yaml = require('js-yaml'); -var map = require('map-stream'); - -var srcFiles = [ - 'src/**/*.js', - 'index.js', - 'gulpfile.js', - 'test/**/*.js' -]; - -function handleError(err) { - console.error(err.toString()); - process.exit(1); -} - -function exitOnError(type) { - return map(function(file, callback) { - if (!file[type].success) { - process.exit(1); - } - - callback(null, file); - }); -} - -function generateDoc(options) { - var simplifyMark = function(mark) { - if (mark) { - mark.buffer = mark.buffer - .split('\n', mark.line + 1)[mark.line] - .trim(); - } - }; - - if (!options) { - options = {}; - } - - switch (options.type) { - case 'json': - options.config = { - template: function(obj) { - return JSON.stringify(obj, null, 2); - } - }; - break; - case 'yaml': - options.config = { - template: function(obj) { - return yaml.safeDump(obj, { - skipInvalid: true - }); - } - }; - break; - default: - options.type = 'html'; - if (!options.config) { - options.config = raml2html.getDefaultConfig( - options.https, - options.template, - options.resourceTemplate, - options.itemTemplate - ); - } - } - - if (!options.extension) { - options.extension = '.' + options.type; - } - - var stream = through.obj(function(file, enc, done) { - var fail = function(message) { - done(new gutil.PluginError('raml2html', message)); - }; - - if (file.isBuffer()) { - var cwd = process.cwd(); - process.chdir(path.resolve(path.dirname(file.path))); - raml2html - .render(file.contents, options.config) - .then(function(output) { - process.chdir(cwd); - stream.push(new gutil.File({ - base: file.base, - cwd: file.cwd, - path: gutil.replaceExtension( - file.path, options.extension), - contents: new Buffer(output) - })); - done(); - }, - function(error) { - process.chdir(cwd); - simplifyMark(error.context_mark); - simplifyMark(error.problem_mark); - process.nextTick(function() { - fail(JSON.stringify(error, null, 2)); - }); - } - ); - } - else if (file.isStream()) { - fail('Streams are not supported: ' + file.inspect()); - } - else if (file.isNull()) { - fail('Input file is null: ' + file.inspect()); - } - }); - - return stream; -} - -gulp.task('raml', function() { - gulp.src('specs/*.raml') - .pipe(raml()) - .pipe(raml.reporter('default')) - .pipe(exitOnError('raml')); -}); - -gulp.task('doc', function() { - return gulp.src('specs/*.raml') - .pipe(generateDoc()) - .on('error', handleError) - .pipe(rename({ extname: '.html' })) - .pipe(gulp.dest('doc/build')); -}); - -gulp.task('pre-test', function() { - return gulp.src(['src/**/*.js']) - .pipe(istanbul()) - .pipe(istanbul.hookRequire()); -}); - -gulp.task('test', ['pre-test'], function() { - return gulp.src('test/**/*.spec.js', { read: false }) - .pipe(mocha({ - require: ['./test/common.js'], - reporter: 'spec', - ui: 'bdd', - recursive: true, - colors: true, - timeout: 60000, - slow: 300, - delay: true - })) - .pipe(istanbul.writeReports()) - .once('error', function() { - process.exit(1); - }) - .once('end', function() { - process.exit(); - }); -}); - -gulp.task('lint', function() { - return gulp.src(srcFiles) - .pipe(jshint()) - .pipe(jscs()) - .pipe(stylish.combineWithHintResults()) - .pipe(jshint.reporter('jshint-stylish')) - .pipe(size()) - .pipe(exitOnError('jshint')); -}); - -gulp.task('check', ['raml', 'lint', 'test']); - -gulp.task('develop', function() { - return nodemon({ - script: 'index.js', - ext: 'js', - tasks: ['lint'] - }); -}); diff --git a/index.js b/index.js old mode 100755 new mode 100644 index 4a39bcfb7e55943ba61ee039b6a2d4443ce5cad7..fccc3fcd8d5993977136dc3aa4546f3ecd367b9b --- a/index.js +++ b/index.js @@ -1,68 +1,4 @@ #!/usr/bin/env node -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ -'use strict'; - -// Add the ./src directory to require's search path to facilitate import -// modules later on (avoiding the require('../../../../module') problem). -require('app-module-path').addPath(__dirname + '/src'); - -// external libraries -const osprey = require('osprey'); -const express = require('express'); -const path = require('path'); -const ramlParser = require('raml-parser'); - -// connect to mongodb -const mongo = require('core/mongo'); -mongo.connect('mongodb://pyke/blend'); - -// create a new express app -const app = module.exports = express(); - -// load router -const router = require('api/router-v1.js'); - -// parse the RAML spec and load osprey middleware -ramlParser.loadFile(path.join(__dirname, 'specs/blendb-api-v1.raml')) - .then(raml => { - app.use('/v1', - osprey.security(raml), - osprey.server(raml), - router); - - if (!module.parent) { - let port = process.env.PORT || 3000; - app.listen(port); - - if (app.get('env') === 'development') { - console.log('Server listening on port ' + port + '.'); - } - } - else { - // signalize to the test suite that the server is ready to be tested - app.ready = true; - } - }, - err => { - console.error('RAML Parsing Error: ' + err.message); - process.exit(1); - }); +require('ts-node/register'); +require('./src/main.ts'); diff --git a/package.json b/package.json index e1d61a3e355e97e5b66e95ed5dd8def04cf7b117..94d5607152b269b56939b0382cc2f6406437a8cf 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,8 @@ "main": "index.js", "scripts": { "postinstall": "typings install", - "prestart": "tsc", - "start": "node build/src/boot", - "pretest": "tsc", - "test": "mocha", + "start": "node index", + "test": "istanbul cover -x \"**/*.spec.ts\" -e .ts _mocha", "lint": "tslint -s node_modules/tslint-stylish -t stylish src/**/*.ts test/**/*.ts" }, "repository": { @@ -18,30 +16,15 @@ "author": "Centro de Computação Científica e Software Livre (C3SL)", "license": "GPL-3.0", "dependencies": { - "app-module-path": "^1.1.0", - "async": "^2.0.1", - "eslint": "^3.2.2", "express": "^4.14.0", - "gulp": "^3.9.1", - "gulp-istanbul": "^1.0.0", - "gulp-jscs": "^4.0.0", - "gulp-jscs-stylish": "^1.4.0", - "gulp-jshint": "^2.0.1", - "gulp-mocha": "^3.0.0", - "gulp-nodemon": "^2.1.0", - "gulp-raml": "^0.1.3", - "gulp-rename": "^1.2.2", - "gulp-size": "^2.1.0", - "gulp-util": "^3.0.7", - "jshint": "^2.9.2", - "mongodb": "^2.2.5", "osprey": "^0.3.2", - "raml2html": "^2.4.0", + "ts-node": "^1.2.3", "typescript": "^1.8.10", "typings": "^1.3.2" }, "devDependencies": { "chai": "^3.5.0", + "istanbul": "1.1.0-alpha.1", "mocha": "^3.0.2", "tslint": "^3.14.0", "tslint-stylish": "^2.1.0-beta" diff --git a/src/boot.ts b/src/main.ts similarity index 100% rename from src/boot.ts rename to src/main.ts diff --git a/test.js b/test.js deleted file mode 100644 index 0bd182e7c4a7c69b232d55a6359f022af0ce459f..0000000000000000000000000000000000000000 --- a/test.js +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env node -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -'use strict'; - -// Add the ./src directory to require's search path to facilitate import -// modules later on (avoiding the require('../../../../module') problem). -require('app-module-path').addPath(__dirname + '/src'); - -// connect to mongodb -// const mongo = require('core/mongo'); -// mongo.connect('mongodb://pyke/blend'); - -const blendb = require('blendb'); - -const db = new blendb.BlenDB(); - -const netSource = db.source('networkData'); - -for (let i = 0; i < 100; i++) { - netSource.push({ - a: i - }); -} - -db.transformer('networkTraffic', { - source: 'networkData', - metrics: ['met:downBytes', 'met:upBytes'], - dimensions: ['dim:date', 'dim:city', 'dim:state', 'dim:point'], - extractors: { - metrics: function extractMetrics(doc) { - return { - 'met:downBytes': 5464, - 'met:upBytes': 342 - }; - }, - dimensions: function extractDimensions(doc) { - return { - 'dim:date': '2016/06/12', - 'dim:city': 41442, - 'dim:state': 41, - 'dim:point': 5344 - }; - } - } -}); - -db.process(); diff --git a/test/mocha.opts b/test/mocha.opts index 701d3701b30095eeb86e1bb2d12120a777b6b4d3..769579ae3f5df2c2b8990eecbe45e9418329d3fe 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,4 @@ ---require ./build/test/global.js +--require ./test/global.ts --reporter spec --ui bdd --recursive @@ -7,4 +7,5 @@ --slow 300 --check-leaks --globals expect -./build/**/*.spec.js +--compilers ts:ts-node/register +./src/**/*.spec.ts diff --git a/tsconfig.json b/tsconfig.json index 00e2014e5a9dc88fe25778da3f6a91f423c8f940..fbde5211ce78cc4eb38dd0f25e171c82e292283a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,14 +3,10 @@ "pretty": true, "target": "es5", "module": "commonjs", - "outDir": "./build", - "noImplicitAny": true, - "removeComments": true, - "preserveConstEnums": true, - "sourceMap": true + "noImplicitAny": true }, "exclude": [ - "node_modules" + "node_modules" ], "compileOnSave": false }