1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var path_1 = require("path");
|
4 | var fs_1 = require("fs");
|
5 | var errors_1 = require("./errors");
|
6 | exports.GRAPHQL_CONFIG_NAME = '.graphqlconfig';
|
7 | exports.GRAPHQL_CONFIG_YAML_NAME = '.graphqlconfig.yaml';
|
8 | exports.GRAPHQL_CONFIG_YML_NAME = '.graphqlconfig.yml';
|
9 | function isRootDir(path) {
|
10 | return path_1.dirname(path) === path;
|
11 | }
|
12 | function 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 | }
|
36 | exports.findGraphQLConfigFile = findGraphQLConfigFile;
|