1.9.8 • Published 2 years ago

@steffy/core v1.9.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@steffy/core

Package containing core functionalities for Smart Enterpise Framework For You application.

Installation

npm i -S @steffy/core @steffy/di

Usage

After installing import the required module from @steffy/core and @steffy/di.

import {} from '@steffy/core';
import {} from '@steffy/di';

Bootstrap application

index.ts

import { storage } from '@steffy/di';
import { Application } from './application';
import { boot } from './boot.sequence';

export async function main() {
  await boot();
  const app = storage.get(Application);
  await app.start();
}

main();

application.ts

import { LoggerPlugin } from '@steffy/core';
import { Inject, Optional, Singleton } from '@steffy/di';

@Singleton()
export class Application {
  constructor(@Inject() private logger: LoggerPlugin, @Optional('SteffyConfig') private config: any) {}

  public async start() {
    this.logger.log('my application', 'hello world!');
    console.log(this.config);
  }
}

boot.sequence.ts

import { moduleLoader, jsonLoader } from '@steffy/core';

const boot = async () => {
  await jsonLoader('./configs', 'config');
  await moduleLoader('./lib/plugins', 'plugin');
};

export { boot };

logger.plugin.ts

import { IPlugin, Logger } from '@steffy/core';
import { Singleton } from '@steffy/di';

@Singleton()
export class LoggerPlugin implements IPlugin {
  public pluginName = 'Logger';
  private _logger = new Logger();
  public debug = (mod: string, ...messages: any[]) => this._logger.debug(mod, ...messages);
  public error = (mod: string, ...messages: any[]) => this._logger.error(mod, ...messages);
  public info = (mod: string, ...messages: any[]) => this._logger.info(mod, ...messages);
  public log = (mod: string, ...messages: any[]) => this._logger.log(mod, ...messages);
}