From 1680d2994d297eaecd67cf71dec1d6c2a4c49df8 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 11 Jun 2019 23:35:57 +0800 Subject: [PATCH] fix: fix tsconfig in template --- .../midway-init/boilerplate/boilerplate.json | 6 +-- .../boilerplate/.editorconfig | 17 ------- .../boilerplate/.vscode/launch.json | 34 ------------- .../boilerplate/.vscode/settings.json | 46 ----------------- .../boilerplate/.vscode/tasks.json | 50 ------------------- .../boilerplate/README.md | 8 ++- .../boilerplate/src/app/controller/home.ts | 9 ++-- .../boilerplate/src/app/controller/user.ts | 12 +++-- .../boilerplate/tsconfig.json | 1 + .../server/src/app/controller/home.ts | 10 ++-- .../server/src/app/controller/user.ts | 26 ++++++---- .../boilerplate/server/tsconfig.json | 1 + .../boilerplate/src/app/controller/home.ts | 9 ++-- .../boilerplate/src/app/controller/user.ts | 10 ++-- .../boilerplate/tsconfig.json | 1 + 15 files changed, 62 insertions(+), 178 deletions(-) delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.editorconfig delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json diff --git a/packages/midway-init/boilerplate/boilerplate.json b/packages/midway-init/boilerplate/boilerplate.json index 32d1d7e07484..2c98eb2c4496 100644 --- a/packages/midway-init/boilerplate/boilerplate.json +++ b/packages/midway-init/boilerplate/boilerplate.json @@ -2,12 +2,12 @@ "midway-ts": { "package": "midway-ts-boilerplate", "description": "Simple midway application boilerplate by ts", - "name": "midway typescript template" + "name": "midway standard typescript template" }, "midway-demo": { "package": "midway-demo-boilerplate", - "description": "Simple boilerplate for create a midway demo", - "name": "midway demo template" + "description": "Simple example boilerplate for find bug or submit to midway-examples", + "name": "midway mini example template" }, "midway-ts-ant-design-pro": { "package": "midway-ts-ant-design-pro-boilerplate", diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.editorconfig b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.editorconfig deleted file mode 100644 index fdaed3a356b6..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.editorconfig +++ /dev/null @@ -1,17 +0,0 @@ -# http://editorconfig.org -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -max_line_length = off -trim_trailing_whitespace = false - -[Makefile] -indent_style = tab diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json deleted file mode 100644 index 31c5b5faf782..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Midway Debug", - "type": "node", - "autoAttachChildProcesses": true, - "console": "integratedTerminal", - "env": { - "NODE_ENV": "local" - }, - "port": 9229, - "preLaunchTask": "TypeScript compile", - "protocol": "auto", - "request": "launch", - "restart": true, - "runtimeArgs": [ - "run", - "debug", - "--", - "--inspect-brk" - ], - "runtimeExecutable": "npm", - "skipFiles": [ - // "${workspaceFolder}/node_modules/**/*.js", - "${workspaceFolder}/node_modules/rxjs/**/*.js", - "/**/*.js" - ] - } - ] -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json deleted file mode 100644 index 31976b3964cd..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "files.insertFinalNewline": true, - "files.eol": "\n", - "files.exclude": { - "USE_GITIGNORE": true, - "**/*.js": { - "when": "$(basename).ts" - }, - "**/*.map": true, - "**/*.swp": true, - "**/.git": true, - "**/.DS_Store": true, - ".vscode": true, - ".git": true, - ".build": true, - ".githooks": true, - ".sourcemaps": true, - "run": true, - "logs": true, - "out": true, - "node_modules": true, - "node_modules*": true, - "coverage": true, - "dist": true, - "platforms": true - }, - "files.watcherExclude": { - "**/.git/objects/**": true, - "**/node_modules/**": true, - "**/node_modules*/**": true, - "coverage/**": true, - "dist/**": true - }, - "files.trimTrailingWhitespace": true, - "search.exclude": { - "**/node_modules": true, - ".vscode/**": true, - ".build/**": true, - "out/**": true, - "i18n/**": true - }, - "[markdown]": { - "files.trimTrailingWhitespace": false - }, - "tslint.configFile": "./tslint.json" -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json deleted file mode 100644 index 95684c98d80e..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - // 有关 tasks.json 格式的文档,请参见 - // https://go.microsoft.com/fwlink/?LinkId=733558 - "version": "2.0.0", - "tasks": [ - { - "label": "TypeScript compile", - "command": "tsc", - "args": [ - "-p", - "." - ], - "problemMatcher": [ - "$tsc" - ], - "type": "shell" - }, - { - "label": "watch", - "command": "tsc", - "args": [ - "-w", - "-p", - "." - ], - "isBackground": true, - "problemMatcher": [ - "$tsc-watch" - ], - "type": "shell" - }, - { - // Ctrl+Shift+B - "type": "npm", - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { - "reveal": "silent" - }, - "problemMatcher": [ - "$eslint-stylish", - "$tsc", - "$tslint5" - ], - "script": "build" - } - ] -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/README.md b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/README.md index 1f488bf17fd9..1dad32483e74 100755 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/README.md +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/README.md @@ -1,3 +1,9 @@ # demo-{{name}} -this is a demo for midway. +this is a simple template for midway examples. +you can push it to midway-examples after created or find bugs. +this template not include tslint and @types package.this can be find in package called midway-demo-lib. + +这是一个最精简的用于提交到 midway-examples 的代码模板。 +通常用于复现代码 bug 或者创建一个 demo 提交到 midway-exmaples。 +这个模板不包括 tslint,以及常见的 @types 等,这些都被包括在一个叫 midway-demo-lib 的包中。 diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/home.ts b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/home.ts index e271b00db242..edb2cbfe0fb7 100755 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/home.ts +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/home.ts @@ -1,11 +1,14 @@ -import { controller, get, provide } from 'midway'; +import { Context, controller, inject, get, provide } from 'midway'; @provide() @controller('/') export class HomeController { + @inject() + ctx: Context; + @get('/') - async index(ctx) { - ctx.body = `Welcome to midwayjs!`; + async index() { + this.ctx.body = `Welcome to midwayjs!`; } } diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/user.ts b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/user.ts index 9dad788f0bf0..1f65399fb24f 100644 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/user.ts +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/app/controller/user.ts @@ -1,16 +1,20 @@ -import { controller, get, inject, provide } from 'midway'; +import { Context, controller, get, inject, provide } from 'midway'; import { IUserService, IUserResult } from '../../interface'; @provide() @controller('/user') export class UserController { + + @inject() + ctx: Context; + @inject('userService') service: IUserService; @get('/:id') - async getUser(ctx): Promise { - const id: number = ctx.params.id; + async getUser(): Promise { + const id: number = this.ctx.params.id; const user: IUserResult = await this.service.getUser({id}); - ctx.body = {success: true, message: 'OK', data: user}; + this.ctx.body = {success: true, message: 'OK', data: user}; } } diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/tsconfig.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/tsconfig.json index 3ddce6b39c26..8d528bd5bb6a 100644 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/tsconfig.json +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/tsconfig.json @@ -17,6 +17,7 @@ "pretty": true, "skipLibCheck": true, "strict": true, + "strictPropertyInitialization": false, "stripInternal": true, "target": "ES2017" }, diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/home.ts b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/home.ts index 5e1f5b6de2c1..d9d9891469ae 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/home.ts +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/home.ts @@ -1,10 +1,14 @@ -import { Context, controller, get, provide } from 'midway'; +import { Context, inject, controller, get, provide } from 'midway'; @provide() @controller('/') export class HomeController { + + @inject() + ctx: Context; + @get('/') - async index(ctx: Context) { - await ctx.render('index'); + async index() { + await this.ctx.render('index'); } } diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/user.ts b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/user.ts index 27b1972dc6c1..034f11dbcb63 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/user.ts +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/app/controller/user.ts @@ -4,6 +4,10 @@ import { IUserService } from '../../lib/interface'; @provide() @controller('/user') export class UserController { + + @inject() + ctx: Context; + @inject('userService') service: IUserService; @@ -11,32 +15,32 @@ export class UserController { * GET /user/profile */ @get('/profile') - async profile(ctx: Context) { + async profile() { const res = await this.service.profile(); - ctx.body = res.data; + this.ctx.body = res.data; } /** * POST /user/login */ @post('/login') - async login(ctx: Context) { - const { username, password } = ctx.query; + async login() { + const { username, password } = this.ctx.query; if (username === 'admin' && password === 'admin') { - ctx.body = { + this.ctx.body = { status: 200, statusText: 'ok', currentAuthority: 'admin', }; } else if (username === 'user' && password === 'user') { - ctx.body = { + this.ctx.body = { status: 200, statusText: 'ok', currentAuthority: 'user', }; } else { - ctx.body = { + this.ctx.body = { status: 401, statusText: 'unauthorized', currentAuthority: 'guest', @@ -48,8 +52,8 @@ export class UserController { * POST /user/register */ @post('/register') - async register(ctx: Context) { - ctx.body = { + async register() { + this.ctx.body = { status: 200, statusText: 'ok', currentAuthority: 'user', @@ -60,8 +64,8 @@ export class UserController { * POST /user/logout */ @post('/logout') - async logout(ctx: Context) { - ctx.body = { + async logout() { + this.ctx.body = { status: 200, statusText: 'ok', currentAuthority: 'guest', diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/tsconfig.json b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/tsconfig.json index 3ddce6b39c26..8d528bd5bb6a 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/tsconfig.json +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/tsconfig.json @@ -17,6 +17,7 @@ "pretty": true, "skipLibCheck": true, "strict": true, + "strictPropertyInitialization": false, "stripInternal": true, "target": "ES2017" }, diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/home.ts b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/home.ts index 664af4e11a2a..5d18833b3304 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/home.ts +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/home.ts @@ -1,11 +1,14 @@ -import { Context, controller, get, provide } from 'midway'; +import { Context, inject, controller, get, provide } from 'midway'; @provide() @controller('/') export class HomeController { + @inject() + ctx: Context; + @get('/') - async index(ctx: Context) { - ctx.body = `Welcome to midwayjs!`; + async index() { + this.ctx.body = `Welcome to midwayjs!`; } } diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/user.ts b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/user.ts index c401173e147b..1f65399fb24f 100644 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/user.ts +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/app/controller/user.ts @@ -4,13 +4,17 @@ import { IUserService, IUserResult } from '../../interface'; @provide() @controller('/user') export class UserController { + + @inject() + ctx: Context; + @inject('userService') service: IUserService; @get('/:id') - async getUser(ctx: Context): Promise { - const id: number = ctx.params.id; + async getUser(): Promise { + const id: number = this.ctx.params.id; const user: IUserResult = await this.service.getUser({id}); - ctx.body = {success: true, message: 'OK', data: user}; + this.ctx.body = {success: true, message: 'OK', data: user}; } } diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/tsconfig.json b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/tsconfig.json index 3ddce6b39c26..8d528bd5bb6a 100644 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/tsconfig.json +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/tsconfig.json @@ -17,6 +17,7 @@ "pretty": true, "skipLibCheck": true, "strict": true, + "strictPropertyInitialization": false, "stripInternal": true, "target": "ES2017" },