th3mon
1/28/2017 - 5:49 PM

aurelia dist task

aurelia dist task

import gulp from 'gulp';
import project from '../aurelia.json';
import build from './build';
import del from 'del';

function dist() {
  let defaults = {
    index: 'index.html',
    dist: {
      root: 'dist',
      source: [
        'scripts',
        'img',
        'locales',
        'fonts'
      ]
    }
  };

  return gulp.src([
    getIndex(defaults),
    ...getSource(defaults)
  ], {
    base: '.'
  }).pipe(gulp.dest(getRoot(defaults)));
}

function getIndex(defaults) {
  let index = (project.platform &&
    project.platform.index) ||
    defaults.index;

  return index;
}

function getSource(defaults) {
  let sources = (project.paths &&
    project.paths.dist &&
    project.paths.dist.source) ||
    defaults.dist.source;

  return sources.map((source) => `${source}/**/*`);
}

function getRoot(defaults) {
  let root = (project.paths &&
    project.paths.dist &&
    project.paths.dist.root) ||
    defaults.dist.root;

  return root;
}

function cleanDist() {
  return del('dist');
}

export default gulp.series(
  build,
  cleanDist,
  dist
);

// Usage
// au dist --env prod