vibe-seo
Version:
AI-friendly SEO generator for modern web frameworks
86 lines (68 loc) • 3.31 kB
JavaScript
const { Command } = require('commander');
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const ora = require('ora');
const { detectFramework, createConfig, copyTemplates } = require('../lib');
const program = new Command();
program
.name('vibe-seo-init')
.description('Initialize vibe-seo in your project')
.version('1.0.0')
.option('-f, --framework <type>', 'specify framework (nextjs, react, vue, angular, static)')
.option('-d, --dir <directory>', 'output directory', './seo')
.option('--force', 'overwrite existing configuration')
.action(async (options) => {
const spinner = ora('Initializing vibe-seo...').start();
try {
// Detect framework if not specified
let framework = options.framework;
if (!framework) {
spinner.text = 'Detecting framework...';
framework = await detectFramework(process.cwd());
spinner.stop();
console.log(chalk.cyan('Framework detected:'), framework);
console.log(chalk.cyan('Project directory:'), process.cwd());
// Show directory existence check
const projectDir = process.cwd();
const fs = require('fs-extra');
const appDirExists = await fs.pathExists(path.join(projectDir, 'app'));
const srcAppDirExists = await fs.pathExists(path.join(projectDir, 'src', 'app'));
const pagesDirExists = await fs.pathExists(path.join(projectDir, 'pages'));
const srcPagesDirExists = await fs.pathExists(path.join(projectDir, 'src', 'pages'));
console.log(chalk.cyan('Directory check:'));
console.log(` ./app: ${appDirExists ? '✓' : '✗'}`);
console.log(` ./src/app: ${srcAppDirExists ? '✓' : '✗'}`);
console.log(` ./pages: ${pagesDirExists ? '✓' : '✗'}`);
console.log(` ./src/pages: ${srcPagesDirExists ? '✓' : '✗'}`);
spinner.start();
}
spinner.text = `Setting up for ${framework}...`;
// Create output directory
const outputDir = path.resolve(options.dir);
await fs.ensureDir(outputDir);
// Check if config exists
const configPath = path.join(outputDir, 'config', 'seo.config.yaml');
if (await fs.pathExists(configPath) && !options.force) {
spinner.fail('Configuration already exists. Use --force to overwrite.');
process.exit(1);
}
// Create configuration
spinner.text = 'Creating configuration...';
await createConfig(framework, outputDir);
// Copy templates
spinner.text = 'Setting up templates...';
await copyTemplates(outputDir);
spinner.succeed(chalk.green('vibe-seo initialized successfully!'));
console.log('\nNext steps:');
console.log(chalk.cyan('1. Edit your configuration:'), `${options.dir}/config/seo.config.yaml`);
console.log(chalk.cyan('2. Generate SEO files:'), 'npx vibe-seo-gen');
console.log(chalk.cyan('3. Check the documentation:'), 'https://www.juancolmenares.com/vibe-seo/docs');
} catch (error) {
spinner.fail(chalk.red('Failed to initialize vibe-seo'));
console.error(error.message);
process.exit(1);
}
});
program.parse();