jLinux

Untitled

Dec 29th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const gulp    = require('gulp');
  4. const babel   = require('gulp-babel');
  5. const argv    = require('yargs').argv;
  6.  
  7. const jsSrc   = 'src/**/*.js';
  8. const jsonSrc = 'src/*.json';
  9. const dist    = 'dist';
  10.  
  11.  
  12. // Transpile from ES6 to ES5
  13. gulp.task( 'transpile', () => {
  14.     return gulp
  15.         .src( jsSrc )
  16.         .pipe( babel( {
  17.             presets: [ 'es2015' ]
  18.         }))
  19.         .pipe( gulp.dest( dist ) );
  20. });
  21.  
  22. // Copy JSON files
  23. gulp.task( 'copy-json-files', () => {
  24.     return gulp
  25.         .src( jsonSrc )
  26.         .pipe( gulp.dest( dist ) )
  27. });
  28.  
  29. // Check if --watch true was passed to the command line
  30. if( typeof argv.watch !== 'undefined' && !!argv.watch ){
  31.     console.log('Watching enabled!');
  32.  
  33.     gulp.task('default',[ 'transpile' ], () => {
  34.         return gulp.watch( jsSrc, ['transpile']);
  35.     });
  36.  
  37.     gulp.task('default',[ 'copy-json-files' ], () => {
  38.         return gulp.watch( jsonSrc, ['copy-json-files']);
  39.     });
  40. }
  41. else {
  42.     gulp.task('default',[ 'transpile', 'copy-json-files' ]);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment