UNPKG

@citiwave/im-disclaimer-modal

Version:

A customizable React disclaimer modal component with theme support

98 lines (97 loc) 4.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDisclaimer = createDisclaimer; exports.removeDisclaimer = removeDisclaimer; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const chalk_1 = __importDefault(require("chalk")); const config_1 = require("../utils/config"); async function createDisclaimer(name, options) { try { // Use provided directory or get default from config const disclaimerDir = options.dir ? path_1.default.resolve(process.cwd(), options.dir) : await (0, config_1.getDefaultDirectory)(); const disclaimerPath = path_1.default.join(disclaimerDir, `${name}.json`); const configPath = path_1.default.join(disclaimerDir, '_config.json'); // Ensure directory exists await fs_extra_1.default.ensureDir(disclaimerDir); // Check if disclaimer already exists if (await fs_extra_1.default.pathExists(disclaimerPath)) { console.error(chalk_1.default.red(`Disclaimer '${name}' already exists`)); return; } // Create template disclaimer content const template = { 'section-1': { title: 'Section 1', required: true, content: { title: 'Main Terms', sections: [ { heading: 'Introduction', text: 'Please read these terms carefully.', list: [ 'Item 1', 'Item 2', 'Item 3' ] } ] } } }; // Save disclaimer content await fs_extra_1.default.writeJson(disclaimerPath, template, { spaces: 2 }); // Load existing config or create new one const config = await fs_extra_1.default.pathExists(configPath) ? await fs_extra_1.default.readJson(configPath) : {}; // Update config with new disclaimer settings config[name] = { title: options.title || name, prefix: options.prefix || 'disclaimer', defaultOpen: options.defaultOpen !== undefined ? options.defaultOpen : true, theme: options.theme || 'dark', accent: options.accent || '#3B82F6' }; // Save updated config await fs_extra_1.default.writeJson(configPath, config, { spaces: 2 }); console.log(chalk_1.default.green(`✓ Created disclaimer '${name}'`)); console.log(chalk_1.default.gray(` Location: ${disclaimerPath}`)); } catch (error) { console.error(chalk_1.default.red('Failed to create disclaimer:'), error); } } async function removeDisclaimer(name, options) { try { // Use provided directory or get default from config const disclaimerDir = options.dir ? path_1.default.resolve(process.cwd(), options.dir) : await (0, config_1.getDefaultDirectory)(); const disclaimerPath = path_1.default.join(disclaimerDir, `${name}.json`); const configPath = path_1.default.join(disclaimerDir, '_config.json'); // Check if disclaimer exists if (!await fs_extra_1.default.pathExists(disclaimerPath)) { console.error(chalk_1.default.red(`Disclaimer '${name}' does not exist`)); return; } // Remove disclaimer file await fs_extra_1.default.remove(disclaimerPath); // Update config if it exists if (await fs_extra_1.default.pathExists(configPath)) { const config = await fs_extra_1.default.readJson(configPath); delete config[name]; await fs_extra_1.default.writeJson(configPath, config, { spaces: 2 }); } console.log(chalk_1.default.green(`✓ Removed disclaimer '${name}'`)); } catch (error) { console.error(chalk_1.default.red('Failed to remove disclaimer:'), error); } }