Commit 3c47a8d2 authored by maggie's avatar maggie

自定义util编译

parent 3bdb9585
......@@ -113,6 +113,10 @@
"type": "common",
"name": "preUpdate",
"params": [
{
"type": "custom",
"name": "test"
},
{
"type": "common",
"behave": "update",
......
......@@ -30,6 +30,11 @@ const customFileMap = (controllers = {}) => {
if (decorator.type === 'custom') {
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 = {}) => {
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
//编译自定义文件
const { decorators } = customFileMap(config.controllers)
const { decorators, utils } = customFileMap(config.controllers)
for (let decorator in decorators) {
await gulp
.src(`${serverTemplatePath}/decorator.njk`)
......@@ -66,6 +71,32 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
)
.pipe(rename(`index.ts`))
.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
for (let commonController in config.controllers.common) {
await gulp
......
......@@ -11,3 +11,9 @@ const 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 {
@commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['vipInfo'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime])
@commonDecorator.preUpdate([commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods])
@commonDecorator.preUpdate([customUtil.test, commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods])
@services([TaskService])
async getTaskList(
context: IContext<IParams>,
......
......@@ -7,3 +7,7 @@ const 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