Skip to content

Commit

Permalink
feat: add tsconfig-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes committed Jan 7, 2019
1 parent a45662c commit 99cef31
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 29 deletions.
3 changes: 3 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Application } from 'egg';
import * as path from 'path';
import { formatDate } from '~/app/lib/utils';

export default (app: Application) => {
app.logger.info(`App started in ${formatDate(new Date())}`);

const directory = path.resolve(app.baseDir, './app/model');
app.loader.loadToApp(directory, 'model', {
caseStyle: 'upper',
Expand Down
2 changes: 2 additions & 0 deletions app/controller/home.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

import { Controller } from 'egg';
import { formatDate } from '~/app/lib/utils';

export default class HomeController extends Controller {
public async index() {
const { ctx, service } = this;
const time = service.time.today();
this.app.logger.info(ctx.app.model.User.getData());
this.app.logger.info(ctx.app.model.Castle.getData());
this.app.logger.info(`request visit in ${formatDate(new Date())}`);

if (ctx.isAjax()) {
ctx.body = { time };
Expand Down
6 changes: 6 additions & 0 deletions app/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as moment from 'moment';

export function formatDate(time: string | number | Date) {
const date = time instanceof Date ? time : new Date(time);
return moment(date).format('YYYY-MM-DD HH:mm:ss');
}
1 change: 1 addition & 0 deletions config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import 'tsconfig-paths/register';
import { EggPlugin } from 'egg';

const plugin: EggPlugin = {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"description": "egg ts boilerplate using d.ts",
"scripts": {
"start": "egg-scripts start",
"start": "npm run tsc && egg-scripts start",
"dev": "egg-bin dev",
"tsc": "ets && tsc -p tsconfig.json",
"tsc": "ets && tsc",
"clean": "ets clean",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
Expand All @@ -21,11 +21,10 @@
]
},
"dependencies": {
"@types/ioredis": "^4.0.4",
"egg": "^2.6.0",
"egg-redis": "^2.2.0",
"egg-scripts": "^2.0.0",
"moment": "^2.20.1",
"tsconfig-paths": "^3.7.0",
"tslib": "^1.8.1",
"typescript": "^3.0.0",
"uuid": "^3.2.1"
Expand All @@ -43,7 +42,8 @@
"mocha": "^4.1.0",
"trash-cli": "^1.4.0",
"ts-loader": "^3.2.0",
"tslint": "^4.0.0"
"tslint": "^4.0.0",
"tslint-config-egg": "^1.0.0"
},
"author": "whxaxes<whxaxes@gmail.com>"
}
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
"allowUnusedLabels": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
// "skipLibCheck": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true
"inlineSourceMap": true,
"baseUrl": ".",
"paths": {
"~/*": [ "./*" ]
}
}
}
23 changes: 1 addition & 22 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
{
"extends": "tslint:latest",
"rules": {
"quotemark": [true, "single", "jsx-double"],
"no-console": [true, "dir", "log", "error", "warn"],
"space-before-function-paren": false,
"interface-name": [true, "no-prefix"],
"arrow-parens": [true, "ban-single-arg-parens"],
"adjacent-overload-signatures": true,
"member-access": [false],
"object-literal-key-quotes": [true, "as-needed"],
"member-ordering": [
true,
{
"order": "fields-first"
}
],
"object-literal-sort-keys": false,
"max-classes-per-file": [true, 10],
"max-line-length": false,
"variable-name": false,
"align": [true, "statements"]
}
"extends": "tslint-config-egg"
}

0 comments on commit 99cef31

Please sign in to comment.