|
| 1 | +import { $command, CliProvider } from "@alepha/command"; |
| 2 | +import { $inject, t } from "@alepha/core"; |
| 3 | +import { $logger } from "@alepha/logger"; |
| 4 | + |
| 5 | +export class AlephaCli { |
| 6 | + log = $logger(); |
| 7 | + |
| 8 | + cli = $inject(CliProvider); |
| 9 | + |
| 10 | + root = $command({ |
| 11 | + name: "", |
| 12 | + handler: async () => { |
| 13 | + this.cli.printHelp(); |
| 14 | + }, |
| 15 | + }); |
| 16 | + |
| 17 | + create = $command({ |
| 18 | + name: "create", |
| 19 | + description: "Create a new Alepha project", |
| 20 | + args: t.string({ title: "name" }), |
| 21 | + flags: t.object({ |
| 22 | + yarn: t.boolean({ description: "Use Yarn package manager" }), |
| 23 | + pnpm: t.boolean({ description: "Use pnpm package manager" }), |
| 24 | + bun: t.boolean({ description: "Use Bun package manager" }), |
| 25 | + }), |
| 26 | + summary: false, |
| 27 | + handler: async ({ run, args, flags }) => { |
| 28 | + const name = args; |
| 29 | + |
| 30 | + // Determine package manager |
| 31 | + let installCmd = "npm install"; |
| 32 | + let runCmd = "npm run"; |
| 33 | + |
| 34 | + if (flags.yarn) { |
| 35 | + installCmd = "yarn"; |
| 36 | + runCmd = "yarn"; |
| 37 | + } else if (flags.pnpm) { |
| 38 | + installCmd = "pnpm install"; |
| 39 | + runCmd = "pnpm"; |
| 40 | + } else if (flags.bun) { |
| 41 | + installCmd = "bun install"; |
| 42 | + runCmd = "bun run"; |
| 43 | + } |
| 44 | + |
| 45 | + await run(`git clone https://github.com/feunard/alepha-starter ${name}`, { |
| 46 | + alias: "📥 Cloning repository", |
| 47 | + }); |
| 48 | + |
| 49 | + // Remove .git directory to start fresh |
| 50 | + await run(`rm -rf ${name}/.git`, { |
| 51 | + alias: "🔧 Setting up project", |
| 52 | + }); |
| 53 | + |
| 54 | + await run(`cd ${name} && ${installCmd}`, { |
| 55 | + alias: "📦 Installing dependencies", |
| 56 | + }); |
| 57 | + |
| 58 | + await run(`cd ${name} && ${runCmd} lint`, { |
| 59 | + alias: "🔍 Linting code", |
| 60 | + }); |
| 61 | + |
| 62 | + await run(`cd ${name} && ${runCmd} check`, { |
| 63 | + alias: "✅ Type checking", |
| 64 | + }); |
| 65 | + |
| 66 | + await run(`cd ${name} && ${runCmd} test`, { |
| 67 | + alias: "🧪 Running tests", |
| 68 | + }); |
| 69 | + |
| 70 | + await run(`cd ${name} && ${runCmd} build`, { |
| 71 | + alias: "🏗️ Building project", |
| 72 | + }); |
| 73 | + |
| 74 | + this.log.info( |
| 75 | + `\n🎉 Project is ready! |
| 76 | +
|
| 77 | +$ cd ${name} && ${runCmd} dev |
| 78 | + `, |
| 79 | + ); |
| 80 | + }, |
| 81 | + }); |
| 82 | +} |
0 commit comments