UNPKG

@vendure/cli

Version:

A modern, headless ecommerce framework

57 lines 3.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addDashboardCommand = void 0; exports.addDashboard = addDashboard; const prompts_1 = require("@clack/prompts"); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const cli_command_1 = require("../../../shared/cli-command"); const shared_prompts_1 = require("../../../shared/shared-prompts"); const vendure_plugin_ref_1 = require("../../../shared/vendure-plugin-ref"); const ast_utils_1 = require("../../../utilities/ast-utils"); exports.addDashboardCommand = new cli_command_1.CliCommand({ id: 'add-dashboard', category: 'Plugin: Dashboard', description: 'Add Dashboard extensions', run: addDashboard, }); async function addDashboard(options) { const providedVendurePlugin = options === null || options === void 0 ? void 0 : options.plugin; const { project } = await (0, shared_prompts_1.analyzeProject)({ providedVendurePlugin, config: options === null || options === void 0 ? void 0 : options.config }); const isNonInteractive = (options === null || options === void 0 ? void 0 : options.isNonInteractive) === true; let vendurePlugin = providedVendurePlugin; if (!vendurePlugin && (options === null || options === void 0 ? void 0 : options.pluginName)) { const pluginClasses = (0, ast_utils_1.getPluginClasses)(project); const foundPlugin = pluginClasses.find(p => p.getName() === options.pluginName); if (!foundPlugin) { const availablePlugins = pluginClasses.map(p => p.getName()).filter(Boolean); throw new Error(`Plugin "${options.pluginName}" not found. Available plugins:\n` + availablePlugins.map(name => ` - ${name}`).join('\n')); } vendurePlugin = new vendure_plugin_ref_1.VendurePluginRef(foundPlugin); } if (isNonInteractive && !vendurePlugin) { throw new Error('Plugin must be specified when running in non-interactive mode'); } vendurePlugin = vendurePlugin !== null && vendurePlugin !== void 0 ? vendurePlugin : (await (0, shared_prompts_1.selectPlugin)(project, 'Add UI extensions cancelled')); try { vendurePlugin.addMetadataProperty('dashboard', './dashboard/index.tsx'); prompts_1.log.success('Updated the plugin class'); } catch (e) { prompts_1.log.error(e instanceof Error ? e.message : String(e)); return { project, modifiedSourceFiles: [] }; } const pluginDir = vendurePlugin.getPluginDir().getPath(); const dashboardEntrypointFile = path_1.default.join(pluginDir, 'dashboard', 'index.tsx'); if (!fs_extra_1.default.existsSync(dashboardEntrypointFile)) { (0, ast_utils_1.createFile)(project, path_1.default.join(__dirname, 'templates/index.template.tsx'), dashboardEntrypointFile); } prompts_1.log.success('Created Dashboard extension scaffold'); await project.save(); return { project, modifiedSourceFiles: [vendurePlugin.classDeclaration.getSourceFile()] }; } //# sourceMappingURL=add-dashboard.js.map