This commit is contained in:
qitmac000249 2017-07-26 16:49:52 +08:00
commit a95d505889
4 changed files with 167 additions and 30 deletions

View File

@ -2,6 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types'
import { changeMenuItem } from '../actions/menu'
import { message } from 'antd'
export function requireAuthentication(Component) {
@ -26,6 +27,7 @@ export function requireAuthentication(Component) {
if( !this.props.isAuthenticated ){
this.props.history.push('/');
this.props.changeMenuItem('/');
message.info('请先登录',1);
}
}
render() {

View File

@ -13,6 +13,7 @@ import QueueAnim from 'rc-queue-anim';
const oneAnim = { y: '+=30', opacity: 0, type: 'from', ease: 'easeOutQuad' };
const imgAnim = { y: '+=50', opacity: 0, type: 'from', ease: 'easeOutQuad', duration: '1500'};
const style = {
'height':'100%',
'width':'100%',
@ -36,11 +37,19 @@ const HomeGuest = (props) => (
<Col span={8} className="main-one-left">
<Login/>
</Col>
<Col span={16} className="main-one-right">
<div className="img-container">
<img src="./image/demo-img.png"/>
</div>
</Col>
<OverPack>
<TweenOne
key="feat-motion-one"
animation={imgAnim}
>
<Col span={16} className="main-one-right">
<div className="img-container">
<img src="./image/demo-img.png"/>
</div>
</Col>
</TweenOne>
</OverPack>
</Row>
</div>
</div>

View File

@ -1,32 +1,154 @@
const fs = require('fs-extra');
const path = require('path');
const gulp = require('gulp');
const babel = require('gulp-babel');
const watch = require('gulp-watch');
const nodemon = require('nodemon');
const dist = './server_dist/'
const ora = require('ora');
const chalk = require('chalk');
const { spawn } = require('child_process');
let spinner = ora('请稍等...').start();
const DIST = 'server_dist/';
const SRC = 'server/**/*.js';
gulp.task('default', ['clearLib', 'compileJS']);
gulp.task('clearLib', [], function() {
return fs.removeSync(dist)
});
gulp.task('compileJS', ['clearLib'], function() {
var babelProcess = babel({
presets: ['es2015', "stage-3"],
function generateBabel(status) {
const babelProcess = babel({
presets: ['es2015', "stage-3"],
plugins: ['transform-runtime']
})
babelProcess.on('error', function(e) {
console.log(e);
process.exit(1);
});
gulp.src('server/**/*.!(js)').pipe(gulp.dest(dist));
babelProcess.on('error', function (e) {
const restart = status ? status.count < 2 : true;
return watch(['server/**/*.js'], {
verbose: true,
ignoreInitial: false
}).pipe(babelProcess).pipe(gulp.dest(dist));
})
console.error(e);
output('error', 'babel 编译失败!', restart);
if (status) {
status.count++;
}
});
return babelProcess;
}
function excuteCmd(cmd, args, opts) {
const command = spawn(cmd, args, opts);
command.stdout.on('data', data => {
output('log', `${cmd}: ${data.toString()}`, true);
});
command.stderr.on('data', data => {
output('log', `${cmd}: ${data.toString()}`, true);
});
command.on('close', code => {
if (code !== 0) {
output('log', `${cmd}: ${data.toString()}`);
}
});
}
function output(type, message, restart = false) {
spinner.stop();
if (type === 'success') {
message = '✔ ' + message;
console.log(chalk.green(message));
} else if (type === 'error') {
message = '✖ ' + message;
console.log(chalk.red(message));
} else {
console.log(message);
}
if (restart) {
spinner.start();
}
}
gulp.task('removeDist', [], function () {
return fs.removeSync(DIST)
});
gulp.task('initialBuild', ['removeDist'], () => {
spinner.text = '初始编译...';
return gulp.src(SRC)
.pipe(generateBabel())
.pipe(gulp.dest(DIST))
.on('end', () => {
output('success', '初始编译成功!');
spinner = ora({
text: '等待文件变更...',
spinner: 'pong',
color: 'green'
}).start();
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js', 'dev'], {
cwd: __dirname
});
excuteCmd('ykit', ['s', '-p', '4000'], {
cwd: path.resolve(__dirname, '../')
});
});
});
gulp.task('default', ['initialBuild'], () => {
gulp.watch(SRC, (event) => {
spinner.text = `正在编译 ${event.path}...`;
gulp.src(event.path).pipe(generateBabel())
.pipe(gulp.dest(DIST)).on('end', () => {
output('success', `成功编译 ${event.path}`);
spinner = ora({
text: 'waiting changes...',
spinner: 'pong',
color: 'green'
});
spinner.start();
});
});
});
gulp.task('build', () => {
let status = {
count: 0
};
let ykitOutput = '';
spinner.text = '正在编译...';
gulp.src(SRC)
.pipe(generateBabel(status))
.pipe(gulp.dest(DIST))
.on('error', (err) => {
status.count++;
output('error', err, status.count < 2);
})
.on('end', () => {
status.count++;
output('success', '后端编译成功!', status.count < 2);
});
const ykitBuild = spawn('ykit', ['pack', '-m'], {
cwd: __dirname
});
ykitBuild.stderr.on('data', data => {
ykitOutput += data.toString();
});
ykitBuild.stdout.on('data', data => {
ykitOutput += data.toString();
});
ykitBuild.on('close', code => {
if (code === 0) {
status.count++;
output('success', '前端编译成功!', status.count < 2);
} else {
status.count++;
output('error', '前端编译失败!', status.count < 2);
output('log', ykitOutput);
}
});
});

View File

@ -6,7 +6,9 @@
"scripts": {
"build-server": "babel server -d server_dist",
"dev-server": "nodemon server_dist/app.js",
"install-server" : "node server_dist/install.js"
"install-server" : "node server_dist/install.js",
"dev": "gulp --silent",
"build": "gulp build --silent"
},
"repository": {
"type": "git",
@ -76,6 +78,7 @@
"babel-register": "^6.9.0",
"babel-runtime": "^6.9.2",
"buffer-shims": "^1.0.0",
"chalk": "^2.0.1",
"css-loader": "^0.28.4",
"eslint": "^3.19.0",
"eslint-plugin-import": "^2.2.0",
@ -90,6 +93,7 @@
"gulp-watch": "^4.3.11",
"node-sass": "^4.5.3",
"nodemon": "^1.11.0",
"ora": "^1.3.0",
"prop-types": "^15.5.10",
"react": "^15.6.1",
"react-dom": "^15.6.1",