Commit 7248fe8e authored by maggie's avatar maggie

导出接口

parent 897acef5
...@@ -18,22 +18,6 @@ const controllerImport = (controller = {}) => { ...@@ -18,22 +18,6 @@ const controllerImport = (controller = {}) => {
} }
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => { 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 //编译controller.common
for (let commonController in config.controllers.common) { for (let commonController in config.controllers.common) {
await gulp await gulp
...@@ -68,6 +52,19 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => { ...@@ -68,6 +52,19 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
.pipe(rename(`${customController}.controller.ts`)) .pipe(rename(`${customController}.controller.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/controller/custom')) .pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath + '/controller/custom'))
} }
//接口导出
await gulp
.src(`${serverTemplatePath}/controller.export.njk`)
.pipe(
nunjucksRender({
...nunjucksRenderConfig,
data: {
controllers: config.controllers
}
})
)
.pipe(rename(`index.ts`))
.pipe(gulp.dest(nunjucksRenderConfig.ServerFullPath))
} }
module.exports = { module.exports = {
......
{%- for type, type_item in controllers -%}
{%- for controller, controller_item in type_item %}
import {{type | capitalize}}{{controller | capitalize}}Controller from './controller/{{type}}/{{controller}}.controller'
const {{type | capitalize}}{{controller | capitalize}}ControllerInstance = new {{type | capitalize}}{{controller | capitalize}}Controller()
{%- endfor -%}
{%- endfor %}
export default {
{%- for type, type_item in controllers -%}
{%- for controller, controller_item in type_item -%}
{%- for function, fucntion_item in controller_item %}
{{type}}{{controller | capitalize}}{{function | capitalize}}: {{type | capitalize}}{{controller | capitalize}}ControllerInstance.{{function}}
{%-if loop.last-%}{%else%},{%-endif-%}
{%- endfor -%}
{%- endfor -%}
{%- endfor %}
}
\ No newline at end of file
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