setup-next-project
Version:
CLI to quickly create a pre-configured Next.js project with modular components and features
99 lines • 3.52 kB
JavaScript
import fs from "fs-extra";
import * as path from "path";
import { dirname } from "path";
import { fileURLToPath } from "url";
export const AVAILABLE_COMPONENTS = [
{
id: 'button',
name: 'Button',
description: 'Versatile button component with multiple variants and sizes',
dependencies: ['@radix-ui/react-slot', 'class-variance-authority'],
targetPath: 'src/components/ui/button.tsx'
},
{
id: 'input',
name: 'Input',
description: 'Styled input component for forms',
targetPath: 'src/components/ui/input.tsx'
},
{
id: 'card',
name: 'Card',
description: 'Card component with header, content, and footer sections',
targetPath: 'src/components/ui/card.tsx'
},
{
id: 'badge',
name: 'Badge',
description: 'Small status indicators and labels',
dependencies: ['class-variance-authority'],
targetPath: 'src/components/ui/badge.tsx'
},
{
id: 'alert',
name: 'Alert',
description: 'Alert component for important messages and notifications',
dependencies: ['class-variance-authority'],
targetPath: 'src/components/ui/alert.tsx'
},
{
id: 'textarea',
name: 'Textarea',
description: 'Multi-line text input component',
targetPath: 'src/components/ui/textarea.tsx'
},
{
id: 'dropdown-menu',
name: 'Dropdown Menu',
description: 'Dropdown menu with items, separators, and sub-menus',
dependencies: ['@radix-ui/react-dropdown-menu', 'lucide-react'],
targetPath: 'src/components/ui/dropdown-menu.tsx'
}
];
function getComponentsPath() {
let templatesDir;
// First, try to find the templates directory relative to the script location
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
templatesDir = path.join(__dirname, "../../templates");
// If templates doesn't exist relative to script, try current working directory method
if (!fs.existsSync(templatesDir)) {
if (process.cwd().includes("setup-next-project")) {
templatesDir = path.join(process.cwd(), "templates");
}
else {
// Look for setup-next-project in parent directories
let currentDir = process.cwd();
while (currentDir !== path.dirname(currentDir)) {
const possibleTemplatesDir = path.join(currentDir, "templates");
if (fs.existsSync(possibleTemplatesDir)) {
templatesDir = possibleTemplatesDir;
break;
}
currentDir = path.dirname(currentDir);
}
}
}
return path.join(templatesDir, "components");
}
export async function getComponentContent(componentId) {
const componentsPath = getComponentsPath();
const componentFile = path.join(componentsPath, `${componentId}.tsx`);
try {
if (await fs.pathExists(componentFile)) {
return await fs.readFile(componentFile, 'utf8');
}
return null;
}
catch (error) {
console.error(`Error reading component ${componentId}:`, error);
return null;
}
}
export function getComponent(componentId) {
return AVAILABLE_COMPONENTS.find(component => component.id === componentId);
}
export function getAvailableComponents() {
return AVAILABLE_COMPONENTS;
}
//# sourceMappingURL=components.js.map