UNPKG

@diagramers/cli

Version:

Diagramers CLI - Command-line tools for managing Diagramers projects

144 lines 7.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.adminCommand = adminCommand; const chalk_1 = __importDefault(require("chalk")); const child_process_1 = require("child_process"); function adminCommand(program) { const admin = program .command('admin') .description('Admin-specific commands for Diagramers projects'); admin .command('init <projectName>') .description('Initialize a new admin application') .option('-f, --framework <framework>', 'Framework to use (react, vue, angular)', 'react') .option('-a, --api-url <url>', 'API URL for backend integration', 'http://localhost:3000') .option('-p, --port <port>', 'Port number for development server', '3000') .option('-v, --version <version>', 'Specific version to use') .option('-y, --yes', 'Skip prompts and use defaults') .action(async (projectName, options) => { try { let version = options.version || 'latest'; if (options.version) { console.log(chalk_1.default.blue(`ℹ️ Using user-specified @diagramers/admin version: ${version}`)); } else { version = 'latest'; console.log(chalk_1.default.blue(`ℹ️ Using @diagramers/admin@latest (fetches the latest from npm)`)); } let command = `npx @diagramers/admin@${version} init ${projectName}`; if (options.framework) { command += ` --framework ${options.framework}`; } if (options.apiUrl) { command += ` --api-url ${options.apiUrl}`; } if (options.port) { command += ` --port ${options.port}`; } if (options.yes) { command += ` --yes`; } console.log(chalk_1.default.gray(`Executing: ${command}`)); (0, child_process_1.execSync)(command, { stdio: 'inherit' }); console.log(chalk_1.default.green(`✅ Admin application '${projectName}' initialized successfully!`)); console.log(chalk_1.default.blue(`📁 Project created at: ${process.cwd()}/${projectName}`)); console.log(chalk_1.default.blue(`🚀 To start development: cd ${projectName} && npm start`)); console.log(chalk_1.default.yellow(`🎨 After starting the app, you'll be redirected to the setup page to configure:`)); console.log(chalk_1.default.yellow(` • Upload your project logo`)); console.log(chalk_1.default.yellow(` • Set your project name`)); console.log(chalk_1.default.yellow(` • Choose your default theme`)); console.log(chalk_1.default.blue(`🔧 You can also access project settings later from the admin panel`)); } catch (error) { console.error(chalk_1.default.red(`❌ Failed to initialize admin project: ${error.message}`)); process.exit(1); } }); admin .command('update') .description('Update an existing admin project with the latest template') .option('-v, --version <version>', 'Specific version to update to (e.g., 1.1.27, latest)') .option('-f, --force', 'Force update even if conflicts detected') .option('-b, --backup', 'Create backup before updating') .action(async (options) => { try { // Check if we're in a valid admin project const fs = require('fs'); const path = require('path'); if (!fs.existsSync('package.json')) { console.error(chalk_1.default.red('❌ No package.json found. Please run this command from your admin project directory.')); process.exit(1); } const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); const isAdminProject = packageJson.dependencies && (packageJson.dependencies['@diagramers/admin'] || packageJson.devDependencies && packageJson.devDependencies['@diagramers/admin']); if (!isAdminProject) { console.error(chalk_1.default.red('❌ This does not appear to be a Diagramers admin project.')); process.exit(1); } let version = options.version || 'latest'; console.log(chalk_1.default.blue(`🔄 Updating admin project to version: ${version}`)); // Create backup if requested if (options.backup) { const backupDir = `backup-${new Date().toISOString().replace(/[:.]/g, '-')}`; console.log(chalk_1.default.yellow(`📦 Creating backup in: ${backupDir}`)); (0, child_process_1.execSync)(`cp -r . ${backupDir}`, { stdio: 'inherit' }); } // Update the admin package let updateCommand = `npm update @diagramers/admin`; if (version !== 'latest') { updateCommand = `npm install @diagramers/admin@${version}`; } console.log(chalk_1.default.gray(`Executing: ${updateCommand}`)); (0, child_process_1.execSync)(updateCommand, { stdio: 'inherit' }); // Run the admin update script if it exists if (fs.existsSync('scripts/update.js')) { console.log(chalk_1.default.blue(`🔄 Running admin update script...`)); (0, child_process_1.execSync)('node scripts/update.js', { stdio: 'inherit' }); } console.log(chalk_1.default.green(`✅ Admin project updated successfully!`)); console.log(chalk_1.default.blue(`📦 Updated to @diagramers/admin@${version}`)); console.log(chalk_1.default.yellow(`💡 Run "npm install" to update dependencies if needed`)); console.log(chalk_1.default.yellow(`💡 Run "npm start" to start the updated application`)); } catch (error) { console.error(chalk_1.default.red(`❌ Failed to update admin project: ${error.message}`)); process.exit(1); } }); admin .command('versions') .description('List available admin template versions') .option('-a, --all', 'Show all versions (default: show last 10)') .action(async (options) => { try { console.log(chalk_1.default.blue(`📦 Fetching available @diagramers/admin versions...`)); const { execSync } = require('child_process'); const versions = execSync('npm view @diagramers/admin versions --json', { encoding: 'utf8' }); const versionList = JSON.parse(versions); if (options.all) { console.log(chalk_1.default.green(`📋 All available versions:`)); versionList.forEach((version) => { console.log(chalk_1.default.cyan(` • ${version}`)); }); } else { console.log(chalk_1.default.green(`📋 Last 10 versions:`)); versionList.slice(-10).forEach((version) => { console.log(chalk_1.default.cyan(` • ${version}`)); }); } console.log(chalk_1.default.blue(`💡 Use "diagramers admin update --version <version>" to update to a specific version`)); } catch (error) { console.error(chalk_1.default.red(`❌ Failed to fetch versions: ${error.message}`)); process.exit(1); } }); return admin; } //# sourceMappingURL=admin.js.map