Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to egg v4 #126

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@master
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '14, 16, 18'
version: '18, 20, 22'
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Examples for [egg](https://github.com/eggjs/egg)

---

[![build status][travis-image]][travis-url]
[![CI](https://github.com/eggjs/examples/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/eggjs/examples/actions/workflows/ci.yml)
[![node version][node-image]][node-url]
[![egg version][egg-image]][egg-url]

[travis-image]: https://img.shields.io/travis/eggjs/examples.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/examples
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
[node-image]: https://img.shields.io/badge/node.js-%3E=_18-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[egg-image]: https://img.shields.io/badge/egg-%3E=_1-green.svg?style=flat-square
[egg-image]: https://img.shields.io/badge/egg-%3E=_4-green.svg?style=flat-square
[egg-url]: https://github.com/eggjs/egg

## Usage
Expand All @@ -23,7 +19,7 @@ $ npm install
$ npm run dev
```

**Recommend to use Node >= 8**
**Recommend to use Node >= 18**

## List of examples

Expand Down Expand Up @@ -64,12 +60,6 @@ You can use `--verbose` to show more infomation
$ npm test -- --verbose
```

### Generate dependencies

```bash
$ npm run autod
```

### Show list of examples

```bash
Expand Down
14 changes: 14 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

test() {
echo "Test $1"
cd $1
pwd
rm -rf node_modules package-lock.json
npm install --registry=https://registry.npmmirror.com
npm run ci
cd ..
}

test helloworld
test hello-tegg
1 change: 1 addition & 0 deletions hello-tegg/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ test/**/*.map
config/**/*.map
*.d.ts
*.tsbuildinfo
.egg/
2 changes: 1 addition & 1 deletion hello-tegg/app/middleware/trace_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { EggContext, Next } from '@eggjs/tegg';

export async function traceMethod(ctx: EggContext, next: Next) {
await next();
ctx.body.data.message += ` (${ctx.method})`;
(ctx.body as any).data.message += ` (${ctx.method})`;
}
5 changes: 3 additions & 2 deletions hello-tegg/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EggAppConfig, PowerPartial } from 'egg';
import { EggAppConfig } from 'egg';
// import { EggAppConfig, PowerPartial } from 'egg';

export default (appInfo: EggAppConfig) => {
const config = {} as PowerPartial<EggAppConfig>;
const config = {} as EggAppConfig;

// override config from framework / plugin
config.keys = appInfo.name + '123456';
Expand Down
5 changes: 3 additions & 2 deletions hello-tegg/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EggPlugin } from 'egg';
// import { EggPlugin } from 'egg';

const plugin: EggPlugin = {
// const plugin: EggPlugin = {
const plugin = {
tegg: {
enable: true,
package: '@eggjs/tegg-plugin',
Expand Down
36 changes: 19 additions & 17 deletions hello-tegg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@
"private": true,
"description": "tegg application example",
"scripts": {
"start": "egg-scripts start",
"stop": "egg-scripts stop",
"start": "eggctl start --daemon",
"stop": "eggctl stop",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test-local": "egg-bin test",
"test": "npm run lint -- --fix && npm run test-local",
"cov": "egg-bin cov",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"tsc": "tsc -p tsconfig.json",
"ci": "npm run lint && npm run cov && npm run tsc",
"preci": "npm run lint",
"ci": "egg-bin cov",
"postci": "npm run tsc && npm run clean",
"lint": "eslint .",
"clean": "tsc -b --clean"
"clean": "tsc -b --clean",
"prepublishOnly": "npm run clean && tsc"
},
"egg": {
"typescript": true
},
"license": "MIT",
"dependencies": {
"@eggjs/scripts": "^4.0.0",
"@eggjs/tegg": "^3.2.1",
"@eggjs/tegg-config": "^3.1.0",
"@eggjs/tegg-controller-plugin": "^3.2.1",
"@eggjs/tegg-plugin": "^3.2.1",
"@eggjs/tsconfig": "^1.2.0",
"@eggjs/tegg-config": "^3.1.0",
"egg": "^3.9.1",
"egg-scripts": "^2.17.0"
"egg": "beta"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^16.18.10",
"egg-bin": "^6.0.0",
"egg-mock": "^5.4.0",
"eslint": "^8.30.0",
"eslint-config-egg": "^12.1.0",
"typescript": "^4.9.4"
"@types/mocha": "10",
"@types/node": "22",
"@eggjs/bin": "7",
"@eggjs/mock": "6",
"eslint": "8",
"eslint-config-egg": "14",
"typescript": "5"
},
"repository": "[email protected]:eggjs/examples.git"
}
9 changes: 5 additions & 4 deletions hello-tegg/test/biz/HelloService.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Context } from 'egg';
import assert from 'assert';
import { app } from 'egg-mock/bootstrap';
import { strict as assert } from 'node:assert';
// import { EggContext } from 'egg';
import { app } from '@eggjs/mock/bootstrap';
import { HelloService } from '../../app/biz/HelloService';

describe('test/biz/HelloService.test.ts', () => {
let ctx: Context;
let ctx: any;
// let ctx: EggContext;
let helloService: HelloService;

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions hello-tegg/test/controller/HelloController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from 'egg-mock/bootstrap';
import assert from 'assert';
import { strict as assert } from 'node:assert';
import { app } from '@eggjs/mock/bootstrap';

describe('test/controller/HelloController.test.ts', () => {
it('should work', async () => {
Expand Down
13 changes: 11 additions & 2 deletions hello-tegg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"baseUrl": "./"
}
"baseUrl": ".",
"strict": true,
"noImplicitAny": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": false
},
"exclude": [
"test"
]
}
6 changes: 6 additions & 0 deletions helloworld/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
2 changes: 2 additions & 0 deletions helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.js
13 changes: 0 additions & 13 deletions helloworld/app/controller/foo.js

This file was deleted.

11 changes: 11 additions & 0 deletions helloworld/app/controller/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Controller } from 'egg';

export default class FooController extends Controller {
async render() {
const ctx = this.ctx;
ctx.status = 400;
ctx.body = {
foo: 'bar',
};
}
}
13 changes: 0 additions & 13 deletions helloworld/app/controller/home.js

This file was deleted.

8 changes: 8 additions & 0 deletions helloworld/app/controller/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Controller } from 'egg';

export default class HomeController extends Controller {
async render() {
const ctx = this.ctx;
ctx.body = 'Hello World';
}
}
4 changes: 2 additions & 2 deletions helloworld/app/router.js → helloworld/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { Application } from 'egg';

module.exports = app => {
export default (app: Application) => {
app.router.get('/', app.controller.home.render);
app.router.get('/foo', app.controller.foo.render);
};
3 changes: 0 additions & 3 deletions helloworld/config/config.default.js

This file was deleted.

5 changes: 5 additions & 0 deletions helloworld/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { EggAppConfig } from 'egg';

export default {
keys: 'my secret keys',
} as EggAppConfig;
27 changes: 22 additions & 5 deletions helloworld/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
{
"name": "helloworld",
"dependencies": {
"egg": "^1.10.1"
"@eggjs/scripts": "^4.0.0",
"egg": "beta"
},
"devDependencies": {
"egg-bin": "^4.3.5",
"egg-mock": "^3.13.1"
"@eggjs/bin": "7",
"@eggjs/mock": "6",
"@eggjs/tsconfig": "1",
"@types/mocha": "10",
"@types/node": "22",
"eslint": "8",
"eslint-config-egg": "14",
"typescript": "5"
},
"scripts": {
"start": "eggctl start --daemon",
"stop": "eggctl stop",
"lint": "eslint . --ext .ts",
"predev": "npm run clean && npm run lint -- --fix",
"dev": "egg-bin dev",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"cov": "egg-bin cov"
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"clean": "tsc -b --clean",
"prepublishOnly": "npm run clean && tsc"
},
"private": true
"private": true,
"repository": "[email protected]:eggjs/examples.git"
}
29 changes: 0 additions & 29 deletions helloworld/test/index.test.js

This file was deleted.

Loading
Loading