diff --git a/fresh.gen.ts b/fresh.gen.ts index fbb4408..62756f9 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -5,7 +5,6 @@ import * as $_apps_layout from "./routes/(apps)/_layout.tsx"; import * as $_apps_mobility_index from "./routes/(apps)/mobility/index.tsx"; import * as $_apps_mobility_partials_index from "./routes/(apps)/mobility/partials/index.tsx"; -import * as $_apps_notes_api_example from "./routes/(apps)/notes/api/example.ts"; import * as $_apps_notes_index from "./routes/(apps)/notes/index.tsx"; import * as $_apps_notes_partials_admin_courses from "./routes/(apps)/notes/partials/(admin)/courses.tsx"; import * as $_apps_notes_partials_admin_students from "./routes/(apps)/notes/partials/(admin)/students.tsx"; @@ -29,7 +28,6 @@ const manifest = { "./routes/(apps)/mobility/index.tsx": $_apps_mobility_index, "./routes/(apps)/mobility/partials/index.tsx": $_apps_mobility_partials_index, - "./routes/(apps)/notes/api/example.ts": $_apps_notes_api_example, "./routes/(apps)/notes/index.tsx": $_apps_notes_index, "./routes/(apps)/notes/partials/(admin)/courses.tsx": $_apps_notes_partials_admin_courses, diff --git a/routes/(apps)/notes/api/example.ts b/routes/(apps)/notes/api/example.ts deleted file mode 100644 index 68399cd..0000000 --- a/routes/(apps)/notes/api/example.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Handlers } from "$fresh/server.ts"; - -export const handler: Handlers = { - async GET(request, context) { - return new Response({ - test: await request.json(), - context, - }); - }, -}; diff --git a/toolbox/module/create.ts b/toolbox/module/create.ts index 0d9f2b0..f289d98 100644 --- a/toolbox/module/create.ts +++ b/toolbox/module/create.ts @@ -1,4 +1,9 @@ export async function createModule(name: string): Promise { + if (!name.match(/^[a-zA-Z0-9](?:(?:\-(?!\-))?[a-zA-Z0-9]*)*[a-zA-Z0-9]$/)) { + console.error("Module names must be in kebab case."); + Deno.exit(1); + } + console.log(`Checking for module ${name}...`); try { @@ -12,9 +17,10 @@ export async function createModule(name: string): Promise { Deno.exit(1); } - const capitalizedName = `${name[0].toUpperCase()}${ - name.substring(1).toLowerCase() - }`; + const capitalizedName = name.match(/(^\w)|(\-\w)/g)!.reduce( + (word, pattern) => word.replace(pattern, pattern.at(-1)!.toUpperCase()), + name, + ); Promise.allSettled([ createDir(`routes/(apps)/${name}/(_props)`), @@ -106,20 +112,29 @@ function getPropsContent(name: string) { `; } -function getApiExampleContent(name: string) { +function getApiExampleContent(_name: string) { return ` - import { AppProperties } from "$root/defaults/interfaces.ts"; + import { Handlers } from "$fresh/server.ts"; - const properties: AppProperties = { - name: "${name}", - icon: "school", - pages: { - index: "Homepage", + export const handler: Handlers = { + async POST(request, context) { + if (request.headers.get("content-type") != "application/json") { + return new Response(null, { + status: 400 + }); + } + + const responseBody = { + requestBody: await request.json(), + context, + }; + + return new Response(JSON.stringify(responseBody), { + headers: { + "content-type": "application/json", + }, + }); }, - adminOnly: [], - hint: "PolyMPR module", }; - - export default properties; `; } diff --git a/toolbox/module/list.ts b/toolbox/module/list.ts index ce38149..a348047 100644 --- a/toolbox/module/list.ts +++ b/toolbox/module/list.ts @@ -4,4 +4,4 @@ export async function listModules(): Promise { console.log(path.name); } } -} \ No newline at end of file +}