create-egg 3.0.0 → 4.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -16
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +254 -0
- package/dist/templates/egg3-simple-js/.eslintignore +1 -0
- package/dist/templates/egg3-simple-js/.eslintrc +4 -0
- package/dist/templates/egg3-simple-js/.vscode/launch.json +26 -0
- package/dist/templates/egg3-simple-js/README.md +31 -0
- package/dist/templates/egg3-simple-js/_.gitignore +15 -0
- package/dist/templates/egg3-simple-js/app/controller/home.js +10 -0
- package/dist/templates/egg3-simple-js/app/router.js +7 -0
- package/dist/templates/egg3-simple-js/config/config.default.js +28 -0
- package/dist/templates/egg3-simple-js/config/plugin.js +7 -0
- package/dist/templates/egg3-simple-js/package.json +38 -0
- package/dist/templates/egg3-simple-js/test/app/controller/home.test.js +20 -0
- package/dist/templates/egg3-simple-ts/.eslintignore +3 -0
- package/dist/templates/egg3-simple-ts/.eslintrc +6 -0
- package/dist/templates/egg3-simple-ts/README.md +33 -0
- package/dist/templates/egg3-simple-ts/_.gitignore +20 -0
- package/dist/templates/egg3-simple-ts/app/controller/home.ts +8 -0
- package/dist/templates/egg3-simple-ts/app/router.ts +7 -0
- package/dist/templates/egg3-simple-ts/app/service/Test.ts +14 -0
- package/dist/templates/egg3-simple-ts/config/config.default.ts +23 -0
- package/dist/templates/egg3-simple-ts/config/config.local.ts +6 -0
- package/dist/templates/egg3-simple-ts/config/config.prod.ts +6 -0
- package/dist/templates/egg3-simple-ts/config/plugin.ts +11 -0
- package/dist/templates/egg3-simple-ts/package.json +45 -0
- package/dist/templates/egg3-simple-ts/test/app/controller/home.test.ts +9 -0
- package/dist/templates/egg3-simple-ts/test/app/service/Test.test.ts +16 -0
- package/dist/templates/egg3-simple-ts/tsconfig.json +4 -0
- package/dist/templates/egg3-simple-ts/typings/index.d.ts +3 -0
- package/dist/templates/egg3-tegg/.vscode/launch.json +26 -0
- package/dist/templates/egg3-tegg/README.md +33 -0
- package/dist/templates/egg3-tegg/_.gitignore +21 -0
- package/dist/templates/egg3-tegg/app/module/bar/controller/home.ts +24 -0
- package/dist/templates/egg3-tegg/app/module/bar/controller/user.ts +24 -0
- package/dist/templates/egg3-tegg/app/module/bar/package.json +6 -0
- package/dist/templates/egg3-tegg/app/module/foo/index.ts +1 -0
- package/dist/templates/egg3-tegg/app/module/foo/package.json +6 -0
- package/dist/templates/egg3-tegg/app/module/foo/service/HelloService.ts +19 -0
- package/dist/templates/egg3-tegg/config/config.default.ts +30 -0
- package/dist/templates/egg3-tegg/config/config.local.ts +6 -0
- package/dist/templates/egg3-tegg/config/config.prod.ts +6 -0
- package/dist/templates/egg3-tegg/config/config.unittest.ts +6 -0
- package/dist/templates/egg3-tegg/config/plugin.ts +34 -0
- package/dist/templates/egg3-tegg/package.json +58 -0
- package/dist/templates/egg3-tegg/test/app/module/bar/controller/home.test.ts +11 -0
- package/dist/templates/egg3-tegg/test/app/module/bar/controller/user.test.ts +14 -0
- package/dist/templates/egg3-tegg/test/app/module/foo/service/HelloService.test.ts +14 -0
- package/dist/templates/egg3-tegg/tsconfig.json +13 -0
- package/dist/templates/simple-ts/README.md +33 -0
- package/dist/templates/simple-ts/_.gitignore +20 -0
- package/dist/templates/simple-ts/app/controller/home.ts +8 -0
- package/dist/templates/simple-ts/app/router.ts +7 -0
- package/dist/templates/simple-ts/app/service/Test.ts +14 -0
- package/dist/templates/simple-ts/config/config.default.ts +23 -0
- package/dist/templates/simple-ts/config/config.local.ts +6 -0
- package/dist/templates/simple-ts/config/config.prod.ts +6 -0
- package/dist/templates/simple-ts/config/plugin.ts +11 -0
- package/dist/templates/simple-ts/package.json +51 -0
- package/dist/templates/simple-ts/test/app/controller/home.test.ts +8 -0
- package/dist/templates/simple-ts/test/app/service/Test.test.ts +9 -0
- package/dist/templates/simple-ts/tsconfig.json +10 -0
- package/dist/templates/simple-ts/typings/index.d.ts +3 -0
- package/dist/templates/tegg/.vscode/launch.json +26 -0
- package/dist/templates/tegg/README.md +33 -0
- package/dist/templates/tegg/_.gitignore +21 -0
- package/dist/templates/tegg/app/module/bar/controller/home.ts +24 -0
- package/dist/templates/tegg/app/module/bar/controller/user.ts +24 -0
- package/dist/templates/tegg/app/module/bar/package.json +6 -0
- package/dist/templates/tegg/app/module/foo/index.ts +1 -0
- package/dist/templates/tegg/app/module/foo/package.json +6 -0
- package/dist/templates/tegg/app/module/foo/service/HelloService.ts +19 -0
- package/dist/templates/tegg/config/config.default.ts +30 -0
- package/dist/templates/tegg/config/config.local.ts +6 -0
- package/dist/templates/tegg/config/config.prod.ts +6 -0
- package/dist/templates/tegg/config/config.unittest.ts +6 -0
- package/dist/templates/tegg/config/plugin.ts +34 -0
- package/dist/templates/tegg/package.json +58 -0
- package/dist/templates/tegg/test/app/module/bar/controller/home.test.ts +8 -0
- package/dist/templates/tegg/test/app/module/bar/controller/user.test.ts +11 -0
- package/dist/templates/tegg/test/app/module/foo/service/HelloService.test.ts +9 -0
- package/dist/templates/tegg/tsconfig.json +13 -0
- package/package.json +38 -29
- package/bin/create-egg.js +0 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
|
2
|
+
|
|
3
|
+
export default (appInfo: EggAppInfo) => {
|
|
4
|
+
const config = {} as PowerPartial<EggAppConfig>;
|
|
5
|
+
|
|
6
|
+
// override config from framework / plugin
|
|
7
|
+
// use for cookie sign key, should change to your own and keep security
|
|
8
|
+
config.keys = appInfo.name + '_{{keys}}';
|
|
9
|
+
|
|
10
|
+
// add your egg config in here
|
|
11
|
+
config.middleware = [];
|
|
12
|
+
|
|
13
|
+
// add your special config in here
|
|
14
|
+
const bizConfig = {
|
|
15
|
+
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// the return config will combines to EggAppConfig
|
|
19
|
+
return {
|
|
20
|
+
...config,
|
|
21
|
+
...bizConfig,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "hello Egg.js",
|
|
5
|
+
"private": true,
|
|
6
|
+
"egg": {
|
|
7
|
+
"typescript": true,
|
|
8
|
+
"declarations": true
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "egg-scripts start --daemon --title=egg-server-{{name}}",
|
|
12
|
+
"stop": "egg-scripts stop --title=egg-server-{{name}}",
|
|
13
|
+
"dev": "egg-bin dev",
|
|
14
|
+
"test-local": "egg-bin test",
|
|
15
|
+
"test": "npm run lint -- --fix && npm run test-local",
|
|
16
|
+
"cov": "egg-bin cov",
|
|
17
|
+
"tsc": "ets && tsc -p tsconfig.json",
|
|
18
|
+
"ci": "npm run lint && npm run cov && npm run tsc",
|
|
19
|
+
"lint": "eslint . --ext .ts --resolve-plugins-relative-to .",
|
|
20
|
+
"clean": "ets clean"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"egg": "^3.31.0",
|
|
24
|
+
"egg-scripts": "3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/mocha": "10",
|
|
28
|
+
"@types/node": "24",
|
|
29
|
+
"@eggjs/tsconfig": "1",
|
|
30
|
+
"egg-bin": "6",
|
|
31
|
+
"egg-mock": "5",
|
|
32
|
+
"eslint": "8",
|
|
33
|
+
"eslint-config-egg": "13",
|
|
34
|
+
"typescript": "5"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20.0.0"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": ""
|
|
42
|
+
},
|
|
43
|
+
"author": "Author Name <author.name@mail.com>",
|
|
44
|
+
"license": "MIT"
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { app } from 'egg-mock/bootstrap';
|
|
3
|
+
|
|
4
|
+
describe('test/app/controller/home.test.ts', () => {
|
|
5
|
+
it('should GET /', async () => {
|
|
6
|
+
const result = await app.httpRequest().get('/').expect(200);
|
|
7
|
+
assert(result.text === 'hi, egg');
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { Context } from 'egg';
|
|
3
|
+
import { app } from 'egg-mock/bootstrap';
|
|
4
|
+
|
|
5
|
+
describe('test/app/service/Test.test.js', () => {
|
|
6
|
+
let ctx: Context;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
ctx = app.mockContext();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('sayHi', async () => {
|
|
13
|
+
const result = await ctx.service.test.sayHi('egg');
|
|
14
|
+
assert(result === 'hi, egg');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "Egg Debug",
|
|
11
|
+
"runtimeExecutable": "npm",
|
|
12
|
+
"runtimeArgs": ["run", "dev", "--", "--inspect-brk"],
|
|
13
|
+
"console": "integratedTerminal",
|
|
14
|
+
"restart": true,
|
|
15
|
+
"autoAttachChildProcesses": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "node",
|
|
19
|
+
"request": "launch",
|
|
20
|
+
"name": "Egg Test",
|
|
21
|
+
"runtimeExecutable": "npm",
|
|
22
|
+
"runtimeArgs": ["run", "test:local", "--", "--inspect-brk"],
|
|
23
|
+
"autoAttachChildProcesses": true
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# tegg app
|
|
2
|
+
|
|
3
|
+
[Hacker News](https://news.ycombinator.com/) showcase using [tegg](https://github.com/eggjs/tegg)
|
|
4
|
+
|
|
5
|
+
## QuickStart
|
|
6
|
+
|
|
7
|
+
### Development
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i
|
|
11
|
+
npm run dev
|
|
12
|
+
open http://localhost:7001/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Don't tsc compile at development mode, if you had run `tsc` then you need to `npm run clean` before `npm run dev`.
|
|
16
|
+
|
|
17
|
+
### Deploy
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm run tsc
|
|
21
|
+
npm start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Npm Scripts
|
|
25
|
+
|
|
26
|
+
- Use `npm run lint` to check code style
|
|
27
|
+
- Use `npm test` to run unit test
|
|
28
|
+
- se `npm run clean` to clean compiled js at development mode once
|
|
29
|
+
|
|
30
|
+
### Requirement
|
|
31
|
+
|
|
32
|
+
- Node.js >= 20.x
|
|
33
|
+
- Typescript >= 5.x
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
logs/
|
|
2
|
+
npm-debug.log
|
|
3
|
+
node_modules/
|
|
4
|
+
coverage/
|
|
5
|
+
.idea/
|
|
6
|
+
run/
|
|
7
|
+
logs/
|
|
8
|
+
.DS_Store
|
|
9
|
+
.vscode
|
|
10
|
+
*.swp
|
|
11
|
+
*.lock
|
|
12
|
+
*.js
|
|
13
|
+
.eslintcache
|
|
14
|
+
|
|
15
|
+
app/**/*.js
|
|
16
|
+
test/**/*.js
|
|
17
|
+
config/**/*.js
|
|
18
|
+
app/**/*.map
|
|
19
|
+
test/**/*.map
|
|
20
|
+
config/**/*.map
|
|
21
|
+
.package-lock.json
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EggLogger } from 'egg';
|
|
2
|
+
import {
|
|
3
|
+
Inject,
|
|
4
|
+
HTTPController,
|
|
5
|
+
HTTPMethod,
|
|
6
|
+
HTTPMethodEnum,
|
|
7
|
+
} from '@eggjs/tegg';
|
|
8
|
+
|
|
9
|
+
@HTTPController({
|
|
10
|
+
path: '/',
|
|
11
|
+
})
|
|
12
|
+
export class HomeController {
|
|
13
|
+
@Inject()
|
|
14
|
+
private logger: EggLogger;
|
|
15
|
+
|
|
16
|
+
@HTTPMethod({
|
|
17
|
+
method: HTTPMethodEnum.GET,
|
|
18
|
+
path: '/',
|
|
19
|
+
})
|
|
20
|
+
async index() {
|
|
21
|
+
this.logger.info('hello egg logger');
|
|
22
|
+
return 'hello egg';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
HTTPController,
|
|
4
|
+
HTTPMethod,
|
|
5
|
+
HTTPMethodEnum,
|
|
6
|
+
HTTPQuery,
|
|
7
|
+
} from '@eggjs/tegg';
|
|
8
|
+
import { HelloService } from '@/module/foo';
|
|
9
|
+
|
|
10
|
+
@HTTPController({
|
|
11
|
+
path: '/bar',
|
|
12
|
+
})
|
|
13
|
+
export class UserController {
|
|
14
|
+
@Inject()
|
|
15
|
+
private helloService: HelloService;
|
|
16
|
+
|
|
17
|
+
@HTTPMethod({
|
|
18
|
+
method: HTTPMethodEnum.GET,
|
|
19
|
+
path: 'user',
|
|
20
|
+
})
|
|
21
|
+
async user(@HTTPQuery({ name: 'userId' }) userId: string) {
|
|
22
|
+
return await this.helloService.hello(userId);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HelloService } from './service/HelloService';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EggLogger } from 'egg';
|
|
2
|
+
import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg';
|
|
3
|
+
|
|
4
|
+
@SingletonProto({
|
|
5
|
+
// 如果需要在上层使用,需要把 accessLevel 显示声明为 public
|
|
6
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
7
|
+
})
|
|
8
|
+
export class HelloService {
|
|
9
|
+
// 注入一个 logger
|
|
10
|
+
@Inject()
|
|
11
|
+
private logger: EggLogger;
|
|
12
|
+
|
|
13
|
+
// 封装业务
|
|
14
|
+
async hello(userId: string): Promise<string> {
|
|
15
|
+
const result = { userId, handledBy: 'foo module' };
|
|
16
|
+
this.logger.info('[hello] get result: %j', result);
|
|
17
|
+
return `hello, ${result.userId}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
|
2
|
+
|
|
3
|
+
export default (appInfo: EggAppInfo) => {
|
|
4
|
+
const config = {} as PowerPartial<EggAppConfig>;
|
|
5
|
+
|
|
6
|
+
// override config from framework / plugin
|
|
7
|
+
// use for cookie sign key, should change to your own and keep security
|
|
8
|
+
config.keys = appInfo.name + '_{{keys}}';
|
|
9
|
+
|
|
10
|
+
// add your egg config in here
|
|
11
|
+
config.middleware = [];
|
|
12
|
+
|
|
13
|
+
// change multipart mode to file
|
|
14
|
+
// @see https://github.com/eggjs/multipart/blob/master/src/config/config.default.ts#L104
|
|
15
|
+
config.multipart = {
|
|
16
|
+
mode: 'file',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// add your special config in here
|
|
20
|
+
// Usage: `app.config.bizConfig.sourceUrl`
|
|
21
|
+
const bizConfig = {
|
|
22
|
+
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// the return config will combines to EggAppConfig
|
|
26
|
+
return {
|
|
27
|
+
...config,
|
|
28
|
+
bizConfig,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EggPlugin } from 'egg';
|
|
2
|
+
|
|
3
|
+
const plugin: EggPlugin = {
|
|
4
|
+
tegg: {
|
|
5
|
+
enable: true,
|
|
6
|
+
package: '@eggjs/tegg-plugin',
|
|
7
|
+
},
|
|
8
|
+
teggConfig: {
|
|
9
|
+
enable: true,
|
|
10
|
+
package: '@eggjs/tegg-config',
|
|
11
|
+
},
|
|
12
|
+
teggController: {
|
|
13
|
+
enable: true,
|
|
14
|
+
package: '@eggjs/tegg-controller-plugin',
|
|
15
|
+
},
|
|
16
|
+
teggSchedule: {
|
|
17
|
+
enable: true,
|
|
18
|
+
package: '@eggjs/tegg-schedule-plugin',
|
|
19
|
+
},
|
|
20
|
+
eventbusModule: {
|
|
21
|
+
enable: true,
|
|
22
|
+
package: '@eggjs/tegg-eventbus-plugin',
|
|
23
|
+
},
|
|
24
|
+
aopModule: {
|
|
25
|
+
enable: true,
|
|
26
|
+
package: '@eggjs/tegg-aop-plugin',
|
|
27
|
+
},
|
|
28
|
+
tracer: {
|
|
29
|
+
enable: true,
|
|
30
|
+
package: 'egg-tracer',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default plugin;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"description": "Hello Egg.js",
|
|
4
|
+
"private": true,
|
|
5
|
+
"egg": {
|
|
6
|
+
"typescript": true
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "eggctl start --daemon --title=egg-server-{{name}}",
|
|
10
|
+
"stop": "eggctl stop --title=egg-server-{{name}}",
|
|
11
|
+
"dev": "egg-bin dev",
|
|
12
|
+
"pretest": "npm run clean && npm run lint -- --fix",
|
|
13
|
+
"test": "egg-bin test",
|
|
14
|
+
"preci": "npm run clean && npm run lint",
|
|
15
|
+
"ci": "egg-bin cov",
|
|
16
|
+
"postci": "npm run prepublishOnly && npm start && sleep 10 && npm stop && npm run clean",
|
|
17
|
+
"lint": "oxlint --type-aware",
|
|
18
|
+
"tsc": "tsc",
|
|
19
|
+
"clean": "tsc -b --clean",
|
|
20
|
+
"prepublishOnly": "npm run clean && npm run tsc"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"egg-scripts": "^3.1.0",
|
|
24
|
+
"@eggjs/tegg": "^3.5.2",
|
|
25
|
+
"@eggjs/tegg-aop-plugin": "^3.5.2",
|
|
26
|
+
"@eggjs/tegg-config": "^3.5.2",
|
|
27
|
+
"@eggjs/tegg-controller-plugin": "^3.5.2",
|
|
28
|
+
"@eggjs/tegg-eventbus-plugin": "^3.5.2",
|
|
29
|
+
"@eggjs/tegg-plugin": "^3.5.2",
|
|
30
|
+
"@eggjs/tegg-schedule-plugin": "^3.5.2",
|
|
31
|
+
"egg-scripts": "^2.17.0",
|
|
32
|
+
"egg-tracer": "^2.0.0",
|
|
33
|
+
"egg": "^3.31.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"egg-bin": "^6.13.0",
|
|
37
|
+
"egg-mock": "^5.15.2",
|
|
38
|
+
"@eggjs/tsconfig": "1",
|
|
39
|
+
"@types/mocha": "10",
|
|
40
|
+
"@types/node": "24",
|
|
41
|
+
"oxlint": "1",
|
|
42
|
+
"oxlint-tsgolint": "^0.2.0",
|
|
43
|
+
"typescript": "5"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.19.0"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/YOUR_USERNAME/YOUR_REPO#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/YOUR_USERNAME/YOUR_REPO/issues"
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/YOUR_USERNAME/YOUR_REPO.git"
|
|
55
|
+
},
|
|
56
|
+
"author": "Author Name <author.name@mail.com>",
|
|
57
|
+
"license": "MIT"
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
|
|
3
|
+
import { app } from 'egg-mock/bootstrap';
|
|
4
|
+
|
|
5
|
+
describe('test/app/module/bar/controller/home.test.ts', () => {
|
|
6
|
+
it('should GET / status 200', async () => {
|
|
7
|
+
const res = await app.httpRequest().get('/');
|
|
8
|
+
assert.equal(res.status, 200);
|
|
9
|
+
assert.equal(res.text, 'hello egg');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
|
|
3
|
+
import { app } from 'egg-mock/bootstrap';
|
|
4
|
+
|
|
5
|
+
describe('test/app/module/bar/controller/user.test.ts', () => {
|
|
6
|
+
it('should GET /bar/user status 200', async () => {
|
|
7
|
+
const res = await app
|
|
8
|
+
.httpRequest()
|
|
9
|
+
.get('/bar/user')
|
|
10
|
+
.query({ userId: '20170901' });
|
|
11
|
+
assert.equal(res.status, 200);
|
|
12
|
+
assert.equal(res.text, 'hello, 20170901');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
|
|
3
|
+
import { app } from 'egg-mock/bootstrap';
|
|
4
|
+
|
|
5
|
+
import { HelloService } from '@/module/foo/service/HelloService';
|
|
6
|
+
|
|
7
|
+
describe('test/app/module/foo/service/HelloService.test.ts', () => {
|
|
8
|
+
it('should hello() work', async () => {
|
|
9
|
+
// @ts-expect-error getEggObject no type defination
|
|
10
|
+
const helloService = await app.getEggObject(HelloService);
|
|
11
|
+
const msg = await helloService.hello('123456');
|
|
12
|
+
assert.equal(msg, 'hello, 123456');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Hello Egg.js
|
|
2
|
+
|
|
3
|
+
[Hello Egg.js](https://eggjs.org/) showcase using typescript && egg
|
|
4
|
+
|
|
5
|
+
## QuickStart
|
|
6
|
+
|
|
7
|
+
### Development
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm i
|
|
11
|
+
$ npm run dev
|
|
12
|
+
$ open http://localhost:7001/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Don't tsc compile at development mode, if you had run `tsc` then you need to `npm run clean` before `npm run dev`.
|
|
16
|
+
|
|
17
|
+
### Deploy
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
$ npm run tsc
|
|
21
|
+
$ npm start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Npm Scripts
|
|
25
|
+
|
|
26
|
+
- Use `npm run lint` to check code style
|
|
27
|
+
- Use `npm test` to run unit test
|
|
28
|
+
- se `npm run clean` to clean compiled js at development mode once
|
|
29
|
+
|
|
30
|
+
### Requirement
|
|
31
|
+
|
|
32
|
+
- Node.js 20.x
|
|
33
|
+
- Typescript 5.x
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
logs/
|
|
2
|
+
npm-debug.log
|
|
3
|
+
node_modules/
|
|
4
|
+
coverage/
|
|
5
|
+
.idea/
|
|
6
|
+
run/
|
|
7
|
+
logs/
|
|
8
|
+
.DS_Store
|
|
9
|
+
.vscode
|
|
10
|
+
*.swp
|
|
11
|
+
*.lock
|
|
12
|
+
*.js
|
|
13
|
+
!.autod.conf.js
|
|
14
|
+
|
|
15
|
+
app/**/*.js
|
|
16
|
+
test/**/*.js
|
|
17
|
+
config/**/*.js
|
|
18
|
+
app/**/*.map
|
|
19
|
+
test/**/*.map
|
|
20
|
+
config/**/*.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
|
2
|
+
|
|
3
|
+
export default (appInfo: EggAppInfo) => {
|
|
4
|
+
const config = {} as PowerPartial<EggAppConfig>;
|
|
5
|
+
|
|
6
|
+
// override config from framework / plugin
|
|
7
|
+
// use for cookie sign key, should change to your own and keep security
|
|
8
|
+
config.keys = appInfo.name + '_{{keys}}';
|
|
9
|
+
|
|
10
|
+
// add your egg config in here
|
|
11
|
+
config.middleware = [];
|
|
12
|
+
|
|
13
|
+
// add your special config in here
|
|
14
|
+
const bizConfig = {
|
|
15
|
+
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// the return config will combines to EggAppConfig
|
|
19
|
+
return {
|
|
20
|
+
...config,
|
|
21
|
+
...bizConfig,
|
|
22
|
+
};
|
|
23
|
+
};
|