Skip to content

Commit

Permalink
fix: Added Logged level and normalized client path
Browse files Browse the repository at this point in the history
  • Loading branch information
William Luke committed Apr 30, 2019
1 parent 26fd2fb commit 0bb6ed9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const diagnosticHost: ts.FormatDiagnosticsHost = {
}

export default (argv: Record<string, string>) => {
argv.log && logger.setLogLevel(parseInt(argv.log))
const config = importYogaConfig({ env: argv.env })
const tsConfig = readConfigFromTsConfig(config)

Expand Down
5 changes: 5 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function run() {
alias: 'e',
description: 'Pass a custom NODE_ENV variable',
})
.option('log', {
alias: 'l',
description: 'Set the Verbosity Level',
type: 'number',
})
.help('help')
.showHelpOnFail(true)
.version().argv
Expand Down
20 changes: 15 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Borrowed from vue-cli
import chalk from 'chalk'
import readline from 'readline'
let logLevel = 0

export function setLogLevel(level: number){
logLevel=level
}

function format(label: string, msg: string) {
return msg
Expand All @@ -17,23 +22,27 @@ function chalkTag(msg: string) {
return chalk.bgBlackBright.white.dim(` ${msg} `)
}

export function log(msg: string = '', tag: string | null = null) {
export function log(msg: string = '', tag?: string, level: number = 3) {
if(level > logLevel) return
tag ? console.log(format(chalkTag(tag), msg)) : console.log(msg)
}

export function info(msg: string, tag: string | null = null) {
export function info(msg: string, tag?: string, level: number = 2) {
if(level > logLevel) return
console.log(
format(chalk.bgBlue.black(' INFO ') + (tag ? chalkTag(tag) : ''), msg),
)
}

export function done(msg: string, tag: string | null = null) {
export function done(msg: string, tag?: string, level: number = 2) {
if(level > logLevel) return
console.log(
format(chalk.bgGreen.black(' DONE ') + (tag ? chalkTag(tag) : ''), msg),
)
}

export function warn(msg: string, tag: string | null = null) {
export function warn(msg: string, tag?: string, level: number = 1) {
if(level > logLevel) return
console.warn(
format(
chalk.bgYellow.black(' WARN ') + (tag ? chalkTag(tag) : ''),
Expand All @@ -42,7 +51,8 @@ export function warn(msg: string, tag: string | null = null) {
)
}

export function error(msg: string, tag: string | null = null) {
export function error(msg: string, tag?: string, level: number = 0) {
if(level > logLevel) return
console.error(
format(chalk.bgRed(' ERROR ') + (tag ? chalkTag(tag) : ''), msg),
)
Expand Down
4 changes: 2 additions & 2 deletions src/yogaDefaults.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import { existsSync } from 'fs';
import { PrismaClientInput } from 'nexus-prisma/dist/types';
import { join, relative } from 'path';
import { join, normalize, relative } from 'path';
import { findPrismaConfigFile } from './config';
import { importFile } from './helpers';
import * as logger from './logger';
Expand Down Expand Up @@ -217,7 +217,7 @@ export function client(
): PrismaClientInput {
if (input === undefined) {
logger.warn("No Prisma Client Input found trying to resolve path")
const defaultPath = join(projectDir, datamodelInfo.clientPath, 'index.ts')
const defaultPath = normalize(join(projectDir, datamodelInfo.clientPath, 'index.ts'))
logger.info(`Looking for Prisma Client in ${defaultPath}`)
const clientPath = requiredPath(
defaultPath,
Expand Down

0 comments on commit 0bb6ed9

Please sign in to comment.