Commit 3c47a8d2 authored by maggie's avatar maggie

自定义util编译

parent 3bdb9585
...@@ -113,6 +113,10 @@ ...@@ -113,6 +113,10 @@
"type": "common", "type": "common",
"name": "preUpdate", "name": "preUpdate",
"params": [ "params": [
{
"type": "custom",
"name": "test"
},
{ {
"type": "common", "type": "common",
"behave": "update", "behave": "update",
......
...@@ -30,6 +30,11 @@ const customFileMap = (controllers = {}) => { ...@@ -30,6 +30,11 @@ const customFileMap = (controllers = {}) => {
if (decorator.type === 'custom') { if (decorator.type === 'custom') {
result.decorators[decorator.name] = true result.decorators[decorator.name] = true
} }
for (let util of decorator.params) {
if (util.type && util.type === 'custom') {
result.utils[util.name] = true
}
}
} }
} }
} }
...@@ -39,7 +44,7 @@ const customFileMap = (controllers = {}) => { ...@@ -39,7 +44,7 @@ const customFileMap = (controllers = {}) => {
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => { const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
//编译自定义文件 //编译自定义文件
const { decorators } = customFileMap(config.controllers) const { decorators, utils } = customFileMap(config.controllers)
for (let decorator in decorators) { for (let decorator in decorators) {
await gulp await gulp
.src(`${serverTemplatePath}/decorator.njk`) .src(`${serverTemplatePath}/decorator.njk`)
...@@ -66,6 +71,32 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => { ...@@ -66,6 +71,32 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
) )
.pipe(rename(`index.ts`)) .pipe(rename(`index.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/decorator/custom')) .pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/decorator/custom'))
for (let util in utils) {
await gulp
.src(`${serverTemplatePath}/util.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
name: util
}
})
)
.pipe(rename(`${util}.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/utils/custom'))
}
await gulp
.src(`${serverTemplatePath}/util.export.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
utils
}
})
)
.pipe(rename(`index.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/utils/custom'))
//编译controller.common //编译controller.common
for (let commonController in config.controllers.common) { for (let commonController in config.controllers.common) {
await gulp await gulp
......
...@@ -11,3 +11,9 @@ const custom = { ...@@ -11,3 +11,9 @@ const custom = {
} }
export default custom export default custom
export {
{%-for decorator, decorator_item in decorators%}
{{decorator}}{%if loop.last%}{%else%},{%endif%}
{%-endfor%}
}
/** @format */
{%for util, util_item in utils-%}
import {{util}} from './{{util}}'
{%-endfor%}
const custom = {
{%-for util, util_item in utils%}
{{util}}{%if loop.last%}{%else%},{%endif%}
{%-endfor%}
}
export default custom
export {
{%-for util, util_item in utils%}
{{util}}{%if loop.last%}{%else%},{%endif%}
{%-endfor%}
}
/** @format */
import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../errorCode'
export default async function {{name}}(context: IContext<IParams>, { activityInfo }: IControllerInfos) {
// TO DO
}
...@@ -12,7 +12,7 @@ export default class TaskController { ...@@ -12,7 +12,7 @@ export default class TaskController {
@commonDecorator.checkParams(['activityId']) @commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['vipInfo']) @commonDecorator.registeInfos(['vipInfo'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime]) @commonDecorator.preCheck([commonUtilCheck.checkActivityTime])
@commonDecorator.preUpdate([commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods]) @commonDecorator.preUpdate([customUtil.test, commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods])
@services([TaskService]) @services([TaskService])
async getTaskList( async getTaskList(
context: IContext<IParams>, context: IContext<IParams>,
......
...@@ -7,3 +7,7 @@ const custom = { ...@@ -7,3 +7,7 @@ const custom = {
} }
export default custom export default custom
export {
test
}
/** @format */
import test from './test'
const custom = {
test
}
export default custom
export {
test
}
/** @format */
import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../errorCode'
export default async function test(context: IContext<IParams>, { activityInfo }: IControllerInfos) {
// TO DO
}
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