Makes the dev file built more gulp-ish way

This commit is contained in:
2016-02-23 18:22:21 +01:00
parent 603943c4a1
commit 924ea137b9
6 changed files with 97 additions and 28 deletions

1
.gitignore vendored
View File

@@ -32,3 +32,4 @@ tmp/
bower_components
node_modules
/webapp/index.html
dist/

View File

@@ -1,6 +1,82 @@
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({});
var karma = require('karma');
var es = require('event-stream');
var bowerFiles = require('main-bower-files');
var exists = require('path-exists').sync
var pipes = {};
var paths = {
appFiles: 'webapp/js/**/*.js',
cssFiles: 'webapp/css/**/*.css',
partials: 'webapp/js/**/*.html',
pages : ['webapp/html/**/*.html', '!webapp/html/index.html'],
index : 'webapp/html/index.html',
distDev : 'dist/dev',
distProd: 'dist/prod'
}
pipes.vendorJsFiles = function() {
return gulp.src(bowerFiles({
overrides : {
jquery : {
main: []
},
bootstrap : {
main: [ "dist/**/*.css" ]
}
}
}).map(function(path, index,arr) {
var newPath = path.replace(/.([^.]+)$/g, '.min.$1');
console.log('path: ' + path + ' newpath:' + newPath + ' exits: ' + exists(newPath) )
return exists ( newPath ) ? newPath : path;
}))
.pipe(plugins.debug({title: 'vendor-js:'}))
}
pipes.validatedAppScripts = function() {
return gulp.src(paths.appFiles)
.pipe(plugins.jshint())
.pipe(plugins.debug({title: 'validated-js:'}));
}
pipes.validatedIndex = function() {
return gulp.src(paths.index);
}
pipes.validatedPartials = function() {
return gulp.src(paths.partials);
}
pipes.validatedPages = function() {
return gulp.src(paths.pages)
}
pipes.builtIndexDev = function() {
var vendorFiles = pipes.vendorJsFiles()
.pipe(gulp.dest(paths.distDev + '/vendor'));
var appScript = pipes.validatedAppScripts()
.pipe(plugins.angularFilesort())
.pipe(gulp.dest(paths.distDev + '/js'))
var appStyle = gulp.src(paths.cssFiles)
.pipe(gulp.dest(paths.distDev + '/css'))
var partials = pipes.validatedPartials()
.pipe(gulp.dest(paths.distDev + '/js'))
var pages = pipes.validatedPages()
.pipe(gulp.dest(paths.distDev + '/html'))
return pipes.validatedIndex()
.pipe(plugins.inject(vendorFiles, {ignorePath: '/'+ paths.distDev, name:'bower'}))
.pipe(plugins.inject(es.merge(appStyle,partials,pages), {ignorePath: '/'+ paths.distDev}))
.pipe(plugins.inject(appScript, {ignorePath: '/'+ paths.distDev}))
.pipe(gulp.dest(paths.distDev));
}
gulp.task('test', function(done) {
server = new karma.Server({
@@ -17,17 +93,4 @@ gulp.task('test', function(done) {
gulp.task('build', function() {
return gulp.src('./webapp/html/index.html')
.pipe(plugins.inject(
gulp.src(['./webapp/js/**/*.js']).pipe(plugins.angularFilesort()),
{
ignorePath: '/webapp'
}
))
.pipe(gulp.dest('./webapp'));
});
gulp.task('autobuild', function() {
return gulp.watch(['webapp/js/**/*.js','webapp/html/index.html'], ['build']);
});
gulp.task('build-dev', pipes.builtIndexDev);

View File

@@ -27,6 +27,7 @@ type Options struct {
RequestWindow time.Duration `long:"request-window" description:"Window over which no more --max-request are done"`
CacheTTL time.Duration `long:"chache-ttl" description:"TTL of the cached data" `
BatchSize int `long:"batch-size" description:"Sizes of the batch for indexing" default:"1000"`
BasePath string `long:"basepath" short:"b" description:"basepath of the webapp" default:"dist/prod"`
}
type appData struct {
@@ -378,7 +379,7 @@ func Execute() error {
log.Printf("Listening on %s", opts.Listen)
a.start(srv.StopChan())
srv.Server.Handler = a.buildRouter()
srv.Server.Handler = a.buildRouter(opts.BasePath)
if err := srv.ListenAndServe(); err != nil {
if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
return err

View File

@@ -6,18 +6,24 @@
"bower": "^1.7.7",
"gulp": "^3.9.1",
"gulp-angular-filesort": "^1.1.1",
"gulp-debug": "^2.1.2",
"gulp-inject": "^3.0.0",
"gulp-jasmine": "^2.2.1",
"gulp-jshint": "^2.0.0",
"gulp-karma": "0.0.5",
"gulp-load-plugins": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-util": "^3.0.7",
"jasmine-core": "^2.4.1",
"jshint": "^2.9.1",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.7",
"karma-junit-reporter": "^0.3.8",
"karma-safari-launcher": "^0.1.1",
"main-bower-files": "^2.11.1",
"path-exists": "^2.1.0",
"protractor": "^3.1.1"
},
"scripts": {

View File

@@ -19,7 +19,7 @@ import (
"golang.org/x/net/context"
)
func (a *appData) buildRouter() http.Handler {
func (a *appData) buildRouter(basepath string) http.Handler {
router := httprouter.New()
logger := narco.NewLogger()
@@ -126,19 +126,19 @@ func (a *appData) buildRouter() http.Handler {
})))
dirs := []string{"css", "js", "img", "bower_components", "html"}
dirs := []string{"css", "js", "vendor", "html"}
for _, d := range dirs {
router.ServeFiles(path.Join("/", d, "/*filepath"), http.Dir(filepath.Join("webapp", d)))
router.ServeFiles(path.Join("/", d, "/*filepath"), http.Dir(filepath.Join(basepath, d)))
}
router.GET("/", narco.EndChain(ch, narco.HandlerFunc(
func(ctx context.Context, w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
f, err := os.Open(filepath.Join("webapp", "index.html"))
f, err := os.Open(filepath.Join(basepath, "index.html"))
if err != nil {
narco.Error(ctx, w, err, http.StatusInternalServerError)
return
}
defer closeOrPanic(f, filepath.Join("webapp", "index.html"))
defer closeOrPanic(f, filepath.Join(basepath, "index.html"))
_, err = io.Copy(w, f)
if err != nil {

View File

@@ -4,10 +4,12 @@
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link rel="icon" href="https://satellite.bar/images/sat.ico" />
<link href="/css/satbd.sateliite.bar.css" rel="stylesheet" />
<title>satbd: explorez la betheque de sat</title>
<!-- bower:css -->
<!-- endinject -->
<!-- inject:css -->
<!-- endinject -->
</head>
<body ng-app="satbd.satellite.bar">
<nav class="navbar navbar-inverse navbar-fixed-top">
@@ -46,12 +48,8 @@
<div class="container-fluid" ng-view>
</div>
<script src="/bower_components/angular/angular.min.js"></script>
<script src="/bower_components/angular-animate/angular-animate.min.js"></script>
<script src="/bower_components/angular-route/angular-route.min.js"></script>
<script src="/bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="/bower_components/angular-inview/angular-inview.js"></script>
<!-- bower:js -->
<!-- endinject -->
<!-- inject:js -->
<!-- endinject -->
</body>