UNPKG

2.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var path_1 = require("path");
4var utils_1 = require("./utils");
5var GraphQLProjectConfig_1 = require("./GraphQLProjectConfig");
6var GraphQLConfig = /** @class */ (function () {
7 function GraphQLConfig(config, configPath) {
8 utils_1.validateConfig(config);
9 this.config = config;
10 this.configPath = configPath;
11 }
12 Object.defineProperty(GraphQLConfig.prototype, "configDir", {
13 get: function () {
14 return path_1.dirname(this.configPath);
15 },
16 enumerable: true,
17 configurable: true
18 });
19 GraphQLConfig.prototype.getProjectConfig = function (projectName) {
20 return new GraphQLProjectConfig_1.GraphQLProjectConfig(this.config, this.configPath, projectName);
21 };
22 GraphQLConfig.prototype.getConfigForFile = function (filePath) {
23 var projects = this.config.projects;
24 if (!projects || Object.keys(projects).length === 0) {
25 var config = new GraphQLProjectConfig_1.GraphQLProjectConfig(this.config, this.configPath, undefined);
26 return config.includesFile(filePath) ? config : undefined;
27 }
28 return Object.values(this.getProjects()).find(function (project) { return project.includesFile(filePath); }) || undefined;
29 };
30 GraphQLConfig.prototype.getProjectNameForFile = function (filePath) {
31 var proj = this.getConfigForFile(filePath);
32 return proj && proj.projectName || undefined;
33 };
34 GraphQLConfig.prototype.getProjects = function () {
35 var result = {};
36 for (var projectName in (this.config.projects || {})) {
37 result[projectName] = this.getProjectConfig(projectName);
38 }
39 if (Object.keys(result).length === 0) {
40 return undefined;
41 }
42 return result;
43 };
44 GraphQLConfig.prototype.saveConfig = function (newConfig, projectName) {
45 var config;
46 if (projectName) {
47 config = this.config;
48 config.projects = config.projects || {};
49 config.projects[projectName] = config.projects[projectName] || {};
50 config.projects[projectName] = newConfig;
51 }
52 else {
53 config = newConfig;
54 }
55 utils_1.writeConfig(this.configPath, config);
56 };
57 return GraphQLConfig;
58}());
59exports.GraphQLConfig = GraphQLConfig;