Add common templates
This commit is contained in:
parent
cae260b9ce
commit
d1013f1a00
@ -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() {
|
||||
|
19
src/templates/config.ts
Normal file
19
src/templates/config.ts
Normal file
@ -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 }
|
28
src/templates/controller.ts
Normal file
28
src/templates/controller.ts
Normal file
@ -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 }
|
28
src/templates/middleware.ts
Normal file
28
src/templates/middleware.ts
Normal file
@ -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 }
|
23
src/templates/routes.ts
Normal file
23
src/templates/routes.ts
Normal file
@ -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 }
|
35
src/templates/unit.ts
Normal file
35
src/templates/unit.ts
Normal file
@ -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 }
|
@ -1,8 +1,9 @@
|
||||
`{
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"sourceMap": true
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
Loading…
Reference in New Issue
Block a user