Skip to content

Commit

Permalink
Merge pull request #23 from expressots/feature/22-add-bun-support-in-…
Browse files Browse the repository at this point in the history
…the-cli

Add bun as package manager
  • Loading branch information
rsaz committed Sep 27, 2023
2 parents c87e7ac + 2e665e3 commit b1396db
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"@expressots/boost-ts": "^1.1.1",
"chalk-animation": "^1",
"cli-progress": "^3.11.2",
"degit": "^2.8.4",
"glob": "^10.2.6",
"inquirer": "^8.0.0",
"mustache": "^4.2.0",
"ts-node": "^10.9.1",
"yargs": "^17.6.2"
"@expressots/boost-ts": "1.1.1",
"chalk-animation": "2.0.3",
"cli-progress": "3.11.2",
"degit": "2.8.4",
"glob": "10.2.6",
"inquirer": "8.0.0",
"mustache": "4.2.0",
"ts-node": "10.9.1",
"yargs": "17.6.2"
},
"devDependencies": {
"@commitlint/cli": "^17.7.1",
Expand Down
8 changes: 7 additions & 1 deletion src/new/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { projectForm } from "./form";
type CommandModuleArgs = {};

const createProject = (): CommandModule<CommandModuleArgs, any> => {
const packageManagers: Array<string> = ["npm", "yarn", "pnpm"];

if (process.platform !== "win32") {
packageManagers.push("bun");
}

return {
command: "new <project-name> [package-manager] [template] [directory]",
describe: "Create a new project",
Expand All @@ -23,7 +29,7 @@ const createProject = (): CommandModule<CommandModuleArgs, any> => {
.option("package-manager", {
describe: "The package manager to use",
type: "string",
choices: ["npm", "yarn", "pnpm"],
choices: packageManagers,
alias: "p",
})
.option("directory", {
Expand Down
22 changes: 20 additions & 2 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const enum PackageManager {
npm = "npm",
yarn = "yarn",
pnpm = "pnpm",
bun = "bun",
}

const projectForm = async (projectName: string, args: any[]): Promise<void> => {
Expand All @@ -100,7 +101,12 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
// Resolving the argument order problem
for (const arg of args) {
if (args.length >= 3) {
if (arg === "npm" || arg === "yarn" || arg === "pnpm") {
if (
arg === "npm" ||
arg === "yarn" ||
arg === "pnpm" ||
arg === "bun"
) {
packageManager = arg as PackageManager;
} else if (arg === "non-opinionated" || arg === "opinionated") {
template = arg as keyof typeof Template;
Expand Down Expand Up @@ -132,7 +138,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
type: "list",
name: "packageManager",
message: "Package manager",
choices: ["npm", "yarn", "pnpm"],
choices: ["npm", "yarn", "pnpm", "bun"],
},
{
type: "list",
Expand Down Expand Up @@ -168,6 +174,15 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
};

if (answer.confirm) {
// Check if package manager is bun and OS is Windows
if (answer.packageManager === "bun" && process.platform === "win32") {
printError(
"bun is not supported on Windows. Please use",
"npm, yarn or pnpm",
);
process.exit(1);
}

await checkIfPackageManagerExists(answer.packageManager);
console.log("\n");
const progressBar = new SingleBar(
Expand Down Expand Up @@ -241,6 +256,9 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
case "pnpm":
console.log(chalk.bold.gray("$ pnpm run dev"));
break;
case "bun":
console.log(chalk.bold.gray("$ bun dev"));
break;
}

console.log("\n");
Expand Down

0 comments on commit b1396db

Please sign in to comment.