const gulp = require('gulp');
const replace = require('gulp-replace');
const yaml = require('gulp-yaml');
const del = require('del');
const connect = require('gulp-connect');

const swaggerRoot = 'specs/maas-v1.json'

// Wait for clean:docs to finish to avoid filesystem errors
gulp.task('copy-swagger-ui', ['clean:docs'], function() {
  // Copies everything
  return gulp.src(['node_modules/swagger-ui-dist/*', '!node_modules/swagger-ui-dist/index.html'])
    .pipe(gulp.dest('docs'));
});

// Wait for clean:docs to finish to avoid filesystem errors
gulp.task('copy-specs', ['clean:docs'], function() {
  return gulp.src(['specs/**/*.json', 'specs/**/*.png', 'specs/**/*.svg'])
    .pipe(gulp.dest('docs/specs'));
});

gulp.task('watch-specs', function() {
  gulp.watch(['specs/**/*.yml'], ['clean:docs', 'transform-yaml', 'copy-swagger-ui', 'copy-specs']);
})

gulp.task('transform-yaml', function() {
  return gulp.src('./specs/*.yml')
    .pipe(yaml({ safe: true, space: 2 }))
    .pipe(gulp.dest('./specs/'))
});

gulp.task('clean:docs', function () {
  return del(['docs/*', '!docs/index.html']);
});

gulp.task('serve', function() {
  return connect.server({
    root: 'docs',
    livereload: true
  });
});

// Aliases

gulp.task('docs', ['copy-swagger-ui', 'copy-specs']);
gulp.task('build', ['transform-yaml']);
gulp.task('clean', ['clean:docs']);
gulp.task('watch', ['watch-specs']);

@@ -167,16 +167,52 @@
 nnect');
+%0Aconst shell = require('gulp-shell')
 %0A%0Aconst 
@@ -1246,16 +1246,744 @@
 );%0A%7D);%0A%0A
+gulp.task(%0A  'create-temp-gh-pages-deployment-branch',%0A  shell.task(%0A    %5B%0A      'git checkout -b gh-pages-tmp',%0A      'rm .gitignore'%0A    %5D%0A  )%0A)%0A%0Agulp.task(%0A  'deploy-temp-gh-pages-deployment-branch',%0A  shell.task(%0A    %5B%0A      'git checkout -b gh-pages-tmp',%0A      'rm .gitignore',%0A      'git add .',%0A      'git commit -am %22Remove gitignore; add built docs%22',%0A      // Push the docs folder to the Github Pages branch%0A      'git subtree push --prefix docs upstream gh-pages',%0A    %5D%0A  )%0A)%0A%0Agulp.task(%0A  'delete-temp-gh-pages-deployment-branch',%0A  shell.task(%0A    %5B%0A      // TODO: change the following line to 'git checkout master' after test%0A      'git checkout gh-pages-deploy-script',%0A      'git -d gh-pages-tmp'%0A    %5D%0A  )%0A)%0A%0A
 // Alias
@@ -2145,16 +2145,172 @@
 watch-specs'%5D);%0A
+gulp.task('deploy' %5B%0A  'create-temp-gh-pages-deployment-branch',%0A  'deploy-temp-gh-pages-deployment-branch',%0A  'delete-temp-gh-pages-deployment-branch',%0A%5D)%0A

Add 'deploy' task with sub-tasks