-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: intergration with egg-ts-helper (#123)
- Loading branch information
Showing
26 changed files
with
276 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as path from 'path'; | ||
|
||
export default (app: Egg.Application) => { | ||
let directory = path.resolve(app.baseDir, './app/model'); | ||
app.loader.loadToApp(directory, 'model', { | ||
caseStyle: 'upper', | ||
directory, | ||
}); | ||
|
||
directory = path.resolve(app.baseDir, './app/custom'); | ||
app.loader.loadToApp(directory, 'custom', { | ||
caseStyle: 'lower', | ||
directory, | ||
}); | ||
|
||
app.customLog(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class HomeController extends Controller { | ||
async index() { | ||
const { ctx, app } = this; | ||
ctx.customLog(); | ||
app.customLog(); | ||
ctx.request.customLog(); | ||
ctx.response.customLog(); | ||
ctx.helper.customLog(); | ||
console.info(app.config.otherBizConfig.type); | ||
console.info(await ctx.service.db.fetch()); | ||
console.info(await app.model.User.get()); | ||
console.info('biz config', ctx.app.config.biz.type); | ||
ctx.body = 'ok'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default () => { | ||
return { | ||
abc: '123', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
customLog() { | ||
console.info('application log'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
customLog() { | ||
console.info('context log'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
customLog() { | ||
console.info('helper log'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
customLog() { | ||
console.info('request log'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
customLog() { | ||
console.info('response log'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default () => { | ||
return async (_ctx, next) => { | ||
await next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function() { | ||
return { | ||
get() { | ||
return 'model get'; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default function(app: Application) { | ||
const { router, controller } = app; | ||
|
||
console.info(app.custom.test.abc); | ||
router.get('/', controller.home.index); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Service } from 'egg'; | ||
|
||
export default class DbService extends Service { | ||
async fetch() { | ||
return 'service fetch'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function() { | ||
// built-in config | ||
const config: Egg.PowerPartial<Egg.EggAppConfig> = {}; | ||
|
||
config.keys = '123123'; | ||
|
||
// biz config | ||
const bizConfig = { | ||
biz: { | ||
type: 'biz', | ||
}, | ||
}; | ||
|
||
return { | ||
...config as {}, | ||
...bizConfig, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { EggAppConfig, PowerPartial } from 'egg'; | ||
|
||
export default function() { | ||
// built-in config | ||
const config: PowerPartial<EggAppConfig> = {}; | ||
|
||
config.keys = '123123'; | ||
|
||
config.biz = { | ||
type: 'local', | ||
}; | ||
|
||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function() { | ||
return { | ||
otherBizConfig: { | ||
type: 'value', | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EggPlugin } from 'egg'; | ||
|
||
const plugin: EggPlugin = { | ||
}; | ||
|
||
export default plugin; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "real-app", | ||
"egg": { | ||
"typescript": true, | ||
"declarations": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noImplicitAny": false, | ||
"baseUrl": ".", | ||
"paths": { | ||
"egg": [ | ||
"../../../node_modules/egg" | ||
], | ||
"egg-mock": [ | ||
"../../../node_modules/egg-mock" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"./**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
watchDirs: { | ||
model: { | ||
path: 'app/model', // dir path | ||
generator: 'class', // generator name | ||
interface: 'IModel', // interface name | ||
declareTo: 'Application.model', // declare to this interface | ||
interfaceHandle: val => `ReturnType<typeof ${val}>`, // interfaceHandle | ||
}, | ||
|
||
custom: { | ||
path: 'app/custom', // dir path | ||
generator: 'auto', // generator name | ||
declareTo: 'Application.custom', // declare to this interface | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters