Skip to content

Commit f60aec3

Browse files
committed
⚡ feat: create initial project
1 parent 620fe85 commit f60aec3

17 files changed

+300
-105
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 🎨 editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_style = space
9+
indent_size = 2
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./node_modules/mwts/",
3+
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
4+
"env": {
5+
"jest": true
6+
}
7+
}

.gitignore

+14-103
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,15 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
1+
logs/
2+
npm-debug.log
3+
yarn-error.log
414
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
5+
package-lock.json
6+
yarn.lock
7+
coverage/
8+
dist/
9+
.idea/
10+
run/
11+
.DS_Store
12+
*.sw*
13+
*.un~
14+
.tsbuildinfo
15+
.tsbuildinfo.*

.prettierrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('mwts/.prettierrc.json')
3+
}

README.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# midwayjs-dataloader
2-
MidwayJS + GraphQL + TypeGraphQL + DataLoader. 💕
1+
# my_midway_project
2+
3+
## QuickStart
4+
5+
<!-- add docs here for user -->
6+
7+
see [midway docs][midway] for more detail.
8+
9+
### Development
10+
11+
```bash
12+
$ npm i
13+
$ npm run dev
14+
$ open http://localhost:7001/
15+
```
16+
17+
### Deploy
18+
19+
```bash
20+
$ npm start
21+
```
22+
23+
### npm scripts
24+
25+
- Use `npm run lint` to check code style.
26+
- Use `npm test` to run unit test.
27+
28+
29+
[midway]: https://midwayjs.org

README.zh-CN.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# my_midway_project
2+
3+
## 快速入门
4+
5+
<!-- 在此次添加使用文档 -->
6+
7+
如需进一步了解,参见 [midway 文档][midway]
8+
9+
### 本地开发
10+
11+
```bash
12+
$ npm i
13+
$ npm run dev
14+
$ open http://localhost:7001/
15+
```
16+
17+
### 部署
18+
19+
```bash
20+
$ npm start
21+
```
22+
23+
### 内置指令
24+
25+
- 使用 `npm run lint` 来做代码风格检查。
26+
- 使用 `npm test` 来执行单元测试。
27+
28+
29+
[midway]: https://midwayjs.org

bootstrap.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const WebFramework = require('@midwayjs/koa').Framework;
2+
const web = new WebFramework().configure({
3+
port: 7001,
4+
});
5+
6+
const { Bootstrap } = require('@midwayjs/bootstrap');
7+
Bootstrap.load(web).run();

jest.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testPathIgnorePatterns: ['<rootDir>/test/fixtures'],
5+
coveragePathIgnorePatterns: ['<rootDir>/test/'],
6+
};

package.json

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "my-midway-project",
3+
"version": "1.0.0",
4+
"description": "",
5+
"private": true,
6+
"dependencies": {
7+
"@midwayjs/bootstrap": "^2.3.0",
8+
"@midwayjs/core": "^2.3.0",
9+
"@midwayjs/decorator": "^2.3.0",
10+
"@midwayjs/koa": "^2.3.0",
11+
"koa-bodyparser": "^4.3.0"
12+
},
13+
"devDependencies": {
14+
"@midwayjs/cli": "^1.0.0",
15+
"@midwayjs/luckyeye": "^1.0.0",
16+
"@midwayjs/mock": "^2.3.0",
17+
"@types/jest": "^26.0.10",
18+
"@types/node": "14",
19+
"cross-env": "^6.0.0",
20+
"jest": "^26.4.0",
21+
"mwts": "^1.0.5",
22+
"ts-jest": "^26.2.0",
23+
"typescript": "^4.0.0"
24+
},
25+
"engines": {
26+
"node": ">=12.0.0"
27+
},
28+
"scripts": {
29+
"start": "NODE_ENV=production node ./bootstrap.js",
30+
"dev": "cross-env NODE_ENV=local midway-bin dev --ts",
31+
"test": "midway-bin test --ts",
32+
"cov": "midway-bin cov --ts",
33+
"lint": "mwts check",
34+
"lint:fix": "mwts fix",
35+
"ci": "npm run cov",
36+
"build": "midway-bin build -c",
37+
"check": "luckyeye"
38+
},
39+
"midway-bin-clean": [
40+
".vscode/.tsbuildinfo",
41+
"dist"
42+
],
43+
"midway-luckyeye": {
44+
"packages": [
45+
"midway_v2"
46+
]
47+
},
48+
"repository": {
49+
"type": "git",
50+
"url": ""
51+
},
52+
"author": "anonymous",
53+
"license": "MIT"
54+
}

