Skip to content

Commit

Permalink
[balance fetching] add remove gql files script (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-diamond authored Jun 5, 2024
1 parent 1d2bf8c commit fd49b10
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/generateGraphqlExports/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'

import removeOldFiles from './removeOldFiles'
import addGraphqlNamespace from './addGraphqlNamespace'
import generateGraphqlQueryFiles from './generateGraphqlQueryFiles'

Expand All @@ -19,6 +20,7 @@ const endpoints = [

try {
endpoints.forEach(({ dir, types, client }) => {
removeOldFiles(dir)
addGraphqlNamespace(types, client)
generateGraphqlQueryFiles(dir, client)
})
Expand Down
38 changes: 38 additions & 0 deletions scripts/generateGraphqlExports/removeOldFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import fs from 'fs'
import path from 'path'


const removeOldFiles = (dirPath: string) => {
const gqlFolders = fs.readdirSync(dirPath).filter((dirName: string) => !dirName.includes('.'))

gqlFolders.forEach((gqlModelName: string) => {
const gqlModelDir = path.resolve(dirPath, gqlModelName)

const gqlFiles = fs.readdirSync(gqlModelDir)
.filter((fileName: string) => /\.graphql$/.test(fileName))

const typeFilesToRemove = fs.readdirSync(gqlModelDir)
.filter((fileName: string) => {
const isTypeFile = /\.graphql\.ts$/.test(fileName)
const hasGqlFile = gqlFiles.includes(fileName.replace(/\.ts$/, ''))

return isTypeFile && !hasGqlFile
})

if (gqlFiles.length) {
typeFilesToRemove.forEach((typeFileName: string) => {
const typeFile = path.resolve(gqlModelDir, typeFileName)

console.log('remove file', typeFile)
fs.rmSync(typeFile)
})
}
else {
console.log('remove dir', gqlModelDir)
fs.rmSync(gqlModelDir, { recursive: true })
}
})
}


export default removeOldFiles

0 comments on commit fd49b10

Please sign in to comment.