Skip to content

Commit

Permalink
Timing info
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Sep 5, 2024
1 parent f79b2d9 commit dc8f925
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### 2.0.0

Redwood uses prettier 3, and prettier 3 removes the sync API. This means we now have to operate entirely async. This is a breaking change from the sdl-codegen API, as you need to await the exposed public fns.
- Redwood uses prettier 3, and prettier 3 removes the sync API. This means we now have to operate entirely async. This is a breaking change from the sdl-codegen API, as you need to await the exposed public fns.
- There is a verbose option which provides info on the timings of the codegen.

### 1.1.2

Expand Down
26 changes: 18 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export async function runFullCodegen(preset: string, config: unknown): Promise<S

export async function runFullCodegen(preset: string, config: unknown): Promise<SDLCodeGenReturn> {
if (preset !== "redwood") throw new Error("Only Redwood codegen is supported at this time")
const verbose = (config as { verbose?: true }).verbose
const verbose = !!(config as { verbose?: true }).verbose
const startTime = Date.now()
const step = makeStep(verbose)

const paths = (config as { paths: RedwoodPaths }).paths
const sys = typescript.sys
Expand Down Expand Up @@ -61,8 +62,8 @@ export async function runFullCodegen(preset: string, config: unknown): Promise<S
prismaSchema = prismaModeller(prismaSchemaBlocks)
}

getGraphQLSDLFromFile(pathSettings)
getPrismaSchemaFromFile(pathSettings)
await step("Read the GraphQL schema", () => getGraphQLSDLFromFile(pathSettings))
await step("Read the Prisma schema", () => getPrismaSchemaFromFile(pathSettings))

if (!gqlSchema) throw new Error("No GraphQL Schema was created during setup")

Expand All @@ -82,8 +83,10 @@ export async function runFullCodegen(preset: string, config: unknown): Promise<S
const filepaths = [] as string[]

// Create the two shared schema files
const sharedDTSes = await createSharedSchemaFiles(appContext)
filepaths.push(...sharedDTSes)
await step("Create shared schema files", async () => {
const sharedDTSes = await createSharedSchemaFiles(appContext)
filepaths.push(...sharedDTSes)
})

let knownServiceFiles: string[] = []
const createDTSFilesForAllServices = async () => {
Expand All @@ -97,10 +100,10 @@ export async function runFullCodegen(preset: string, config: unknown): Promise<S
}

// Initial run
await createDTSFilesForAllServices()
await step("Create DTS files for all services", createDTSFilesForAllServices)

const endTime = Date.now()
const timeTaken = endTime - startTime

if (verbose) console.log(`[sdl-codegen]: Full run took ${timeTaken}ms`)

const createWatcher = () => {
Expand All @@ -116,7 +119,7 @@ export async function runFullCodegen(preset: string, config: unknown): Promise<S
getPrismaSchemaFromFile(appContext.pathSettings)
await createDTSFilesForAllServices()
} else if (isRedwoodServiceFile(path)) {
if (knownServiceFiles.includes(path)) {
if (!knownServiceFiles.includes(path)) {
if (verbose) console.log("[sdl-codegen] New service file")
await createDTSFilesForAllServices()
} else {
Expand All @@ -139,3 +142,10 @@ const isRedwoodServiceFile = (file: string) => {
if (file.endsWith("scenarios.ts") || file.endsWith("scenarios.js")) return false
return file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".js")
}

const makeStep = (verbose: boolean) => async (msg: string, fn: () => Promise<void> | void) => {
if (!verbose) return fn()
console.time(msg)
await fn()
console.timeEnd(msg)
}

0 comments on commit dc8f925

Please sign in to comment.