src/configuration.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Configuration, App } from '@midwayjs/decorator';
2+
import { Application } from '@midwayjs/koa';
3+
import * as bodyParser from 'koa-bodyparser';
4+
5+
@Configuration({
6+
conflictCheck: true,
7+
})
8+
export class ContainerLifeCycle {
9+
@App()
10+
app: Application;
11+
12+
async onReady() {
13+
// bodyparser options see https://github.com/koajs/bodyparser
14+
this.app.use(bodyParser());
15+
}
16+
}

src/controller/api.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Inject, Controller, Post, Provide, Query } from '@midwayjs/decorator';
2+
import { Context } from '@midwayjs/koa';
3+
import { UserService } from '../service/user';
4+
5+
@Provide()
6+
@Controller('/api')
7+
export class APIController {
8+
@Inject()
9+
ctx: Context;
10+
11+
@Inject()
12+
userService: UserService;
13+
14+
@Post('/get_user')
15+
async getUser(@Query() uid) {
16+
const user = await this.userService.getUser({ uid });
17+
return { success: true, message: 'OK', data: user };
18+
}
19+
}

src/controller/home.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Controller, Get, Provide } from '@midwayjs/decorator';
2+
3+
@Provide()
4+
@Controller('/')
5+
export class HomeController {
6+
@Get('/')
7+
async home(): Promise<string> {
8+
return 'Hello Midwayjs!';
9+
}
10+
}

src/interface.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @description User-Service parameters
3+
*/
4+
export interface IUserOptions {
5+
uid: number;
6+
}

src/service/user.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Provide } from '@midwayjs/decorator';
2+
import { IUserOptions } from '../interface';
3+
4+
@Provide()
5+
export class UserService {
6+
async getUser(options: IUserOptions) {
7+
return {
8+
uid: options.uid,
9+
username: 'mockedName',
10+
phone: '12345678901',
11+
12+
};
13+
}
14+
}

test/controller/api.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createApp, close, createHttpRequest } from '@midwayjs/mock';
2+
import { Framework } from '@midwayjs/koa';
3+
import * as assert from 'assert';
4+
5+
describe('test/controller/home.test.ts', () => {
6+
7+
it('should POST /api/get_user', async () => {
8+
// create app
9+
const app = await createApp<Framework>();
10+
11+
// make request
12+
const result = await createHttpRequest(app).post('/api/get_user').query({ uid: 123 });
13+
14+
// use expect by jest
15+
expect(result.status).toBe(200);
16+
expect(result.body.message).toBe('OK');
17+
18+
// or use assert
19+
assert.deepStrictEqual(result.status, 200);
20+
assert.deepStrictEqual(result.body.data.uid, '123');
21+
22+
// close app
23+
await close(app);
24+
});
25+
});

test/controller/home.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createApp, close, createHttpRequest } from '@midwayjs/mock';
2+
import { Framework } from '@midwayjs/koa';
3+
import * as assert from 'assert';
4+
5+
describe('test/controller/home.test.ts', () => {
6+
7+
it('should GET /', async () => {
8+
// create app
9+
const app = await createApp<Framework>();
10+
11+
// make request
12+
const result = await createHttpRequest(app).get('/');
13+
14+
// use expect by jest
15+
expect(result.status).toBe(200);
16+
expect(result.text).toBe('Hello Midwayjs!');
17+
18+
// or use assert
19+
assert.deepStrictEqual(result.status, 200);
20+
assert.deepStrictEqual(result.text, 'Hello Midwayjs!');
21+
22+
// close app
23+
await close(app);
24+
});
25+
26+
});

0 commit comments

Comments
 (0)