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 Aug 21, 2023
1 parent e92790e commit 4f40ce0
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,23 @@ const enum PackageManager {
pnpm = "pnpm"
}

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") {
packageManager = arg as PackageManager;
} else if (arg === "non-opinionated" || arg === "opinionated") {
template = arg as keyof typeof Template;
} else {
directory = arg;
}
}
}
const [packageManager, template, directory] = args;

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

0 comments on commit 4f40ce0

Please sign in to comment.