UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var path_1 = require("path");
4var fs_1 = require("fs");
5var errors_1 = require("./errors");
6exports.GRAPHQL_CONFIG_NAME = '.graphqlconfig';
7exports.GRAPHQL_CONFIG_YAML_NAME = '.graphqlconfig.yaml';
8exports.GRAPHQL_CONFIG_YML_NAME = '.graphqlconfig.yml';
9function isRootDir(path) {
10 return path_1.dirname(path) === path;
11}
12function findGraphQLConfigFile(filePath) {
13 filePath = path_1.resolve(filePath);
14 if (filePath.endsWith(exports.GRAPHQL_CONFIG_NAME) ||
15 filePath.endsWith(exports.GRAPHQL_CONFIG_YAML_NAME) ||
16 filePath.endsWith(exports.GRAPHQL_CONFIG_YML_NAME)) {
17 return filePath;
18 }
19 var currentDir = filePath;
20 while (!isRootDir(currentDir)) {
21 var configPath = path_1.join(currentDir, exports.GRAPHQL_CONFIG_NAME);
22 if (fs_1.existsSync(configPath)) {
23 return configPath;
24 }
25 if (fs_1.existsSync(configPath + '.yaml')) {
26 return configPath + '.yaml';
27 }
28 if (fs_1.existsSync(configPath + '.yml')) {
29 return configPath + '.yml';
30 }
31 currentDir = path_1.dirname(currentDir);
32 }
33 throw new errors_1.ConfigNotFoundError("\"" + exports.GRAPHQL_CONFIG_NAME + "\" file is not available in the provided config " +
34 ("directory: " + filePath + "\nPlease check the config directory."));
35}
36exports.findGraphQLConfigFile = findGraphQLConfigFile;