Skip to content

Commit

Permalink
feat: add vite (#342)
Browse files Browse the repository at this point in the history
* feat: add vite to prompt humanizer

* feat: add sort project types

* feat: update refine vite description
  • Loading branch information
alicanerdurmaz authored May 4, 2023
1 parent 9f68b4d commit 763e1b9
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Helper/humanize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const HumanizeChoices = {
description: "Creates a Next.js project",
value: choice,
};
case "refine-react":
case "refine-vite":
return {
title: "refine(CRA)",
title: "refine(Vite)",
description:
"Creates a basic refine project (Recommended for CRUD applications)",
"Creates a refine React Vite project (Recommended for CRUD applications).",
value: choice,
};
case "refine-nextjs":
Expand All @@ -36,6 +36,14 @@ export const HumanizeChoices = {
"Creates a refine Remix project with SSR support (Recommended for CRUD applications)",
value: choice,
};
case "refine-react":
return {
title: "refine(CRA) [Legacy]",
description:
"Creates a basic refine project (Recommended for CRUD applications)",
value: choice,
};

default:
return {
title: choice,
Expand Down
67 changes: 66 additions & 1 deletion src/Helper/source/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { promisify } from "util";
import { get_source } from "./";
import { get_source, sort_project_types } from "./";

jest.mock("util", () => ({
promisify: jest.fn(),
inherits: () => ({
custom: {},
}),
inspect: () => ({}),
}));

describe("Source Helper", () => {
it("incorrect source url/path", async () => {
const source = await get_source("alibaba");
Expand All @@ -24,4 +26,67 @@ describe("Source Helper", () => {
const source = await get_source("superplate-core-plugins");
expect(source.error).toBe(undefined);
});

it("Sort project types", async () => {
const cases = [
{
input: [
{ title: "Refine React", value: "refine-react" },
{ title: "Next.js", value: "nextjs" },
{ title: "React", value: "react" },
{ title: "Refine Vite", value: "refine-vite" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
],
expectedOutput: [
{ title: "React", value: "react" },
{ title: "Next.js", value: "nextjs" },
{ title: "Refine Vite", value: "refine-vite" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
{ title: "Refine React", value: "refine-react" },
],
},
{
input: [
{ title: "Next.js", value: "nextjs" },
{ title: "Refine React", value: "refine-react" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
{ title: "React", value: "react" },
{ title: "Refine Vite", value: "refine-vite" },
],
expectedOutput: [
{ title: "React", value: "react" },
{ title: "Next.js", value: "nextjs" },
{ title: "Refine Vite", value: "refine-vite" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
{ title: "Refine React", value: "refine-react" },
],
},
{
input: [
{ title: "Refine React", value: "refine-react" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
{ title: "Refine Vite", value: "refine-vite" },
],
expectedOutput: [
{ title: "Refine Vite", value: "refine-vite" },
{ title: "Refine Next.js", value: "refine-nextjs" },
{ title: "Refine Remix", value: "refine-remix" },
{ title: "Refine React", value: "refine-react" },
],
},
{
input: [],
expectedOutput: [],
},
];

cases.forEach((c) => {
expect(sort_project_types(c.input)).toEqual(c.expectedOutput);
});
});
});
26 changes: 25 additions & 1 deletion src/Helper/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ export const is_multi_type = async (
return false;
};

export const sort_project_types = (
projectTypes: { title: string; value: string }[],
): { title: string; value: string }[] => {
const order: Record<string, number> = {
react: 1,
nextjs: 2,
"refine-vite": 3,
"refine-nextjs": 4,
"refine-remix": 5,
"refine-react": 6,
};

const newProjectTypes = [...projectTypes];

newProjectTypes.sort((a, b) => {
const firstValue = order[a?.value] ?? 1;
const secondValue = order[b?.value] ?? 1;

return firstValue - secondValue;
});

return newProjectTypes;
};

export const get_project_types = async (source: string): Promise<any[]> => {
const projectTypes: any[] = [];

Expand All @@ -123,7 +147,7 @@ export const get_project_types = async (source: string): Promise<any[]> => {
}
}

return projectTypes;
return sort_project_types(projectTypes);
};

export const prompt_project_types = async (
Expand Down

0 comments on commit 763e1b9

Please sign in to comment.