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 { Middlewares } from "sealious";
|
||||||
import html from "../html";
|
import { loginRouter } from "./login/index.js";
|
||||||
import { NewTask, TaskList } from "../views/tasks";
|
import { MainView } from "./main-view.js";
|
||||||
import { BaseContext } from "koa";
|
import { tasksRouter } from "./tasks/index.js";
|
||||||
import { Readable } from "stream";
|
|
||||||
import { tempstream } from "tempstream";
|
|
||||||
import { router } from "..";
|
|
||||||
|
|
||||||
export function MainView(ctx: BaseContext): Readable {
|
export const mainRouter = (router: Router): void => {
|
||||||
return html(
|
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
||||||
ctx,
|
ctx.body = MainView(ctx);
|
||||||
/* HTML */ tempstream` <title>My ToDo App</title>
|
});
|
||||||
<body>
|
|
||||||
<h1>My ToDo App</h1>
|
|
||||||
${TaskList(ctx.$context)} ${NewTask()}
|
|
||||||
</body>`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
router.get("/", Middlewares.extractContext(), async (ctx) => {
|
loginRouter(router);
|
||||||
ctx.body = MainView(ctx);
|
tasksRouter(router);
|
||||||
});
|
};
|
||||||
|
|
||||||
require("./login/index");
|
|
||||||
require("./tasks/index");
|
|
||||||
|
@ -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 { Middlewares } from "sealious";
|
||||||
import { MainView } from "..";
|
import { MainView } from "../main-view";
|
||||||
import { router } from "../..";
|
|
||||||
|
|
||||||
router.post(
|
export const tasksRouter = (router: Router): void => {
|
||||||
"/tasks",
|
router.post(
|
||||||
Middlewares.extractContext(),
|
"/tasks",
|
||||||
Middlewares.parseBody(),
|
Middlewares.extractContext(),
|
||||||
async (ctx) => {
|
Middlewares.parseBody(),
|
||||||
await ctx.$app.collections.tasks
|
async (ctx) => {
|
||||||
.make({
|
await ctx.$app.collections.tasks
|
||||||
title: ctx.$body.title as string,
|
.make({
|
||||||
done: false,
|
title: ctx.$body.title as string,
|
||||||
})
|
done: false,
|
||||||
.save(ctx.$context);
|
})
|
||||||
ctx.body = MainView(ctx);
|
.save(ctx.$context);
|
||||||
}
|
ctx.body = MainView(ctx);
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
router.delete("/tasks/:task_id", Middlewares.extractContext(), async (ctx) => {
|
router.delete(
|
||||||
const task = await ctx.$app.collections.tasks.getByID(
|
"/tasks/:task_id",
|
||||||
ctx.$context,
|
Middlewares.extractContext(),
|
||||||
ctx.params.task_id
|
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