Skip to content

Commit

Permalink
feat: find config in subdir - remove dep on fs-finder
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyendu Singh committed Jul 16, 2018
1 parent e4a38c6 commit a598de4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"typescript": "2.7.2"
},
"dependencies": {
"fs-finder": "^1.8.1",
"graphql-import": "^0.4.4",
"graphql-request": "^1.5.0",
"js-yaml": "^3.10.0",
Expand Down
21 changes: 14 additions & 7 deletions src/findGraphQLConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { resolve, join as joinPaths, dirname, basename } from 'path'
import { existsSync } from 'fs'
import * as Finder from 'fs-finder'
import { resolve, join as joinPaths, dirname, basename, join } from 'path'
import { existsSync, readdirSync, lstatSync } from 'fs'

import {
ConfigNotFoundError
Expand Down Expand Up @@ -41,12 +40,20 @@ export function findGraphQLConfigFile(filePath: string): string {
}

// Try to find GraphQL config in first level of sub-directories.
const subDirectories = Finder.in(filePath).showSystemFiles().findDirectories()
const subDirectories = readdirSync(filePath).map(dir => joinPaths(filePath, dir)).filter(dir => {
return (lstatSync(dir).isDirectory())
})
const subDirectoriesWithGraphQLConfig = subDirectories.map(subDirectory => {
const subDirectoryFiles = Finder.in(subDirectory).showSystemFiles().findFiles().map(file => basename(file))
const subDirectoryFiles = readdirSync(subDirectory)
.filter(file => {
return !(lstatSync(joinPaths(subDirectory, file)).isDirectory())
})
.map(file => {
return basename(joinPaths(subDirectory, file))
})
if (subDirectoryFiles.includes(GRAPHQL_CONFIG_NAME)) {
return `${subDirectory}/${GRAPHQL_CONFIG_NAME}`
}
}
if (subDirectoryFiles.includes(`${GRAPHQL_CONFIG_NAME}.yml`)) {
return `${subDirectory}/${GRAPHQL_CONFIG_NAME}.yml`
}
Expand All @@ -55,7 +62,7 @@ export function findGraphQLConfigFile(filePath: string): string {
}
})
if (subDirectoriesWithGraphQLConfig.length > 0) {
return subDirectoriesWithGraphQLConfig[0]
return subDirectoriesWithGraphQLConfig[0] as string
}

throw new ConfigNotFoundError(
Expand Down

0 comments on commit a598de4

Please sign in to comment.