flowtyped everything, some functional, safety, and structural changes

This commit is contained in:
41666 2019-03-10 03:18:11 -05:00
parent 6f3eca7a64
commit d2aecb38ca
92 changed files with 17554 additions and 1440 deletions

View file

@ -1,16 +1,16 @@
const chalk = require('chalk')
// const { debug } = require('yargs').argv
// process.env.DEBUG = process.env.DEBUG || debug
// logger template//
// const log = new (require('../logger'))('server/thing')
// @flow
import chalk from 'chalk'
class Logger {
constructor (name, debugOverride = false) {
export class Logger {
debugOn: boolean
name: string
constructor (name: string, debugOverride: boolean = false) {
this.name = name
this.debugOn = (process.env.DEBUG === 'true' || process.env.DEBUG === '*') || debugOverride
}
fatal (text, ...data) {
fatal (text: string, ...data: any) {
this.error(text, data)
if (typeof data[data.length - 1] === 'number') {
@ -18,41 +18,47 @@ class Logger {
} else {
process.exit(1)
}
throw text
}
error (text, ...data) {
error (text: string, ...data: any) {
console.error(chalk.red.bold(`ERR ${this.name}:`) + `\n ${text}`, data)
}
warn (text, ...data) {
warn (text: string, ...data: any) {
console.warn(chalk.yellow.bold(`WARN ${this.name}:`) + `\n ${text}`, data)
}
notice (text, ...data) {
notice (text: string, ...data: any) {
console.log(chalk.cyan.bold(`NOTICE ${this.name}:`) + `\n ${text}`, data)
}
info (text, ...data) {
info (text: string, ...data: any) {
console.info(chalk.blue.bold(`INFO ${this.name}:`) + `\n ${text}`, data)
}
request (text, ...data) {
deprecated (text: string, ...data: any) {
console.warn(chalk.yellowBright(`DEPRECATED ${this.name}:`) + `\n ${text}`, data)
console.trace()
}
request (text: string, ...data: any) {
console.info(chalk.green.bold(`HTTP ${this.name}:`) + `\n ${text}`)
}
debug (text, ...data) {
debug (text: string, ...data: any) {
if (this.debugOn) {
console.log(chalk.gray.bold(`DEBUG ${this.name}:`) + `\n ${text}`, data)
}
}
sql (logger, ...data) {
sql (logger: Logger, ...data: any) {
if (logger.debugOn) {
console.log(chalk.bold('DEBUG SQL:\n '), data)
}
}
}
module.exports = Logger
export default (pathname: string) => {
const name = pathname.replace(__dirname, '').replace('.js', '')
return new Logger(name)
}