/* eslint-env node */
const gulp = require('gulp');
const ghPages = require('gulp-gh-pages');
const execa = require('execa');
const merge = require('merge-stream');
const striptags = require('striptags');
const transform = require('gulp-transform');
const insert = require('gulp-insert');

gulp.task('docs:api', function() {
  return execa('ember', ['ember-cli-yuidoc']);
});

gulp.task('docs:app', function() {
  return execa('ember', ['build', '--prod'], {
    cwd: 'docs'
  });
});

gulp.task('docs:publish', gulp.series(gulp.parallel('docs:api', 'docs:app'), function() {
  return merge(
    gulp.src('docs/api/**/*', { base: 'docs' }),
    gulp.src('docs/dist/**/*'),
    gulp.src('CHANGELOG.md').pipe(transform(striptags, { encoding: 'utf8' }))
  )
    .pipe(ghPages());
}));

gulp.task('changelog', function() {
  let index = process.argv.indexOf('--tag');
  let args = ['-s'];
  if (index !== -1) {
    let tag = process.argv[index + 1];
    args.push('--next-version', tag);
  }
  return execa('node_modules/lerna-changelog/bin/cli.js', args)
    .then(({ stdout }) => {
      return gulp.src('CHANGELOG.md')
        .pipe(insert.prepend(stdout))
        .pipe(gulp.dest('./'));
    });
});

gulp.task('docs', gulp.series('docs:publish'));

@@ -246,47 +246,8 @@
 m');
-%0Aconst insert = require('gulp-insert');
 %0A%0Agu
@@ -741,426 +741,8 @@
 );%0A%0A
-gulp.task('changelog', function() %7B%0A  let index = process.argv.indexOf('--tag');%0A  let args = %5B'-s'%5D;%0A  if (index !== -1) %7B%0A    let tag = process.argv%5Bindex + 1%5D;%0A    args.push('--next-version', tag);%0A  %7D%0A  return execa('node_modules/lerna-changelog/bin/cli.js', args)%0A    .then((%7B stdout %7D) =%3E %7B%0A      return gulp.src('CHANGELOG.md')%0A        .pipe(insert.prepend(stdout))%0A        .pipe(gulp.dest('./'));%0A    %7D);%0A%7D);%0A%0A
 gulp

remove gulp task for generating changelog