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: update to new egg-bin #63

Merged
merged 11 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions hackernews-async-ts/.autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = {
],
dep: [
'egg',
'egg-scripts',
'egg-view-nunjucks',
'moment',
'source-map-support',
],
devdep: [
'autod',
Expand Down
3 changes: 3 additions & 0 deletions hackernews-async-ts/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

coverage/
**/*.d.ts
7 changes: 7 additions & 0 deletions hackernews-async-ts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个干掉, eslint 也干掉,先保持 tslint 吧

"extends": "eslint-config-egg",
"parser": "typescript-eslint-parser",
"plugins": [
"typescript"
]
}
84 changes: 16 additions & 68 deletions hackernews-async-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,71 +1,19 @@
logs/
npm-debug.log
node_modules/
coverage/
.idea/
run/
logs/
.DS_Store
.vscode
*.swp
*.lock
*.js

app/**/*.js
test/**/*.js
config/**/*.js
*.map
run
logs

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


# End of https://www.gitignore.io/api/node
app/**/*.map
test/**/*.map
config/**/*.map
5 changes: 3 additions & 2 deletions hackernews-async-ts/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"files.exclude": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 这个文件可以干掉?
  • 另外,只注释 when 没用的,要把 **/*.js 也注释才生效,否则是全隐藏

"USE_GITIGNORE": true,
"**/*.js": {
"when": "$(basename).ts"
// "when": "$(basename).ts"
},
"**/*.map": true,
"run": true,
"logs": true,
"out": true,
"node_modules": true
}
},
"typescript.tsdk": "node_modules/typescript/lib"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个用处是? 是不是可以直接加到 tsconfig.json 的?

}
6 changes: 0 additions & 6 deletions hackernews-async-ts/app/controller/index.d.ts

This file was deleted.

11 changes: 6 additions & 5 deletions hackernews-async-ts/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Application } from 'egg';

export default (app: Application) => {
const controller = app.controller;
app.redirect('/', '/news');
app.router.get('/news', controller.news.list);
app.router.get('/news/item/:id', controller.news.detail);
app.router.get('/news/user/:id', controller.news.user);
const { controller, router } = app;

// router.redirect('/', '/news');
router.get('/news', controller.news.list);
router.get('/news/item/:id', controller.news.detail);
router.get('/news/user/:id', controller.news.user);
};
6 changes: 0 additions & 6 deletions hackernews-async-ts/app/service/index.d.ts

This file was deleted.

25 changes: 25 additions & 0 deletions hackernews-async-ts/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
import { EggAppConfig } from 'egg';
import * as fs from 'fs';
import * as path from 'path';

export default (appInfo: EggAppConfig) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EggAppInfo 的那个改改,这里不对

return {
keys: appInfo.name + '123456',
siteFile: {
'/favicon.ico': fs.readFileSync(
path.join(appInfo.baseDir, 'app/public/favicon.png'),
),
},
view: {
defaultViewEngine: 'nunjucks',
mapping: {
'.tpl': 'nunjucks',
},
},
news: {
pageSize: 30,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这几个地方都加注释的话,是否能 IDE 提示?

serverUrl: 'https://hacker-news.firebaseio.com/v0',
},
};
};
3 changes: 3 additions & 0 deletions hackernews-async-ts/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const info = {
msg: 'hello',
};
5 changes: 5 additions & 0 deletions hackernews-async-ts/config/config.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
info: {
msg: 'hello',
},
};
26 changes: 0 additions & 26 deletions hackernews-async-ts/config/config.ts

This file was deleted.

14 changes: 0 additions & 14 deletions hackernews-async-ts/config/defaultConfig.ts

This file was deleted.

15 changes: 15 additions & 0 deletions hackernews-async-ts/config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EggAppConfig } from 'egg';
import defaultConfig from './config.default';
import * as localConfig from './config.local';
import prodConfig from './config.prod';

type DefaultConfig = ReturnType<typeof defaultConfig>;
type LocalConfig = typeof localConfig;
type ProdConfig = typeof prodConfig;
type NewAppConfig = EggAppConfig & DefaultConfig & LocalConfig & ProdConfig;

