Skip to content

Commit 342f18d

Browse files
committed
cli: add pm choice
1 parent 3eddfc9 commit 342f18d

File tree

2 files changed

+84
-62
lines changed

2 files changed

+84
-62
lines changed

packages/cli/src/AlephaCli.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}

packages/cli/src/index.ts

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,7 @@
11
#!/usr/bin/env node
2-
import { $command, CliProvider } from "@alepha/command";
3-
import { $inject, run, t } from "@alepha/core";
4-
import { $logger } from "@alepha/logger";
2+
import { run } from "@alepha/core";
53
import pkg from "../package.json" with { type: "json" };
6-
7-
class AlephaCli {
8-
log = $logger();
9-
10-
cli = $inject(CliProvider);
11-
12-
root = $command({
13-
name: "",
14-
handler: async () => {
15-
this.cli.printHelp();
16-
},
17-
});
18-
19-
create = $command({
20-
name: "create",
21-
description: "Create a new Alepha project",
22-
args: t.string({ title: "name" }),
23-
summary: false,
24-
handler: async ({ run, args }) => {
25-
const name = args;
26-
27-
await run(`git clone https://github.com/feunard/alepha-starter ${name}`, {
28-
alias: "📥 Cloning repository",
29-
});
30-
31-
// Remove .git directory to start fresh
32-
await run(`rm -rf ${name}/.git`, {
33-
alias: "🔧 Setting up project",
34-
});
35-
36-
await run(`cd ${name} && npm install`, {
37-
alias: "📦 Installing dependencies",
38-
});
39-
40-
await run(`cd ${name} && npm run lint`, {
41-
alias: "🔍 Linting code",
42-
});
43-
44-
await run(`cd ${name} && npm run check`, {
45-
alias: "✅ Type checking",
46-
});
47-
48-
await run(`cd ${name} && npm run test`, {
49-
alias: "🧪 Running tests",
50-
});
51-
52-
await run(`cd ${name} && npm run build`, {
53-
alias: "🏗️ Building project",
54-
});
55-
56-
this.log.info(
57-
`\n🎉 Project is ready!
58-
59-
$ cd ${name} && npm run dev
60-
`,
61-
);
62-
},
63-
});
64-
}
4+
import { AlephaCli } from "./AlephaCli.ts";
655

666
run(AlephaCli, {
677
env: {

0 commit comments

Comments
 (0)