Skip to content

Commit

Permalink
Update logging message
Browse files Browse the repository at this point in the history
  • Loading branch information
farreldarian committed Dec 26, 2023
1 parent 00b8df7 commit 403177d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
20 changes: 7 additions & 13 deletions packages/generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand All @@ -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}`)),
Expand All @@ -103,13 +104,6 @@ generatorHandler({
name: 'schema',
declarations: [schemaVar],
})

logger.info(
`✨ Successfully generated Drizzle schema to ${relative(
process.cwd(),
basePath
)}`
)
},
})

Expand Down
8 changes: 4 additions & 4 deletions packages/generator/src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 403177d

Please sign in to comment.