'use strict';

var gulp = require('gulp');
var wrap = require('gulp-wrap');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var shell = require('gulp-shell')
var watch = require('gulp-watch');
var webserver = require('gulp-webserver');

gulp.task('webserver', function() {
  gulp.src('.')
    .pipe(webserver({
      livereload: false,
      directoryListing: false,
      open: false,
      fallback: 'index.html'
    }));
});

gulp.task('scss', function () {
  gulp.src('./assets/css/main.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(wrap('<style type="text/css">\n<%= contents %>\n</style>'))
    .pipe(gulp.dest('./assets/css/dist'));
});

gulp.task('gui', function () {
  gulp.src('./assets/css/gui.scss')
    .pipe(sass().on('error', sass.logError))
    // .pipe(wrap('<style type="text/css">\n<%= contents %>\n</style>'))
    .pipe(gulp.dest('./assets/css/dist'));
});

gulp.task('sync', shell.task([
  './bin/sync.sh'
]));

gulp.task('build', shell.task([
  './bin/build.py'
]));


// default gulp task
gulp.task('default', ['webserver', 'sync', 'scss', 'gui', 'build'], function() {
  gulp.watch('./assets/css/**/*.scss', ['scss']);
  gulp.watch('./assets/css/gui.scss', ['gui']);
  gulp.watch(['bin/build.py', './assets/css/**/*.scss', './assets/js/**/*.js', './templates/*.tpl.html'], ['build']);
});
