Skip to content

Commit

Permalink
chore(strict): Make all project files compliant with new strict rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Koenders committed Sep 10, 2018
1 parent d38e97c commit 3cd2f81
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 64 deletions.
8 changes: 4 additions & 4 deletions src/constants/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface Environment {
appName: string,
port: Number,
loadPaths: Array<string>
}
appName: string;
port: number;
loadPaths: string[];
}
6 changes: 3 additions & 3 deletions src/constants/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const TYPES = {
Environment: Symbol("Environment"),
Logger: Symbol("Logger")
Environment: Symbol('Environment'),
Logger: Symbol('Logger')
};

export default TYPES;
export default TYPES;
10 changes: 4 additions & 6 deletions src/ioc/ioc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import "reflect-metadata";
import 'reflect-metadata';
import { Container, inject } from 'inversify';
import { autoProvide, makeFluentProvideDecorator } from 'inversify-binding-decorators';
import { autoProvide, provide, fluentProvide } from 'inversify-binding-decorators';

let container = new Container();
const container = new Container();

let provide = makeFluentProvideDecorator(container);

export { container, autoProvide, provide, inject };
export { container, autoProvide, provide, inject, fluentProvide };
18 changes: 8 additions & 10 deletions src/ioc/loader.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import * as fs from "fs";
import * as path from "path";
import * as fs from 'fs';
import * as path from 'path';

class Loader {
public static load(baseDir: string) {
Loader.readDir(baseDir);
}

private static readDir(dir) {
private static readDir(dir: string) {
fs.readdirSync(dir).forEach((entity) => {
Loader.processEntity(path.join(dir, entity));
});
}

private static processEntity(entity: string) {
if(fs.statSync(entity).isDirectory()) {
if (fs.statSync(entity).isDirectory()) {
Loader.readDir(entity);
}
else
{
} else {
Loader.loadFile(entity);
}
}

private static loadFile(filePath) {
if(path.extname(filePath) == ".js") {
private static loadFile(filePath: string) {
if (path.extname(filePath) === '.js') {
require(filePath);
}
}
}

export default Loader;
export default Loader;
4 changes: 2 additions & 2 deletions src/libraries/logger/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface Logger {
log(message: string);
log(message: string): void;
}

export default Logger;
export default Logger;
20 changes: 10 additions & 10 deletions src/libraries/logger/loggerImpl.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import TYPES from "../../constants/types";
import Logger from "./logger";
import { provide, inject } from "../../ioc/ioc";
import TYPES from '../../constants/types';
import Logger from './logger';
import { provide, inject } from '../../ioc/ioc';

@provide(TYPES.Logger).done()
/* tslint:disable:no-console */
@provide(TYPES.Logger)
class LoggerImpl implements Logger {
private _appName: string;
private appName: string;

public constructor(@inject(TYPES.Environment) environment: any)
{
this._appName = environment.appName;
public constructor(@inject(TYPES.Environment) environment: any) {
this.appName = environment.appName;
}

public log(message: string) {
console.log(this._appName + " says: " + message);
console.log(this.appName + ' says: ' + message);
}
}

export default LoggerImpl;
export default LoggerImpl;
27 changes: 13 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import * as express from "express";
import Loader from "./ioc/loader";
import * as path from "path";
import { container } from "./ioc/ioc";
import TYPES from "./constants/types";
import * as express from 'express';
import Loader from './ioc/loader';
import * as path from 'path';
import { container } from './ioc/ioc';
import TYPES from './constants/types';

class Main {
private _app: express.Application;
private app: express.Application;

public constructor(environment: any) {
this._app = express();
this.app = express();

this.initializeDependencyInjector(environment);
}

public onListening() {
let helloController: any = container.getNamed("Music/HelloController", "testModule");
const helloController: any = container.getNamed('Music/HelloController', 'testModule');

helloController.hello("Sander");
helloController.hello('Sander');
}

private initializeDependencyInjector(environment: any)
{
private initializeDependencyInjector(environment: any) {
container.bind<Environment>(TYPES.Environment).toConstantValue(environment);

this.loadJsFiles(environment.loadPaths);
}

private loadJsFiles(loadPaths: Array<string>) {
private loadJsFiles(loadPaths: string[]) {
loadPaths.forEach((dir) => {
Loader.load(path.join(__dirname, dir));
});
}

public get App(): express.Application {
return this._app;
return this.app;
}
}

export = Main;
export = Main;
14 changes: 7 additions & 7 deletions src/modules/awesomeModule/helloController.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { inject, provide } from "../../ioc/ioc";
import Logger from "../../libraries/logger/logger";
import TYPES from "../../constants/types";
import { inject, fluentProvide } from '../../ioc/ioc';
import Logger from '../../libraries/logger/logger';
import TYPES from '../../constants/types';

@provide("Music/HelloController").whenTargetNamed("awesomeModule").done()
@fluentProvide('Music/HelloController').whenTargetNamed('awesomeModule').done()
class HelloController {
@inject(TYPES.Logger) private _logger: Logger;
@inject(TYPES.Logger) private logger: Logger;

public hello(name: string) {
this._logger.log("Awesome hello " + name);
this.logger.log('Awesome hello ' + name);
}
}

export default HelloController;
export default HelloController;
16 changes: 8 additions & 8 deletions src/modules/testModule/helloController.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { inject, provide } from "../../ioc/ioc";
import Logger from "../../libraries/logger/logger";
import TYPES from "../../constants/types";
import { inject, fluentProvide } from '../../ioc/ioc';
import Logger from '../../libraries/logger/logger';
import TYPES from '../../constants/types';

@provide("Music/HelloController").whenTargetNamed("testModule").done()
@fluentProvide('Music/HelloController').whenTargetNamed('testModule').done()
class HelloController {
private _logger: Logger;
private logger: Logger;

public constructor(@inject(TYPES.Logger) logger: Logger) {
this._logger = logger;
this.logger = logger;
}

public hello(name: string) {
this._logger.log("Hello " + name);
this.logger.log('Hello ' + name);
}
}

export default HelloController;
export default HelloController;

0 comments on commit 3cd2f81

Please sign in to comment.