UNPKG

@vendure/cli

Version:

A modern, headless ecommerce framework

136 lines 5.24 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.schemaCommand = schemaCommand; const prompts_1 = require("@clack/prompts"); const picocolors_1 = __importDefault(require("picocolors")); const utils_1 = require("../../utilities/utils"); const cancelledMessage = 'Schema generation cancelled.'; async function schemaCommand(options) { if (options === null || options === void 0 ? void 0 : options.api) { await handleNonInteractiveMode(options); return; } await handleInteractiveMode(options === null || options === void 0 ? void 0 : options.config); } async function handleNonInteractiveMode(options) { try { process.env.VENDURE_RUNNING_IN_CLI = 'true'; const { generateSchema } = await Promise.resolve().then(() => __importStar(require('./generate-schema/generate-schema'))); await generateSchema(options); process.env.VENDURE_RUNNING_IN_CLI = undefined; } catch (e) { prompts_1.log.error(e.message); if (e.stack) { prompts_1.log.error(e.stack); } process.exit(1); } } async function handleInteractiveMode(configFile) { console.log(`\n`); (0, prompts_1.intro)(picocolors_1.default.blue('🛠️️ Generate a schema file of your GraphQL API')); const apiType = await (0, utils_1.withInteractiveTimeout)(async () => { return await (0, prompts_1.select)({ message: 'Which API should we target?', options: [ { value: 'admin', label: 'Admin API' }, { value: 'shop', label: 'Shop API' }, ], }); }); if ((0, prompts_1.isCancel)(apiType)) { (0, prompts_1.cancel)(cancelledMessage); process.exit(0); } const format = await (0, utils_1.withInteractiveTimeout)(async () => { return await (0, prompts_1.select)({ message: 'What format should we use for the schema?', options: [ { value: 'sdl', label: 'SDL format (default)' }, { value: 'json', label: 'JSON introspection query result' }, ], }); }); if ((0, prompts_1.isCancel)(format)) { (0, prompts_1.cancel)(cancelledMessage); process.exit(0); } const outputDir = await (0, utils_1.withInteractiveTimeout)(async () => { return await (0, prompts_1.text)({ message: 'Output directory:', initialValue: process.cwd(), }); }); if ((0, prompts_1.isCancel)(outputDir)) { (0, prompts_1.cancel)(cancelledMessage); process.exit(0); } const fileName = await (0, utils_1.withInteractiveTimeout)(async () => { const defaultBase = `schema${apiType === 'shop' ? '-shop' : ''}`; return await (0, prompts_1.text)({ message: 'File name:', initialValue: format === 'sdl' ? `${defaultBase}.graphql` : `${defaultBase}.json`, }); }); if ((0, prompts_1.isCancel)(fileName)) { (0, prompts_1.cancel)(cancelledMessage); process.exit(0); } try { process.env.VENDURE_RUNNING_IN_CLI = 'true'; const { generateSchema } = await Promise.resolve().then(() => __importStar(require('./generate-schema/generate-schema'))); await generateSchema({ api: apiType, format, fileName, outputDir, config: configFile, }); (0, prompts_1.outro)('✅ Done!'); process.env.VENDURE_RUNNING_IN_CLI = undefined; } catch (e) { prompts_1.log.error(e.message); if (e.stack) { prompts_1.log.error(e.stack); } } } //# sourceMappingURL=schema.js.map