Move to esbuild
parent
b24d6d1a0b
commit
c64a950746
@ -0,0 +1,40 @@
|
||||
const { build } = require("esbuild");
|
||||
const { sassPlugin } = require("esbuild-sass-plugin");
|
||||
const glob = require("tiny-glob");
|
||||
|
||||
const watch = process.argv.at(-1) === "--watch";
|
||||
|
||||
(async () => {
|
||||
let entryPoints = Object.fromEntries(
|
||||
(await glob("./src/back/**/*.ts")).map((e) => [
|
||||
e.replace(/\.ts$/, ""),
|
||||
e,
|
||||
])
|
||||
);
|
||||
build({
|
||||
entryPoints,
|
||||
sourcemap: true,
|
||||
outdir: "./dist",
|
||||
logLevel: "info",
|
||||
platform: "node",
|
||||
watch,
|
||||
target: "node16",
|
||||
format: "cjs",
|
||||
});
|
||||
build({
|
||||
entryPoints: ["./src/front/main.scss"],
|
||||
sourcemap: true,
|
||||
outfile: "./public/dist/style.css",
|
||||
logLevel: "info",
|
||||
watch,
|
||||
plugins: [sassPlugin()],
|
||||
});
|
||||
build({
|
||||
entryPoints: ["./src/front/index.ts"],
|
||||
sourcemap: true,
|
||||
outfile: "./public/dist/bundle.js",
|
||||
logLevel: "info",
|
||||
bundle: true,
|
||||
watch,
|
||||
});
|
||||
})();
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,14 @@
|
||||
import Router from "@koa/router";
|
||||
import { Middlewares } from "sealious";
|
||||
import html from "../html";
|
||||
import { NewTask, TaskList } from "../views/tasks";
|
||||
import { BaseContext } from "koa";
|
||||
import { Readable } from "stream";
|
||||
import { tempstream } from "tempstream";
|
||||
import { router } from "..";
|
||||
import { loginRouter } from "./login/index.js";
|
||||
import { MainView } from "./main-view.js";
|
||||
import { tasksRouter } from "./tasks/index.js";
|
||||
|
||||
export function MainView(ctx: BaseContext): Readable {
|
||||
return html(
|
||||
ctx,
|
||||
/* HTML */ tempstream` <title>My ToDo App</title>
|
||||
<body>
|
||||
<h1>My ToDo App</h1>
|
||||
${TaskList(ctx.$context)} ${NewTask()}
|
||||
</body>`
|
||||
);
|
||||
}
|
||||
export const mainRouter = (router: Router): void => {
|
||||
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
||||
ctx.body = MainView(ctx);
|
||||
});
|
||||
|
||||
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
||||
ctx.body = MainView(ctx);
|
||||
});
|
||||
|
||||
require("./login/index");
|
||||
require("./tasks/index");
|
||||
loginRouter(router);
|
||||
tasksRouter(router);
|
||||
};
|
||||
|
@ -0,0 +1,17 @@
|
||||
import html from "../html";
|
||||
import { BaseContext } from "koa";
|
||||
import { Readable } from "stream";
|
||||
import { tempstream } from "tempstream";
|
||||
import { NewTask, TaskList } from "../views/tasks";
|
||||
|
||||
export function MainView(ctx: BaseContext): Readable {
|
||||
return html(
|
||||
ctx,
|
||||
tempstream/* HTML */ ` <title>My Own ToDo App</title>
|
||||
<body>
|
||||
<h1>My ToDo App (with esbuild!)</h1>
|
||||
|
||||
${TaskList(ctx.$context)} ${NewTask()}
|
||||
</body>`
|
||||
);
|
||||
}
|
@ -1,27 +1,33 @@
|
||||
import Router from "@koa/router";
|
||||
import { Middlewares } from "sealious";
|
||||
import { MainView } from "..";
|
||||
import { router } from "../..";
|
||||
import { MainView } from "../main-view";
|
||||
|
||||
router.post(
|
||||
"/tasks",
|
||||
Middlewares.extractContext(),
|
||||
Middlewares.parseBody(),
|
||||
async (ctx) => {
|
||||
await ctx.$app.collections.tasks
|
||||
.make({
|
||||
title: ctx.$body.title as string,
|
||||
done: false,
|
||||
})
|
||||
.save(ctx.$context);
|
||||
ctx.body = MainView(ctx);
|
||||
}
|
||||
);
|
||||
export const tasksRouter = (router: Router): void => {
|
||||
router.post(
|
||||
"/tasks",
|
||||
Middlewares.extractContext(),
|
||||
Middlewares.parseBody(),
|
||||
async (ctx) => {
|
||||
await ctx.$app.collections.tasks
|
||||
.make({
|
||||
title: ctx.$body.title as string,
|
||||
done: false,
|
||||
})
|
||||
.save(ctx.$context);
|
||||
ctx.body = MainView(ctx);
|
||||
}
|
||||
);
|
||||
|
||||
router.delete("/tasks/:task_id", Middlewares.extractContext(), async (ctx) => {
|
||||
const task = await ctx.$app.collections.tasks.getByID(
|
||||
ctx.$context,
|
||||
ctx.params.task_id
|
||||
router.delete(
|
||||
"/tasks/:task_id",
|
||||
Middlewares.extractContext(),
|
||||
async (ctx) => {
|
||||
const task = await ctx.$app.collections.tasks.getByID(
|
||||
ctx.$context,
|
||||
ctx.params.task_id
|
||||
);
|
||||
await task.remove(ctx.$context);
|
||||
ctx.body = MainView(ctx);
|
||||
}
|
||||
);
|
||||
await task.remove(ctx.$context);
|
||||
ctx.body = MainView(ctx);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue