diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..9a5b852 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "google" +} \ No newline at end of file diff --git a/controllers/bindings.js b/controllers/bindings.js index c785ec1..886d69e 100644 --- a/controllers/bindings.js +++ b/controllers/bindings.js @@ -19,63 +19,64 @@ const express = require('express'); const bodyParser = require('body-parser'); -const debug = require('debug')('bindings:bindings') -const fs = require("fs"); +const debug = require('debug')('bindings:bindings'); +const fs = require('fs'); -var bindings = {}; +let bindings = {}; bindings.start = (conf) => { - return new Promise((resolve, reject) => { - const app = express(); - app.use(bodyParser.urlencoded({extended: true})); - debug('Receiving data to create bindings'); - app.post("/api/v1/bindings", function(req, res){ - switch(req.body.purpose){ - case "showFigureCode": - bindings.showFigureCode(req.body); - res.send({callback:"ok"}); - break; - default: - break; - } - }); - - var bindingsListen = app.listen(conf.port, () => { + app.use(bodyParser.urlencoded({extended: true})); + debug('Receiving data to create bindings'); + app.post('/api/v1/bindings', function(req, res) { + switch (req.body.purpose) { + case 'showFigureCode': + bindings.showFigureCode(req.body); + res.send({callback: 'ok'}); + break; + default: + break; + } + }); + let bindingsListen = app.listen(conf.port, () => { + debug('Bindings server listening on port %s', conf.port); resolve(bindingsListen); }); }); }; -bindings.readRmarkdown = function(compendium_id, mainfile){ - if (!compendium_id | !mainfile) +bindings.readRmarkdown = function( compendiumId, mainfile ) { + if ( !compendiumId | !mainfile ) { throw new Error('File does not exist.'); - var paper = __dirname + "/" + compendium_id + "/" + mainfile; - fs.exists(paper,function(ex){ - if (!ex) + } + let paper = __dirname + '/' + compendiumId + '/' + mainfile; + fs.exists(paper, function(ex) { + if (!ex) { throw new Error('File does not exist.'); + } }); const readerStream = fs.createReadStream(paper); readerStream.setEncoding('utf8'); - var data = ''; + let data = ''; readerStream .on('data', function(chunk) { data += chunk; }) - .on('end', function(){ + .on('end', function() { bindings.saveRmarkdown(data); return data; }) - .on('error', function(err){ + .on('error', function(err) { debug(err); - }); + }); }; -bindings.saveRmarkdown = function(data){ - fs.writeFile(__dirname + '/testdata/paper_interactive.Rmd', data,'utf8', function(err){ - debug(err) - }); -} +bindings.saveRmarkdown = function(data) { + fs.writeFile(__dirname + '/testdata/paper_interactive.Rmd', + data, 'utf8', function(err) { + debug(err); + } ); +}; -module.exports = bindings; \ No newline at end of file +module.exports = bindings; diff --git a/index.js b/index.js index 62b738b..212f1e7 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,8 @@ const config = require('./config/config'); const debug = require('debug')('bindings'); -var bindings = require('./controllers/bindings'); +let bindings = require('./controllers/bindings'); bindings.start({ port: config.net.port -}) \ No newline at end of file +}); diff --git a/package.json b/package.json index b8f68b4..10aa776 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,23 @@ { - "name": "o2r-bindings", - "version": "0.0.1", - "description": "Microservice for linking text, data, and code.", - "main": "index.js", - "scripts": { - "start": "node index.js", - "requests": "node bindings.js" - }, - "author": "Markus Konkol (http://o2r.info)", - "license": "Apache-2.0", - "dependencies": { - "express": "~4.16.2", - "body-parser": "^1.18.2", - "debug": "^3.1.0" - }, - "devDependencies": { - "asserthat":"0.11.0", - "eslint":"4.16.0", - "eslint-config-es":"0.9.1" - } + "name": "o2r-bindings", + "version": "0.0.1", + "description": "Microservice for linking text, data, and code.", + "main": "index.js", + "scripts": { + "start": "node index.js", + "requests": "node bindings.js" + }, + "author": "Markus Konkol (http://o2r.info)", + "license": "Apache-2.0", + "dependencies": { + "express": "~4.16.2", + "body-parser": "^1.18.2", + "debug": "^3.1.0" + }, + "devDependencies": { + "asserthat": "0.11.0", + "eslint": "4.16.0", + "eslint-config-es": "0.9.1", + "eslint-config-google": "^0.9.1" + } }