UNPKG

@graphql-cli/init

Version:

Creates a GraphQL project using a template or GraphQL Config file for your existing project.

49 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromExisting = void 0; const tslib_1 = require("tslib"); const rimraf_1 = tslib_1.__importDefault(require("rimraf")); const path_1 = require("path"); const fs_extra_1 = require("fs-extra"); const inquirer_1 = require("inquirer"); const search_codegen_config_1 = require("../search-codegen-config"); async function fromExisting({ context, project }) { const manifestPath = path_1.join(context.path, 'package.json'); if (fs_extra_1.existsSync(manifestPath)) { const { name: projectName } = require(manifestPath); context.name = projectName; } const result = await search_codegen_config_1.searchCodegenConfig(context.path); if (result && !result.isEmpty) { const codegenFilePath = result.filepath; const { willBeMerged } = await inquirer_1.prompt([ { type: 'confirm', name: 'willBeMerged', message: `GraphQL Code Generator configuration has been detected in ${codegenFilePath}.\n Do you want to use the same configuration with GraphQL CLI?`, default: true, }, ]); if (willBeMerged) { project.addDependency('@graphql-cli/codegen'); const codegenConfig = result.config; context.graphqlConfig.extensions.codegen = { generates: {}, }; for (const key in codegenConfig) { if (key === 'schema') { context.graphqlConfig.schema = codegenConfig.schema; } else if (key === 'documents') { context.graphqlConfig.documents = codegenConfig.documents; } else { context.graphqlConfig.extensions.codegen[key] = codegenConfig[key]; } } rimraf_1.default.sync(result.filepath); } } } exports.fromExisting = fromExisting; //# sourceMappingURL=from-existing.js.map