diff --git a/src/service/CommandLine.ts b/src/service/CommandLine.ts index 13b1807..cf9856b 100644 --- a/src/service/CommandLine.ts +++ b/src/service/CommandLine.ts @@ -5,6 +5,11 @@ import {CommandLineApplication} from "./CommandLineApplication" import {Directive} from "../Directive" import {Template} from "../Template" import {directive_template} from "../templates/directive" +import {unit_template} from "../templates/unit"; +import {controller_template} from "../templates/controller"; +import {middleware_template} from "../templates/middleware"; +import {routes_template} from "../templates/routes"; +import {config_template} from "../templates/config"; @Singleton() export class CommandLine extends Unit { @@ -18,6 +23,11 @@ export class CommandLine extends Unit { async up() { this.registerTemplate(directive_template) + this.registerTemplate(unit_template) + this.registerTemplate(controller_template) + this.registerTemplate(middleware_template) + this.registerTemplate(routes_template) + this.registerTemplate(config_template) } public isCLI() { diff --git a/src/templates/config.ts b/src/templates/config.ts new file mode 100644 index 0000000..2188847 --- /dev/null +++ b/src/templates/config.ts @@ -0,0 +1,19 @@ +import {Template} from "../Template" +import {UniversalPath} from "@extollo/util" + +const config_template: Template = { + name: 'config', + fileSuffix: '.config.ts', + description: 'Create a new config file.', + baseAppPath: ['configs'], + render(name: string, fullCanonicalName: string, targetFilePath: UniversalPath) { + return `import { env } from '@extollo/lib' + +export default { + key: env('VALUE_ENV_VAR', 'default value'), +} +` + } +} + +export { config_template } diff --git a/src/templates/controller.ts b/src/templates/controller.ts new file mode 100644 index 0000000..057a4af --- /dev/null +++ b/src/templates/controller.ts @@ -0,0 +1,28 @@ +import {Template} from "../Template" +import {UniversalPath} from "@extollo/util" + +const controller_template: Template = { + name: 'controller', + fileSuffix: '.controller.ts', + description: 'Create a controller class that can be used to handle requests.', + baseAppPath: ['http', 'controllers'], + render(name: string, fullCanonicalName: string, targetFilePath: UniversalPath) { + return `import {Controller, view} from "@extollo/lib" +import {Inject, Injectable} from "@extollo/di" + +/** + * ${name} Controller + * ------------------------------------ + * Put some description here. + */ +@Injectable() +export class ${name} extends Controller { + public ${name.toLowerCase()}() { + return view('${name.toLowerCase()}') + } +} +` + } +} + +export { controller_template } diff --git a/src/templates/middleware.ts b/src/templates/middleware.ts new file mode 100644 index 0000000..7833b5b --- /dev/null +++ b/src/templates/middleware.ts @@ -0,0 +1,28 @@ +import {Template} from "../Template" +import {UniversalPath} from "@extollo/util" + +const middleware_template: Template = { + name: 'middleware', + fileSuffix: '.middleware.ts', + description: 'Create a middleware class that can be applied to routes.', + baseAppPath: ['http', 'middlewares'], + render(name: string, fullCanonicalName: string, targetFilePath: UniversalPath) { + return `import {Middleware} from "@extollo/lib" +import {Injectable} from "@extollo/di" + +/** + * ${name} Middleware + * -------------------------------------------- + * Put some description here. + */ +@Injectable() +export class ${name} extends Middleware { + public async apply() { + + } +} +` + } +} + +export { middleware_template } diff --git a/src/templates/routes.ts b/src/templates/routes.ts new file mode 100644 index 0000000..a28b216 --- /dev/null +++ b/src/templates/routes.ts @@ -0,0 +1,23 @@ +import {Template} from "../Template" +import {UniversalPath} from "@extollo/util" + +const routes_template: Template = { + name: 'routes', + fileSuffix: '.routes.ts', + description: 'Create a file for route definitions.', + baseAppPath: ['http', 'routes'], + render(name: string, fullCanonicalName: string, targetFilePath: UniversalPath) { + return `import {Route} from "@extollo/lib" + +/* + * ${name} Routes + * ------------------------------- + * Put some description here. + */ + + +` + } +} + +export { routes_template } diff --git a/src/templates/unit.ts b/src/templates/unit.ts new file mode 100644 index 0000000..1f88d4a --- /dev/null +++ b/src/templates/unit.ts @@ -0,0 +1,35 @@ +import {Template} from "../Template" +import {UniversalPath} from "@extollo/util" + +const unit_template: Template = { + name: 'unit', + fileSuffix: '.ts', + description: 'Create a service unit that will start and stop with your application.', + baseAppPath: ['units'], + render(name: string, fullCanonicalName: string, targetFilePath: UniversalPath) { + return `import {Singleton, Inject} from "@extollo/di" +import {Unit, Logging} from "@extollo/lib" + +/** + * ${name} Unit + * --------------------------------------- + * Put some description here. + */ +@Singleton() +export class ${name} extends Unit { + @Inject() + protected readonly logging!: Logging + + public async up() { + this.logging.info('${name} has started!') + } + + public async down() { + this.logging.info('${name} has stopped!') + } +} +` + } +} + +export { unit_template } diff --git a/src/tsconfig.json b/src/tsconfig.json index d40a60f..747ab9e 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,8 +1,9 @@ -`{ +{ "compilerOptions": { "module": "commonjs", "target": "es5", - "sourceMap": true + "sourceMap": true, + "experimentalDecorators": true }, "exclude": [ "node_modules"