Added CLI

This commit is contained in:
fedyna-k
2025-01-21 09:19:50 +01:00
parent 9fee9ea0e8
commit f3c0b91f9c
4 changed files with 30 additions and 27 deletions
-2
View File
@@ -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,
-10
View File
@@ -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,
});
},
};
+29 -14
View File
@@ -1,4 +1,9 @@
export async function createModule(name: string): Promise<void> {
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<void> {
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;
`;
}
+1 -1
View File
@@ -4,4 +4,4 @@ export async function listModules(): Promise<void> {
console.log(path.name);
}
}
}
}