feat: Added style templates
7a5474f2
1 file(s) · +43 −11
| 9 | 9 | import ora from 'ora'; |
|
| 10 | 10 | import { execa } from 'execa'; |
|
| 11 | 11 | import degit from 'degit'; |
|
| 12 | - | import figlet from 'figlet'; // Add this import |
|
| 12 | + | import figlet from 'figlet'; |
|
| 13 | 13 | ||
| 14 | 14 | const __filename = fileURLToPath(import.meta.url); |
|
| 15 | 15 | const __dirname = path.dirname(__filename); |
|
| 16 | 16 | ||
| 17 | 17 | // GitHub repository for the template |
|
| 18 | - | const DEFAULT_REPO = 'stevedylandev/bhvr'; // Replace with your actual repo |
|
| 18 | + | const DEFAULT_REPO = 'stevedylandev/bhvr'; |
|
| 19 | + | ||
| 20 | + | // Available templates |
|
| 21 | + | const TEMPLATES = { |
|
| 22 | + | default: { branch: 'main', description: 'Basic setup with Bun, Hono, Vite and React' }, |
|
| 23 | + | tailwind: { branch: 'tailwindcss', description: 'Basic setup + TailwindCSS' }, |
|
| 24 | + | shadcn: { branch: 'shadcn-ui', description: 'Basic setup + TailwindCSS + shadcn/ui' } |
|
| 25 | + | }; |
|
| 19 | 26 | ||
| 20 | 27 | // Function to display a fun banner |
|
| 21 | 28 | function displayBanner() { |
|
| 41 | 48 | .option('-y, --yes', 'skip confirmation prompts') |
|
| 42 | 49 | .option('--ts, --typescript', 'use TypeScript (default)') |
|
| 43 | 50 | .option('--repo <repo>', 'specify a custom GitHub repository as source', DEFAULT_REPO) |
|
| 44 | - | .option('--branch <branch>', 'specify a branch to use from the repository', 'main') |
|
| 51 | + | .option('--template <template>', 'specify a template (default, tailwind, shadcn)', 'default') |
|
| 52 | + | .option('--branch <branch>', 'specify a branch to use from the repository') |
|
| 45 | 53 | .action(async (projectDirectory, options) => { |
|
| 46 | 54 | try { |
|
| 47 | 55 | displayBanner(); |
|
| 48 | 56 | const result = await createProject(projectDirectory, options); |
|
| 49 | 57 | if (result) { |
|
| 50 | - | ||
| 51 | 58 | console.log(chalk.green.bold('🎉 Project created successfully!')); |
|
| 52 | 59 | console.log('\nNext steps:'); |
|
| 53 | 60 | ||
| 70 | 77 | }); |
|
| 71 | 78 | ||
| 72 | 79 | program.parse(); |
|
| 80 | + | ||
| 73 | 81 | async function createProject(projectDirectory, options) { |
|
| 74 | 82 | // If project directory not provided, prompt for it |
|
| 75 | 83 | let projectName = projectDirectory; |
|
| 92 | 100 | projectName = 'my-bhvr-app'; |
|
| 93 | 101 | } |
|
| 94 | 102 | ||
| 103 | + | // Template selection |
|
| 104 | + | let templateChoice = options.template; |
|
| 105 | + | ||
| 106 | + | if (!options.yes && !options.branch) { |
|
| 107 | + | const templateChoices = Object.keys(TEMPLATES).map(key => ({ |
|
| 108 | + | title: `${key} (${TEMPLATES[key].description})`, |
|
| 109 | + | value: key |
|
| 110 | + | })); |
|
| 111 | + | ||
| 112 | + | const templateResponse = await prompts({ |
|
| 113 | + | type: 'select', |
|
| 114 | + | name: 'template', |
|
| 115 | + | message: 'Select a template:', |
|
| 116 | + | choices: templateChoices, |
|
| 117 | + | initial: 0 |
|
| 118 | + | }); |
|
| 119 | + | ||
| 120 | + | if (templateResponse.template === undefined) { |
|
| 121 | + | console.log(chalk.yellow('Project creation cancelled.')); |
|
| 122 | + | return null; |
|
| 123 | + | } |
|
| 124 | + | ||
| 125 | + | templateChoice = templateResponse.template; |
|
| 126 | + | } |
|
| 127 | + | ||
| 95 | 128 | // Create the project directory |
|
| 96 | 129 | const projectPath = path.resolve(process.cwd(), projectName); |
|
| 97 | 130 | ||
| 122 | 155 | ||
| 123 | 156 | // Clone template from GitHub |
|
| 124 | 157 | const repoPath = options.repo || DEFAULT_REPO; |
|
| 125 | - | const branchSpecifier = options.branch ? `#${options.branch}` : ''; |
|
| 126 | - | const repoUrl = `${repoPath}${branchSpecifier}`; |
|
| 127 | - | ||
| 128 | - | //console.log(chalk.blue(`\nCreating a new bhvr project in ${chalk.bold(projectPath)}`)); |
|
| 129 | - | //console.log(chalk.blue(`Downloading template from ${chalk.bold(repoUrl)}...`)); |
|
| 158 | + | // Use provided branch, template branch, or default |
|
| 159 | + | const branch = options.branch || (TEMPLATES[templateChoice] ? TEMPLATES[templateChoice].branch : 'main'); |
|
| 160 | + | const repoUrl = `${repoPath}#${branch}`; |
|
| 130 | 161 | ||
| 131 | 162 | const spinner = ora('Downloading template...').start(); |
|
| 132 | 163 | ||
| 138 | 169 | }); |
|
| 139 | 170 | ||
| 140 | 171 | await emitter.clone(projectPath); |
|
| 141 | - | spinner.succeed('Template downloaded successfully'); |
|
| 172 | + | spinner.succeed(`Template downloaded successfully (${templateChoice} template)`); |
|
| 142 | 173 | ||
| 143 | 174 | // Update package.json with project name |
|
| 144 | 175 | const pkgJsonPath = path.join(projectPath, 'package.json'); |
|
| 246 | 277 | return { |
|
| 247 | 278 | projectName, |
|
| 248 | 279 | gitInitialized, |
|
| 249 | - | dependenciesInstalled |
|
| 280 | + | dependenciesInstalled, |
|
| 281 | + | template: templateChoice, |
|
| 250 | 282 | }; |
|
| 251 | 283 | } catch (err) { |
|
| 252 | 284 | spinner.fail('Failed to download template'); |
|