From 403177d9afd41e24fd3158a94ed1603cb83545c1 Mon Sep 17 00:00:00 2001 From: farreldarian Date: Tue, 26 Dec 2023 09:23:08 +0700 Subject: [PATCH] Update logging message --- packages/generator/src/generator.ts | 20 +++++++------------- packages/generator/src/lib/logger.ts | 8 ++++---- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 405d73c..3e21144 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -33,7 +33,7 @@ const { version } = require('../package.json') generatorHandler({ onManifest() { - logger.info('Generating drizzle schema...') + logger.log('Generating drizzle schema...') return { version, defaultOutput: './drizzle', @@ -53,21 +53,22 @@ generatorHandler({ fs.existsSync(basePath) && fs.rmSync(basePath, { recursive: true }) - const enumCreation = logger.createTask() for await (const prismaEnum of options.dmmf.datamodel.enums) { + const enumCreation = logger.createTask() const enumVar = defineEnumVar(adapter, prismaEnum) + const moduleName = getEnumModuleName(prismaEnum) await writeCode({ declarations: [enumVar], path: basePath, - name: getEnumModuleName(prismaEnum), + name: moduleName, }) + enumCreation.end(`◟ ${moduleName}.ts`) } - enumCreation.end(`${options.dmmf.datamodel.enums.length} Enums generated`) - const modelCreation = logger.createTask() const models = [] for await (const model of options.dmmf.datamodel.models) { + const modelCreation = logger.createTask() const tableVar = defineTableVar(adapter, model) const relationalFields = model.fields.filter(isRelationField) @@ -86,8 +87,8 @@ generatorHandler({ name: tableVar.name, path: `${moduleName}`, }) + modelCreation.end(`◟ ${moduleName}.ts`) } - modelCreation.end(`${options.dmmf.datamodel.enums.length} Models generated`) const schemaVar = createValue({ imports: models.map((m) => v.wilcardImport(m.name, `./${m.path}`)), @@ -103,13 +104,6 @@ generatorHandler({ name: 'schema', declarations: [schemaVar], }) - - logger.info( - `✨ Successfully generated Drizzle schema to ${relative( - process.cwd(), - basePath - )}` - ) }, }) diff --git a/packages/generator/src/lib/logger.ts b/packages/generator/src/lib/logger.ts index ba3ba5b..4cf47b6 100644 --- a/packages/generator/src/lib/logger.ts +++ b/packages/generator/src/lib/logger.ts @@ -1,20 +1,20 @@ import { logger as baseLogger } from '@prisma/sdk' import { GENERATOR_NAME } from 'src/constants' -function info(message: string) { - baseLogger.info(`${GENERATOR_NAME} — ${message}`) +function log(message: string) { + baseLogger.log(`${GENERATOR_NAME}: ${message}`) } function createTask() { const timeStarted = Date.now() return { end(message: string) { - return info(`${message} in ${Date.now() - timeStarted}ms`) + return log(`${message} in ${Date.now() - timeStarted}ms`) }, } } export const logger = { - info, + log, createTask, }