Skip to content

Commit 4fc5e38

Browse files
author
sky
committed
feat: implement node react web framework
0 parents  commit 4fc5e38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+24106
-0
lines changed

.autod.conf.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
module.exports = {
4+
write: true,
5+
prefix: '^',
6+
plugin: 'autod-egg',
7+
test: [
8+
'test',
9+
'benchmark',
10+
],
11+
dep: [
12+
'egg'
13+
],
14+
devdep: [
15+
'egg-ci',
16+
'egg-bin',
17+
'autod',
18+
'eslint',
19+
'eslint-config-egg',
20+
'webstorm-disable-index',
21+
],
22+
exclude: [
23+
'./test/fixtures',
24+
'./dist',
25+
],
26+
};
27+

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "eslint-config-egg"
3+
}

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
logs/
2+
npm-debug.log
3+
node_modules/
4+
coverage/
5+
.idea/
6+
run/
7+
.DS_Store
8+
*.swp
9+
package-lock.json
10+
yarn.lock
11+
.nyc_output/

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '8'
5+
- '10'
6+
install:
7+
- npm i npminstall && npminstall
8+
script:
9+
- npm run ci
10+
after_script:
11+
- npminstall codecov && codecov

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# res
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![build status][travis-image]][travis-url]
5+
[![Test coverage][codecov-image]][codecov-url]
6+
[![David deps][david-image]][david-url]
7+
[![Known Vulnerabilities][snyk-image]][snyk-url]
8+
[![npm download][download-image]][download-url]
9+
10+
[npm-image]: https://img.shields.io/npm/v/res.svg?style=flat-square
11+
[npm-url]: https://npmjs.org/package/res
12+
[travis-image]: https://img.shields.io/travis/easy-team/res.svg?style=flat-square
13+
[travis-url]: https://travis-ci.org/easy-team/res
14+
[codecov-image]: https://img.shields.io/codecov/c/github/easy-team/res.svg?style=flat-square
15+
[codecov-url]: https://codecov.io/github/easy-team/res?branch=master
16+
[david-image]: https://img.shields.io/david/easy-team/res.svg?style=flat-square
17+
[david-url]: https://david-dm.org/easy-team/res
18+
[snyk-image]: https://snyk.io/test/npm/res/badge.svg?style=flat-square
19+
[snyk-url]: https://snyk.io/test/npm/res
20+
[download-image]: https://img.shields.io/npm/dm/res.svg?style=flat-square
21+
[download-url]: https://npmjs.org/package/res
22+
23+
24+
A Powerful, Simple React Node Web Framework, Front-End and Node of The Application are Written in TypeScript or JavaScript! Everything is Simple!
25+
26+
> 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.
27+
28+
## Installation
29+
30+
```bash
31+
$ npm install @easy-team/res --save
32+
```
33+
34+
Node.js >= 8.0.0 required.
35+
36+
## Features
37+
38+
- ✔︎ Based on [Egg](https://eggjs.org/en/intro/index.html) Framework, Powerful, Easy to Expand
39+
- ✔︎ Support React Server Side Render and Client Side Render Modes, Nunjucks & React Render Mode, Rendering Cache, Automatic Downgrade,
40+
- ✔︎ Front-End and Node of The Application are Written in TypeScript or JavaScript
41+
- ✔︎ Build with Webpack, Auto Building, Hot Reload, Code Splitting, High Speed, Performance Optimization
42+
- ✔︎ Powerful Tool Chain [res-cli](https://github.com/easy-team/res-cli)
43+
44+
## Document
45+
46+
- https://www.yuque.com/easy-team/res
47+
48+
## QuickStart
49+
50+
```bash
51+
$ npm install -g @easy-team/res-cli
52+
$ res init
53+
$ npm install
54+
$ npm run dev
55+
$ open http://localhost:7001
56+
```
57+
58+
## Examples
59+
60+
See [res-awesome](https://github.com/easy-team/res-awesome)
61+
62+
## Links
63+
64+
- https://eggjs.org/en/advanced/framework.html
65+
- https://www.yuque.com/easy-team/res
66+
67+
## License
68+
69+
[MIT](LICENSE)

app.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
// https://github.com/eggjs/egg/issues/1520
3+
module.exports = app => {
4+
app.config.coreMiddleware.push('locals');
5+
};

app/extend/application.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
5+
};

app/extend/context.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
5+
};

app/middleware/locals.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
module.exports = () => {
3+
return async function(ctx, next) {
4+
ctx.locals.title = 'res';
5+
await next();
6+
};
7+
};

app/service/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const Service = require('egg').Service;
4+
5+
class TestService extends Service {
6+
constructor(ctx) {
7+
super(ctx);
8+
this.config = this.app.config.test;
9+
}
10+
11+
async get(id) {
12+
return { id, name: this.config.key };
13+
}
14+
}
15+
16+
module.exports = TestService;

app/web/tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../config/tsconfig.json",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "esnext",
6+
"lib": [
7+
"es6",
8+
"dom"
9+
]
10+
},
11+
12+
"exclude": [
13+
"node_modules",
14+
"**/*.spec.ts"
15+
]
16+
}

app/web/typings/vue.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.vue" {
2+
import Vue from 'vue'
3+
export default Vue
4+
}

