Skip to content

Commit

Permalink
initial implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jupe authored Jan 28, 2018
1 parent 211998a commit b046e58
Show file tree
Hide file tree
Showing 13 changed files with 2,623 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2
jobs:
build:
docker:
- image: circleci/node:6.11.4-browsers
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: versions
command: |
node --version
npm --version
- run:
name: install-npm
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: test
command: npm run coverage
environment:
REPORTER: mocha-junit-reporter
MOCHA_FILE: junit/test-results.xml
- run:
name: lint
command: npm run lint
when: always
- store_test_results:
path: junit
- store_artifacts:
path: junit
- store_artifacts:
path: coverage
prefix: coverage
- store_test_results:
path: coverage/coverage.json
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

{
"extends": "airbnb-base",
"env": {
"es6": true,
"node": true,
"mocha": true
},
"plugins": [
"import",
"node",
"promise"
],
"rules": {
"comma-dangle": ["error", "never"],
"max-len": ["error", {"code": 120, "tabWidth": 4, "ignoreUrls": true}],
"indent": [ "warn", 2, { "SwitchCase": 1} ],
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"no-underscore-dangle": ["off"],
"no-console": "error",
"valid-jsdoc": "warn",
"object-curly-spacing": ["error", "never"],
"array-bracket-spacing": ["error", "never"],
"computed-property-spacing": ["error", "never"],
"prefer-arrow-callback": ["error", { "allowNamedFunctions": true }],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"one-var": ["error", { "initialized": "never" }],
"one-var-declaration-per-line": ["error", "initializations"],
"func-names": ["error", "as-needed"],
"object-shorthand": "off"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
REPORTER ?= spec
MOCHA ?= mocha
TESTS = $(addprefix test/,api.js)

.PHONY: test coverage

test:
NODE_ENV=test ${MOCHA} --reporter $(REPORTER) --recursive -g '${FILTER}'

coverage:
NODE_ENV=test istanbul cover -- _mocha --recursive -R ${REPORTER} -g '${FILTER}'

lint:
eslint src test

lint-fix:
eslint src test --fix
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# OpenTMI addon base class

This module contains base class and utils for OpenTMI addons.

## API

### `Addon`

This is base class which stores some basic things, like logger instance, eventBus etc.

**getters**
* `this.logger` to get logger instance
* `this.eventBus` to get opentmi eventBus instance
* `this.app` to get opentmi express application instance
* `this.server` to get express server instance
* `this.io` to get socket.io instance


Usage example:

```
const {Addon} = require('opentmi-addon');
class MyAddon extends Addon {
constructor(...data) {
super(...data);
this.logger.info('MyAddon constructor');
}
}
module.exports = MyAddon;
```

### `singleton()`

singleton mixer can be used to create addon which manage some
background operations like analyse results. Those background operations
is activated when `register` -function is called.
Note that `register` is called only once even opentmi is started ìn cluster mode.

**getters**
* `isRegistered` is true for instance which contains singleton instance

Usage example:
```
const {Addon, singleton} = require('opentmi-addon');
class MyAddon extends Addon {
constructor(...data) {
super(...data);
this.logger.info('MyAddon constructor');
}
}
const MySingletonAddon = singleton(MyAddon);
module.exports = MySingletonAddon;
```
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const singleton = require('./src/singleton');
const Addon = require('./src/addon');

module.exports = {
singleton,
Addon
};
Loading

0 comments on commit b046e58

Please sign in to comment.