Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
wmui committed Jul 4, 2023
1 parent e799c8b commit acede19
Show file tree
Hide file tree
Showing 122 changed files with 4,405 additions and 3,975 deletions.
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion .env

This file was deleted.

24 changes: 0 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 0 additions & 3 deletions .vscode/extensions.json

This file was deleted.

13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Vue 3 + Vite
# platform

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)

### TODO

1. 为什么icon组件在jsx中不用注册可以直接使用
2. Modal的icon属性,直接使用图标组件实现原理
开发中
2 changes: 2 additions & 0 deletions backend/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.d.ts
node_modules/
4 changes: 4 additions & 0 deletions backend/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": "eslint-config-egg/typescript"
}
20 changes: 20 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
logs/
npm-debug.log
node_modules/
coverage/
.idea/
run/
logs/
.DS_Store
.vscode
*.swp
*.lock
*.js
.eslintcache

app/**/*.js
test/**/*.js
config/**/*.js
app/**/*.map
test/**/*.map
config/**/*.map
33 changes: 33 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# hackernews-tegg

[Hacker News](https://news.ycombinator.com/) showcase using [tegg](https://github.com/eggjs/tegg)

## QuickStart

### Development

```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```

Don't tsc compile at development mode, if you had run `tsc` then you need to `npm run clean` before `npm run dev`.

### Deploy

```bash
$ npm run tsc
$ npm start
```

### Npm Scripts

- Use `npm run lint` to check code style
- Use `npm test` to run unit test
- se `npm run clean` to clean compiled js at development mode once

### Requirement

- Node.js >= 16.x
- Typescript >= 4.x
19 changes: 19 additions & 0 deletions backend/app/module/bar/controller/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EggLogger } from 'egg';
import { Inject, HTTPController, HTTPMethod, HTTPMethodEnum } from '@eggjs/tegg';

@HTTPController({
path: '/',
})
export class HomeController {
@Inject()
logger: EggLogger;

@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/',
})
async index() {
this.logger.info('hello egg logger');
return 'hello egg';
}
}
18 changes: 18 additions & 0 deletions backend/app/module/bar/controller/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Inject, HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQuery } from '@eggjs/tegg';
import { HelloService } from '@/module/foo';

@HTTPController({
path: '/bar',
})
export class UserController {
@Inject()
helloService: HelloService;

@HTTPMethod({
method: HTTPMethodEnum.GET,
path: 'user',
})
async user(@HTTPQuery({ name: 'userId' }) userId: string) {
return await this.helloService.hello(userId);
}
}
6 changes: 6 additions & 0 deletions backend/app/module/bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "bar",
"eggModule": {
"name": "bar"
}
}
1 change: 1 addition & 0 deletions backend/app/module/foo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { HelloService } from './service/HelloService';
6 changes: 6 additions & 0 deletions backend/app/module/foo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "foo",
"eggModule": {
"name": "foo"
}
}
19 changes: 19 additions & 0 deletions backend/app/module/foo/service/HelloService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EggLogger } from 'egg';
import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg';

@SingletonProto({
// 如果需要在上层使用,需要把 accessLevel 显示声明为 public
accessLevel: AccessLevel.PUBLIC,
})
export class HelloService {
// 注入一个 logger
@Inject()
logger: EggLogger;

// 封装业务
async hello(userId: string): Promise<string> {
const result = { userId, handledBy: 'foo module' };
this.logger.info('[hello] get result: %j', result);
return `hello, ${result.userId}`;
}
}
23 changes: 23 additions & 0 deletions backend/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

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

// override config from framework / plugin
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1688441299648_5441';

// add your egg config in here
config.middleware = [];

// add your special config in here
const bizConfig = {
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
};

// the return config will combines to EggAppConfig
return {
...config,
...bizConfig,
};
};
6 changes: 6 additions & 0 deletions backend/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';

export default () => {
const config: PowerPartial<EggAppConfig> = {};
return config;
};
6 changes: 6 additions & 0 deletions backend/config/config.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';

export default () => {
const config: PowerPartial<EggAppConfig> = {};
return config;
};
34 changes: 34 additions & 0 deletions backend/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { EggPlugin } from 'egg';

