forked from eggjs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TypeScript framework-ts example
need commits of eggjs/egg#2321
- Loading branch information
1 parent
207d223
commit 9b8eefc
Showing
23 changed files
with
971 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
install: | ||
- npm i npminstall && npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hi, {{ name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "framework-ts-example", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"egg": "^2.6.0", | ||
"egg-scripts": "^2.6.0", | ||
"yadan-ts": "../yadan" | ||
}, | ||
"devDependencies": { | ||
"egg-bin": "^4.3.5", | ||
"egg-mock": "^3.13.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.10.0" | ||
}, | ||
"scripts": { | ||
"autod": "autod", | ||
"clean": "rimraf app/**/*.{js,map} test/**/*.{js,map} config/**/*.{js,map}", | ||
"ci": "npm run lint && npm run cov", | ||
"cov": "egg-bin cov", | ||
"debug": "egg-bin debug", | ||
"dev": "egg-bin dev", | ||
"lint": "tslint --fix -p tsconfig.json -t stylish", | ||
"test": "npm run tsc && npm run test-local", | ||
"test-local": "egg-bin test", | ||
"start": "egg-scripts start --daemon --port=7001 --title=egg-win-test --workers=2", | ||
"stop": "egg-scripts stop --title=egg-win-test", | ||
"tsc": "tsc -p tsconfig.json", | ||
"tsc:w": "tsc -p tsconfig.json -w" | ||
}, | ||
"egg": { | ||
"framework": "yadan-ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
"charset": "utf8", | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"importHelpers": false, | ||
"inlineSourceMap": true, | ||
"module": "commonjs", /* 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ | ||
"newLine": "lf", | ||
"noFallthroughCasesInSwitch": true, | ||
// "outDir": "./dist", | ||
"pretty": true, | ||
"skipLibCheck": true, | ||
"sourceMap": false, | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
// "noImplicitAny": false, | ||
// "noImplicitThis": false, | ||
"target": "ES2017", | ||
"types" : ["node"] | ||
}, | ||
"include": [ | ||
"app/**/*.ts", | ||
"config/**/*.ts", | ||
"test/**/*.ts" | ||
], | ||
"exclude": [ | ||
"app/public", | ||
"app/views", | ||
"node_modules", | ||
"**/*.d.ts", | ||
"**/*.spec.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
{ | ||
"extends": ["tslint:latest", "tslint-eslint-rules"], | ||
"linterOptions": { | ||
"exclude": [ | ||
"node_modules", | ||
"*.d.ts" | ||
] | ||
}, | ||
"rules": { | ||
"adjacent-overload-signatures": true, | ||
"align": [true, "members", "parameters", "statements"], | ||
"array-bracket-spacing": [true, "never", {"singleValue": false, "objectsInArrays": true, "arraysInArrays": true} ], // 设置在括号内使用空格风格 | ||
"arrow-parens": [true, "ban-single-arg-parens"], | ||
"await-promise": [true, "Thenable"], // Warns for an awaited value that is not a Promise. | ||
"ban-comma-operator": true, | ||
"block-spacing": [true, "always"], // 强制在单行代码块中使用一致的空格 | ||
"brace-style": [true, "stroustrup", { "allowSingleLine": true }], // 大括号风格要求 | ||
"comment-format": [true, "check-space", {"ignore-words": ["-", "+"]}], // 强制在注释中 // 或 /* 使用一致的空格 | ||
"curly": [true, "ignore-same-line"], // 要求遵循大括号约定 | ||
"eofline": true, | ||
"forin": false, | ||
"import-blacklist": [ | ||
true, | ||
"rxjs", | ||
"rxjs/Rx" | ||
], | ||
"indent": [true, "spaces", 2], | ||
"interface-name": [ false, "never-prefix" ], | ||
"linebreak-style": [true , "LF" ], | ||
"max-classes-per-file": [ true, 10 ], | ||
"max-line-length": [true, 120], | ||
"member-access": [ false ], | ||
"member-ordering": [true, {"order": [ | ||
"public-static-field", | ||
"public-instance-field", | ||
"public-constructor", | ||
"private-static-field", | ||
"private-instance-field", | ||
"private-constructor", | ||
"public-instance-method", | ||
"protected-instance-method", | ||
"private-instance-method" | ||
]}], | ||
"no-arg": true, | ||
"no-angle-bracket-type-assertion": false, | ||
"no-consecutive-blank-lines": [true, 4], // 多个空行控制 | ||
"no-console": [ true, "dir", "log", "warn" ], | ||
"no-construct": true, // 禁止对 String,Number 和 Boolean 使用 new 操作符 | ||
"no-control-regex": true, | ||
"no-duplicate-variable": true, | ||
"no-duplicate-imports": true, // 禁止单个模块多次导入 | ||
"no-duplicate-switch-case": true, | ||
"no-empty": false, // 禁止空块语句 | ||
"no-extra-semi": true, | ||
"no-eval": true, | ||
"no-implicit-dependencies": [true, "dev"], | ||
"no-multi-spaces": [ true, { "exceptions": { "PropertyAssignment": true, "VariableDeclaration": false } } ] , // 禁止出现多个空格 | ||
"no-object-literal-type-assertion": false, | ||
"no-parameter-reassignment": false, // 禁止参数变量重新赋值 | ||
"no-return-await": true, | ||
"no-reference": true, // Disallows /// <reference path=> imports (use ES6-style imports instead). | ||
"no-shadowed-variable": [ | ||
true, | ||
{ | ||
"class": true, | ||
"enum": true, | ||
"function": true, | ||
"interface": true, | ||
"namespace": true, | ||
"typeAlias": true, | ||
"typeParameter": true | ||
} | ||
], | ||
"no-string-throw": true, | ||
"no-submodule-imports": [true, | ||
"rxjs", | ||
"@angular/platform-browser", | ||
"source-map-support/register" | ||
], | ||
"no-trailing-whitespace": [true, "ignore-comments"], // 禁用行尾空白 | ||
"no-unnecessary-initializer": true, // 禁止变量赋值为 undefined | ||
"no-unused-expression": [true, "allow-fast-null-checks"], | ||
"no-unused-variable": { | ||
"severity": "warning", | ||
"options": [true, { "ignore-pattern": "^_" }] | ||
}, | ||
"no-unnecessary-type-assertion": false, | ||
"no-use-before-declare": true, // 禁止在变量定义之前使用它们 | ||
"no-var-keyword": true, // 要求使用 let 或 const 而不是 var | ||
"no-var-requires": true, // Disallows the use of require statements except in import statements. | ||
"object-curly-spacing": [true, "always"], // 强制在大括号中使用一致的空格 | ||
"object-literal-shorthand": [true], | ||
"object-literal-sort-keys": false, | ||
"one-line": [true, "check-open-brace", "check-whitespace"], | ||
"ordered-imports": [ | ||
true, | ||
{ | ||
"grouped-imports": true, | ||
"import-sources-order": "lowercase-last", | ||
"named-imports-order": "lowercase-first" | ||
} | ||
], | ||
"prefer-for-of": true, | ||
"quotemark": [true, "single", "avoid-escape", "avoid-template"], | ||
"radix": true, | ||
"semicolon": [true, "never"], | ||
"space-before-function-paren": [ | ||
true, | ||
{"anonymous": "always", "named": "never"} | ||
], | ||
"ter-arrow-spacing": [true, { "before": true, "after": true }], // 要求箭头函数的箭头之前或之后有空格 | ||
"ter-func-call-spacing": [true, "never"], // disallow spacing between function identifiers and their invocations | ||
"ter-indent": [true, 2, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"ter-no-irregular-whitespace": true, // 禁止不规则的空白 | ||
"trailing-comma": [true, | ||
{ | ||
"multiline": { | ||
"arrays": "always", | ||
"exports": "always", | ||
"imports": "always", | ||
"functions": "never", | ||
"objects": "always", | ||
"typeLiterals": "always" | ||
}, | ||
"singleline": "never", | ||
"esSpecCompliant": true | ||
} | ||
], // 当最后一个元素或属性与闭括号 ] 或 右大括号 在 不同的行时,要求使用拖尾逗号;当在 同一行时,禁止使用拖尾逗号 | ||
"triple-equals": true, | ||
"use-isnan": true, // 要求使用 isNaN() 检查 NaN | ||
"valid-typeof": true, // 强制 typeof 表达式与有效的字符串进行比较 | ||
"variable-name": [true, "ban-keywords", "allow-leading-underscore"], | ||
"whitespace": { | ||
"options": [true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-separator", | ||
"check-rest-spread", | ||
"check-type", | ||
"check-typecast", | ||
"check-type-operator", | ||
"check-preblock"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# /node_modules/* and /bower_components/* ignored by default | ||
|
||
**/*.min.js | ||
.git/* | ||
bin/* | ||
doc/* | ||
src/* |
Oops, something went wrong.