Skip to content

Commit

Permalink
refactor(createProject): add types and remove useless projectForm arg…
Browse files Browse the repository at this point in the history
…s iteration
  • Loading branch information
joaoneto committed Oct 9, 2023
1 parent 51dd9a4 commit 0a8d7eb
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,22 @@ const enum PackageManager {
bun = "bun",
}

const projectForm = async (projectName: string, args: any[]): Promise<void> => {
let answer: any;
type TemplateKeys = keyof typeof Template;

type ProjectFormArgs = [
PackageManager,
TemplateKeys,
string,
];

const projectForm = async (projectName: string, args: ProjectFormArgs): Promise<void> => {
let answer: {
name: string;
packageManager: string;
template: Template;
confirm: boolean;
};
const projName: string = projectName;
let packageManager: PackageManager | undefined;
let template: keyof typeof Template | undefined;
let directory: string | undefined;

// Resolving the argument order problem
for (const arg of args) {
if (args.length >= 3) {
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;
} else {
directory = arg;
}
}
}

if (packageManager && template) {
answer = {
Expand Down

0 comments on commit 0a8d7eb

Please sign in to comment.