Skip to content

Commit

Permalink
feat(boilerplate): add midway-ts-strict-boilerplate
Browse files Browse the repository at this point in the history
- use `TypeScript ESlint` instead of `TSlint`
- enable more strict lint rules
- use ng filename style,  `file.{controller|service|model}.ts`
- no use of Prettier cause of the ugly breakBeforeElse style and the team won't add options for other style

refs:
- [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)
- [TSLint will be deprecated](palantir/tslint#4534)
- [Eslint: Migrating to v6.0.0](https://eslint.org/docs/user-guide/migrating-to-6.0.0#package-loading-simplification)
  • Loading branch information
waitingsong committed Jul 7, 2019
1 parent a9114d3 commit 8ee325c
Show file tree
Hide file tree
Showing 28 changed files with 583 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/midway-init/boilerplate/boilerplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"description": "Simple example boilerplate for find bug or submit to midway-examples",
"name": "midway mini example template"
},
"midway-ts-strict": {
"package": "midway-ts-strict-boilerplate",
"description": "Simple midway application boilerplate by ts with ng style and strict eslint rules",
"name": "midway strict typescript template"
},
"midway-ts-ant-design-pro": {
"package": "midway-ts-ant-design-pro-boilerplate",
"description": "A front-end and back-end separation project includes midway(ts) and ant-design-pro.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends: '@waiting/eslint-config'

# https://eslint.org/docs/rules/
# https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
#rules:

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Midway Debug",
"type": "node",
"autoAttachChildProcesses": true,
"console": "integratedTerminal",
"env": {
"NODE_ENV": "local"
},
"port": 9229,
"preLaunchTask": "TypeScript compile",
"protocol": "auto",
"request": "launch",
"restart": true,
"runtimeArgs": [
"run",
"debug",
"--",
"--inspect-brk"
],
"runtimeExecutable": "npm",
"skipFiles": [
// "${workspaceFolder}/node_modules/**/*.js",
"${workspaceFolder}/node_modules/rxjs/**/*.js",
"<node_internals>/**/*.js"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"editor.tabSize": 2,
"editor.wordWrap": "on",
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"html",
{
"language": "typescript",
"autoFix": true
},
"typescriptreact"
],
"files.insertFinalNewline": true,
"files.eol": "\n",
"files.exclude": {
"USE_GITIGNORE": true,
"**/*.js": {
"when": "$(basename).ts"
},
"**/*.map": true,
"**/*.swp": true,
"**/.git": true,
"**/.DS_Store": true,
".build": true,
".dockerignore": true,
".eslint*": true,
".editorconfig": true,
".git": true,
".gitignore": true,
".githooks": true,
".npmignore": true,
".nyc_output": true,
".sourcemaps": true,
".travis.yml": true,
".vscode": true,
"appveyor.yml": true,
"commitlint.config.js": true,
"coverage": true,
"dist": true,
"logs": true,
"node_modules*": true,
"out": true,
"package-lock.json": true,
"platforms": true,
"rollup.config.js": true,
"run": true,
"tslint.json": true
},
"files.watcherExclude": {
"**/.classpath": true,
"**/.factorypath": true,
"**/.git/objects/**": true,
"**/.project": true,
"**/.settings": true,
"**/node_modules/**": true,
"**/node_modules*/**": true,
"coverage/**": true,
"dist/**": true
},
"files.trimTrailingWhitespace": true,
"search.exclude": {
"**/node_modules": true,
".vscode/**": true,
".build/**": true,
"dist/": true,
"out/**": true,
"i18n/**": true
},
"[markdown]": {
"files.trimTrailingWhitespace": false
},
"telemetry.enableTelemetry": false,
"typescript.format.enable": true,
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"typescript.format.insertSpaceAfterTypeAssertion": true,
"typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"git.ignoreLimitWarning": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"label": "TypeScript compile",
"command": "tsc",
"args": [
"-p",
"."
],
"problemMatcher": [
"$tsc"
],
"type": "shell"
},
{
"label": "watch",
"command": "tsc",
"args": [
"-w",
"-p",
"."
],
"isBackground": true,
"problemMatcher": [
"$tsc-watch"
],
"type": "shell"
},
{
// Ctrl+Shift+B
"type": "npm",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": [
"$eslint-stylish",
"$tsc",
"$tslint5"
],
"script": "build"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# {{name}}

{{description}}

## QuickStart

<!-- add docs here for user -->

see [midway docs][midway] for more detail.

### Development

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

### Deploy

```bash
$ npm start
$ npm stop
```

### npm scripts

- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.


[midway]: https://midwayjs.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# {{name}}

{{description}}

## 快速入门

<!-- 在此次添加使用文档 -->

如需进一步了解,参见 [midway 文档][midway]

### 本地开发

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

### 部署

```bash
$ npm start
$ npm stop
```

### 单元测试

- [midway-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。
- 断言库非常推荐使用 [power-assert]
- 具体参见 [midway 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)

### 内置指令

- 使用 `npm run lint` 来做代码风格检查。
- 使用 `npm test` 来执行单元测试。
- 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod)


[midway]: https://midwayjs.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "{{name}}",
"version": "1.0.0",
"description": "{{description}}",
"private": true,
"dependencies": {
"midway": "^1.0.0",
"egg-scripts": "^2.10.0"
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.5.5",
"@typescript-eslint/eslint-plugin": "^1.11.0",
"@typescript-eslint/eslint-plugin-tslint": "^1.11.0",
"@typescript-eslint/parser": "^1.11.0",
"@waiting/eslint-config": "^1.0.0",
"cross-env": "^5.2.0",
"egg-ci": "^1.8.0",
"eslint": "^6.0.0",
"eslint-plugin-import": "^2.18.0",
"midway-bin": "1",
"midway-mock": "1",
"tslib": "^1.8.1",
"ts-node": "^8.0.2",
"typescript": "^3.2.0"
},
"engines": {
"node": ">=8.9.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-{{name}} --framework=midway",
"stop": "egg-scripts stop --title=egg-server-{{name}}",
"start_build": "npm run build && cross-env NODE_ENV=development midway-bin dev",
"dev": "cross-env NODE_ENV=local midway-bin dev --ts",
"debug": "cross-env NODE_ENV=local midway-bin debug --ts",
"test": "npm run lint && midway-bin test --ts",
"cov": "midway-bin cov --ts",
"lint": "eslint --fix src/**/*.{ts,js} test/**/*.{ts,js}",
"ci": "npm run cov",
"build": "midway-bin build -c"
},
"ci": {
"version": "8, 10"
},
"repository": {
"type": "git",
"url": ""
},
"author": "{{author}}",
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// you can use this file to deploy by pandora
// please use 'npm i pandora --save' first

'use strict';

module.exports = pandora => {

/**
* default is fork mode
*/
pandora
.fork('{{name}}', require.resolve('midway/server'));

/**
* you can use cluster mode to start application
*/
// pandora
// .cluster('./cluster.js');

/**
* you can create another process here
*/
// pandora
// .process('background')
// .argv(['--expose-gc']);

/**
* more features please visit our document.
* https://github.com/midwayjs/pandora/
*/

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Context, config, controller, get, provide } from 'midway'


@provide()
@controller('/')
export class HomeController {

constructor(
@config() private readonly welcomeMsg: string,
) {}

@get('/')
public index(ctx: Context): void {
ctx.body = this.welcomeMsg
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## public static file directory!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ee325c

Please sign in to comment.