From 9b8eefcafb0aad51074ec35b82cf80decfd396c3 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Sat, 31 Mar 2018 19:44:18 +0800 Subject: [PATCH 01/17] feat: add TypeScript framework-ts example need commits of https://github.com/eggjs/egg/pull/2321 --- framework-ts/app/.travis.yml | 10 + framework-ts/app/app/controller/home.ts | 24 ++ framework-ts/app/app/router.ts | 7 + framework-ts/app/app/view/home.tpl | 1 + framework-ts/app/appveyor.yml | 14 ++ framework-ts/app/package.json | 34 +++ framework-ts/app/tsconfig.json | 35 +++ framework-ts/app/tslint.json | 151 ++++++++++++ framework-ts/yadan/.eslintignore | 7 + framework-ts/yadan/.gitignore | 222 ++++++++++++++++++ framework-ts/yadan/.npmignore | 16 ++ framework-ts/yadan/config/config.default.ts | 34 +++ framework-ts/yadan/config/defaultConfig.ts | 13 + framework-ts/yadan/config/plugin.ts | 6 + framework-ts/yadan/index.ts | 32 +++ framework-ts/yadan/lib/agent.ts | 11 + framework-ts/yadan/lib/application.ts | 12 + framework-ts/yadan/lib/cluster.ts | 46 ++++ framework-ts/yadan/package.json | 37 +++ framework-ts/yadan/test/lib/framework.test.ts | 42 ++++ framework-ts/yadan/test/tsconfig.json | 30 +++ framework-ts/yadan/tsconfig.json | 36 +++ framework-ts/yadan/tslint.json | 151 ++++++++++++ 23 files changed, 971 insertions(+) create mode 100644 framework-ts/app/.travis.yml create mode 100644 framework-ts/app/app/controller/home.ts create mode 100644 framework-ts/app/app/router.ts create mode 100644 framework-ts/app/app/view/home.tpl create mode 100644 framework-ts/app/appveyor.yml create mode 100644 framework-ts/app/package.json create mode 100644 framework-ts/app/tsconfig.json create mode 100644 framework-ts/app/tslint.json create mode 100644 framework-ts/yadan/.eslintignore create mode 100644 framework-ts/yadan/.gitignore create mode 100644 framework-ts/yadan/.npmignore create mode 100644 framework-ts/yadan/config/config.default.ts create mode 100644 framework-ts/yadan/config/defaultConfig.ts create mode 100644 framework-ts/yadan/config/plugin.ts create mode 100644 framework-ts/yadan/index.ts create mode 100644 framework-ts/yadan/lib/agent.ts create mode 100644 framework-ts/yadan/lib/application.ts create mode 100644 framework-ts/yadan/lib/cluster.ts create mode 100644 framework-ts/yadan/package.json create mode 100644 framework-ts/yadan/test/lib/framework.test.ts create mode 100644 framework-ts/yadan/test/tsconfig.json create mode 100644 framework-ts/yadan/tsconfig.json create mode 100644 framework-ts/yadan/tslint.json diff --git a/framework-ts/app/.travis.yml b/framework-ts/app/.travis.yml new file mode 100644 index 0000000..b735efc --- /dev/null +++ b/framework-ts/app/.travis.yml @@ -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 diff --git a/framework-ts/app/app/controller/home.ts b/framework-ts/app/app/controller/home.ts new file mode 100644 index 0000000..de3ec6f --- /dev/null +++ b/framework-ts/app/app/controller/home.ts @@ -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 + } +} diff --git a/framework-ts/app/app/router.ts b/framework-ts/app/app/router.ts new file mode 100644 index 0000000..882b97d --- /dev/null +++ b/framework-ts/app/app/router.ts @@ -0,0 +1,7 @@ +import { Application } from 'egg' + +export default (app: Application) => { + const controller = app.controller + + app.router.get('/', app.controller.home.render); +} diff --git a/framework-ts/app/app/view/home.tpl b/framework-ts/app/app/view/home.tpl new file mode 100644 index 0000000..2349c26 --- /dev/null +++ b/framework-ts/app/app/view/home.tpl @@ -0,0 +1 @@ +hi, {{ name }} \ No newline at end of file diff --git a/framework-ts/app/appveyor.yml b/framework-ts/app/appveyor.yml new file mode 100644 index 0000000..c274b7d --- /dev/null +++ b/framework-ts/app/appveyor.yml @@ -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 diff --git a/framework-ts/app/package.json b/framework-ts/app/package.json new file mode 100644 index 0000000..a269cd1 --- /dev/null +++ b/framework-ts/app/package.json @@ -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" + } +} diff --git a/framework-ts/app/tsconfig.json b/framework-ts/app/tsconfig.json new file mode 100644 index 0000000..19ff08c --- /dev/null +++ b/framework-ts/app/tsconfig.json @@ -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" + ] +} diff --git a/framework-ts/app/tslint.json b/framework-ts/app/tslint.json new file mode 100644 index 0000000..abd4a09 --- /dev/null +++ b/framework-ts/app/tslint.json @@ -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 /// 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"] + } + } +} diff --git a/framework-ts/yadan/.eslintignore b/framework-ts/yadan/.eslintignore new file mode 100644 index 0000000..3d155ce --- /dev/null +++ b/framework-ts/yadan/.eslintignore @@ -0,0 +1,7 @@ +# /node_modules/* and /bower_components/* ignored by default + +**/*.min.js +.git/* +bin/* +doc/* +src/* diff --git a/framework-ts/yadan/.gitignore b/framework-ts/yadan/.gitignore new file mode 100644 index 0000000..3d21770 --- /dev/null +++ b/framework-ts/yadan/.gitignore @@ -0,0 +1,222 @@ +/*.js +app/**/*.js +test/**/*.js +config/**/*.js +lib/**/*.js +*.map +*.swp +*.bak +*.[oa] +*.md5 +*.d.ts +Thumbs.db +node_modules* +.coveralls.yml +install/ +target/ +build/ +run/ + +dbconfig.json + +!.vscode/settings.json.example +!settings/*.example + + +# for java +bin/ +gen/ +.springBeans/ +workspaces/ +WebRoot/WEB-INF/classes/ +/resource/database.properties +/resource/webserviceConfig.xml +/src/config.properties +.buildpath + + + +# Specifies intentionally untracked files to ignore when using Git +# http://git-scm.com/docs/gitignore + +*~ +*.sw[mnpcod] +*.tmp +*.tmp.* +log.txt +*.sublime-project +*.sublime-workspace +.vscode/ + +.idea/ +.sourcemaps/ +.sass-cache/ +.tmp/ +.versions/ +dist/ +tmp/ +temp/ +hooks/ +platforms/ +plugins/ +plugins/android.json +plugins/ios.json +$RECYCLE.BIN/ + +UserInterfaceState.xcuserstate + + +# files for the dex VM +*.dex + +# for Mac +.DS_Store + +# for C +.lib +.so +.dll + +# Python: +*.py[cod] +*.egg +*.egg-info + +# C#: +[Oo]bj +[Bb]in +*.user +*.suo +*.[Cc]ache +*.ncb +[Tt]humbs.db +Ankh.NoLoad + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp_proj +*.vspscc +*.vssscc +.builds +*.pidb +*.scc + +!.gitkeep + + +# 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 + +# 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 + + + +# Eclipse project files +proguard-project.txt +.classpath +.project +.settings +.myeclipse +.apt_generated + +# Proguard folder generated by Eclipse +proguard/ + +# Intellij project files +*.iml +*.ipr +*.iws + +# built application files +*.apk +*.ap_ + + + +# Created by https://www.gitignore.io/api/java + +### Java ### +*.class +*.ctxt + + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +# End of https://www.gitignore.io/api/java + diff --git a/framework-ts/yadan/.npmignore b/framework-ts/yadan/.npmignore new file mode 100644 index 0000000..6b9b19e --- /dev/null +++ b/framework-ts/yadan/.npmignore @@ -0,0 +1,16 @@ +src/ +node_modules/ +node_modules*/ +npm-shrinkwrap.json +tsconfig.json +tslint.json +.eslintignore +.eslintrc.json +.travis.yml +appveyor.yml +*.swp +*.bak +demo/ +test/ +coverage/ +.nyc_output/ diff --git a/framework-ts/yadan/config/config.default.ts b/framework-ts/yadan/config/config.default.ts new file mode 100644 index 0000000..78205e4 --- /dev/null +++ b/framework-ts/yadan/config/config.default.ts @@ -0,0 +1,34 @@ +import { EggAppConfig } from 'egg' +import { readFileSync } from 'fs' +import { join } from 'path' + +import defaultConfig from './defaultConfig' + + +export default (appInfo: EggAppConfig) => { + const config: any = {} + + // should change to your own for every new project! + config.keys = appInfo.name + 1234567890 + + /** + * some description + * @member Config#test + * @property {String} key - some description + */ + config.test = { + key: appInfo.name + '_123456', + } + + // config.siteFile = { + // '/favicon.ico': readFileSync(join(appInfo.baseDir, 'app/public/favicon.png')), + // } + + config.view = { + defaultViewEngine: 'nunjucks', + mapping: { '.tpl': 'nunjucks' }, + } + + + return { ...config, ...defaultConfig } +} diff --git a/framework-ts/yadan/config/defaultConfig.ts b/framework-ts/yadan/config/defaultConfig.ts new file mode 100644 index 0000000..1f05ccd --- /dev/null +++ b/framework-ts/yadan/config/defaultConfig.ts @@ -0,0 +1,13 @@ +import { EggAppConfig } from 'egg' + + +export class DefaultConfig { +} + +export default new DefaultConfig() + +declare module 'egg' { + export interface Application { + config: EggAppConfig & DefaultConfig + } +} diff --git a/framework-ts/yadan/config/plugin.ts b/framework-ts/yadan/config/plugin.ts new file mode 100644 index 0000000..95b279d --- /dev/null +++ b/framework-ts/yadan/config/plugin.ts @@ -0,0 +1,6 @@ + +// add you build-in plugin here, example: +export const nunjucks = { + enable: true, + package: 'egg-view-nunjucks', +} diff --git a/framework-ts/yadan/index.ts b/framework-ts/yadan/index.ts new file mode 100644 index 0000000..2441802 --- /dev/null +++ b/framework-ts/yadan/index.ts @@ -0,0 +1,32 @@ +import { + AgentWorkerLoader, + AppWorkerLoader, + BaseContextClass, + Controller as EggController, + Service, + Subscription, +} from 'egg' +// import * as egg from 'egg' + +import Agent from './lib/agent' +import Application from './lib/application' +import startCluster from './lib/cluster' + +// export = { +// ...egg, +// Agent, +// Application, +// startCluster, +// } + +export { + startCluster, + Application, + Agent, + AppWorkerLoader, + AgentWorkerLoader, + EggController as Controller, + Service, + Subscription, + BaseContextClass, +} diff --git a/framework-ts/yadan/lib/agent.ts b/framework-ts/yadan/lib/agent.ts new file mode 100644 index 0000000..8f07860 --- /dev/null +++ b/framework-ts/yadan/lib/agent.ts @@ -0,0 +1,11 @@ +import { Agent as EggAgent } from 'egg' +import { dirname } from 'path' + + +export const EGG_PATH = Symbol.for('egg#eggPath') + +export default class Agent extends EggAgent { + get [EGG_PATH]() { + return dirname(__dirname) + } +} diff --git a/framework-ts/yadan/lib/application.ts b/framework-ts/yadan/lib/application.ts new file mode 100644 index 0000000..6da25a4 --- /dev/null +++ b/framework-ts/yadan/lib/application.ts @@ -0,0 +1,12 @@ +import { Application as EggApplication } from 'egg' +import { dirname } from 'path' + +export const EGG_PATH = Symbol.for('egg#eggPath') + +export default class Application extends EggApplication { + get [EGG_PATH]() { + return dirname(__dirname) + } +} + + diff --git a/framework-ts/yadan/lib/cluster.ts b/framework-ts/yadan/lib/cluster.ts new file mode 100644 index 0000000..e28f360 --- /dev/null +++ b/framework-ts/yadan/lib/cluster.ts @@ -0,0 +1,46 @@ +import { startCluster, ClusterOptions } from 'egg' + +export interface ClusterOptionsInt extends ClusterOptions { + framework: string + baseDir: string + plugins: object | null + workers: number + port: number + https: boolean + key: string + cert: string + clusterPort: number + title?: string +} + +export interface ClusterMsg { + action: 'egg-ready' | 'egg-pids' + to: 'agent' | 'app' + data?: ClusterOptionsInt | number[] | any + from: 'agent' | 'app' | 'master' +} + +// change window title +process.on('message', (msg: ClusterMsg) => { + if (msg && msg.action) { + const { action, data, from, to } = msg + // let titleNew = data.title ? data.title : data.baseDir + + console.info('::message:', process.pid, process.ppid, msg) + console.info('::window title:' + process.title) + if (action === 'egg-ready') { + if (to === 'app' && from === 'master') { + console.info('::app worker ready') + } + else if (to === 'agent' && from === 'master') { + console.info('::agent worker ready') + } + } + } +}) + + +export default startCluster +// export default (options: ClusterOptions, cb: (...args: any[]) => any) => { +// return startCluster(options, cb) +// } diff --git a/framework-ts/yadan/package.json b/framework-ts/yadan/package.json new file mode 100644 index 0000000..f97b4e5 --- /dev/null +++ b/framework-ts/yadan/package.json @@ -0,0 +1,37 @@ +{ + "name": "yadan-ts", + "version": "1.0.0", + "dependencies": { + "egg": "^2.6.0", + "egg-view-nunjucks": "^2.1.4" + }, + "devDependencies": { + "@types/cheerio": "^0.22.1", + "@types/mocha": "^5.0.0", + "@types/node": "^9.4.7", + "@types/supertest": "^2.0.0", + "autod": "^3.0.1", + "autod-egg": "^1.1.0", + "cheerio": "^1.0.0-rc.2", + "egg-bin": "^4.3.7", + "egg-ci": "^1.8.0", + "egg-mock": "^3.14.0", + "eslint": "^4.19.0", + "mocha": "^5.0.4", + "rimraf": "^2.6.1", + "tslint": "^5.9.1", + "tslint-eslint-rules": "^5.1.0", + "typescript": "^2.8.1" + }, + "engines": { + "node": ">=8.10.0" + }, + "scripts": { + "clean": "rimraf app/**/*.{js,map} test/**/*.{js,map} config/**/*.{js,map}", + "lint": "tslint --fix -p tsconfig.json -t stylish", + "test": "egg-bin test", + "test-local": "egg-bin test", + "tsc": "tsc -p tsconfig.json", + "tsc:w": "tsc -p tsconfig.json -w" + } +} diff --git a/framework-ts/yadan/test/lib/framework.test.ts b/framework-ts/yadan/test/lib/framework.test.ts new file mode 100644 index 0000000..d9fe779 --- /dev/null +++ b/framework-ts/yadan/test/lib/framework.test.ts @@ -0,0 +1,42 @@ +/// + +import * as assert from 'assert' +import mm from 'egg-mock' +import * as path from 'path' + + +const key = 'framework-ts-example_123456' + +describe('test/lib/framework.test.ts', () => { + let app + + before(() => { + app = mm.app({ + baseDir: path.join(__dirname, '../../../app'), + framework: path.join(__dirname, '../../'), + }) + return app.ready() + }) + after(() => app.close()) + afterEach(mm.restore) + + it('should GET /', () => { + return app.httpRequest() + .get('/') + .expect(`hi, ${key}`) + .expect(200) + }) + + it('should load config', () => { + assert(app.config.test.key === key) + }) + + it('should load service', async () => { + const ctx = app.mockContext() + const data = await ctx.service.test.get(123) + assert.deepEqual(data, { + id: 123, + name: key, + }) + }) +}) diff --git a/framework-ts/yadan/test/tsconfig.json b/framework-ts/yadan/test/tsconfig.json new file mode 100644 index 0000000..efcbde2 --- /dev/null +++ b/framework-ts/yadan/test/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + "charset": "utf8", + "declaration": false, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "importHelpers": true, + "inlineSourceMap": false, + "module": "commonjs", /* 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "newLine": "lf", + "noFallthroughCasesInSwitch": true, + "pretty": true, + "skipLibCheck": true, + "sourceMap": false, + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, + "noImplicitThis": false, + "target": "ES2017", /* 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ + "types" : ["node"] + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.d.ts", + "**/*.spec.ts" + ] +} diff --git a/framework-ts/yadan/tsconfig.json b/framework-ts/yadan/tsconfig.json new file mode 100644 index 0000000..80018e8 --- /dev/null +++ b/framework-ts/yadan/tsconfig.json @@ -0,0 +1,36 @@ +{ + "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, + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": false, + // "noImplicitThis": false, + "target": "ES2017", /* 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ + "types" : ["node"] + }, + "include": [ + "*.ts", + "app/**/*", + "config/**/*", + "test/**/*.ts" + ], + "exclude": [ + "app/public", + "app/views", + "test/", + "node_modules", + "**/*.d.ts", + "**/*.spec.ts" + ] +} diff --git a/framework-ts/yadan/tslint.json b/framework-ts/yadan/tslint.json new file mode 100644 index 0000000..abd4a09 --- /dev/null +++ b/framework-ts/yadan/tslint.json @@ -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 /// 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"] + } + } +} From 03343484cd9158a009eecc6b7c82a3378472b19e Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 5 Apr 2018 19:32:20 +0800 Subject: [PATCH 02/17] fix(scripts): run tsc before run test --- framework-ts/yadan/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework-ts/yadan/package.json b/framework-ts/yadan/package.json index f97b4e5..e825822 100644 --- a/framework-ts/yadan/package.json +++ b/framework-ts/yadan/package.json @@ -29,7 +29,7 @@ "scripts": { "clean": "rimraf app/**/*.{js,map} test/**/*.{js,map} config/**/*.{js,map}", "lint": "tslint --fix -p tsconfig.json -t stylish", - "test": "egg-bin test", + "test": "npm run tsc && egg-bin test", "test-local": "egg-bin test", "tsc": "tsc -p tsconfig.json", "tsc:w": "tsc -p tsconfig.json -w" From fd0473cc7c90a4507fd10def764cd79faa3ba482 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 5 Apr 2018 19:34:01 +0800 Subject: [PATCH 03/17] chore(scripts): run tsc before run cov --- framework-ts/app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework-ts/app/package.json b/framework-ts/app/package.json index a269cd1..5e8efd0 100644 --- a/framework-ts/app/package.json +++ b/framework-ts/app/package.json @@ -17,7 +17,7 @@ "autod": "autod", "clean": "rimraf app/**/*.{js,map} test/**/*.{js,map} config/**/*.{js,map}", "ci": "npm run lint && npm run cov", - "cov": "egg-bin cov", + "cov": "npm run tsc && egg-bin cov", "debug": "egg-bin debug", "dev": "egg-bin dev", "lint": "tslint --fix -p tsconfig.json -t stylish", From 2846434ea96ca52363140b43db3396a55c3231f0 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 5 Apr 2018 19:40:39 +0800 Subject: [PATCH 04/17] test: add home.test.js --- .../app/test/app/controller/home.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 framework-ts/app/test/app/controller/home.test.js diff --git a/framework-ts/app/test/app/controller/home.test.js b/framework-ts/app/test/app/controller/home.test.js new file mode 100644 index 0000000..f60869d --- /dev/null +++ b/framework-ts/app/test/app/controller/home.test.js @@ -0,0 +1,19 @@ +'use strict'; + +const mock = require('egg-mock'); + +describe('test/app/controller/home.test.js', () => { + + let app; + before(() => { + app = mock.app(); + return app.ready(); + }); + + it('should GET /', () => { + return app.httpRequest() + .get('/') + .expect(200) + .expect('hi, framework-ts-example_123456'); + }); +}); From db955cf1057138192f1e069c578307163ea57a70 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 5 Apr 2018 19:41:10 +0800 Subject: [PATCH 05/17] chore: npm install ts-node before test --- framework-ts/app/.travis.yml | 1 + framework-ts/app/appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/framework-ts/app/.travis.yml b/framework-ts/app/.travis.yml index b735efc..c48d667 100644 --- a/framework-ts/app/.travis.yml +++ b/framework-ts/app/.travis.yml @@ -3,6 +3,7 @@ language: node_js node_js: - '8' install: + - npm i -g ts-node - npm i npminstall && npminstall script: - npm run ci diff --git a/framework-ts/app/appveyor.yml b/framework-ts/app/appveyor.yml index c274b7d..62954d0 100644 --- a/framework-ts/app/appveyor.yml +++ b/framework-ts/app/appveyor.yml @@ -4,6 +4,7 @@ environment: install: - ps: Install-Product node $env:nodejs_version + - npm i -g ts-node - npm i npminstall && node_modules\.bin\npminstall test_script: From 157ba27635d15f8c5de9268f1f0cabafbac1da3c Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Thu, 5 Apr 2018 20:30:05 +0800 Subject: [PATCH 06/17] fix: test.ts missing --- framework-ts/yadan/app/service/test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 framework-ts/yadan/app/service/test.ts diff --git a/framework-ts/yadan/app/service/test.ts b/framework-ts/yadan/app/service/test.ts new file mode 100644 index 0000000..550625c --- /dev/null +++ b/framework-ts/yadan/app/service/test.ts @@ -0,0 +1,24 @@ +import { Context, EggAppConfig, Service } from 'egg' + + +/** + * Test Service + */ +export default class Test extends Service { + config: EggAppConfig + + constructor(ctx: Context) { + super(ctx) + this.config = this.app.config.test + } + + async get(id: number) { + return { id, name: this.config.key } + } +} + +declare module 'egg' { + export interface IService { + test: Test + } +} From 9dbcd6eb29f8da1c2194b9c8b84e4315e80366f9 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Mon, 9 Apr 2018 19:53:02 +0800 Subject: [PATCH 07/17] chore: update export --- framework-ts/yadan/index.ts | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/framework-ts/yadan/index.ts b/framework-ts/yadan/index.ts index 2441802..5fed444 100644 --- a/framework-ts/yadan/index.ts +++ b/framework-ts/yadan/index.ts @@ -1,32 +1,13 @@ -import { - AgentWorkerLoader, - AppWorkerLoader, - BaseContextClass, - Controller as EggController, - Service, - Subscription, -} from 'egg' -// import * as egg from 'egg' +import * as egg from 'egg' import Agent from './lib/agent' import Application from './lib/application' import startCluster from './lib/cluster' -// export = { -// ...egg, -// Agent, -// Application, -// startCluster, -// } - -export { - startCluster, - Application, +const newEgg = { + ...egg, Agent, - AppWorkerLoader, - AgentWorkerLoader, - EggController as Controller, - Service, - Subscription, - BaseContextClass, + Application, + startCluster, } +export = newEgg From 5d5422c54dc8f5dc44a802ae9c92ba7bef06d3eb Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 09:41:45 +0800 Subject: [PATCH 08/17] feat: use new code style --- framework-ts/yadan/config/config.default.ts | 19 ++++++++----------- framework-ts/yadan/config/config.local.ts | 7 +++++++ framework-ts/yadan/config/config.prod.ts | 7 +++++++ framework-ts/yadan/config/defaultConfig.ts | 13 ------------- framework-ts/yadan/config/plugin.ts | 12 +++++++----- 5 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 framework-ts/yadan/config/config.local.ts create mode 100644 framework-ts/yadan/config/config.prod.ts delete mode 100644 framework-ts/yadan/config/defaultConfig.ts diff --git a/framework-ts/yadan/config/config.default.ts b/framework-ts/yadan/config/config.default.ts index 78205e4..83ceb3c 100644 --- a/framework-ts/yadan/config/config.default.ts +++ b/framework-ts/yadan/config/config.default.ts @@ -1,15 +1,13 @@ -import { EggAppConfig } from 'egg' +import { EggAppConfig, PowerPartial } from 'egg'; import { readFileSync } from 'fs' import { join } from 'path' -import defaultConfig from './defaultConfig' +// for config.{env}.ts +export type DefaultConfig = PowerPartial; export default (appInfo: EggAppConfig) => { - const config: any = {} - - // should change to your own for every new project! - config.keys = appInfo.name + 1234567890 + const config = > {} /** * some description @@ -20,15 +18,14 @@ export default (appInfo: EggAppConfig) => { key: appInfo.name + '_123456', } - // config.siteFile = { - // '/favicon.ico': readFileSync(join(appInfo.baseDir, 'app/public/favicon.png')), - // } - config.view = { defaultViewEngine: 'nunjucks', mapping: { '.tpl': 'nunjucks' }, } + config.siteFile = { + '/favicon.ico': readFileSync(join(appInfo.baseDir, 'app/public/favicon.png')), + }; - return { ...config, ...defaultConfig } + return config; } diff --git a/framework-ts/yadan/config/config.local.ts b/framework-ts/yadan/config/config.local.ts new file mode 100644 index 0000000..79df3f2 --- /dev/null +++ b/framework-ts/yadan/config/config.local.ts @@ -0,0 +1,7 @@ +import { DefaultConfig } from './config.default'; + +export default () => { + const config: DefaultConfig = {}; + + return config; +}; diff --git a/framework-ts/yadan/config/config.prod.ts b/framework-ts/yadan/config/config.prod.ts new file mode 100644 index 0000000..79df3f2 --- /dev/null +++ b/framework-ts/yadan/config/config.prod.ts @@ -0,0 +1,7 @@ +import { DefaultConfig } from './config.default'; + +export default () => { + const config: DefaultConfig = {}; + + return config; +}; diff --git a/framework-ts/yadan/config/defaultConfig.ts b/framework-ts/yadan/config/defaultConfig.ts deleted file mode 100644 index 1f05ccd..0000000 --- a/framework-ts/yadan/config/defaultConfig.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { EggAppConfig } from 'egg' - - -export class DefaultConfig { -} - -export default new DefaultConfig() - -declare module 'egg' { - export interface Application { - config: EggAppConfig & DefaultConfig - } -} diff --git a/framework-ts/yadan/config/plugin.ts b/framework-ts/yadan/config/plugin.ts index 95b279d..99c3979 100644 --- a/framework-ts/yadan/config/plugin.ts +++ b/framework-ts/yadan/config/plugin.ts @@ -1,6 +1,8 @@ +'use strict'; -// add you build-in plugin here, example: -export const nunjucks = { - enable: true, - package: 'egg-view-nunjucks', -} +export default { + nunjucks: { + enable: true, + package: 'egg-view-nunjucks', + }, +}; From 403a74aa0ddfc5ab75942c24ad5783bab65385d7 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 09:55:28 +0800 Subject: [PATCH 09/17] chore: prune --- framework-ts/app/tsconfig.json | 17 +++++------ framework-ts/app/tslint.json | 50 ++++++++++++++++---------------- framework-ts/yadan/tsconfig.json | 18 +++++------- framework-ts/yadan/tslint.json | 50 ++++++++++++++++---------------- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/framework-ts/app/tsconfig.json b/framework-ts/app/tsconfig.json index 19ff08c..0430ef0 100644 --- a/framework-ts/app/tsconfig.json +++ b/framework-ts/app/tsconfig.json @@ -1,22 +1,21 @@ { "compilerOptions": { - "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + "alwaysStrict": true, "charset": "utf8", - "declaration": true, /* Generates corresponding '.d.ts' file. */ - "experimentalDecorators": true, + "declaration": false, "emitDecoratorMetadata": true, + "experimentalDecorators": true, "importHelpers": false, "inlineSourceMap": true, - "module": "commonjs", /* 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", "newLine": "lf", "noFallthroughCasesInSwitch": true, - // "outDir": "./dist", "pretty": true, "skipLibCheck": true, "sourceMap": false, - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": false, - // "noImplicitThis": false, + "strict": true, + "noImplicitAny": true, + "noImplicitThis": true, "target": "ES2017", "types" : ["node"] }, @@ -28,7 +27,7 @@ "exclude": [ "app/public", "app/views", - "node_modules", + "node_modules*", "**/*.d.ts", "**/*.spec.ts" ] diff --git a/framework-ts/app/tslint.json b/framework-ts/app/tslint.json index abd4a09..532fd40 100644 --- a/framework-ts/app/tslint.json +++ b/framework-ts/app/tslint.json @@ -9,14 +9,14 @@ "rules": { "adjacent-overload-signatures": true, "align": [true, "members", "parameters", "statements"], - "array-bracket-spacing": [true, "never", {"singleValue": false, "objectsInArrays": true, "arraysInArrays": true} ], // 设置在括号内使用空格风格 + "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. + "await-promise": [true, "Thenable"], "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"], // 要求遵循大括号约定 + "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": [ @@ -43,22 +43,22 @@ ]}], "no-arg": true, "no-angle-bracket-type-assertion": false, - "no-consecutive-blank-lines": [true, 4], // 多个空行控制 + "no-consecutive-blank-lines": [true, 4], "no-console": [ true, "dir", "log", "warn" ], - "no-construct": true, // 禁止对 String,Number 和 Boolean 使用 new 操作符 + "no-construct": true, "no-control-regex": true, "no-duplicate-variable": true, - "no-duplicate-imports": true, // 禁止单个模块多次导入 + "no-duplicate-imports": true, "no-duplicate-switch-case": true, - "no-empty": false, // 禁止空块语句 + "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-multi-spaces": [ true, { "exceptions": { "PropertyAssignment": true, "VariableDeclaration": false } } ], "no-object-literal-type-assertion": false, - "no-parameter-reassignment": false, // 禁止参数变量重新赋值 + "no-parameter-reassignment": false, "no-return-await": true, - "no-reference": true, // Disallows /// imports (use ES6-style imports instead). + "no-reference": true, "no-shadowed-variable": [ true, { @@ -77,18 +77,18 @@ "@angular/platform-browser", "source-map-support/register" ], - "no-trailing-whitespace": [true, "ignore-comments"], // 禁用行尾空白 - "no-unnecessary-initializer": true, // 禁止变量赋值为 undefined + "no-trailing-whitespace": [true, "ignore-comments"], + "no-unnecessary-initializer": true, "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"], // 强制在大括号中使用一致的空格 + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-curly-spacing": [true, "always"], "object-literal-shorthand": [true], "object-literal-sort-keys": false, "one-line": [true, "check-open-brace", "check-whitespace"], @@ -108,14 +108,14 @@ 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-arrow-spacing": [true, { "before": true, "after": true }], + "ter-func-call-spacing": [true, "never"], "ter-indent": [true, 2, { "SwitchCase": 1 } ], - "ter-no-irregular-whitespace": true, // 禁止不规则的空白 + "ter-no-irregular-whitespace": true, "trailing-comma": [true, { "multiline": { @@ -129,10 +129,10 @@ "singleline": "never", "esSpecCompliant": true } - ], // 当最后一个元素或属性与闭括号 ] 或 右大括号 在 不同的行时,要求使用拖尾逗号;当在 同一行时,禁止使用拖尾逗号 + ], "triple-equals": true, - "use-isnan": true, // 要求使用 isNaN() 检查 NaN - "valid-typeof": true, // 强制 typeof 表达式与有效的字符串进行比较 + "use-isnan": true, + "valid-typeof": true, "variable-name": [true, "ban-keywords", "allow-leading-underscore"], "whitespace": { "options": [true, diff --git a/framework-ts/yadan/tsconfig.json b/framework-ts/yadan/tsconfig.json index 80018e8..3a543f8 100644 --- a/framework-ts/yadan/tsconfig.json +++ b/framework-ts/yadan/tsconfig.json @@ -1,26 +1,24 @@ { "compilerOptions": { - "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + "alwaysStrict": true, "charset": "utf8", - "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": false, "experimentalDecorators": true, "emitDecoratorMetadata": true, "importHelpers": false, "inlineSourceMap": true, - "module": "commonjs", /* 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", "newLine": "lf", "noFallthroughCasesInSwitch": true, - // "outDir": "./dist", "pretty": true, "skipLibCheck": true, - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": false, - // "noImplicitThis": false, - "target": "ES2017", /* 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ + "strict": true, + "noImplicitAny": false, + "noImplicitThis": false, + "target": "ES2017", "types" : ["node"] }, "include": [ - "*.ts", "app/**/*", "config/**/*", "test/**/*.ts" @@ -29,7 +27,7 @@ "app/public", "app/views", "test/", - "node_modules", + "node_modules*", "**/*.d.ts", "**/*.spec.ts" ] diff --git a/framework-ts/yadan/tslint.json b/framework-ts/yadan/tslint.json index abd4a09..532fd40 100644 --- a/framework-ts/yadan/tslint.json +++ b/framework-ts/yadan/tslint.json @@ -9,14 +9,14 @@ "rules": { "adjacent-overload-signatures": true, "align": [true, "members", "parameters", "statements"], - "array-bracket-spacing": [true, "never", {"singleValue": false, "objectsInArrays": true, "arraysInArrays": true} ], // 设置在括号内使用空格风格 + "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. + "await-promise": [true, "Thenable"], "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"], // 要求遵循大括号约定 + "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": [ @@ -43,22 +43,22 @@ ]}], "no-arg": true, "no-angle-bracket-type-assertion": false, - "no-consecutive-blank-lines": [true, 4], // 多个空行控制 + "no-consecutive-blank-lines": [true, 4], "no-console": [ true, "dir", "log", "warn" ], - "no-construct": true, // 禁止对 String,Number 和 Boolean 使用 new 操作符 + "no-construct": true, "no-control-regex": true, "no-duplicate-variable": true, - "no-duplicate-imports": true, // 禁止单个模块多次导入 + "no-duplicate-imports": true, "no-duplicate-switch-case": true, - "no-empty": false, // 禁止空块语句 + "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-multi-spaces": [ true, { "exceptions": { "PropertyAssignment": true, "VariableDeclaration": false } } ], "no-object-literal-type-assertion": false, - "no-parameter-reassignment": false, // 禁止参数变量重新赋值 + "no-parameter-reassignment": false, "no-return-await": true, - "no-reference": true, // Disallows /// imports (use ES6-style imports instead). + "no-reference": true, "no-shadowed-variable": [ true, { @@ -77,18 +77,18 @@ "@angular/platform-browser", "source-map-support/register" ], - "no-trailing-whitespace": [true, "ignore-comments"], // 禁用行尾空白 - "no-unnecessary-initializer": true, // 禁止变量赋值为 undefined + "no-trailing-whitespace": [true, "ignore-comments"], + "no-unnecessary-initializer": true, "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"], // 强制在大括号中使用一致的空格 + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-curly-spacing": [true, "always"], "object-literal-shorthand": [true], "object-literal-sort-keys": false, "one-line": [true, "check-open-brace", "check-whitespace"], @@ -108,14 +108,14 @@ 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-arrow-spacing": [true, { "before": true, "after": true }], + "ter-func-call-spacing": [true, "never"], "ter-indent": [true, 2, { "SwitchCase": 1 } ], - "ter-no-irregular-whitespace": true, // 禁止不规则的空白 + "ter-no-irregular-whitespace": true, "trailing-comma": [true, { "multiline": { @@ -129,10 +129,10 @@ "singleline": "never", "esSpecCompliant": true } - ], // 当最后一个元素或属性与闭括号 ] 或 右大括号 在 不同的行时,要求使用拖尾逗号;当在 同一行时,禁止使用拖尾逗号 + ], "triple-equals": true, - "use-isnan": true, // 要求使用 isNaN() 检查 NaN - "valid-typeof": true, // 强制 typeof 表达式与有效的字符串进行比较 + "use-isnan": true, + "valid-typeof": true, "variable-name": [true, "ban-keywords", "allow-leading-underscore"], "whitespace": { "options": [true, From 6c78f2e68d4ceb2e592ae8658b8bcbaba3ba1650 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:02:49 +0800 Subject: [PATCH 10/17] chore: add css and favicon.png --- framework-ts/app/app/public/css/news.css | 203 +++++++++++++++++++++++ framework-ts/app/app/public/favicon.png | Bin 0 -> 3113 bytes 2 files changed, 203 insertions(+) create mode 100644 framework-ts/app/app/public/css/news.css create mode 100644 framework-ts/app/app/public/favicon.png diff --git a/framework-ts/app/app/public/css/news.css b/framework-ts/app/app/public/css/news.css new file mode 100644 index 0000000..b922c98 --- /dev/null +++ b/framework-ts/app/app/public/css/news.css @@ -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 +} \ No newline at end of file diff --git a/framework-ts/app/app/public/favicon.png b/framework-ts/app/app/public/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..41d69cdc414faa424c7a12c783f8009f0fec2da8 GIT binary patch literal 3113 zcmZ8jZBLU|7;d3ZWE2q)Xlb$VFc1-~76A)Ipyf@V2$b@sWrea8kctAcQoxuknVnejbDQUT)ar7-EP*Yj9 z9H_(DMlcW`6@8>mG&rnVFzRn`q^8zL=rs2(-rBaTNlMDPCDm9~AePJ|Ko?7@A{E zi`C}YRTxiyj4oe-4u&7yh@1Y;d|MMjwuPXX>js!@iJ}f&J>-ganq^!Zo#2|*)Co8Wo4?lI0osj= zaM<92=EpbkU_HCeAAbCa1YcZx@U2+IhoP&|9t;8;Q%gBsEUV$`Un zX)cC8oZ%~E)%zPQ0VWlg-#?mU*#!Bk?8ZXBszxYP4ply8^x>Dz`@hNjt~dP=?ra0X zqcyf)9W>ZnF2McW`ABT=sr|YMgVobCRWOx_ki;u;oCVC?EUHVc`z?4fPt%C-WGejpaloW zLt-{;J`lhYckg2mx5hyMv*YCp0Us*>a8H_;Pt;)+&r>N{*x};*)lGh7!YU^)JIB|X zpavi%_6g6~WVsRMJCJqeho_M10(@@X5p!&%z;w;31jix)o-EeN264`SPO1i~hAk)! zIjpd_XMn%(8muOb$6K|??!j6X2k=7naH|0OmD||9KDm7z+Ff5CWzBUkO@hPW?ohw_ zK6w%>PN6>5!Q-yQ2jWntAz>~)?-GdF;LcsGb}%<4xWMZ*ntr+XimCzJS6+M$0hVr< z69Im*bo3RC&Dq!pIu7Ypj?#lp&C<#bEyNI?LmAu%3Dr}JIcHS z#EuowINstc%TqhlcIu~QiVE>{WoNuk-#f%2Cyc36D-*y*-74cv0wmQem)CaSKyhp8 z7Fy?Y)&nTrFsUku59Yd`{2r`-+n;J7iR;|H2=neu-4|m+EsGm+rAbV+&OaZ(ZRKk2f9-tbOvUg18ZpUS z;nV?v&x>{-2+EzVJ~YD{N-!&G4eB6-*E+y-h9GQYV4F8=jo3O*>(&Kc2!oJlX}ccG rwB+~k1jb$SF@uF0YU2~ecQe815J!PJps)e_<2Uqn2K+EP_$~Pl&{xhR literal 0 HcmV?d00001 From 2c9afcda144812af7010b4b8eba3e64d3b0ab4ba Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:04:02 +0800 Subject: [PATCH 11/17] chore: prune --- framework-ts/yadan/config/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/framework-ts/yadan/config/plugin.ts b/framework-ts/yadan/config/plugin.ts index 99c3979..b425d68 100644 --- a/framework-ts/yadan/config/plugin.ts +++ b/framework-ts/yadan/config/plugin.ts @@ -1,4 +1,3 @@ -'use strict'; export default { nunjucks: { From aad95558039149d1b946794f69e9e99f15e5a5f6 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:07:26 +0800 Subject: [PATCH 12/17] feat: add config files to override settings defined in framework --- framework-ts/app/config/config.default.ts | 29 +++++++++++++++++++++++ framework-ts/app/config/config.local.ts | 9 +++++++ framework-ts/app/config/config.prod.ts | 9 +++++++ framework-ts/app/config/plugin.ts | 3 +++ 4 files changed, 50 insertions(+) create mode 100644 framework-ts/app/config/config.default.ts create mode 100644 framework-ts/app/config/config.local.ts create mode 100644 framework-ts/app/config/config.prod.ts create mode 100644 framework-ts/app/config/plugin.ts diff --git a/framework-ts/app/config/config.default.ts b/framework-ts/app/config/config.default.ts new file mode 100644 index 0000000..234109c --- /dev/null +++ b/framework-ts/app/config/config.default.ts @@ -0,0 +1,29 @@ +import { EggAppConfig, PowerPartial } from 'egg'; + +// for config.{env}.ts +export type DefaultConfig = PowerPartial; + +// app special config scheme +export interface BizConfig { + sourceUrl: string; + news: { + pageSize: number; + serverUrl: string; + }; +} + +export default (appInfo: EggAppConfig) => { + const config = & 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; +}; diff --git a/framework-ts/app/config/config.local.ts b/framework-ts/app/config/config.local.ts new file mode 100644 index 0000000..c790a63 --- /dev/null +++ b/framework-ts/app/config/config.local.ts @@ -0,0 +1,9 @@ +import { DefaultConfig } from './config.default'; + +export default () => { + const config: DefaultConfig = {}; + config.news = { + pageSize: 20, + }; + return config; +}; diff --git a/framework-ts/app/config/config.prod.ts b/framework-ts/app/config/config.prod.ts new file mode 100644 index 0000000..a1cb344 --- /dev/null +++ b/framework-ts/app/config/config.prod.ts @@ -0,0 +1,9 @@ +import { DefaultConfig } from './config.default'; + +export default () => { + const config: DefaultConfig = {}; + config.news = { + pageSize: 30, + }; + return config; +}; diff --git a/framework-ts/app/config/plugin.ts b/framework-ts/app/config/plugin.ts new file mode 100644 index 0000000..2554dd8 --- /dev/null +++ b/framework-ts/app/config/plugin.ts @@ -0,0 +1,3 @@ + +export default { +}; From faf573a33b52f32523b6b56e93cee87422041f34 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:14:35 +0800 Subject: [PATCH 13/17] chore: update log message --- framework-ts/yadan/lib/cluster.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework-ts/yadan/lib/cluster.ts b/framework-ts/yadan/lib/cluster.ts index e28f360..4e00836 100644 --- a/framework-ts/yadan/lib/cluster.ts +++ b/framework-ts/yadan/lib/cluster.ts @@ -26,7 +26,9 @@ process.on('message', (msg: ClusterMsg) => { const { action, data, from, to } = msg // let titleNew = data.title ? data.title : data.baseDir - console.info('::message:', process.pid, process.ppid, msg) + // process.ppid need node.js v8.10 + // console.info('::message:', process.pid, process.ppid, msg) + console.info('::message:', process.pid, msg) console.info('::window title:' + process.title) if (action === 'egg-ready') { if (to === 'app' && from === 'master') { From ff2644e674d8a1ccb295782829148e1b2f723130 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:41:23 +0800 Subject: [PATCH 14/17] fix: compile .ts under app root --- framework-ts/app/tsconfig.json | 1 + framework-ts/yadan/tsconfig.json | 1 + 2 files changed, 2 insertions(+) diff --git a/framework-ts/app/tsconfig.json b/framework-ts/app/tsconfig.json index 0430ef0..2181abc 100644 --- a/framework-ts/app/tsconfig.json +++ b/framework-ts/app/tsconfig.json @@ -20,6 +20,7 @@ "types" : ["node"] }, "include": [ + "./*.ts", "app/**/*.ts", "config/**/*.ts", "test/**/*.ts" diff --git a/framework-ts/yadan/tsconfig.json b/framework-ts/yadan/tsconfig.json index 3a543f8..8511d9b 100644 --- a/framework-ts/yadan/tsconfig.json +++ b/framework-ts/yadan/tsconfig.json @@ -19,6 +19,7 @@ "types" : ["node"] }, "include": [ + "./*.ts", "app/**/*", "config/**/*", "test/**/*.ts" From 470e075b3a3b5545aa83f2d4636f18502cea0324 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 10 Apr 2018 10:46:19 +0800 Subject: [PATCH 15/17] docs: add README.md --- framework-ts/README.md | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 framework-ts/README.md diff --git a/framework-ts/README.md b/framework-ts/README.md new file mode 100644 index 0000000..23a909c --- /dev/null +++ b/framework-ts/README.md @@ -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 From 4d2c3b18577f4eacdaebf019e7371c22a4aef8ed Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Sun, 29 Apr 2018 18:00:05 +0800 Subject: [PATCH 16/17] chore(deps): update egg, egg-bin --- framework-ts/app/package.json | 4 ++-- framework-ts/yadan/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework-ts/app/package.json b/framework-ts/app/package.json index 5e8efd0..c8dc0e4 100644 --- a/framework-ts/app/package.json +++ b/framework-ts/app/package.json @@ -2,12 +2,12 @@ "name": "framework-ts-example", "version": "1.0.0", "dependencies": { - "egg": "^2.6.0", + "egg": "^2.7.1", "egg-scripts": "^2.6.0", "yadan-ts": "../yadan" }, "devDependencies": { - "egg-bin": "^4.3.5", + "egg-bin": "^4.7.0", "egg-mock": "^3.13.1" }, "engines": { diff --git a/framework-ts/yadan/package.json b/framework-ts/yadan/package.json index e825822..bb7f2ee 100644 --- a/framework-ts/yadan/package.json +++ b/framework-ts/yadan/package.json @@ -2,7 +2,7 @@ "name": "yadan-ts", "version": "1.0.0", "dependencies": { - "egg": "^2.6.0", + "egg": "^2.7.1", "egg-view-nunjucks": "^2.1.4" }, "devDependencies": { @@ -13,7 +13,7 @@ "autod": "^3.0.1", "autod-egg": "^1.1.0", "cheerio": "^1.0.0-rc.2", - "egg-bin": "^4.3.7", + "egg-bin": "^4.7.0", "egg-ci": "^1.8.0", "egg-mock": "^3.14.0", "eslint": "^4.19.0", From 880204a68b0d4d058428b1737e7f145c47239bfe Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Sun, 29 Apr 2018 18:03:50 +0800 Subject: [PATCH 17/17] chore: use standart output format of ESM --- framework-ts/yadan/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/framework-ts/yadan/index.ts b/framework-ts/yadan/index.ts index 5fed444..7354224 100644 --- a/framework-ts/yadan/index.ts +++ b/framework-ts/yadan/index.ts @@ -1,13 +1,16 @@ -import * as egg from 'egg' +import { BaseContextClass, Controller, EggApplication, Service } from 'egg' import Agent from './lib/agent' import Application from './lib/application' import startCluster from './lib/cluster' -const newEgg = { - ...egg, +export { Agent, Application, startCluster, + + BaseContextClass, + Controller, + EggApplication, + Service, } -export = newEgg