From ea5d86a3c2565c95d73c3996c575c1bcff6eacfc Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Wed, 27 Jan 2021 18:29:43 +0100 Subject: [PATCH] Move app class to separate module to make it easier to import for typing --- src/back/app.ts | 40 +++++++++++++++++++++++++++++++++ src/back/index.ts | 51 ++++-------------------------------------- src/back/tsconfig.json | 2 -- 3 files changed, 44 insertions(+), 49 deletions(-) create mode 100644 src/back/app.ts diff --git a/src/back/app.ts b/src/back/app.ts new file mode 100644 index 0000000..50fbf62 --- /dev/null +++ b/src/back/app.ts @@ -0,0 +1,40 @@ +import _locreq from "locreq"; +import { resolve } from "path"; +import { App, Collection, FieldTypes, Policies } from "sealious"; +const locreq = _locreq(__dirname); + +export default class TheApp extends App { + config = { + upload_path: locreq.resolve("uploaded_files"), + datastore_mongo: { + host: "localhost", + port: 20723, + db_name: "sealious-playground", + }, + email: { + from_address: "sealious-playground@example.com", + from_name: "Sealious playground app", + }, + }; + manifest = { + name: "Sealious Playground", + logo: resolve(__dirname, "../assets/logo.png"), + version: "0.0.1", + default_language: "en", + base_url: "localhost:8080", + admin_email: "admin@example.com", + colors: { + primary: "#5294a1", + }, + }; + collections = { + ...App.BaseCollections, + tasks: new (class extends Collection { + fields = { + title: new FieldTypes.Text(), + done: new FieldTypes.Boolean(), + }; + defaultPolicy = new Policies.Public(); + })(), + }; +} diff --git a/src/back/index.ts b/src/back/index.ts index ef35e66..bdc2b4a 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -1,14 +1,6 @@ import _locreq from "locreq"; -import { resolve } from "path"; -import Sealious, { - App, - Collection, - Context, - FieldTypes, - Policies, - Middlewares, - CollectionItem, -} from "sealious"; +import Sealious, { CollectionItem, Context, Middlewares } from "sealious"; +import TheApp from "./app"; import frame from "./frame"; import html from "./html"; const locreq = _locreq(__dirname); @@ -16,47 +8,12 @@ const locreq = _locreq(__dirname); declare module "koa" { interface BaseContext { $context: Sealious.Context; - $app: Sealious.App; + $app: TheApp; $body: Record; } } -const app = new (class extends App { - config = { - upload_path: locreq.resolve("uploaded_files"), - datastore_mongo: { - host: "localhost", - port: 20723, - db_name: "sealious-playground", - }, - email: { - from_address: "sealious-playground@example.com", - from_name: "Sealious playground app", - }, - }; - manifest = { - name: "Sealious Playground", - logo: resolve(__dirname, "../assets/logo.png"), - version: "0.0.1", - default_language: "en", - base_url: "localhost:8080", - admin_email: "admin@example.com", - colors: { - primary: "#5294a1", - }, - }; - collections = { - ...App.BaseCollections, - tasks: new (class extends Collection { - fields = { - title: new FieldTypes.Text(), - done: new FieldTypes.Boolean(), - }; - defaultPolicy = new Policies.Public(); - })(), - }; -})(); - +const app = new TheApp(); app.start(); const router = app.HTTPServer.router; diff --git a/src/back/tsconfig.json b/src/back/tsconfig.json index f9b773e..044a19e 100644 --- a/src/back/tsconfig.json +++ b/src/back/tsconfig.json @@ -6,13 +6,11 @@ "noImplicitThis": true, "strictNullChecks": true, "target": "ES2019", - "declaration": true, "esModuleInterop": true, "lib": ["es6", "esnext"], "outDir": "../../dist", "checkJs": true, "allowJs": true, - "declarationDir": "@types", "resolveJsonModule": true, "sourceMap": true },