Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
897acef5
Commit
897acef5
authored
Nov 06, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save
parent
d4474579
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
261 additions
and
145 deletions
+261
-145
config.json
v2.0/compileServer/config.json
+130
-0
generate.js
v2.0/compileServer/generate.js
+47
-17
controller.njk
v2.0/compileServer/templates/controller.njk
+2
-2
task.controller.njk
...leServer/templates/controllers/common/task.controller.njk
+0
-27
user.controller.njk
...leServer/templates/controllers/common/user.controller.njk
+0
-27
custom.controller.njk
...compileServer/templates/controllers/custom.controller.njk
+0
-63
macro.njk
v2.0/compileServer/templates/macro.njk
+1
-3
stat.controller.ts
v2.0/src/controller/common/stat.controller.ts
+1
-2
task.controller.ts
v2.0/src/controller/common/task.controller.ts
+1
-2
user.controller.ts
v2.0/src/controller/common/user.controller.ts
+1
-2
test1.controller.ts
v2.0/src/controller/custom/test1.controller.ts
+39
-0
test2.controller.ts
v2.0/src/controller/custom/test2.controller.ts
+39
-0
No files found.
v2.0/compileServer/config.json
View file @
897acef5
...
...
@@ -340,6 +340,136 @@
]
}
}
},
"custom"
:
{
"test1"
:
{
"addStat"
:
{
"desc"
:
"增加埋点记录"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"type"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"addStat"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.type"
},
{
"type"
:
"var"
,
"value"
:
"userInfo"
}
],
"return"
:
true
}
]
},
"getStats"
:
{
"desc"
:
"统计数据"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"startDay"
,
"endDay"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"getStats"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.activityId"
},
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
}
]
},
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"buildExcel"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
},
{
"type"
:
"var"
,
"value"
:
"commonStatGetstatsResult1"
}
],
"return"
:
true
}
]
}
},
"test2"
:
{
"addStat"
:
{
"desc"
:
"增加埋点记录"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"type"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"addStat"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.type"
},
{
"type"
:
"var"
,
"value"
:
"userInfo"
}
],
"return"
:
true
}
]
},
"getStats"
:
{
"desc"
:
"统计数据"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"startDay"
,
"endDay"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"getStats"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.activityId"
},
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
}
]
},
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"buildExcel"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
},
{
"type"
:
"var"
,
"value"
:
"commonStatGetstatsResult1"
}
],
"return"
:
true
}
]
}
}
}
}
}
\ No newline at end of file
v2.0/compileServer/generate.js
View file @
897acef5
...
...
@@ -4,40 +4,70 @@ const fs = require('fs-extra')
const
config
=
require
(
'./config.json'
)
const
serverTemplatePath
=
'templates'
const
run
=
async
(
gulp
,
nunjucksRender
,
rename
,
nunjucksRenderConfig
)
=>
{
//生成控制器service
const
controllerServices
=
{
common
:
{},
custom
:
{}
const
controllerImport
=
(
controller
=
{})
=>
{
const
result
=
{
service
:
{}
}
//通用控制器
for
(
let
commonController
in
config
.
controllers
.
common
)
{
controllerServices
.
common
[
commonController
]
=
{}
for
(
let
fn
in
config
.
controllers
.
common
[
commonController
])
{
for
(
let
main
of
config
.
controllers
.
common
[
commonController
][
fn
].
main
)
{
if
(
!
controllerServices
.
common
[
commonController
][
main
.
type
])
{
controllerServices
.
common
[
commonController
][
main
.
type
]
=
{}
}
controllerServices
.
common
[
commonController
][
main
.
type
][
main
.
service
]
=
true
}
for
(
let
fn
in
controller
)
{
for
(
let
main
of
controller
[
fn
].
main
)
{
result
.
service
[
main
.
service
]
=
true
}
}
console
.
log
(
result
)
return
result
}
const
run
=
async
(
gulp
,
nunjucksRender
,
rename
,
nunjucksRenderConfig
)
=>
{
// //生成控制器service
// const controllerServices = {
// common: {},
// custom: {}
// }
// for (let customController in config.controllers.common) {
// controllerServices.common[commonController] = {}
// for (let fn in config.controllers.common[commonController]) {
// for (let main of config.controllers.common[commonController][fn].main) {
// if (!controllerServices.common[commonController][main.type]) {
// controllerServices.common[commonController][main.type] = {}
// }
// controllerServices.common[commonController][main.type][main.service] = true
// }
// }
// }
//编译controller.common
for
(
let
commonController
in
config
.
controllers
.
common
)
{
await
gulp
.
src
(
`
${
serverTemplatePath
}
/controller
s/common/
${
commonController
}
.controller
.njk`
)
.
src
(
`
${
serverTemplatePath
}
/controller.njk`
)
.
pipe
(
nunjucksRender
({
...
nunjucksRenderConfig
,
data
:
{
name
:
commonController
,
model
:
config
.
controllers
.
common
[
commonController
],
service
:
controllerServices
.
common
[
commonController
]
...
controllerImport
(
config
.
controllers
.
common
[
commonController
])
}
})
)
.
pipe
(
rename
(
`
${
commonController
}
.controller.ts`
))
.
pipe
(
gulp
.
dest
(
nunjucksRenderConfig
.
ServerFullPath
+
'/controller/common'
))
}
//编译controller.custom
for
(
let
customController
in
config
.
controllers
.
custom
)
{
await
gulp
.
src
(
`
${
serverTemplatePath
}
/controller.njk`
)
.
pipe
(
nunjucksRender
({
...
nunjucksRenderConfig
,
data
:
{
name
:
customController
,
model
:
config
.
controllers
.
custom
[
customController
],
...
controllerImport
(
config
.
controllers
.
custom
[
customController
])
}
})
)
.
pipe
(
rename
(
`
${
customController
}
.controller.ts`
))
.
pipe
(
gulp
.
dest
(
nunjucksRenderConfig
.
ServerFullPath
+
'/controller/custom'
))
}
}
module
.
exports
=
{
...
...
v2.0/compileServer/templates/controller
s/common/stat.controller
.njk
→
v2.0/compileServer/templates/controller.njk
View file @
897acef5
...
...
@@ -5,9 +5,9 @@ import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
{{-macro.genControllerService(service)
-
}}
export default class
Stat
{
export default class
{{name | capitalize}}Controller
{
{%- for fn, item in model %}
/**
* {{item.desc}}
...
...
v2.0/compileServer/templates/controllers/common/task.controller.njk
deleted
100644 → 0
View file @
d4474579
/** @format */
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export default class Task {
{%- for fn, item in model %}
/**
* {{item.desc}}
*/
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
{{-macro.genMain(model[fn].main)}}
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
v2.0/compileServer/templates/controllers/common/user.controller.njk
deleted
100644 → 0
View file @
d4474579
/** @format */
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export default class User {
{%- for fn, item in model %}
/**
* {{item.desc}}
*/
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
{{-macro.genMain(model[fn].main)}}
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
v2.0/compileServer/templates/controllers/custom.controller.njk
deleted
100644 → 0
View file @
d4474579
/** @format */
{# {% import "macro.njk" as macro -%} #}
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
{# {{-macro.genControllerService(service)}} #}
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
interface IRankList {
userNick: string
avatar: string
score: any
rank: number
}
export interface IRankResult {
rank: number
userNick: string
avatar: string
score: number
list: IRankList[]
}
{# export default class User {
/**
* 获取会员信息
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([{{-macro.genServicesDecorator(model.getVipInfo.main)}}])
async getVipInfo(
context: IContext<IVipParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getVipInfo.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
{{-macro.genMain(model.getVipInfo.main)}}
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([{{-macro.genServicesDecorator(model.getRankList.main)}}])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getRankList.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getRankList.main)}}
) {
{{-macro.genMain(model.getRankList.main)}}
{{-macro.genReturn(model.getRankList.main)}}
}
} #}
\ No newline at end of file
v2.0/compileServer/templates/macro.njk
View file @
897acef5
{# 生成控制器引用的服务 #}
{% macro genControllerService(service)%}
{%- for type, item1 in service %}
import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{% endfor %} } from '../../service'
{%- endfor -%}
import { {% for key, item in service %}{{key | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{%- endfor %} } from '../../service'
{% endmacro %}
{# 生成装饰器 #}
...
...
v2.0/src/controller/common/stat.controller.ts
View file @
897acef5
...
...
@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
StatService
}
from
'../../service'
export
default
class
Stat
{
export
default
class
StatController
{
/**
* 增加埋点记录
*/
...
...
v2.0/src/controller/common/task.controller.ts
View file @
897acef5
...
...
@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
TaskService
,
BaseService
}
from
'../../service'
export
default
class
Task
{
export
default
class
TaskController
{
/**
* 任务列表
*/
...
...
v2.0/src/controller/common/user.controller.ts
View file @
897acef5
...
...
@@ -4,8 +4,7 @@ import commonUtilCheck from '../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
UserService
}
from
'../../service'
export
default
class
User
{
export
default
class
UserController
{
/**
* 获取会员信息
*/
...
...
v2.0/src/controller/custom/test1.controller.ts
0 → 100644
View file @
897acef5
/** @format */
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonUtilCheck
from
'../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
StatService
}
from
'../../service'
export
default
class
Test1Controller
{
/**
* 增加埋点记录
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'type'
])
@
services
([
StatService
])
async
addStat
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatAddstatResult1
=
await
statService
.
addStat
(
context
.
data
.
type
,
userInfo
)
return
resultsModel
.
success
({
...
commonStatAddstatResult1
})
}
/**
* 统计数据
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'startDay'
,
'endDay'
])
@
services
([
StatService
])
async
getStats
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatGetstatsResult1
=
await
statService
.
getStats
(
context
.
data
.
activityId
,
context
.
data
.
startDay
,
context
.
data
.
endDay
)
const
commonStatBuildexcelResult2
=
await
statService
.
buildExcel
(
context
.
data
.
startDay
,
context
.
data
.
endDay
,
commonStatGetstatsResult1
)
return
resultsModel
.
success
({
...
commonStatBuildexcelResult2
})
}
}
v2.0/src/controller/custom/test2.controller.ts
0 → 100644
View file @
897acef5
/** @format */
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonUtilCheck
from
'../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
StatService
}
from
'../../service'
export
default
class
Test2Controller
{
/**
* 增加埋点记录
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'type'
])
@
services
([
StatService
])
async
addStat
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatAddstatResult1
=
await
statService
.
addStat
(
context
.
data
.
type
,
userInfo
)
return
resultsModel
.
success
({
...
commonStatAddstatResult1
})
}
/**
* 统计数据
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'startDay'
,
'endDay'
])
@
services
([
StatService
])
async
getStats
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatGetstatsResult1
=
await
statService
.
getStats
(
context
.
data
.
activityId
,
context
.
data
.
startDay
,
context
.
data
.
endDay
)
const
commonStatBuildexcelResult2
=
await
statService
.
buildExcel
(
context
.
data
.
startDay
,
context
.
data
.
endDay
,
commonStatGetstatsResult1
)
return
resultsModel
.
success
({
...
commonStatBuildexcelResult2
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment