Commit f58b6761 authored by maggie's avatar maggie

save

parent ec44152d
...@@ -18,6 +18,13 @@ ...@@ -18,6 +18,13 @@
"params": [ "params": [
"session" "session"
] ]
},
{
"type": "custom",
"name": "test",
"params": [
"tt"
]
} }
], ],
"main": [ "main": [
......
...@@ -17,7 +17,55 @@ const controllerImport = (controller = {}) => { ...@@ -17,7 +17,55 @@ const controllerImport = (controller = {}) => {
return result return result
} }
const customFileMap = (controllers = {}) => {
const result = {
decorators: {},
utils: {},
services: {}
}
for (let controllerType in controllers) {
for (let controller in controllers[controllerType]) {
for (let fn in controllers[controllerType][controller]) {
for (let decorator of controllers[controllerType][controller][fn].decorators) {
if (decorator.type === 'custom') {
result.decorators[decorator.name] = true
}
}
}
}
}
return result
}
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => { const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
//编译自定义文件
const { decorators } = customFileMap(config.controllers)
for (let decorator in decorators) {
await gulp
.src(`${serverTemplatePath}/decorator.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
name: decorator
}
})
)
.pipe(rename(`${decorator}.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/decorator/custom'))
}
await gulp
.src(`${serverTemplatePath}/decorator.export.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
decorators
}
})
)
.pipe(rename(`index.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/decorator/custom'))
//编译controller.common //编译controller.common
for (let commonController in config.controllers.common) { for (let commonController in config.controllers.common) {
await gulp await gulp
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)-}} {{-macro.genControllerService(service)-}}
......
/** @format */
{%for decorator, decorator_item in decorators-%}
import {{decorator}} from './{{decorator}}'
{%-endfor%}
const custom = {
{%-for decorator, decorator_item in decorators%}
{{decorator}}{%if loop.last%}{%else%},{%endif%}
{%-endfor%}
}
export default custom
/** @format */
import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../constants'
export default function {{name}}(params) {
return function (target: Object, name: string, descriptor: PropertyDescriptor) {
const method = descriptor.value
descriptor.value = function (...args: any[]) {
const [context, otherArgs = {}] = args
return method.apply(target, [context, { ...otherArgs }])
}
}
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { StatService } from '../../service' import { StatService } from '../../service'
export default class StatController { export default class StatController {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { TaskService, BaseService } from '../../service' import { TaskService, BaseService } from '../../service'
export default class TaskController { export default class TaskController {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { UserService } from '../../service' import { UserService } from '../../service'
export default class UserController { export default class UserController {
...@@ -10,6 +11,7 @@ export default class UserController { ...@@ -10,6 +11,7 @@ export default class UserController {
*/ */
@commonDecorator.checkParams(['activityId']) @commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['session']) @commonDecorator.registeInfos(['session'])
@customDecorator.test(['tt'])
@services([UserService]) @services([UserService])
async getVipInfo( async getVipInfo(
context: IContext<IParams>, context: IContext<IParams>,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { StatService } from '../../service' import { StatService } from '../../service'
export default class Test1Controller { export default class Test1Controller {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import commonDecorator, { services } from '../../decorator/common' import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check' import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update' import commonUtilUpdate from '../../utils/common/update'
import customDecorator from '../../decorator/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { StatService } from '../../service' import { StatService } from '../../service'
export default class Test2Controller { export default class Test2Controller {
......
/** @format */
import test from './test'
const custom = {
test
}
export default custom
/** @format */
import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../constants'
export default function test(params) {
return function (target: Object, name: string, descriptor: PropertyDescriptor) {
const method = descriptor.value
descriptor.value = function (...args: any[]) {
const [context, otherArgs = {}] = args
return method.apply(target, [context, { ...otherArgs }])
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment