Skip to content

Commit

Permalink
feat(logger): add initial working module (#104)
Browse files Browse the repository at this point in the history
* feat(logger): add initial working module

Add basic logger module

* chore(logger): add eslint files

* chore(logger): add lint scripts
  • Loading branch information
omermorad committed Aug 30, 2021
1 parent e201d8e commit 6b6e69d
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ const base = require('./jest.config.base');
module.exports = {
...base,
roots: ['<rootDir>'],
projects: ['<rootDir>/packages/mockingbird', '<rootDir>/packages/reflect', '<rootDir>/packages/parser'],
projects: [
'<rootDir>/packages/mockingbird',
'<rootDir>/packages/reflect',
'<rootDir>/packages/parser',
'<rootDir>/packages/logger',
],
};
2 changes: 2 additions & 0 deletions packages/logger/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
jest.config.js
3 changes: 3 additions & 0 deletions packages/logger/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc"
}
1 change: 1 addition & 0 deletions packages/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/logger';
46 changes: 46 additions & 0 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@mockinbird/logger",
"version": "0.0.0",
"license": "MIT",
"description": "Mockingbird Logger Package",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"contributors": [
{
"name": "Omer Morad",
"email": "omer.moradd@gmail.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/omermorad/mockingbird.git"
},
"bugs": {
"url": "https://github.com/omermorad/mockingbird/issues"
},
"readme": "https://github.com/omermorad/mockingbird/tree/refactor/master/packages/logger/README.md",
"scripts": {
"prebuild": "yarn rimraf dist",
"build": "tsc",
"watch": "tsc --watch",
"lint": "eslint '{src,test}/**/*.ts'",
"lint:fix": "eslint '{src,test}/**/*.ts' --fix"
},
"files": [
"dist",
"README.md",
"CHANGELOG.md"
],
"dependencies": {
"@types/chalk": "^2.2.0",
"chalk": "^4.1.2"
},
"devDependencies": {
"ts-node": "8.10.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.7"
},
"publishConfig": {
"access": "public"
}
}
41 changes: 41 additions & 0 deletions packages/logger/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import chalk from 'chalk';
import util from 'util';

const prefix = '\u{1F426} ';

function format(args: Array<any>, customPrefix?: string) {
const fullPrefix = prefix + (customPrefix === undefined ? '' : ' ' + customPrefix);
return (
fullPrefix +
util
.format('', ...args)
.split('\n')
.join('\n' + fullPrefix + ' ')
);
}

export interface MockingbirdLogger {
info(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
log(message: string, ...args: any[]): void;
success(message: string, ...args: any[]): void;
}

export const Logger: MockingbirdLogger = {
info: (...args: any[]): void => {
console.info(format(args, chalk.cyan('info')));
},
log: (...args: any[]): void => {
console.log(format(args));
},
error: (...args: any[]): void => {
console.error(format(args, chalk.red('error')));
},
success: (...args: any[]): void => {
console.log(format(args, chalk.green('success')));
},
warn: (...args: any[]): void => {
console.warn(format(args, chalk.yellow('warn')));
},
};
15 changes: 15 additions & 0 deletions packages/logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"target": "es6"
},
"exclude": [
"node_modules",
"test",
"src/**/*.test.ts",
"index.ts"
],
"include": ["src/"]
}
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
},
{
"path": "packages/mockingbird"
}
},
{
"path": "packages/logger"
},
]
}

0 comments on commit 6b6e69d

Please sign in to comment.