1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 19:02:14 +00:00

Initial commit With Logger

This commit is contained in:
Florian Bouillon 2020-06-25 17:29:41 +02:00
commit 55d8a3bd67
13 changed files with 7517 additions and 0 deletions

8
.editorconfig Normal file
View File

@ -0,0 +1,8 @@
root = true
[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
*.d.ts

8
lerna.json Normal file
View File

@ -0,0 +1,8 @@
{
"packages": [
"packages/*"
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent"
}

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"name": "components",
"private": true,
"workspaces": ["packages/*"],
"license": "MIT",
"dependencies": {
"lerna": "^3.22.1"
}
}

5
packages/logger/.babelrc Normal file
View File

@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}

1
packages/logger/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/dist/

View File

@ -0,0 +1,31 @@
{
"name": "@aviortheking/logger",
"version": "1.0.0",
"description": "My Personnal Logger",
"repository": {
"type": "git",
"url": "https://github.com/Aviortheking/components.git",
"directory": "packages/Logger"
},
"author": "Aviortheking",
"license": "MIT",
"private": false,
"main": "./dist/Logger.js",
"browser": "./dist/browser.js",
"types": "./dist/types/Logger.d.ts",
"dependencies": {
"chalk": "^4.1.0"
},
"devDependencies": {
"@babel/core": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"babel-loader": "^8.1.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"scripts": {
"build": "webpack --mode=\"production\" && tsc"
}
}

View File

@ -0,0 +1,40 @@
import chalk from 'chalk'
export default class Logger {
public static isBlocked = false
private static queue: Array<string> = []
private static prefixLen = 0
public static log(prefix: string, ...message: Array<any>) {
this.queue.push(this.formatMessage(prefix, ...message))
while (this.queue.length > 0 && !this.isBlocked) {
console.log(this.queue.shift())
}
}
public static urgent(prefix: string, ...message: Array<any>) {
console.log(this.formatMessage(prefix, ...message))
}
private static formatMessage(prefix: string, ...message: Array<any>): string {
if (this.prefixLen < prefix.length) {
this.prefixLen = prefix.length
}
const els: Array<string> = ['', '']
if (this.prefixLen > prefix.length) {
const diff = this.prefixLen - prefix.length
els[0] = this.buildSpace(diff / 2 - (diff % 2 !== 0 ? 1 : 0))
els[1] = this.buildSpace(diff / 2)
}
return `${chalk.white('[ ')}${els[0]}${chalk.blue(prefix)}${els[1]}${chalk.white(' ]')}: ${message.map((el) => typeof el === 'number' ? chalk.yellow(el.toString()) : chalk.white(el)).join(' ')}`
}
private static buildSpace(count: number): string {
let str = ''
for(let i = 0; i < count; i++) {
str += ' '
}
return str
}
}

View File

@ -0,0 +1,6 @@
import Logger from './Logger'
// Browser Import
// @ts-ignore
window.Logger = Logger

View File

@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "dist"
},
"exclude": [
"node_modules"
],
"files": [
"src/Logger.ts"
]
}

View File

@ -0,0 +1,17 @@
module.exports = {
entry: './src/index',
output: {
path: __dirname,
filename: './dist/browser.js',
},
resolve: {
extensions: ['.js', '.ts'],
},
module: {
rules: [
{
test: /\.ts$/, use: ['babel-loader', 'ts-loader'], exclude: /node_modules/
}
]
}
};

21
tsconfig.base.json Normal file
View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"moduleResolution": "node",
"noImplicitReturns": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"allowJs": true,
// "sourceMap": true,
"strict": true,
"target": "es5",
"module": "commonjs",
}
}

7355
yarn.lock Normal file

File diff suppressed because it is too large Load Diff