Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[balance fetching] remove gql files script #115

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading