Skip to content

Commit

Permalink
feat: implement node react web framework
Browse files Browse the repository at this point in the history
  • Loading branch information
sky committed Oct 13, 2019
0 parents commit 4fc5e38
Show file tree
Hide file tree
Showing 47 changed files with 24,106 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .autod.conf.js
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',
],
};

3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-egg"
}
11 changes: 11 additions & 0 deletions .gitignore
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/
11 changes: 11 additions & 0 deletions .travis.yml
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


69 changes: 69 additions & 0 deletions README.md
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)
5 changes: 5 additions & 0 deletions app.js
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');
};
5 changes: 5 additions & 0 deletions app/extend/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {

};
5 changes: 5 additions & 0 deletions app/extend/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {

};
7 changes: 7 additions & 0 deletions app/middleware/locals.js
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();
};
};
16 changes: 16 additions & 0 deletions app/service/test.js
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;
16 changes: 16 additions & 0 deletions app/web/tsconfig.json
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"
]
}
4 changes: 4 additions & 0 deletions app/web/typings/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.vue" {
import Vue from 'vue'
export default Vue
}
8 changes: 8 additions & 0 deletions app/web/typings/webpack.d.ts
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 added app/web/typings/window.d.ts
Empty file.
13 changes: 13 additions & 0 deletions app/web/view/layout.html
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>
15 changes: 15 additions & 0 deletions appveyor.yml
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
14 changes: 14 additions & 0 deletions bin/cli.js
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();
}
38 changes: 38 additions & 0 deletions config/config.default.js
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;
};
31 changes: 31 additions & 0 deletions config/config.local.js
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;
};
10 changes: 10 additions & 0 deletions config/plugin.js
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',
};
15 changes: 15 additions & 0 deletions config/plugin.local.js
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',
};
3 changes: 3 additions & 0 deletions index.d.ts
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;
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./lib/framework.js');
22 changes: 22 additions & 0 deletions lib/framework.js
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,
});
16 changes: 16 additions & 0 deletions lib/utils.js
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 [];
};

0 comments on commit 4fc5e38

Please sign in to comment.