Skip to content

Commit

Permalink
code refactor (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonyarianto committed Apr 8, 2023
1 parent 32b7428 commit 31ff912
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 117 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"keywords": [
"project",
"generator",
"framework"
"framework",
"tooling",
"cli"
],
"author": "Sony Arianto Kurniawan <[email protected]>",
"license": "MIT",
Expand Down
117 changes: 3 additions & 114 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,117 +17,6 @@ type Project = {
name: ProjectName;
};

const projectTypeOptions = [
{
value: "angular",
label: "Angular",
hint: "Deliver web apps with confidence",
cli: "npm init @angular",
},
{
value: "nextjs",
label: "Next.js",
hint: "The React framework for the web",
cli: "npx create-next-app@latest",
},
{
value: "nuxt",
label: "Nuxt.js",
hint: "The intuitive Vue framework",
cli: "npx create-nuxt-app",
},
{
value: "remix",
label: "Remix",
hint: "Build better websites. Create modern, resilient user experiences with web fundamentals",
cli: "npx create-remix@latest",
},
{
value: "svelte",
label: "SvelteKit",
hint: "Rapidly developing robust, performant web applications using Svelte",
cli: "npm create svelte@latest",
},
{
value: "vuejs",
label: "Vue.js",
hint: "The progressive JavaScript framework",
cli: "npm init vue@latest",
},
{
value: "astro",
label: "Astro",
hint: "Build the web you want",
cli: "npm create astro@latest",
},
{
value: "nestjs",
label: "NestJS",
hint: "A progressive Node.js framework",
cli: "npx nest new",
},
{
value: "emberjs",
label: "Ember.js",
hint: "A framework for ambitious web developers",
cli: "npx ember new",
},
{
value: "gatsby",
label: "Gatsby",
hint: "The fastest frontend for the headless web",
cli: "npx gatsby new",
},
{
value: "qwik",
label: "Qwik",
hint: "Framework reimagined for the edge!",
cli: "npm create qwik@latest",
},
{
value: "sails",
label: "Sails",
hint: "Realtime MVC framework for Node.js",
cli: "npx sails new",
},
{
value: "vite",
label: "Vite",
hint: "Next Generation Frontend Tooling",
cli: "npm create vite@latest",
},
{
value: "aurelia",
label: "Aurelia",
hint: "Simple. Powerful. Unobtrusive.",
cli: "npx aurelia-cli new",
},
{
value: "solidstart",
label: "SolidStart",
hint: "The Solid app framework",
cli: "npm init solid@latest",
},
{
value: "preact",
label: "Preact",
hint: "A different kind of library",
cli: "npx preact-cli create default",
},
{
value: "createreactapp",
label: "React (create-react-app)",
hint: "Set up a modern web app by running one command",
cli: "npx create-react-app",
},
{
value: "adonisjs",
label: "AdonisJS",
hint: "A fully featured web framework for Node.js",
cli: "npm init adonis-ts-app@latest",
},
];

function mainMenuOptions(projectTypeOptions: ProjectType[]): ProjectType[] {
// sort options by label

Expand All @@ -153,12 +42,12 @@ function mainMenuOptions(projectTypeOptions: ProjectType[]): ProjectType[] {
return projectTypeOptions;
}

export async function mainMenu(): Promise<void> {
export async function mainMenu(options: ProjectType[]): Promise<void> {
// construct menu options and show menu

const selectedMenuValue = await select({
message: "Which framework do you want to use?",
options: mainMenuOptions(projectTypeOptions),
options: mainMenuOptions(options),
});

if (isCancel(selectedMenuValue)) {
Expand All @@ -171,7 +60,7 @@ export async function mainMenu(): Promise<void> {

let selectedProjectType: ProjectType | null | undefined = null;

selectedProjectType = projectTypeOptions.find(
selectedProjectType = options.find(
(option: ProjectType) => option.value === selectedMenuValue
);

Expand Down
111 changes: 111 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,114 @@ import { name, version } from "../package.json";

export const appName = name;
export const appVersion = version;

export const projectTypeOptions = [
{
value: "angular",
label: "Angular",
hint: "Deliver web apps with confidence",
cli: "npm init @angular",
},
{
value: "nextjs",
label: "Next.js",
hint: "The React framework for the web",
cli: "npx create-next-app@latest",
},
{
value: "nuxt",
label: "Nuxt.js",
hint: "The intuitive Vue framework",
cli: "npx create-nuxt-app",
},
{
value: "remix",
label: "Remix",
hint: "Build better websites. Create modern, resilient user experiences with web fundamentals",
cli: "npx create-remix@latest",
},
{
value: "svelte",
label: "SvelteKit",
hint: "Rapidly developing robust, performant web applications using Svelte",
cli: "npm create svelte@latest",
},
{
value: "vuejs",
label: "Vue.js",
hint: "The progressive JavaScript framework",
cli: "npm init vue@latest",
},
{
value: "astro",
label: "Astro",
hint: "Build the web you want",
cli: "npm create astro@latest",
},
{
value: "nestjs",
label: "NestJS",
hint: "A progressive Node.js framework",
cli: "npx nest new",
},
{
value: "emberjs",
label: "Ember.js",
hint: "A framework for ambitious web developers",
cli: "npx ember new",
},
{
value: "gatsby",
label: "Gatsby",
hint: "The fastest frontend for the headless web",
cli: "npx gatsby new",
},
{
value: "qwik",
label: "Qwik",
hint: "Framework reimagined for the edge!",
cli: "npm create qwik@latest",
},
{
value: "sails",
label: "Sails",
hint: "Realtime MVC framework for Node.js",
cli: "npx sails new",
},
{
value: "vite",
label: "Vite",
hint: "Next Generation Frontend Tooling",
cli: "npm create vite@latest",
},
{
value: "aurelia",
label: "Aurelia",
hint: "Simple. Powerful. Unobtrusive.",
cli: "npx aurelia-cli new",
},
{
value: "solidstart",
label: "SolidStart",
hint: "The Solid app framework",
cli: "npm init solid@latest",
},
{
value: "preact",
label: "Preact",
hint: "A different kind of library",
cli: "npx preact-cli create default",
},
{
value: "createreactapp",
label: "React (create-react-app)",
hint: "Set up a modern web app by running one command",
cli: "npx create-react-app",
},
{
value: "adonisjs",
label: "AdonisJS",
hint: "A fully featured web framework for Node.js",
cli: "npm init adonis-ts-app@latest",
},
];
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { intro } from "@clack/prompts";
import color from "picocolors";
import { appName, appVersion } from "./config";
import { appName, appVersion, projectTypeOptions } from "./config";
import { mainMenu } from "./app";
import { cli } from "cleye";

Expand All @@ -14,7 +14,7 @@ async function main() {

intro(`${color.bgCyan(color.black(` ${appName} `))}`);

mainMenu();
mainMenu(projectTypeOptions);
}

main();

0 comments on commit 31ff912

Please sign in to comment.