From 0a8d7eb5ac211e18a08f3442fee8a7b8551e3584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neto?= Date: Mon, 21 Aug 2023 03:52:26 -0300 Subject: [PATCH 1/3] refactor(createProject): add types and remove useless projectForm args iteration --- src/new/form.ts | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/new/form.ts b/src/new/form.ts index 430766b..5dc3567 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -91,30 +91,22 @@ const enum PackageManager { bun = "bun", } -const projectForm = async (projectName: string, args: any[]): Promise => { - let answer: any; +type TemplateKeys = keyof typeof Template; + +type ProjectFormArgs = [ + PackageManager, + TemplateKeys, + string, +]; + +const projectForm = async (projectName: string, args: ProjectFormArgs): Promise => { + 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 = { From 37d04eb826c0e26570a27257c24f30d41da7b922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neto?= Date: Thu, 24 Aug 2023 16:45:57 -0300 Subject: [PATCH 2/3] remove unused const --- src/new/form.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/new/form.ts b/src/new/form.ts index 5dc3567..8ba925a 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -106,7 +106,7 @@ const projectForm = async (projectName: string, args: ProjectFormArgs): Promise< template: Template; confirm: boolean; }; - const projName: string = projectName; + const [packageManager, template, directory] = args; if (packageManager && template) { answer = { @@ -222,7 +222,7 @@ const projectForm = async (projectName: string, args: ProjectFormArgs): Promise< changePackageName({ directory: answer.name, - name: projName, + name: projectName, }); progressBar.update(100); From 6d1da808a5a1e98266ee83f05c1b08b3c9404952 Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Wed, 31 Jul 2024 13:48:33 -0700 Subject: [PATCH 3/3] refactor: update 'new' cmd removing unnecessary options --- src/new/form.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/new/form.ts b/src/new/form.ts index ee829c7..51ddd62 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -125,13 +125,12 @@ const enum PackageManager { type TemplateKeys = keyof typeof Template; -type ProjectFormArgs = [ - PackageManager, - TemplateKeys, - string, -]; +type ProjectFormArgs = [PackageManager, TemplateKeys, string]; -const projectForm = async (projectName: string, args: ProjectFormArgs): Promise => { +const projectForm = async ( + projectName: string, + args: ProjectFormArgs, +): Promise => { let answer: { name: string; packageManager: string;