Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
fix(drizzle): build migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Mar 21, 2024
1 parent c96eb2c commit d04e08e
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 1,082 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/runtime/modules/drizzle/core.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { cpSync, existsSync, lstatSync, mkdirSync } from 'node:fs'
import { resolve } from 'node:path'
import { join, resolve } from 'node:path'
import { useLogger } from '@nuxt/kit'
import { consola } from 'consola'
import type { NuxtPergel } from '../../core/types/nuxtModule'
import type { ResolvedDrizzleConfig } from './types'

export async function copyMigrationFolder(
nuxt: NuxtPergel,
options: ResolvedDrizzleConfig,
) {
/**
* Public Assets
Expand All @@ -18,7 +20,7 @@ export async function copyMigrationFolder(
for (const [moduleName, _module] of Object.entries(modules)) {
if (moduleName === 'drizzle') {
const outDir = resolve(nitroCtx.options.output.dir, 'pergel', projectName, moduleName, 'migrations')
const folderDir = resolve(nitroCtx.options.rootDir, 'pergel', projectName, moduleName, 'migrations')
const folderDir = resolve(join(options.serverDir, 'migrations'))
// check folder in files > 0
const folderSize = lstatSync(folderDir).size

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/runtime/modules/drizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default definePergelModule<DrizzleConfig, ResolvedDrizzleConfig>({
],
})

copyMigrationFolder(nuxt)
copyMigrationFolder(nuxt, options)

if (nuxt.options.dev) {
// Watch for changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'
import type { PluginFunction, Types } from '@graphql-codegen/plugin-helpers'
import type { GraphQLSchema } from 'graphql'
import { codegen } from '@graphql-codegen/core'
import { parse, printSchema } from 'graphql'
import { parse } from 'graphql'
import type { TypeScriptDocumentsPluginConfig } from '@graphql-codegen/typescript-operations'
import { plugin as typescriptOperationsPlugin } from '@graphql-codegen/typescript-operations'
import type { TypeScriptPluginConfig } from '@graphql-codegen/typescript'
Expand Down Expand Up @@ -163,7 +163,7 @@ async function urqlIntrospection(

const res = await codegen({
filename: 'a.ts',
schema: parse(printSchema(schema)),
schema: parse(printSchemaWithDirectives(schema)),
documents: [],
config: mergeConfig,
plugins: [
Expand Down Expand Up @@ -198,7 +198,7 @@ async function generateTypedDocumentNode(
const res = await codegen({
// Filename is not used. This is because the typescript plugin returns a string instead of writing to a file.
filename: 'a.ts',
schema: parse(printSchema(schema)),
schema: parse(printSchemaWithDirectives(schema)),
// TODO: Add support for fragments
documents,
config: mergeConfig,
Expand Down Expand Up @@ -231,7 +231,7 @@ async function generateTypedDocumentNode(
}

async function writeSchema(schema: GraphQLSchema, path: string) {
const schemaString = printSchema(schema)
const schemaString = printSchemaWithDirectives(schema)

writeFilePergel(path, schemaString)
return schemaString
Expand Down
Loading

0 comments on commit d04e08e

Please sign in to comment.