declare module 'egg' {
interface Application {
config: NewAppConfig;
}
}
41 changes: 25 additions & 16 deletions hackernews-async-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "1.0.0",
"description": "hackernews showcase using async/await for egg",
"private": true,
"egg": {
"typescript": true
},
"dependencies": {
"egg": "^2.0.0",
"egg-view-nunjucks": "^2.1.4",
"moment": "^2.19.4",
"source-map-support": "^0.5.0",
"tslib": "^1.8.1",
"typescript": "^2.6.2"
"egg": "^2.5.0",
"egg-scripts": "^2.5.1",
"egg-view-nunjucks": "^2.2.0",
"moment": "^2.21.0",
"source-map-support": "^0.5.4"
},
"devDependencies": {
"@types/cheerio": "^0.22.1",
Expand All @@ -19,25 +21,32 @@
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"cheerio": "^1.0.0-rc.2",
"egg-bin": "^4.3.7",
"egg-mock": "^3.14.0",
"egg-bin": "^4.6.0",
"egg-mock": "^3.16.0",
"egg-ts-helper": "^1.1.3",
"eslint": "^4.19.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint 干掉

"eslint-config-egg": "^7.0.0",
"eslint-plugin-typescript": "^0.11.0",
"rimraf": "^2.6.1",
"tslint": "^4.0.0"
"tslib": "^1.8.1",
"tslint": "^4.0.0",
"typescript": "^2.6.2",
"typescript-eslint-parser": "^14.0.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

干掉

},
"engines": {
"node": ">=8.9.0"
},
"scripts": {
"clean": "rimraf app/**/*.{js,map} test/**/*.{js,map} config/**/*.{js,map}",
"tsc": "tsc -p tsconfig.json",
"tsc:w": "tsc -p tsconfig.json -w",
"debug": "egg-bin debug",
"dev": "egg-bin dev",
"test": "npm run tsc && npm run test-local",
"test-local": "egg-bin test",
"start": "egg-scripts start",
"dev": "egg-bin dev -r 'egg-ts-helper/register'",
"tsc": "ets && tsc -p tsconfig.json",
"clean": "rimraf ./app.js ./agent.js ./{app,test,config}/**/*.{js,map}",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换为 ets clean

"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test -r 'egg-ts-helper/register'",
"cov": "egg-bin cov",
"lint": "tslint .",
"ci": "npm run lint && npm run cov",
"debug": "egg-bin debug",
"autod": "autod"
}
}
12 changes: 1 addition & 11 deletions hackernews-async-ts/test/app/controller/news.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
'use strict';

import * as assert from 'assert';
import * as cheerio from 'cheerio';
import mm from 'egg-mock';
import { app, assert } from 'egg-mock/bootstrap';

describe('test/app/controller/news.test.ts', () => {
const app = mm.app();
before(async () => {
await app.ready();
});

after(() => app.close());

afterEach(mm.restore);

it('should GET /news', async () => {
const result = await app.httpRequest().get('/news').expect(200);
const $ = cheerio.load(result.text);
Expand Down
8 changes: 1 addition & 7 deletions hackernews-async-ts/test/app/service/HackerNews.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
'use strict';

import * as assert from 'assert';
import { Context } from 'egg';
import mm from 'egg-mock';
import { app, assert } from 'egg-mock/bootstrap';

describe('test/app/service/HackerNews.test.js', () => {
const app = mm.app();
let ctx: Context;

before(async () => {
await app.ready();
ctx = app.mockContext();
});

after(() => app.close());
afterEach(mm.restore);

it('getTopStories', async () => {
const list = await ctx.service.hackerNews.getTopStories();
assert(list.length === 30);
Expand Down
7 changes: 2 additions & 5 deletions hackernews-async-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"strict": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
Expand All @@ -14,17 +15,13 @@
"noUnusedParameters": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"inlineSourceMap": true,
"importHelpers": true
},
"include": [
"app/**/*",
"config/**/*",
"test/**/*.ts"
],
"exclude": [
"app/public",
"app/views"
Expand Down
Loading