FE-40: Added browserify, uglify, eslint, http proxy

This commit is contained in:
Ildar Galeev 2016-08-27 18:54:38 +03:00
parent cc414427a3
commit 8a70587e60
7 changed files with 92 additions and 35 deletions

13
.eslintrc.json Normal file
View File

@ -0,0 +1,13 @@
{
"env": {
"browser": true
},
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"quotes": [2, "single"]
}
}

View File

@ -1,13 +1,38 @@
const gulp = require('gulp');
const pug = require('gulp-pug');
const connect = require('gulp-connect');
const livereload = require('gulp-livereload');
const nodemon = require('gulp-nodemon');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
gulp.task('thrift', () => {
return gulp.src('src/thrift.js')
.pipe(gulp.dest('dist/woody'));
const config = {
dist: 'dist'
};
gulp.task('lint', () => {
return gulp.src('src/**/*.js')
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('browserify', ['lint'], () => {
return browserify({
entries: 'src/bootstrap.js',
extensions: ['.js'],
debug: true
}).bundle()
.pipe(source('woody.js'))
.pipe(gulp.dest(config.dist));
});
gulp.task('uglify', ['browserify'], () => {
return gulp.src(`${config.dist}/woody.js`)
.pipe(rename('woody.min.js'))
.pipe(uglify())
.pipe(gulp.dest(config.dist));
});
gulp.task('index', () => {
@ -15,28 +40,24 @@ gulp.task('index', () => {
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('dist'))
.pipe(livereload());
.pipe(gulp.dest(config.dist));
});
// gulp.task('connectDist', () => {
// connect.server({
// root: 'dist',
// host: '127.0.0.1',
// port: 8000
// });
// });
gulp.task('client', () => {
return gulp.src('sample/client.js')
.pipe(gulp.dest(config.dist));
});
gulp.task('watch', () => {
livereload.listen();
gulp.watch('sample/index.pug', ['index']);
gulp.watch('src/thrift.js', ['thrift']);
gulp.watch('sample/client.js', ['client']);
gulp.watch('src/**/*.js', ['browserify']);
});
gulp.task('thriftServer', () => {
gulp.task('server', () => {
var started = false;
return nodemon({
script: 'dist/thrift-server.js'
script: 'server.js'
}).on('start', () => {
if (!started) {
cb();
@ -45,4 +66,5 @@ gulp.task('thriftServer', () => {
});
});
gulp.task('default', ['thrift', 'index', 'watch']);
gulp.task('build', ['uglify']);
gulp.task('default', ['browserify', 'index', 'watch', 'client', 'server']);

View File

@ -8,11 +8,16 @@
},
"author": "rbkmoney",
"devDependencies": {
"browserify": "^13.1.0",
"express": "^4.14.0",
"express-http-proxy": "^0.9.1",
"gulp": "^3.9.1",
"gulp-connect": "^5.0.0",
"gulp-livereload": "^3.8.1",
"gulp-eslint": "^3.0.1",
"gulp-nodemon": "^2.1.0",
"gulp-pug": "^3.0.4"
"gulp-pug": "^3.0.4",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.0.0",
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {
"thrift": "^0.9.3"

6
sample/client.js Normal file
View File

@ -0,0 +1,6 @@
var transport = new Thrift.TXHRTransport("/v1/domain/repository");
var protocol = new Thrift.TJSONProtocol(transport);
var client = new RepositoryClient(protocol);
client.send_Pull(0, result => console.log(result));

View File

@ -2,17 +2,10 @@ doctype html
html(lang="en")
head
meta(charset="utf-8")
title WoodyJS Sample
script(src="gen-js/hello_svc.js")
script(src="woody/thrift.js")
script().
var transport = new Thrift.TXHRTransport("/hello");
var protocol = new Thrift.TJSONProtocol(transport);
var client = new hello_svcClient(protocol);
var test = function () {
client.get_message("Дратути", function (result) {
console.log(result);
});
}
title Woody JS Sample
script(src="woody.js")
script(src="gen-js-damsel/domain_config_types.js")
script(src="gen-js-damsel/Repository.js")
script(src="gen-js-damsel/RepositoryClient.js")
script(src="client.js")
body

13
server.js Normal file
View File

@ -0,0 +1,13 @@
var proxy = require('express-http-proxy');
var express = require('express');
var app = express();
app.use(proxy('http://localhost:8022', {
filter: function (req, res) {
return req.method == 'POST';
}
// preserveHostHdr: true
}));
app.use(express.static('dist'));
app.listen(9000);

5
src/bootstrap.js vendored Normal file
View File

@ -0,0 +1,5 @@
const thrift = require('./thrift.js');
(function init() {
window.Thrift = thrift;
}());