Skip to content

Commit

Permalink
Merge pull request #17 from joaoneto/refact/create-project-args
Browse files Browse the repository at this point in the history
refactor(createProject): add types and remove useless projectForm arg…
  • Loading branch information
rsaz authored Jul 31, 2024
2 parents 79a40ed + 6d1da80 commit 5b83b02
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,21 @@ const enum PackageManager {
bun = "bun",
}

const projectForm = async (projectName: string, args: any[]): Promise<void> => {
let answer: any;
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;
}
}
}
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 [packageManager, template, directory] = args;

if (packageManager && template) {
answer = {
Expand Down Expand Up @@ -265,7 +256,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {

changePackageName({
directory: answer.name,
name: projName,
name: projectName,
});

renameEnvFile(answer.name);
Expand Down

0 comments on commit 5b83b02

Please sign in to comment.