Import Extollo framework

This commit is contained in:
2021-04-09 20:33:40 -05:00
parent 7d712fa1a9
commit 0996361e43
46 changed files with 2661 additions and 0 deletions

18
src/Units.extollo.ts Normal file
View File

@@ -0,0 +1,18 @@
import {Config, Controllers, HTTPServer, Files, Middlewares, Routing, Unit} from '@extollo/lib'
import {Database, Models} from "@extollo/orm";
import {CommandLine} from "@extollo/cli";
import {Internationalization} from "@extollo/i18n";
export const Units = [
Config,
Files,
CommandLine,
Controllers,
Middlewares,
Database,
Models,
Internationalization,
Routing,
HTTPServer,
] as (typeof Unit)[]

View File

@@ -0,0 +1,5 @@
import { env } from '@extollo/lib'
export default {
name: env('APP_NAME', 'Extollo'),
}

View File

@@ -0,0 +1,14 @@
import { env } from "@extollo/lib";
export default {
connections: {
default: {
user: env('DATABASE_USERNAME', 'extollo'),
password: env('DATABASE_PASSWORD'),
host: env('DATABASE_HOST', 'localhost'),
port: env('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'extollo_1'),
dialect: env('DATABASE_DIALECT', 'postgres'),
},
},
}

View File

@@ -0,0 +1,5 @@
import { env } from "@extollo/lib"
export default {
app_name: env('APP_NAME', 'Extollo'),
}

View File

@@ -0,0 +1,6 @@
import {env} from '@extollo/lib'
export default {
welcome_to_extollo: 'Welcome to Extollo!',
viewed_page_num_times: 'You have viewed this page :num: times.',
}

View File

@@ -0,0 +1,44 @@
import {env, basePath} from "@extollo/lib"
import {ORMSession} from "@extollo/orm"
import {LocalFilesystem, LocalFilesystemConfig} from "@extollo/util"
export default {
debug: env('DEBUG_MODE', false),
session: {
/* The implementation of @extollo/lib.Session that serves as the session backend. */
driver: ORMSession,
},
/*
* Here, you can define various filesystem drivers that can be used in
* your application to store/retrieve files.
*
* The key in the object is the 'name' of the filesystem as it will be
* fetched in code. For example, if you have a `fubar: { ... }` item,
* then you can retrieve that filesystem using the Files service like
* so:
*
* files.getFilesystem('fubar') // => Filesystem { ... }
*/
filesystems: {
default: {
/* If true, this will serve as the default filesystem for modules in your application. */
isDefault: true,
/* The implementation of @extollo/util.Filesystem that serves as the backend. */
driver: LocalFilesystem,
/* The config required by the filesystem driver. */
config: {
baseDir: basePath('..', 'uploads').toLocal,
} as LocalFilesystemConfig,
}
},
middleware: {
global: {
pre: ['LogRequest'],
},
},
}

View File

@@ -0,0 +1,21 @@
import {Controller, view, Session} from '@extollo/lib';
import {Inject, Injectable} from "@extollo/di";
import {Locale} from "@extollo/i18n"
@Injectable()
export class Home extends Controller {
@Inject()
protected readonly session!: Session;
@Inject()
protected readonly locale!: Locale;
public welcome() {
this.session.set('app_visits', this.session.get('app_visits', 0) + 1)
return view('welcome', {
app_visits: this.session.get('app_visits'),
locale: this.locale.helper(),
})
}
}

View File

@@ -0,0 +1,12 @@
import {json, Logging, Middleware} from "@extollo/lib";
import {Inject, Injectable} from "@extollo/di";
@Injectable()
export class LogRequest extends Middleware {
@Inject()
protected readonly logging!: Logging
public async apply() {
this.logging.info(`Incoming request: ${this.request.method} @ ${this.request.path}`)
}
}

View File

@@ -0,0 +1,3 @@
import {Route} from "@extollo/lib"
Route.get('/', 'main:Home.welcome')

View File

@@ -0,0 +1,6 @@
import {Model} from "@extollo/orm";
export class User extends Model<User> {
protected static table = 'users';
protected static key = 'user_id';
}

View File

@@ -0,0 +1,6 @@
html
head
title !{locale('app_name')}
body
h1 !{locale('welcome_to_extollo')}
h2 !{locale('viewed_page_num_times', { interp: { num: app_visits } })}

23
src/cli.ts Normal file
View File

@@ -0,0 +1,23 @@
import {Application} from "@extollo/lib";
import {Units} from './Units.extollo';
import {CommandLineApplication} from "@extollo/cli";
(async () => {
/*
* The Application
* -----------------------------------------------------
* The application instance is a global inversion of control container that
* ties your entire application together. The app container manages services
* and lifecycle.
*/
const app = Application.getApplication()
app.forceStartupMessage = false
Units.reverse()
CommandLineApplication.setReplacement(Units[0])
Units[0] = CommandLineApplication
Units.reverse()
app.scaffold(__dirname, Units)
await app.run()
})()

15
src/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import {Application} from "@extollo/lib";
import {Units} from './Units.extollo'
;(async () => {
/*
* The Application
* -----------------------------------------------------
* The application instance is a global inversion of control container that
* ties your entire application together. The app container manages services
* and lifecycle.
*/
const app = Application.getApplication()
app.scaffold(__dirname, Units)
await app.run()
})()