-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[balance fetching] add remove gql files script (#115)
- Loading branch information
1 parent
1d2bf8c
commit fd49b10
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |