@graphql-cli/init
Version:
Creates a GraphQL project using a template or GraphQL Config file for your existing project.
46 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchCodegenConfig = void 0;
const cosmiconfig_1 = require("cosmiconfig");
const string_env_interpolation_1 = require("string-env-interpolation");
function generateSearchPlaces(moduleName) {
const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
// gives codegen.json...
const regular = extensions.map((ext) => `${moduleName}.${ext}`);
// gives .codegenrc.json... but no .codegenrc.config.js
const dot = extensions.filter((ext) => ext !== 'config.js').map((ext) => `.${moduleName}rc.${ext}`);
return regular.concat(dot);
}
function customLoader(ext) {
function loader(filepath, content) {
if (typeof process !== 'undefined' && 'env' in process) {
content = string_env_interpolation_1.env(content);
}
if (ext === 'json') {
return cosmiconfig_1.defaultLoaders['.json'](filepath, content);
}
if (ext === 'yaml') {
return cosmiconfig_1.defaultLoaders['.yaml'](filepath, content);
}
if (ext === 'js') {
return cosmiconfig_1.defaultLoaders['.js'](filepath, content);
}
}
return loader;
}
async function searchCodegenConfig(cwd) {
const moduleName = 'codegen';
const cosmi = cosmiconfig_1.cosmiconfig(moduleName, {
searchPlaces: generateSearchPlaces(moduleName),
loaders: {
'.json': customLoader('json'),
'.yaml': customLoader('yaml'),
'.yml': customLoader('yaml'),
'.js': customLoader('js'),
noExt: customLoader('yaml'),
},
});
return cosmi.search(cwd);
}
exports.searchCodegenConfig = searchCodegenConfig;
//# sourceMappingURL=search-codegen-config.js.map