mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-12 09:32:49 +00:00
初始化项目
This commit is contained in:
parent
87b1cb3514
commit
c9ccd2a754
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# 🎨 editorconfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
7
.eslintrc.json
Normal file
7
.eslintrc.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./node_modules/mwts/",
|
||||||
|
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
|
||||||
|
"env": {
|
||||||
|
"jest": true
|
||||||
|
}
|
||||||
|
}
|
||||||
15
.gitignore
vendored
Executable file
15
.gitignore
vendored
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
logs/
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
|
yarn.lock
|
||||||
|
coverage/
|
||||||
|
dist/
|
||||||
|
.idea/
|
||||||
|
run/
|
||||||
|
.DS_Store
|
||||||
|
*.sw*
|
||||||
|
*.un~
|
||||||
|
.tsbuildinfo
|
||||||
|
.tsbuildinfo.*
|
||||||
3
.prettierrc.js
Normal file
3
.prettierrc.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
...require('mwts/.prettierrc.json')
|
||||||
|
}
|
||||||
34
.vscode/launch.json
vendored
Normal file
34
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Midway Debug",
|
||||||
|
"type": "node",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"env": {
|
||||||
|
"NODE_ENV": "local"
|
||||||
|
},
|
||||||
|
"port": 9229,
|
||||||
|
// "preLaunchTask": "TypeScript compile",
|
||||||
|
"protocol": "auto",
|
||||||
|
"request": "launch",
|
||||||
|
"restart": true,
|
||||||
|
"runtimeArgs": [
|
||||||
|
"run",
|
||||||
|
"debug",
|
||||||
|
"--",
|
||||||
|
"--inspect-brk"
|
||||||
|
],
|
||||||
|
"runtimeExecutable": "npm",
|
||||||
|
"skipFiles": [
|
||||||
|
// "${workspaceFolder}/node_modules/**/*.js",
|
||||||
|
"${workspaceFolder}/node_modules/rxjs/**/*.js",
|
||||||
|
"<node_internals>/**/*.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
31
README.md
Normal file → Executable file
31
README.md
Normal file → Executable file
@ -1 +1,30 @@
|
|||||||
#cool-admin
|
# my_midway_project
|
||||||
|
|
||||||
|
## QuickStart
|
||||||
|
|
||||||
|
<!-- add docs here for user -->
|
||||||
|
|
||||||
|
see [midway docs][midway] for more detail.
|
||||||
|
|
||||||
|
### Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm i
|
||||||
|
$ npm run dev
|
||||||
|
$ open http://localhost:7001/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deploy
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm start
|
||||||
|
$ npm stop
|
||||||
|
```
|
||||||
|
|
||||||
|
### npm scripts
|
||||||
|
|
||||||
|
- Use `npm run lint` to check code style.
|
||||||
|
- Use `npm test` to run unit test.
|
||||||
|
|
||||||
|
|
||||||
|
[midway]: https://midwayjs.org
|
||||||
|
|||||||
30
README.zh-CN.md
Executable file
30
README.zh-CN.md
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
# my_midway_project
|
||||||
|
|
||||||
|
## 快速入门
|
||||||
|
|
||||||
|
<!-- 在此次添加使用文档 -->
|
||||||
|
|
||||||
|
如需进一步了解,参见 [midway 文档][midway]。
|
||||||
|
|
||||||
|
### 本地开发
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm i
|
||||||
|
$ npm run dev
|
||||||
|
$ open http://localhost:7001/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 部署
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm start
|
||||||
|
$ npm stop
|
||||||
|
```
|
||||||
|
|
||||||
|
### 内置指令
|
||||||
|
|
||||||
|
- 使用 `npm run lint` 来做代码风格检查。
|
||||||
|
- 使用 `npm test` 来执行单元测试。
|
||||||
|
|
||||||
|
|
||||||
|
[midway]: https://midwayjs.org
|
||||||
49
package.json
Executable file
49
package.json
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "my_midway_project",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@midwayjs/web": "^2.3.0",
|
||||||
|
"@midwayjs/decorator": "^2.3.0",
|
||||||
|
"egg": "^2.0.0",
|
||||||
|
"egg-scripts": "^2.10.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@midwayjs/cli": "^1.0.0",
|
||||||
|
"@midwayjs/egg-ts-helper": "^1.0.1",
|
||||||
|
"@midwayjs/mock": "^2.3.0",
|
||||||
|
"@types/jest": "^26.0.10",
|
||||||
|
"@types/node": "14",
|
||||||
|
"cross-env": "^6.0.0",
|
||||||
|
"mwts": "^1.0.5",
|
||||||
|
"jest": "^26.4.0",
|
||||||
|
"ts-jest": "^26.2.0",
|
||||||
|
"typescript": "^3.9.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "egg-scripts start --daemon --title=midway-server-my_midway_project --framework=@midwayjs/web",
|
||||||
|
"stop": "egg-scripts stop --title=midway-server-my_midway_project",
|
||||||
|
"start_build": "npm run build && cross-env NODE_ENV=development midway-bin dev",
|
||||||
|
"dev": "cross-env ets && cross-env NODE_ENV=local midway-bin dev --ts",
|
||||||
|
"test": "midway-bin test",
|
||||||
|
"cov": "midway-bin cov",
|
||||||
|
"lint": "mwts check",
|
||||||
|
"lint:fix": "mwts fix",
|
||||||
|
"ci": "npm run cov",
|
||||||
|
"build": "midway-bin build -c"
|
||||||
|
},
|
||||||
|
"midway-bin-clean": [
|
||||||
|
".vscode/.tsbuildinfo",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": ""
|
||||||
|
},
|
||||||
|
"author": "anonymous",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
15
src/config/config.default.ts
Normal file
15
src/config/config.default.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||||
|
|
||||||
|
export type DefaultConfig = PowerPartial<EggAppConfig>;
|
||||||
|
|
||||||
|
export default (appInfo: EggAppInfo) => {
|
||||||
|
const config = {} as DefaultConfig;
|
||||||
|
|
||||||
|
// use for cookie sign key, should change to your own and keep security
|
||||||
|
config.keys = appInfo.name + '_1610416114197_5726';
|
||||||
|
|
||||||
|
// add your config here
|
||||||
|
config.middleware = [];
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
0
src/config/config.local.ts
Normal file
0
src/config/config.local.ts
Normal file
3
src/config/config.unittest.ts
Normal file
3
src/config/config.unittest.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const security = {
|
||||||
|
csrf: false
|
||||||
|
}
|
||||||
4
src/config/plugin.ts
Executable file
4
src/config/plugin.ts
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
import { EggPlugin } from 'egg';
|
||||||
|
export default {
|
||||||
|
static: false, // default is true
|
||||||
|
} as EggPlugin;
|
||||||
19
src/controller/api.ts
Normal file
19
src/controller/api.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Inject, Controller, Post, Provide, Query } from '@midwayjs/decorator';
|
||||||
|
import { Context } from 'egg';
|
||||||
|
import { UserService } from '../service/user';
|
||||||
|
|
||||||
|
@Provide()
|
||||||
|
@Controller('/api')
|
||||||
|
export class APIController {
|
||||||
|
@Inject()
|
||||||
|
ctx: Context;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
userService: UserService;
|
||||||
|
|
||||||
|
@Post('/get_user')
|
||||||
|
async getUser(@Query() uid) {
|
||||||
|
const user = await this.userService.getUser({ uid });
|
||||||
|
return { success: true, message: 'OK', data: user };
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/controller/home.ts
Executable file
10
src/controller/home.ts
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
import { Controller, Get, Provide } from '@midwayjs/decorator';
|
||||||
|
|
||||||
|
@Provide()
|
||||||
|
@Controller('/')
|
||||||
|
export class HomeController {
|
||||||
|
@Get('/')
|
||||||
|
async home() {
|
||||||
|
return 'Hello Midwayjs!';
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/interface.ts
Normal file
6
src/interface.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @description User-Service parameters
|
||||||
|
*/
|
||||||
|
export interface IUserOptions {
|
||||||
|
uid: number;
|
||||||
|
}
|
||||||
14
src/service/user.ts
Normal file
14
src/service/user.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { Provide } from '@midwayjs/decorator';
|
||||||
|
import { IUserOptions } from '../interface';
|
||||||
|
|
||||||
|
@Provide()
|
||||||
|
export class UserService {
|
||||||
|
async getUser(options: IUserOptions) {
|
||||||
|
return {
|
||||||
|
uid: options.uid,
|
||||||
|
username: 'mockedName',
|
||||||
|
phone: '12345678901',
|
||||||
|
email: 'xxx.xxx@xxx.com',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
25
test/controller/api.test.ts
Executable file
25
test/controller/api.test.ts
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
import { createApp, close, createHttpRequest } from '@midwayjs/mock';
|
||||||
|
import { Framework } from '@midwayjs/web';
|
||||||
|
import * as assert from 'assert';
|
||||||
|
|
||||||
|
describe('test/controller/home.test.ts', () => {
|
||||||
|
|
||||||
|
it('should POST /api/get_user', async () => {
|
||||||
|
// create app
|
||||||
|
const app = await createApp<Framework>();
|
||||||
|
|
||||||
|
// make request
|
||||||
|
const result = await createHttpRequest(app).post('/api/get_user').query({ uid: 123 });
|
||||||
|
|
||||||
|
// use expect by jest
|
||||||
|
expect(result.status).toBe(200);
|
||||||
|
expect(result.body.message).toBe('OK');
|
||||||
|
|
||||||
|
// or use assert
|
||||||
|
assert.deepStrictEqual(result.status, 200);
|
||||||
|
assert.deepStrictEqual(result.body.data.uid, '123');
|
||||||
|
|
||||||
|
// close app
|
||||||
|
await close(app);
|
||||||
|
});
|
||||||
|
});
|
||||||
26
test/controller/home.test.ts
Executable file
26
test/controller/home.test.ts
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
import { createApp, close, createHttpRequest } from '@midwayjs/mock';
|
||||||
|
import { Framework } from '@midwayjs/web';
|
||||||
|
import * as assert from 'assert';
|
||||||
|
|
||||||
|
describe('test/controller/home.test.ts', () => {
|
||||||
|
|
||||||
|
it('should GET /', async () => {
|
||||||
|
// create app
|
||||||
|
const app = await createApp<Framework>();
|
||||||
|
|
||||||
|
// make request
|
||||||
|
const result = await createHttpRequest(app).get('/');
|
||||||
|
|
||||||
|
// use expect by jest
|
||||||
|
expect(result.status).toBe(200);
|
||||||
|
expect(result.text).toBe('Hello Midwayjs!');
|
||||||
|
|
||||||
|
// or use assert
|
||||||
|
assert.deepStrictEqual(result.status, 200);
|
||||||
|
assert.deepStrictEqual(result.text, 'Hello Midwayjs!');
|
||||||
|
|
||||||
|
// close app
|
||||||
|
await close(app);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
23
tsconfig.json
Normal file
23
tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"compileOnSave": true,
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2018",
|
||||||
|
"module": "commonjs",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"inlineSourceMap":true,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"stripInternal": true,
|
||||||
|
"pretty": true,
|
||||||
|
"declaration": true,
|
||||||
|
"typeRoots": [ "./typings", "./node_modules/@types"],
|
||||||
|
"outDir": "dist"
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist",
|
||||||
|
"node_modules",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
}
|
||||||
7
typings/app/index.d.ts
vendored
Normal file
7
typings/app/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// This file is created by egg-ts-helper@1.25.8
|
||||||
|
// Do not modify this file!!!!!!!!!
|
||||||
|
|
||||||
|
import 'egg';
|
||||||
|
import '@midwayjs/web';
|
||||||
|
export * from 'egg';
|
||||||
|
export as namespace Egg;
|
||||||
32
typings/config/index.d.ts
vendored
Normal file
32
typings/config/index.d.ts
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// This file is created by egg-ts-helper@1.25.8
|
||||||
|
// Do not modify this file!!!!!!!!!
|
||||||
|
|
||||||
|
import '@midwayjs/web';
|
||||||
|
import 'egg';
|
||||||
|
import 'egg-onerror';
|
||||||
|
import 'egg-session';
|
||||||
|
import 'egg-i18n';
|
||||||
|
import 'egg-multipart';
|
||||||
|
import 'egg-security';
|
||||||
|
import 'egg-schedule';
|
||||||
|
import 'egg-jsonp';
|
||||||
|
import 'egg-view';
|
||||||
|
import 'midway-schedule';
|
||||||
|
import { EggPluginItem } from 'egg';
|
||||||
|
declare module 'egg' {
|
||||||
|
interface EggPlugin {
|
||||||
|
onerror?: EggPluginItem;
|
||||||
|
session?: EggPluginItem;
|
||||||
|
i18n?: EggPluginItem;
|
||||||
|
watcher?: EggPluginItem;
|
||||||
|
multipart?: EggPluginItem;
|
||||||
|
security?: EggPluginItem;
|
||||||
|
development?: EggPluginItem;
|
||||||
|
logrotator?: EggPluginItem;
|
||||||
|
schedule?: EggPluginItem;
|
||||||
|
static?: EggPluginItem;
|
||||||
|
jsonp?: EggPluginItem;
|
||||||
|
view?: EggPluginItem;
|
||||||
|
schedulePlus?: EggPluginItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
typings/config/plugin.d.ts
vendored
Normal file
31
typings/config/plugin.d.ts
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// This file is created by egg-ts-helper@1.25.8
|
||||||
|
// Do not modify this file!!!!!!!!!
|
||||||
|
|
||||||
|
import 'egg';
|
||||||
|
import 'egg-onerror';
|
||||||
|
import 'egg-session';
|
||||||
|
import 'egg-i18n';
|
||||||
|
import 'egg-multipart';
|
||||||
|
import 'egg-security';
|
||||||
|
import 'egg-schedule';
|
||||||
|
import 'egg-jsonp';
|
||||||
|
import 'egg-view';
|
||||||
|
import 'midway-schedule';
|
||||||
|
import { EggPluginItem } from 'egg';
|
||||||
|
declare module 'egg' {
|
||||||
|
interface EggPlugin {
|
||||||
|
onerror?: EggPluginItem;
|
||||||
|
session?: EggPluginItem;
|
||||||
|
i18n?: EggPluginItem;
|
||||||
|
watcher?: EggPluginItem;
|
||||||
|
multipart?: EggPluginItem;
|
||||||
|
security?: EggPluginItem;
|
||||||
|
development?: EggPluginItem;
|
||||||
|
logrotator?: EggPluginItem;
|
||||||
|
schedule?: EggPluginItem;
|
||||||
|
static?: EggPluginItem;
|
||||||
|
jsonp?: EggPluginItem;
|
||||||
|
view?: EggPluginItem;
|
||||||
|
schedulePlus?: EggPluginItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user