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: add TypeScript framework-ts example #68

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions framework-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Framework with TypeScript Example

This example contains [app] and [framework]

## Quick Start

Start an application using custom framework called yadan

```bash
$ cd yadan
$ npm install
$ npm run tsc
$ cd ../app
$ npm install
$ npm run tsc
$ npm run dev
```

Yadan is a framework by TypeScript, it should be published to npm normally. With this example, you need `npm run tsc`.

## Run Test

Application

```bash
$ cd app
$ npm run tsc
$ npm test
```

Framework

```bash
$ cd yadan
$ npm run tsc
$ npm test
```

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

[app]: https://github.com/eggjs/examples/tree/master/framework-ts/app
[framework]: https://github.com/eggjs/examples/tree/master/framework-ts/yadan
11 changes: 11 additions & 0 deletions framework-ts/app/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo: false
language: node_js
node_js:
- '8'
install:
- npm i -g ts-node
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
24 changes: 24 additions & 0 deletions framework-ts/app/app/controller/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, Service } from 'yadan-ts'

export default class HomeController extends Controller {
async render() {
const { ctx } = this

// use service defined in framework
const data = await ctx.service.test.get(123);
await ctx.render('home.tpl', data);
}
}

declare module 'egg' {
export interface IController {
home: HomeController;
}
}

// @FIXME
declare module 'egg' {
export interface IService {
test: any
}
}
203 changes: 203 additions & 0 deletions framework-ts/app/app/public/css/news.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
body,
html {
font-family: Verdana;
font-size: 13px;
height: 100%
}
ul {
list-style-type: none;
padding: 0;
margin: 0
}
a {
color: #000;
cursor: pointer;
text-decoration: none
}
#wrapper {
background-color: #f6f6ef;
width: 85%;
min-height: 80px;
margin: 0 auto
}
#header,
#wrapper {
position: relative
}
#header {
background-color: #f60;
height: 24px
}
#header h1 {
font-weight: 700;
font-size: 13px;
display: inline-block;
vertical-align: middle;
margin: 0
}
#header .source {
color: #fff;
font-size: 11px;
position: absolute;
top: 4px;
right: 4px
}
#header .source a {
color: #fff
}
#header .source a:hover {
text-decoration: underline
}
#yc {
border: 1px solid #fff;
margin: 2px;
display: inline-block
}
#yc,
#yc img {
vertical-align: middle
}
.view {
position: absolute;
background-color: #f6f6ef;
width: 100%;
-webkit-transition: opacity .2s ease;
transition: opacity .2s ease;
box-sizing: border-box;
padding: 8px 20px
}
.view.v-enter,
.view.v-leave {
opacity: 0
}
@media screen and (max-width: 700px) {
body,
html {
margin: 0
}
#wrapper {
width: 100%
}
}
.news-view {
padding-left: 5px;
padding-right: 15px
}
.news-view.loading:before {
content: "Loading...";
position: absolute;
top: 16px;
left: 20px
}
.news-view .nav {
padding: 10px 10px 10px 40px;
margin-top: 10px;
border-top: 2px solid #f60
}
.news-view .nav a {
margin-right: 10px
}
.news-view .nav a:hover {
text-decoration: underline
}
.item {
padding: 2px 0 2px 40px;
position: relative;
-webkit-transition: background-color .2s ease;
transition: background-color .2s ease
}
.item p {
margin: 2px 0
}
.item .index,
.item .title:visited {
color: #828282
}
.item .index {
position: absolute;
width: 30px;
text-align: right;
left: 0;
top: 4px
}
.item .domain,
.item .subtext {
font-size: 11px;
color: #828282
}
.item .domain a,
.item .subtext a {
color: #828282
}
.item .subtext a:hover {
text-decoration: underline
}
.item-view .item {
padding-left: 0;
margin-bottom: 30px
}
.item-view .item .index {
display: none
}
.item-view .poll-options {
margin-left: 30px;
margin-bottom: 40px
}
.item-view .poll-options li {
margin: 12px 0
}
.item-view .poll-options p {
margin: 8px 0
}
.item-view .poll-options .subtext {
color: #828282;
font-size: 11px
}
.item-view .itemtext {
color: #828282;
margin-top: 0;
margin-bottom: 30px
}
.item-view .itemtext p {
margin: 10px 0
}
.comhead {
font-size: 11px;
margin-bottom: 8px
}
.comhead,
.comhead a {
color: #828282
}
.comhead a:hover {
text-decoration: underline
}
.comhead .toggle {
margin-right: 4px
}
.comment-content {
margin: 0 0 16px 24px;
word-wrap: break-word
}
.comment-content code {
white-space: pre-wrap
}
.child-comments {
margin: 8px 0 8px 22px
}
.user-view {
color: #828282
}
.user-view li {
margin: 5px 0
}
.user-view .label {
display: inline-block;
min-width: 60px
}
.user-view .about {
margin-top: 1em
}
.user-view .links a {
text-decoration: underline
}
Binary file added framework-ts/app/app/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions framework-ts/app/app/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Application } from 'egg'

export default (app: Application) => {
const controller = app.controller

app.router.get('/', app.controller.home.render);
}
1 change: 1 addition & 0 deletions framework-ts/app/app/view/home.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi, {{ name }}
15 changes: 15 additions & 0 deletions framework-ts/app/appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
environment:
matrix:
- nodejs_version: '8'

install:
- ps: Install-Product node $env:nodejs_version
- npm i -g ts-node
- npm i npminstall && node_modules\.bin\npminstall

test_script:
- node --version
- npm --version
- npm run test

build: off
29 changes: 29 additions & 0 deletions framework-ts/app/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { EggAppConfig, PowerPartial } from 'egg';

// for config.{env}.ts
export type DefaultConfig = PowerPartial<EggAppConfig & BizConfig>;

// app special config scheme
export interface BizConfig {
sourceUrl: string;
news: {
pageSize: number;
serverUrl: string;
};
}

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

// app special config
config.sourceUrl = `https://github.com/eggjs/examples/tree/master/${appInfo.name}`;
config.news = {
pageSize: 30,
serverUrl: 'https://hacker-news.firebaseio.com/v0',
};

// override config from framework / plugin
config.keys = appInfo.name + '123456';

return config;
};
9 changes: 9 additions & 0 deletions framework-ts/app/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DefaultConfig } from './config.default';

export default () => {
const config: DefaultConfig = {};
config.news = {
pageSize: 20,
};
return config;
};
9 changes: 9 additions & 0 deletions framework-ts/app/config/config.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DefaultConfig } from './config.default';

export default () => {
const config: DefaultConfig = {};
config.news = {
pageSize: 30,
};
return config;
};
3 changes: 3 additions & 0 deletions framework-ts/app/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

export default {
};
Loading