app/web/typings/webpack.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare var EASY_ENV_IS_NODE: boolean;
2+
declare var EASY_ENV_IS_BROWSER: boolean;
3+
declare var EASY_ENV_IS_DEV: boolean;
4+
declare var process : {
5+
env: {
6+
NODE_ENV: string
7+
}
8+
}

app/web/typings/window.d.ts

Whitespace-only changes.

app/web/view/layout.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title></title>
5+
<meta name="keywords">
6+
<meta name="description">
7+
<meta http-equiv="content-type" content="text/html;charset=utf-8">
8+
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
9+
</head>
10+
<body>
11+
<div id="app"></div>
12+
</body>
13+
</html>

appveyor.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: '8'
4+
- nodejs_version: '10'
5+
6+
install:
7+
- ps: Install-Product node $env:nodejs_version
8+
- npm i npminstall && node_modules\.bin\npminstall
9+
10+
test_script:
11+
- node --version
12+
- npm --version
13+
- npm run test
14+
15+
build: off

bin/cli.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
const path = require('path');
5+
const fs = require('fs');
6+
const EggScriptCommand = require('egg-scripts');
7+
const cliFilePath = path.join(process.cwd(), 'node_modules', '@easy-team/res-cli');
8+
// fix when production mode, ves-cli not exists, start app error by ves start
9+
if (fs.existsSync(cliFilePath)) {
10+
const ResCLI = require(cliFilePath);
11+
new ResCLI.Command().start();
12+
} else {
13+
new EggScriptCommand().start();
14+
}

config/config.default.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const path = require('path');
3+
module.exports = appInfo => {
4+
const config = {};
5+
6+
config.view = {
7+
defaultViewEngine: 'nunjucks',
8+
mapping: {
9+
'.tpl': 'nunjucks'
10+
},
11+
};
12+
13+
/**
14+
* some description
15+
* @member Config#test
16+
* @property {String} key - some description
17+
*/
18+
config.test = {
19+
key: appInfo.name + '_123456',
20+
};
21+
22+
/**
23+
* cookie secret key
24+
*/
25+
config.keys = appInfo.name + '_123456';
26+
27+
/**
28+
* vue ssr plugin config
29+
* @member Config#vuessr
30+
* @property {String} layout - client render default html layout file path
31+
* @property {renderOptions} Object - vue server side render options
32+
*/
33+
config.reactssr = {
34+
layout: path.resolve(__dirname, '../app/web/view/layout.html')
35+
};
36+
37+
return config;
38+
};

config/config.local.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const utils = require('../lib/utils');
3+
module.exports = app => {
4+
5+
const exports = {};
6+
7+
exports.view = {
8+
cache: false,
9+
};
10+
11+
exports.static = {
12+
maxAge: 0, // maxAge cache, default one year, local disabled
13+
};
14+
15+
exports.development = {
16+
watchDirs: [],
17+
ignoreDirs: [ 'app/web', 'public', 'config/manifest.json' ],
18+
};
19+
20+
/**
21+
* egg-webpack plugin config
22+
* @member Config#webpack
23+
* @property {Array} webpackConfigList - webpack config
24+
*/
25+
exports.webpack = {
26+
cli: utils.getCli(),
27+
webpackConfigList: utils.getWebpackConfig(app),
28+
};
29+
30+
return exports;
31+
};

config/plugin.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
exports.reactssr = {
3+
enable: true,
4+
package: 'egg-view-react-ssr',
5+
};
6+
7+
exports.nunjucks = {
8+
enable: true,
9+
package: 'egg-view-nunjucks',
10+
};

config/plugin.local.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
exports.cors = {
3+
enable: true,
4+
package: 'egg-cors',
5+
};
6+
7+
exports.webpack = {
8+
enable: true,
9+
package: 'egg-webpack',
10+
};
11+
12+
exports.webpackreact = {
13+
enable: true,
14+
package: 'egg-webpack-react',
15+
};

index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as Egg from 'egg';
2+
export = Egg;
3+
export as namespace Egg;

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./lib/framework.js');

lib/framework.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const egg = require('egg');
5+
const EGG_PATH = Symbol.for('egg#eggPath');
6+
7+
class Application extends egg.Application {
8+
get [EGG_PATH]() {
9+
return path.dirname(__dirname);
10+
}
11+
}
12+
13+
class Agent extends egg.Agent {
14+
get [EGG_PATH]() {
15+
return path.dirname(__dirname);
16+
}
17+
}
18+
19+
module.exports = Object.assign(egg, {
20+
Application,
21+
Agent,
22+
});

lib/utils.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const path = require('path');
3+
const fs = require('fs');
4+
exports.getCli = () => {
5+
return { name: 'res-cli', cmd: 'res', package: '@easy-team/res-cli' };
6+
};
7+
exports.getWebpackConfig = appInfo => {
8+
const cli = exports.getCli();
9+
const filepath = path.join(appInfo.baseDir, 'node_modules', cli.package);
10+
const cwdFilepath = path.join(process.cwd(), 'node_modules', cli.package);
11+
if (fs.existsSync(filepath) || fs.existsSync(cwdFilepath)) {
12+
const resCli = require(cli.package);
13+
return resCli.getWebpackConfig();
14+
}
15+
return [];
16+
};

0 commit comments

Comments
 (0)