Commit 5738e350 authored by Tim Kinnane's avatar Tim Kinnane
Browse files

refactor: Add archetecutre, tests, coverage and build

parents
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
\ No newline at end of file
/node_modules
/yarn-error.log
/.nyc_output
/.DS_Store
{
"check-coverage": true,
"per-file": true,
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts",
"**/*.spec.ts"
],
"reporter": [
"lcovonly",
"text"
],
"all": true
}
\ No newline at end of file
{
"tslint.autoFixOnSave": true,
"tslint.jsEnable": false,
"mocha.files.glob": "src/**/*.spec.ts",
"mocha.requires": [
"dotenv/config",
"ts-node/register"
],
"mocha.options": {},
"coverage-gutters.showGutterCoverage": true
}
\ No newline at end of file
TN:
SF:/Volumes/x/code/rocketchat-bot-driver/src/index.ts
FNF:0
FNH:0
DA:1,1
LF:1
LH:1
BRF:0
BRH:0
end_of_record
TN:
SF:/Volumes/x/code/rocketchat-bot-driver/src/lib/Driver.ts
FN:19,(anonymous_1)
FN:25,(anonymous_2)
FN:26,(anonymous_3)
FNF:3
FNH:2
FNDA:2,(anonymous_1)
FNDA:2,(anonymous_2)
FNDA:0,(anonymous_3)
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:11,1
DA:19,2
DA:20,2
DA:21,2
DA:25,2
DA:26,2
LF:10
LH:10
BRDA:19,0,0,1
BRF:1
BRH:1
end_of_record
export * from './lib/Driver';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./lib/Driver"));
//# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,kCAA4B","sourcesContent":["export * from './lib/Driver'\n"]}
\ No newline at end of file
/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* Main interface for interacting with Rocket.Chat
* @param asteroid An Asteroid instance to connect to Meteor server
*/
export declare class Driver extends EventEmitter {
host: string;
private asteroid;
/**
* Creates a new driver instance with given options or defaults
* @param host Rocket.Chat instance Host URL:PORT (without protocol)
*/
constructor(host?: string);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore // Asteroid is not typed
const asteroid_1 = require("asteroid");
const events_1 = require("events");
const ws_1 = __importDefault(require("ws"));
const Asteroid = asteroid_1.createClass();
/**
* Main interface for interacting with Rocket.Chat
* @param asteroid An Asteroid instance to connect to Meteor server
*/
class Driver extends events_1.EventEmitter {
/**
* Creates a new driver instance with given options or defaults
* @param host Rocket.Chat instance Host URL:PORT (without protocol)
*/
// @ts-ignore // host is unused (doesn't notice use in template literal)
constructor(host = 'localhost:3000') {
super();
this.host = host;
this.asteroid = new Asteroid({
endpoint: `ws://${host}/websocket`,
SocketConstructor: ws_1.default
});
this.asteroid.on('connected', () => this.emit('connected'));
this.asteroid.on('reconnected', () => this.emit('reconnected'));
}
}
exports.Driver = Driver;
//# sourceMappingURL=Driver.js.map
\ No newline at end of file
{"version":3,"file":"Driver.js","sourceRoot":"","sources":["../../src/lib/Driver.ts"],"names":[],"mappings":";;;;;AAAA,sCAAsC;AACtC,uCAAsC;AACtC,mCAAqC;AACrC,4CAAmB;AACnB,MAAM,QAAQ,GAAG,sBAAW,EAAE,CAAA;AAE9B;;;GAGG;AACH,YAAoB,SAAQ,qBAAY;IAGtC;;;OAGG;IACH,wEAAwE;IACxE,YAAoB,OAAO,gBAAgB;QACzC,KAAK,EAAE,CAAA;QADW,SAAI,GAAJ,IAAI,CAAmB;QAEzC,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC;YAC3B,QAAQ,EAAE,QAAQ,IAAI,YAAY;YAClC,iBAAiB,EAAE,YAAE;SACtB,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;QAC3D,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;IACjE,CAAC;CACF;AAjBD,wBAiBC","sourcesContent":["// @ts-ignore // Asteroid is not typed\nimport { createClass } from 'asteroid'\nimport { EventEmitter } from 'events'\nimport ws from 'ws'\nconst Asteroid = createClass()\n\n/**\n * Main interface for interacting with Rocket.Chat\n * @param asteroid An Asteroid instance to connect to Meteor server\n */\nexport class Driver extends EventEmitter {\n private asteroid: any /** @TODO update with Asteroid type (submit to tsd) */\n\n /**\n * Creates a new driver instance with given options or defaults\n * @param host Rocket.Chat instance Host URL:PORT (without protocol)\n */\n // @ts-ignore // host is unused (doesn't notice use in template literal)\n constructor (public host = 'localhost:3000') {\n super()\n this.asteroid = new Asteroid({\n endpoint: `ws://${host}/websocket`,\n SocketConstructor: ws\n })\n this.asteroid.on('connected', () => this.emit('connected'))\n this.asteroid.on('reconnected', () => this.emit('reconnected'))\n }\n}\n"]}
\ No newline at end of file
--require dotenv/config
--require ts-node/register
--require source-map-support/register
--recursive
--sort
--use_strict
--reporter list
--exit
src/**/*.spec.ts
\ No newline at end of file
{
"name": "rocketchat-bot-driver",
"version": "0.0.0-develop",
"description": "Agnostic interface for bot adaptors to interact with Rocket.Chat",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"repository": "rocketchat-bot-driver",
"author": "Tim Kinnane <tim.kinnane@rocket.chat>",
"license": "MIT",
"private": false,
"keywords": [
"adapter",
"rocketchat",
"rocket",
"chat",
"messaging",
"CUI",
"typescript"
],
"files": [
"./lib"
],
"engines": {
"node": "> 8.0.0",
"npm": "> 5.0.0"
},
"scripts": {
"pretest": "tslint -p .",
"test": "nyc mocha --opts ./mocha.opts",
"test:hook": "mocha --opts ./mocha.opts",
"test:debug": "mocha --opts ./mocha.opts --inspect --debug-brk",
"docs": "rimraf ./docs/*; typedoc --options ./typedoc.json ./src",
"prebuild": "npm run test",
"build": "rimraf ./dist/*; tsc",
"_postbuild": "npm run docs"
},
"husky": {
"hooks": {
"pre-push": "npm run test:hook"
}
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^2.2.48",
"chai": "^4.1.2",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
"mocha": "^5.0.1",
"nyc": "^11.4.1",
"rimraf": "^2.6.2",
"source-map-support": "^0.5.3",
"ts-node": "^5.0.0",
"tslint": "^5.9.1",
"tslint-config-standard": "^7.0.0",
"typedoc": "0.8.0",
"typescript": "^2.7.2"
},
"dependencies": {
"@types/lodash": "^4.14.102",
"@types/node": "^9.4.6",
"@types/ws": "^4.0.1",
"asteroid": "^2.0.3",
"dotenv": "^5.0.0",
"ws": "^4.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
import { expect } from 'chai'
import { Driver } from './index'
describe('Index', () => {
describe('Driver', () => {
it('class is accessible', () => {
expect(Driver).to.have.property('name', 'Driver')
})
})
})
export * from './lib/Driver'
import { expect } from 'chai'
import { Driver } from './Driver'
describe('lib:', () => {
describe('Driver', () => {
describe('#constuctor', () => {
context('without url', () => {
it('takes localhost as default', () => {
const d: Driver = new Driver()
expect(d.host).to.equal('localhost:3000')
})
})
context('with localhost url', () => {
it('emits connected event', (done) => {
new Driver('localhost:3000').on('connected', () => done())
})
})
})
})
})
// @ts-ignore // Asteroid is not typed
import { createClass } from 'asteroid'
import { EventEmitter } from 'events'
import ws from 'ws'
const Asteroid = createClass()
/**
* Main interface for interacting with Rocket.Chat
* @param asteroid An Asteroid instance to connect to Meteor server
*/
export class Driver extends EventEmitter {
private asteroid: any /** @TODO update with Asteroid type (submit to tsd) */
/**
* Creates a new driver instance with given options or defaults
* @param host Rocket.Chat instance Host URL:PORT (without protocol)
*/
// @ts-ignore // host is unused (doesn't notice use in template literal)
constructor (public host = 'localhost:3000') {
super()
this.asteroid = new Asteroid({
endpoint: `ws://${host}/websocket`,
SocketConstructor: ws
})
this.asteroid.on('connected', () => this.emit('connected'))
this.asteroid.on('reconnected', () => this.emit('reconnected'))
}
}
declare module 'asteroid'
\ No newline at end of file
{
"compilerOptions": {
/* Basic Options */
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
"inlineSources": true /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "node_modules"]
}
\ No newline at end of file
{
"extends": "tslint-config-standard",
"linterOptions": {
"exclude": [
"**/*.json"
]
},
"rules": {
"semicolon": [
true,
"never"
]
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment