-
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: implement node react web framework
- Loading branch information
sky
committed
Oct 13, 2019
0 parents
commit 4fc5e38
Showing
47 changed files
with
24,106 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,27 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg' | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'autod', | ||
'eslint', | ||
'eslint-config-egg', | ||
'webstorm-disable-index', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
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,3 @@ | ||
{ | ||
"extends": "eslint-config-egg" | ||
} |
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,11 @@ | ||
logs/ | ||
npm-debug.log | ||
node_modules/ | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.swp | ||
package-lock.json | ||
yarn.lock | ||
.nyc_output/ |
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,11 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
- '10' | ||
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,2 @@ | ||
|
||
|
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,69 @@ | ||
# res | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/res.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/res | ||
[travis-image]: https://img.shields.io/travis/easy-team/res.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/easy-team/res | ||
[codecov-image]: https://img.shields.io/codecov/c/github/easy-team/res.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/easy-team/res?branch=master | ||
[david-image]: https://img.shields.io/david/easy-team/res.svg?style=flat-square | ||
[david-url]: https://david-dm.org/easy-team/res | ||
[snyk-image]: https://snyk.io/test/npm/res/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/res | ||
[download-image]: https://img.shields.io/npm/dm/res.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/res | ||
|
||
|
||
A Powerful, Simple React Node Web Framework, Front-End and Node of The Application are Written in TypeScript or JavaScript! Everything is Simple! | ||
|
||
> You don't need to care about React server-side rendering implementation details and the Webpack + Babel + TypeScript build process. You just need to write React isomorphic applications just like you would write a React front-end application. | ||
## Installation | ||
|
||
```bash | ||
$ npm install @easy-team/res --save | ||
``` | ||
|
||
Node.js >= 8.0.0 required. | ||
|
||
## Features | ||
|
||
- ✔︎ Based on [Egg](https://eggjs.org/en/intro/index.html) Framework, Powerful, Easy to Expand | ||
- ✔︎ Support React Server Side Render and Client Side Render Modes, Nunjucks & React Render Mode, Rendering Cache, Automatic Downgrade, | ||
- ✔︎ Front-End and Node of The Application are Written in TypeScript or JavaScript | ||
- ✔︎ Build with Webpack, Auto Building, Hot Reload, Code Splitting, High Speed, Performance Optimization | ||
- ✔︎ Powerful Tool Chain [res-cli](https://github.com/easy-team/res-cli) | ||
|
||
## Document | ||
|
||
- https://www.yuque.com/easy-team/res | ||
|
||
## QuickStart | ||
|
||
```bash | ||
$ npm install -g @easy-team/res-cli | ||
$ res init | ||
$ npm install | ||
$ npm run dev | ||
$ open http://localhost:7001 | ||
``` | ||
|
||
## Examples | ||
|
||
See [res-awesome](https://github.com/easy-team/res-awesome) | ||
|
||
## Links | ||
|
||
- https://eggjs.org/en/advanced/framework.html | ||
- https://www.yuque.com/easy-team/res | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
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,5 @@ | ||
'use strict'; | ||
// https://github.com/eggjs/egg/issues/1520 | ||
module.exports = app => { | ||
app.config.coreMiddleware.push('locals'); | ||
}; |
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,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
|
||
}; |
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,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
|
||
}; |
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 @@ | ||
'use strict'; | ||
module.exports = () => { | ||
return async function(ctx, next) { | ||
ctx.locals.title = 'res'; | ||
await next(); | ||
}; | ||
}; |
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,16 @@ | ||
'use strict'; | ||
|
||
const Service = require('egg').Service; | ||
|
||
class TestService extends Service { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.config = this.app.config.test; | ||
} | ||
|
||
async get(id) { | ||
return { id, name: this.config.key }; | ||
} | ||
} | ||
|
||
module.exports = TestService; |
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,16 @@ | ||
{ | ||
"extends": "../../config/tsconfig.json", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esnext", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
] | ||
}, | ||
|
||
"exclude": [ | ||
"node_modules", | ||
"**/*.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,4 @@ | ||
declare module "*.vue" { | ||
import Vue from 'vue' | ||
export default Vue | ||
} |
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,8 @@ | ||
declare var EASY_ENV_IS_NODE: boolean; | ||
declare var EASY_ENV_IS_BROWSER: boolean; | ||
declare var EASY_ENV_IS_DEV: boolean; | ||
declare var process : { | ||
env: { | ||
NODE_ENV: string | ||
} | ||
} |
Empty file.
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title></title> | ||
<meta name="keywords"> | ||
<meta name="description"> | ||
<meta http-equiv="content-type" content="text/html;charset=utf-8"> | ||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
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,15 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
- nodejs_version: '10' | ||
|
||
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,14 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const EggScriptCommand = require('egg-scripts'); | ||
const cliFilePath = path.join(process.cwd(), 'node_modules', '@easy-team/res-cli'); | ||
// fix when production mode, ves-cli not exists, start app error by ves start | ||
if (fs.existsSync(cliFilePath)) { | ||
const ResCLI = require(cliFilePath); | ||
new ResCLI.Command().start(); | ||
} else { | ||
new EggScriptCommand().start(); | ||
} |
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,38 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
module.exports = appInfo => { | ||
const config = {}; | ||
|
||
config.view = { | ||
defaultViewEngine: 'nunjucks', | ||
mapping: { | ||
'.tpl': 'nunjucks' | ||
}, | ||
}; | ||
|
||
/** | ||
* some description | ||
* @member Config#test | ||
* @property {String} key - some description | ||
*/ | ||
config.test = { | ||
key: appInfo.name + '_123456', | ||
}; | ||
|
||
/** | ||
* cookie secret key | ||
*/ | ||
config.keys = appInfo.name + '_123456'; | ||
|
||
/** | ||
* vue ssr plugin config | ||
* @member Config#vuessr | ||
* @property {String} layout - client render default html layout file path | ||
* @property {renderOptions} Object - vue server side render options | ||
*/ | ||
config.reactssr = { | ||
layout: path.resolve(__dirname, '../app/web/view/layout.html') | ||
}; | ||
|
||
return config; | ||
}; |
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,31 @@ | ||
'use strict'; | ||
const utils = require('../lib/utils'); | ||
module.exports = app => { | ||
|
||
const exports = {}; | ||
|
||
exports.view = { | ||
cache: false, | ||
}; | ||
|
||
exports.static = { | ||
maxAge: 0, // maxAge cache, default one year, local disabled | ||
}; | ||
|
||
exports.development = { | ||
watchDirs: [], | ||
ignoreDirs: [ 'app/web', 'public', 'config/manifest.json' ], | ||
}; | ||
|
||
/** | ||
* egg-webpack plugin config | ||
* @member Config#webpack | ||
* @property {Array} webpackConfigList - webpack config | ||
*/ | ||
exports.webpack = { | ||
cli: utils.getCli(), | ||
webpackConfigList: utils.getWebpackConfig(app), | ||
}; | ||
|
||
return exports; | ||
}; |
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 @@ | ||
'use strict'; | ||
exports.reactssr = { | ||
enable: true, | ||
package: 'egg-view-react-ssr', | ||
}; | ||
|
||
exports.nunjucks = { | ||
enable: true, | ||
package: 'egg-view-nunjucks', | ||
}; |
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,15 @@ | ||
'use strict'; | ||
exports.cors = { | ||
enable: true, | ||
package: 'egg-cors', | ||
}; | ||
|
||
exports.webpack = { | ||
enable: true, | ||
package: 'egg-webpack', | ||
}; | ||
|
||
exports.webpackreact = { | ||
enable: true, | ||
package: 'egg-webpack-react', | ||
}; |
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,3 @@ | ||
import * as Egg from 'egg'; | ||
export = Egg; | ||
export as namespace Egg; |
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,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('./lib/framework.js'); |
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,22 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const egg = require('egg'); | ||
const EGG_PATH = Symbol.for('egg#eggPath'); | ||
|
||
class Application extends egg.Application { | ||
get [EGG_PATH]() { | ||
return path.dirname(__dirname); | ||
} | ||
} | ||
|
||
class Agent extends egg.Agent { | ||
get [EGG_PATH]() { | ||
return path.dirname(__dirname); | ||
} | ||
} | ||
|
||
module.exports = Object.assign(egg, { | ||
Application, | ||
Agent, | ||
}); |
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,16 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
exports.getCli = () => { | ||
return { name: 'res-cli', cmd: 'res', package: '@easy-team/res-cli' }; | ||
}; | ||
exports.getWebpackConfig = appInfo => { | ||
const cli = exports.getCli(); | ||
const filepath = path.join(appInfo.baseDir, 'node_modules', cli.package); | ||
const cwdFilepath = path.join(process.cwd(), 'node_modules', cli.package); | ||
if (fs.existsSync(filepath) || fs.existsSync(cwdFilepath)) { | ||
const resCli = require(cli.package); | ||
return resCli.getWebpackConfig(); | ||
} | ||
return []; | ||
}; |
Oops, something went wrong.