const plugin: EggPlugin = {
tegg: {
enable: true,
package: '@eggjs/tegg-plugin',
},
teggConfig: {
enable: true,
package: '@eggjs/tegg-config',
},
teggController: {
enable: true,
package: '@eggjs/tegg-controller-plugin',
},
teggSchedule: {
enable: true,
package: '@eggjs/tegg-schedule-plugin',
},
eventbusModule: {
enable: true,
package: '@eggjs/tegg-eventbus-plugin',
},
aopModule: {
enable: true,
package: '@eggjs/tegg-aop-plugin',
},
tracer: {
enable: true,
package: 'egg-tracer',
},
};

export default plugin;
52 changes: 52 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "backend",
"version": "1.0.0",
"description": "platform backend api",
"private": true,
"egg": {
"typescript": true
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-backend",
"stop": "egg-scripts stop --title=egg-server-backend",
"dev": "egg-bin dev",
"test-local": "egg-bin test -p",
"test": "npm run lint -- --fix && npm run test-local",
"cov": "egg-bin cov -p",
"ci": "npm run lint && npm run cov && npm run tsc && npm run clean",
"lint": "eslint . --ext .ts --cache",
"tsc": "tsc",
"clean": "tsc -b --clean"
},
"dependencies": {
"@eggjs/tegg": "^3.5.2",
"@eggjs/tegg-aop-plugin": "^3.5.2",
"@eggjs/tegg-config": "^3.2.3",
"@eggjs/tegg-controller-plugin": "^3.5.2",
"@eggjs/tegg-eventbus-plugin": "^3.5.2",
"@eggjs/tegg-plugin": "^3.5.2",
"@eggjs/tegg-schedule-plugin": "^3.5.2",
"egg": "^3.15.0",
"egg-scripts": "^2.17.0",
"egg-tracer": "^2.0.0"
},
"devDependencies": {
"@types/mocha": "10",
"@types/node": "18",
"@eggjs/tsconfig": "1",
"egg-bin": "6",
"egg-mock": "5",
"eslint": "8",
"eslint-config-egg": "12",
"typescript": "4"
},
"engines": {
"node": ">=18.0.0"
},
"repository": {
"type": "git",
"url": ""
},
"author": "wmui",
"license": "MIT"
}
10 changes: 10 additions & 0 deletions backend/test/app/module/bar/controller/home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert';
import { app } from 'egg-mock/bootstrap';

describe('test/app/module/bar/controller/home.test.ts', () => {
it('should GET /', async () => {
const res = await app.httpRequest().get('/');
assert.equal(res.status, 200);
assert.equal(res.text, 'hello egg');
});
});
10 changes: 10 additions & 0 deletions backend/test/app/module/bar/controller/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert';
import { app } from 'egg-mock/bootstrap';

describe('test/app/module/bar/controller/user.test.ts', () => {
it('should GET /', async () => {
const res = await app.httpRequest().get('/bar/user').query({ userId: '20170901' });
assert.equal(res.status, 200);
assert.equal(res.text, 'hello, 20170901');
});
});
11 changes: 11 additions & 0 deletions backend/test/app/module/foo/service/HelloService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'assert';
import { app } from 'egg-mock/bootstrap';
import { HelloService } from '@/module/foo/service/HelloService';

describe('test/app/module/foo/service/HelloService.test.js', () => {
it('should hello work', async () => {
const helloService = await app.getEggObject(HelloService);
const msg = await helloService.hello('123456');
assert.equal(msg, 'hello, 123456');
});
});
10 changes: 10 additions & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"declaration": false,
"paths": {
"@/module/*": ["app/module/*"]
},
"baseUrl": "."
}
}
7 changes: 7 additions & 0 deletions backend/typings/app/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is created by egg-ts-helper@1.34.7
// Do not modify this file!!!!!!!!!
/* eslint-disable */

import 'egg';
export * from 'egg';
export as namespace Egg;
12 changes: 12 additions & 0 deletions backend/typings/config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is created by egg-ts-helper@1.34.7
// Do not modify this file!!!!!!!!!
/* eslint-disable */

import 'egg';
import { EggAppConfig } from 'egg';
import ExportConfigDefault from '../../config/config.default';
type ConfigDefault = ReturnType<typeof ExportConfigDefault>;
type NewEggAppConfig = ConfigDefault;
declare module 'egg' {
interface EggAppConfig extends NewEggAppConfig { }
}
Loading

0 comments on commit acede19

Please sign in to comment.