Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(createProject): add types and remove useless projectForm arg… #17

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 17 additions & 25 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;
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 @@ -230,7 +222,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {

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

progressBar.update(100);
Expand Down