<commit_before>var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var shell = require('gulp-shell');
var Fs = require('fire-fs');
var Path = require('path');
var pjson = JSON.parse(Fs.readFileSync('./package.json'));
var mkdirp = require('mkdirp');
var git = require('./utils/git.js');
var spawn = require('child_process').spawn;

// require tasks
require('./utils/download-shell');

// public tasks

gulp.task('bootstrap', gulpSequence('init-submodules', 'install-builtin', 'install-runtime', 'update-electron', 'npm', 'bower'));

gulp.task('update', gulpSequence('pull-fireball', ['update-builtin', 'update-runtime', 'update-electron']));

gulp.task('update-deps', ['npm', 'bower']);

gulp.task('run', ['run-electron']);

gulp.task('fireball', ['run-canvasstudio']);

gulp.task('package-studio', ['run-packagestudio']);

// run
gulp.task('run-electron', function(cb) {
  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--show-devtools'];
  }
  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-fireshell', function(cb) {
  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\fire-shell\\fireball.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
  } else {
    cmdStr = 'bin/fire-shell/Fireball.app/Contents/MacOS/Fireball';
    optArr = ['./','--debug=3030','--dev','--show-devtools'];
  }
  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-packagestudio', function(cb) {
  var Commander = require('commander');
  Commander.option('--path <path>', 'Run packages in path' )
           .parse(process.argv)
           ;

  var packagePath = Commander.path;
  if ( packagePath ) {
      console.log('Load packages from %s', packagePath);
  } else {
    console.log('Please provide a valid project path with "--path" arguments');
  }

  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--dev-mode=packages', '--show-devtools', packagePath];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--dev-mode=packages','--show-devtools', packagePath];
  }

  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-canvasstudio', function(cb) {
  var Commander = require('commander');
  Commander.option('--path <path>', 'Run open fireball project in path' )
           .parse(process.argv)
           ;

  var projectPath = Commander.path;
  if ( projectPath ) {
      console.log('Load project from %s', projectPath);
  }

  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools', projectPath];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--show-devtools', projectPath];
  }

  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('init-submodules', function(cb) {
  git.runGitCmdInPath(['submodule', 'update', '--init'], './', function() {
    console.log('Git submodules inited!');
    cb();
  });
});

gulp.task('pull-fireball', function(cb) {
  git.runGitCmdInPath(['pull', 'https://github.com/fireball-x/fireball.git', 'dev'], './', function() {
    console.log('Fireball update complete!');
    cb();
  });
});

gulp.task('pull-submodules', function(cb) {
  var modules = pjson.submodules;
  var count = modules.length;
  modules.map(function(module) {
    if (Fs.existsSync(Path.join(module, '.git'))) {
      git.runGitCmdInPath(['pull', 'origin', 'master'], module, function() {
        if (--count <= 0) {
          console.log('Git submodules pull complete!');
          cb();
        }
      });
    } else {
      console.log(module + ' not initialized. Please run "gulp init-submodules" first!');
      return cb();
    }
  });
});

gulp.task('install-builtin', function(cb) {
  var count = pjson.builtins.length;
  if (Fs.isDirSync('builtin')) {
    pjson.builtins.map(function(packageName) {
      if (!Fs.existsSync(Path.join('builtin', packageName, '.git'))) {
        git.runGitCmdInPath(['clone', 'https://github.com/fireball-packages/' + packageName], 'builtin', function() {
          if (--count <= 0) {
            console.log('Builtin packages installation complete!');
            cb();
          }
        });
      } else {
        console.log(packageName + ' has already installed in builtin/' + packageName + ' folder!');
        console.log(count);
        if (--count <= 0) {
          cb();
        }
      }
    });
  } else {
    mkdirp('builtin');
    pjson.builtins.map(function(packageName) {
      count++;
      git.runGitCmdInPath(['clone', 'https://github.com/fireball-packages/' + packageName], 'builtin', function() {
        if (--count <= 0) {
          console.log('Builtin packages installation complete!');
          cb();
        }
      });
    });
  }
});

gulp.task('update-builtin', function(cb) {
  var count = 0;
  if (Fs.isDirSync('builtin')) {
    pjson.builtins.map(function(packageName) {
      if (Fs.existsSync(Path.join('builtin', packageName, '.git'))) {
        count++;
        git.runGitCmdInPath(['pull', 'https://github.com/fireball-packages/' + packageName, 'master'], Path.join('builtin', packageName), function() {
          if (--count <= 0) {
            console.log('Builtin packages update complete!');
            cb();
          }
        });
      } else {
        console.warn('Builtin package ' + packageName + ' not initialized, please run "gulp install-builtin" first!');
        return cb();
      }
    });
  } else {
    console.warn('Builtin folder not initialized, please run "gulp install-builtin" first!');
    cb();
  }
});

gulp.task('install-runtime', function(cb) {
  var count = pjson.runtimes.length;
  if (Fs.isDirSync('runtime')) {
    pjson.runtimes.map(function(runtimeName) {
      if (!Fs.existsSync(Path.join('runtime', runtimeName, '.git'))) {
        git.runGitCmdInPath(['clone', 'https://github.com/fireball-x/' + runtimeName], 'runtime', function() {
          if (--count <= 0) {
            console.log('Runtime engines installation complete!');
            console.log(count);
            cb();
          }
        });
      } else {
        console.log(runtimeName + ' has already installed in runtime/' + runtimeName + ' folder!');
        if (--count <= 0) {
          console.log(count);
          cb();
        }
      }
    });
  } else {
    mkdirp('runtime');
    pjson.runtimes.map(function(runtimeName) {
      count++;
      git.runGitCmdInPath(['clone', 'https://github.com/fireball-x/' + runtimeName], 'runtime', function() {
        if (--count <= 0) {
          console.log('Runtime engines installation complete!');
          cb();
        }
      });
    });
  }
});

gulp.task('update-runtime', function(cb) {
  var count = 0;
  if (Fs.isDirSync('runtime')) {
    pjson.runtimes.map(function(runtimeName) {
      if (Fs.existsSync(Path.join('runtime', runtimeName, '.git'))) {
        count++;
        git.runGitCmdInPath(['pull', 'https://github.com/fireball-x/' + runtimeName, 'master'], Path.join('runtime', runtimeName), function() {
          if (--count <= 0) {
            console.log('Runtime engines update complete!');
            cb();
          }
        });
      } else {
        console.warn('Runtime engine ' + runtimeName + ' not initialized, please run "gulp install-runtime" first!');
        return cb();
      }
    });
  } else {
    console.warn('Runtime folder not initialized, please run "gulp install-runtime" first!');
    cb();
  }
});

gulp.task('npm', ['rm-native-modules'], function(cb) {
  var cmdstr = process.platform === 'win32' ? 'npm.cmd' : 'npm';
  var tmpenv = process.env;
  var os = require('os');
  tmpenv.npm_config_disturl = 'https://atom.io/download/atom-shell';
  tmpenv.npm_config_target = pjson['electron-version'];
  tmpenv.npm_config_arch = os.arch();
  tmpenv.HOME = Path.join(tmpenv.HOME, '.electron-gyp');
  var child = spawn(cmdstr, ['install'], {
    stdio: 'inherit',
    env: tmpenv
  });
  child.on('exit', cb);
});

gulp.task('bower', shell.task(['bower install']));

gulp.task('rm-native-modules', function(cb) {
  var del = require('del');
  var nativeModules = pjson['native-modules'];
  var nativePaths = nativeModules.map(function(filepath) { return 'node_modules/' + filepath; });
  console.log("Deleting existing native modules to make sure rebuild triggers.");
  del(nativePaths, function(err) {
    if (err) throw err;
    else cb();
  });
});

gulp.task('check-deps', function(cb) {
  var checkDeps = require('./utils/check-deps');
  checkDeps.checkSubmoduleDeps(pjson.submodules);
});
<commit_msg>fixed `gulp update` leaves local remote head unchanged issue.<commit_after>var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var shell = require('gulp-shell');
var Fs = require('fire-fs');
var Path = require('path');
var pjson = JSON.parse(Fs.readFileSync('./package.json'));
var mkdirp = require('mkdirp');
var git = require('./utils/git.js');
var spawn = require('child_process').spawn;

// require tasks
require('./utils/download-shell');

// public tasks

gulp.task('bootstrap', gulpSequence('init-submodules', 'install-builtin', 'install-runtime', 'update-electron', 'npm', 'bower'));

gulp.task('update', gulpSequence('pull-fireball', ['update-builtin', 'update-runtime', 'update-electron']));

gulp.task('update-deps', ['npm', 'bower']);

gulp.task('run', ['run-electron']);

gulp.task('fireball', ['run-canvasstudio']);

gulp.task('package-studio', ['run-packagestudio']);

// run
gulp.task('run-electron', function(cb) {
  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--show-devtools'];
  }
  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-fireshell', function(cb) {
  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\fire-shell\\fireball.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools'];
  } else {
    cmdStr = 'bin/fire-shell/Fireball.app/Contents/MacOS/Fireball';
    optArr = ['./','--debug=3030','--dev','--show-devtools'];
  }
  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-packagestudio', function(cb) {
  var Commander = require('commander');
  Commander.option('--path <path>', 'Run packages in path' )
           .parse(process.argv)
           ;

  var packagePath = Commander.path;
  if ( packagePath ) {
      console.log('Load packages from %s', packagePath);
  } else {
    console.log('Please provide a valid project path with "--path" arguments');
  }

  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--dev-mode=packages', '--show-devtools', packagePath];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--dev-mode=packages','--show-devtools', packagePath];
  }

  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('run-canvasstudio', function(cb) {
  var Commander = require('commander');
  Commander.option('--path <path>', 'Run open fireball project in path' )
           .parse(process.argv)
           ;

  var projectPath = Commander.path;
  if ( projectPath ) {
      console.log('Load project from %s', projectPath);
  }

  var cmdStr = '';
  var optArr = [];
  if (process.platform === "win32") {
    cmdStr = 'bin\\electron\\electron.exe';
    optArr = ['.\\', '--debug=3030', '--dev', '--show-devtools', projectPath];
  } else {
    cmdStr = 'bin/electron/Electron.app/Contents/MacOS/Electron';
    optArr = ['./','--debug=3030','--dev','--show-devtools', projectPath];
  }

  var child = spawn(cmdStr, optArr, { stdio: 'inherit'});
  child.on('exit', function() {
    cb();
  });
});

gulp.task('init-submodules', function(cb) {
  git.runGitCmdInPath(['submodule', 'update', '--init'], './', function() {
    console.log('Git submodules inited!');
    cb();
  });
});

gulp.task('pull-fireball', function(cb) {
  git.runGitCmdInPath(['pull', 'https://github.com/fireball-x/fireball.git', 'dev'], './', function() {
    console.log('Fireball update complete!');
    git.runGitCmdInPath(['fetch', '--all'], './', function() {
      console.log('Remote head updated!');
      cb();
    });
  });
});

gulp.task('pull-submodules', function(cb) {
  var modules = pjson.submodules;
  var count = modules.length;
  modules.map(function(module) {
    if (Fs.existsSync(Path.join(module, '.git'))) {
      git.runGitCmdInPath(['pull', 'origin', 'master'], module, function() {
        if (--count <= 0) {
          console.log('Git submodules pull complete!');
          cb();
        }
      });
    } else {
      console.log(module + ' not initialized. Please run "gulp init-submodules" first!');
      return cb();
    }
  });
});

gulp.task('install-builtin', function(cb) {
  var count = pjson.builtins.length;
  if (Fs.isDirSync('builtin')) {
    pjson.builtins.map(function(packageName) {
      if (!Fs.existsSync(Path.join('builtin', packageName, '.git'))) {
        git.runGitCmdInPath(['clone', 'https://github.com/fireball-packages/' + packageName], 'builtin', function() {
          if (--count <= 0) {
            console.log('Builtin packages installation complete!');
            cb();
          }
        });
      } else {
        console.log(packageName + ' has already installed in builtin/' + packageName + ' folder!');
        console.log(count);
        if (--count <= 0) {
          cb();
        }
      }
    });
  } else {
    mkdirp('builtin');
    pjson.builtins.map(function(packageName) {
      count++;
      git.runGitCmdInPath(['clone', 'https://github.com/fireball-packages/' + packageName], 'builtin', function() {
        if (--count <= 0) {
          console.log('Builtin packages installation complete!');
          cb();
        }
      });
    });
  }
});

gulp.task('update-builtin', function(cb) {
  var count = 0;
  if (Fs.isDirSync('builtin')) {
    pjson.builtins.map(function(packageName) {
      if (Fs.existsSync(Path.join('builtin', packageName, '.git'))) {
        count++;
        git.runGitCmdInPath(['pull', 'https://github.com/fireball-packages/' + packageName, 'master'], Path.join('builtin', packageName), function() {
          git.runGitCmdInPath(['fetch', '--all'], Path.join('builtin', packageName), function() {
            console.log('Remote head updated!');
            if (--count <= 0) {
              console.log('Builtin packages update complete!');
              cb();
            }
          });
        });
      } else {
        console.warn('Builtin package ' + packageName + ' not initialized, please run "gulp install-builtin" first!');
        return cb();
      }
    });
  } else {
    console.warn('Builtin folder not initialized, please run "gulp install-builtin" first!');
    cb();
  }
});

gulp.task('install-runtime', function(cb) {
  var count = pjson.runtimes.length;
  if (Fs.isDirSync('runtime')) {
    pjson.runtimes.map(function(runtimeName) {
      if (!Fs.existsSync(Path.join('runtime', runtimeName, '.git'))) {
        git.runGitCmdInPath(['clone', 'https://github.com/fireball-x/' + runtimeName], 'runtime', function() {
          if (--count <= 0) {
            console.log('Runtime engines installation complete!');
            console.log(count);
            cb();
          }
        });
      } else {
        console.log(runtimeName + ' has already installed in runtime/' + runtimeName + ' folder!');
        if (--count <= 0) {
          console.log(count);
          cb();
        }
      }
    });
  } else {
    mkdirp('runtime');
    pjson.runtimes.map(function(runtimeName) {
      count++;
      git.runGitCmdInPath(['clone', 'https://github.com/fireball-x/' + runtimeName], 'runtime', function() {
        if (--count <= 0) {
          console.log('Runtime engines installation complete!');
          cb();
        }
      });
    });
  }
});

gulp.task('update-runtime', function(cb) {
  var count = 0;
  if (Fs.isDirSync('runtime')) {
    pjson.runtimes.map(function(runtimeName) {
      if (Fs.existsSync(Path.join('runtime', runtimeName, '.git'))) {
        count++;
        git.runGitCmdInPath(['pull', 'https://github.com/fireball-x/' + runtimeName, 'master'], Path.join('runtime', runtimeName), function() {
          git.runGitCmdInPath(['fetch', '--all'], Path.join('runtime', runtimeName), function() {
            console.log('Remote head updated!');
            if (--count <= 0) {
              console.log('Runtime engines update complete!');
              cb();
            }
          });
        });
      } else {
        console.warn('Runtime engine ' + runtimeName + ' not initialized, please run "gulp install-runtime" first!');
        return cb();
      }
    });
  } else {
    console.warn('Runtime folder not initialized, please run "gulp install-runtime" first!');
    cb();
  }
});

gulp.task('npm', ['rm-native-modules'], function(cb) {
  var cmdstr = process.platform === 'win32' ? 'npm.cmd' : 'npm';
  var tmpenv = process.env;
  var os = require('os');
  tmpenv.npm_config_disturl = 'https://atom.io/download/atom-shell';
  tmpenv.npm_config_target = pjson['electron-version'];
  tmpenv.npm_config_arch = os.arch();
  tmpenv.HOME = Path.join(tmpenv.HOME, '.electron-gyp');
  var child = spawn(cmdstr, ['install'], {
    stdio: 'inherit',
    env: tmpenv
  });
  child.on('exit', cb);
});

gulp.task('bower', shell.task(['bower install']));

gulp.task('rm-native-modules', function(cb) {
  var del = require('del');
  var nativeModules = pjson['native-modules'];
  var nativePaths = nativeModules.map(function(filepath) { return 'node_modules/' + filepath; });
  console.log("Deleting existing native modules to make sure rebuild triggers.");
  del(nativePaths, function(err) {
    if (err) throw err;
    else cb();
  });
});

gulp.task('check-deps', function(cb) {
  var checkDeps = require('./utils/check-deps');
  checkDeps.checkSubmoduleDeps(pjson.submodules);
});
<|endoftext|>


<commit_before>// including plugins
var gulp = require('gulp'),
    htmlmin = require("gulp-htmlmin"),
    minifyCss = require("gulp-minify-css"),
    uglify = require("gulp-uglify"),
    replace = require("gulp-replace"),
    clean = require("gulp-clean"),
    debug = require("gulp-debug"),
    pjson = require('./package.json');

gulp.task('clean', function () {
    return gulp.src('dist', {read: false})
        .pipe(clean());
});

gulp.task('minify-html', () => {
    return gulp.src('./public/*.html') // path to your files
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('copy-html-templates', function () {
    return gulp.src('./public/scripts/app/templates/*')
        .pipe(gulp.dest('dist/scripts/app/templates'));
})

gulp.task('copy-print-templates', function () {
    return gulp.src('./public/scripts/app/templates/print/*')
        .pipe(gulp.dest('dist/scripts/app/templates/print'));
})

gulp.task('copy-referendum-templates', function () {
    return gulp.src('./public/scripts/app/templates/referendum/*')
        .pipe(gulp.dest('dist/scripts/app/templates/referendum'));
})

gulp.task('minify-css', function () {
    return gulp.src('./public/**/*.css') // path to your files
        .pipe(minifyCss())
        .pipe(gulp.dest('dist'));
});

gulp.task('minify-js', function () {
    return gulp.src(['./public/**/*.js', '!./public/scripts/app/siteconfig.js', '!./public/**/*.min.js']) // path to your files
        .pipe(debug({title: 'minifying:'}))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('images', function () {
    return gulp.src(['./public/**/*.{png,jpg,gif,svg}'])
        .pipe(gulp.dest('dist'));
});

gulp.task('siteconfig-pubstorm', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPubstorm;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-patron', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPatron;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-heroku', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigHeroku;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('appbust', function () {
    return gulp.src('./public/scripts/app.js')
        .pipe(replace('bust=010101', 'bust=' + pjson.version))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts'));
});

gulp.task('indexbust', function () {
    return gulp.src('./public/index.html')
        .pipe(replace('require.js?bust=010101', 'require.js?bust=' + pjson.version))
        .pipe(replace('app.js?bust=010101', 'app.js?bust=' + pjson.version))
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
})

gulp.task('pubstorm', gulp.series('minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-pubstorm', 'appbust', 'indexbust'));

gulp.task('patron', gulp.series('minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-patron', 'appbust', 'indexbust'));

gulp.task('heroku', gulp.series('minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'siteconfig-heroku', 'appbust', 'indexbust'));<commit_msg>No dependencies means every task must be in the list<commit_after>// including plugins
var gulp = require('gulp'),
    htmlmin = require("gulp-htmlmin"),
    minifyCss = require("gulp-minify-css"),
    uglify = require("gulp-uglify"),
    replace = require("gulp-replace"),
    clean = require("gulp-clean"),
    debug = require("gulp-debug"),
    pjson = require('./package.json');

gulp.task('clean', function () {
    return gulp.src('dist', {read: false})
        .pipe(clean());
});

gulp.task('minify-html', () => {
    return gulp.src('./public/*.html') // path to your files
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('copy-html-templates', function () {
    return gulp.src('./public/scripts/app/templates/*')
        .pipe(gulp.dest('dist/scripts/app/templates'));
})

gulp.task('copy-print-templates', function () {
    return gulp.src('./public/scripts/app/templates/print/*')
        .pipe(gulp.dest('dist/scripts/app/templates/print'));
})

gulp.task('copy-referendum-templates', function () {
    return gulp.src('./public/scripts/app/templates/referendum/*')
        .pipe(gulp.dest('dist/scripts/app/templates/referendum'));
})

gulp.task('minify-css', function () {
    return gulp.src('./public/**/*.css') // path to your files
        .pipe(minifyCss())
        .pipe(gulp.dest('dist'));
});

gulp.task('minify-js', function () {
    return gulp.src(['./public/**/*.js', '!./public/scripts/app/siteconfig.js', '!./public/**/*.min.js']) // path to your files
        .pipe(debug({title: 'minifying:'}))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('images', function () {
    return gulp.src(['./public/**/*.{png,jpg,gif,svg}'])
        .pipe(gulp.dest('dist'));
});

gulp.task('siteconfig-pubstorm', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPubstorm;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-patron', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigPatron;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('siteconfig-heroku', function () {
    return gulp.src('./public/scripts/app/siteconfig.js')
        .pipe(replace('return ConfigGnuLorienDev;', 'return ConfigHeroku;'))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts/app'));
});

gulp.task('appbust', function () {
    return gulp.src('./public/scripts/app.js')
        .pipe(replace('bust=010101', 'bust=' + pjson.version))
        .pipe(uglify({outSourceMap: true}))
        .pipe(gulp.dest('dist/scripts'));
});

gulp.task('indexbust', function () {
    return gulp.src('./public/index.html')
        .pipe(replace('require.js?bust=010101', 'require.js?bust=' + pjson.version))
        .pipe(replace('app.js?bust=010101', 'app.js?bust=' + pjson.version))
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
})

gulp.task('pubstorm', gulp.series('clean', 'minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'minify-js', 'siteconfig-pubstorm', 'appbust', 'indexbust'));

gulp.task('patron', gulp.series('clean', 'minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'minify-js', 'siteconfig-patron', 'appbust', 'indexbust'));

gulp.task('heroku', gulp.series('clean', 'minify-html', 'copy-print-templates', 'copy-referendum-templates', 'copy-html-templates', 'minify-css', 'images', 'minify-js', 'siteconfig-heroku', 'appbust', 'indexbust'));<|endoftext|>


<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var imagemin = require('gulp-imagemin');

// Optimize images

gulp.task('default', function() {
  return gulp.src('IMG/*')
    .pipe(imagemin())
    .pipe(gulp.dest('IMG'));
});

// Optimize Angularjs files, concat, uglify + preserving angularjs injections

gulp.task('js', function() {
  gulp.src(['JS/app.js', 'JS/**/*.js'])
    .pipe(sourcemaps.init())
    .pipe(concat('webapp.js'))
    .pipe(ngAnnotate())
    .pipe(uglify())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist/'));
});

gulp.task('copy', function () {
  return gulp
    .src(['index.html', 'JSON/*.json', 'IMG/*', 'CSS/styles.min*', 'TEMPLATES/*'], { base: './' })
    .pipe(gulp.dest('dist/JS/'));
});

// after all done, watch for JS changes and add them to webapp.js

gulp.task('watch', ['js'], function() {
  gulp.watch('JS/**/*.js', ['js']);
  gulp.watch('IMG/*.png', ['images']);
});

gulp.task('default', ['js', 'copy', 'watch']);
<commit_msg>Added comments to gulpfiles.js<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var imagemin = require('gulp-imagemin');

// Optimize images

gulp.task('default', function() {
  return gulp.src('IMG/*')
    .pipe(imagemin())
    .pipe(gulp.dest('IMG'));
});

// Optimize Angularjs files, concat, uglify + preserving angularjs injections

gulp.task('js', function() {
  gulp.src(['JS/app.js', 'JS/**/*.js'])
    .pipe(sourcemaps.init())
    .pipe(concat('webapp.js'))
    .pipe(ngAnnotate())
    .pipe(uglify())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist/'));
});

// Copy paste files that do not require any additional work

gulp.task('copy', function () {
  return gulp
    .src(['index.html', 'JSON/*.json', 'IMG/*', 'CSS/styles.min*', 'TEMPLATES/*'], { base: './' })
    .pipe(gulp.dest('dist/JS/'));
});

// after all done, watch for JS changes and add them to webapp.js

gulp.task('watch', ['js'], function() {
  gulp.watch('JS/**/*.js', ['js']);
  gulp.watch('IMG/*.png', ['images']);
});

gulp.task('default', ['js', 'copy', 'watch']);
<|endoftext|>


<commit_before>/* @flow */

const del = require("del");
const gulp = require("gulp");
const babel = require("gulp-babel");
const mocha = require("gulp-mocha");
const rename = require("gulp-rename");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify");
const rollup = require("rollup-stream");
const rollupCommonjs = require("rollup-plugin-commonjs");
const rollupReplace = require("rollup-plugin-replace");
const rollupResolve = require("rollup-plugin-node-resolve");
const rollupSourcemaps = require("rollup-plugin-sourcemaps");
const buffer = require("vinyl-buffer");
const source = require("vinyl-source-stream");

gulp.task("clean", () => del([
    "cjs/",
    "esm/",
    "dist/",
]));

gulp.task("build:esm", () => gulp
    .src("src/**/*.js")
    .pipe(sourcemaps.init())
    .pipe(babel({
        plugins: [
            "@babel/plugin-transform-runtime",
            [
                "babel-plugin-flow-runtime",
                {
                    assert: true,
                },
            ],
            "babel-plugin-lodash",
        ],
        presets: [
            [
                "@babel/preset-env",
                {
                    modules: false,
                },
            ],
            "@babel/preset-flow",
            "@babel/preset-stage-0",
        ],
    }))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("esm/")),
);

gulp.task("build:cjs", () => gulp
    .src("esm/**/*.js")
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(babel({
        plugins: [
            "@babel/plugin-transform-modules-commonjs",
        ],
    }))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("cjs/")),
);

gulp.task("test", () => gulp
    .src("cjs/**/*.test.js", {
        read: false,
    })
    .pipe(mocha())
    .on("error", () =>
        process.exit(1),
    ),
);

function rollupConfig(env) {
    return {
        cache: rollupConfig.cache,
        format: "umd",
        input: "./esm/index.js",
        name: "core",
        plugins: [
            rollupSourcemaps(),
            rollupReplace({
                "process.env.NODE_ENV": JSON.stringify(env),
            }),
            rollupCommonjs(),
            rollupResolve({
                browser: true,
            }),
        ],
        sourcemap: true,
    };
}

gulp.task("bundle:development", () =>
    rollup(rollupConfig("development"))
    .pipe(source("index.js", "./esm"))
    .pipe(buffer())
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(rename("core.js"))
    .pipe(sourcemaps.mapSources(path => `./core/src/${path}`))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("dist/")),
);

gulp.task("bundle:production", () =>
    rollup(rollupConfig("production"))
    .pipe(source("index.js", "./esm"))
    .pipe(buffer())
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(uglify())
    .pipe(rename("core.min.js"))
    .pipe(sourcemaps.mapSources(path => `./core/src/${path}`))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("dist/")),
);

gulp.task("default", gulp.series(
    "clean",
    "build:esm",
    "build:cjs",
    "test",
    "bundle:development",
    "bundle:production",
));
<commit_msg>rearrange rollup config<commit_after>/* @flow */

const del = require("del");
const gulp = require("gulp");
const babel = require("gulp-babel");
const mocha = require("gulp-mocha");
const rename = require("gulp-rename");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify");
const rollup = require("rollup-stream");
const rollupCommonjs = require("rollup-plugin-commonjs");
const rollupReplace = require("rollup-plugin-replace");
const rollupResolve = require("rollup-plugin-node-resolve");
const rollupSourcemaps = require("rollup-plugin-sourcemaps");
const buffer = require("vinyl-buffer");
const source = require("vinyl-source-stream");

gulp.task("clean", () => del([
    "cjs/",
    "esm/",
    "dist/",
]));

gulp.task("build:esm", () => gulp
    .src("src/**/*.js")
    .pipe(sourcemaps.init())
    .pipe(babel({
        plugins: [
            "@babel/plugin-transform-runtime",
            [
                "babel-plugin-flow-runtime",
                {
                    assert: true,
                },
            ],
            "babel-plugin-lodash",
        ],
        presets: [
            [
                "@babel/preset-env",
                {
                    modules: false,
                },
            ],
            "@babel/preset-flow",
            "@babel/preset-stage-0",
        ],
    }))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("esm/")),
);

gulp.task("build:cjs", () => gulp
    .src("esm/**/*.js")
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(babel({
        plugins: [
            "@babel/plugin-transform-modules-commonjs",
        ],
    }))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("cjs/")),
);

gulp.task("test", () => gulp
    .src("cjs/**/*.test.js", {
        read: false,
    })
    .pipe(mocha())
    .on("error", () =>
        process.exit(1),
    ),
);

function rollupConfig(env) {
    return {
        cache: rollupConfig.cache,
        input: "./esm/index.js",
        plugins: [
            rollupSourcemaps(),
            rollupReplace({
                "process.env.NODE_ENV": JSON.stringify(env),
            }),
            rollupCommonjs(),
            rollupResolve({
                browser: true,
            }),
        ],

        format: "umd",
        name: "core",
        sourcemap: true,
    };
}

gulp.task("bundle:development", () =>
    rollup(rollupConfig("development"))
    .pipe(source("index.js", "./esm"))
    .pipe(buffer())
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(rename("core.js"))
    .pipe(sourcemaps.mapSources(path => `./core/src/${path}`))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("dist/")),
);

gulp.task("bundle:production", () =>
    rollup(rollupConfig("production"))
    .pipe(source("index.js", "./esm"))
    .pipe(buffer())
    .pipe(sourcemaps.init({
        loadMaps: true,
    }))
    .pipe(uglify())
    .pipe(rename("core.min.js"))
    .pipe(sourcemaps.mapSources(path => `./core/src/${path}`))
    .pipe(sourcemaps.write("."))
    .pipe(gulp.dest("dist/")),
);

gulp.task("default", gulp.series(
    "clean",
    "build:esm",
    "build:cjs",
    "test",
    "bundle:development",
    "bundle:production",
));
<|endoftext|>


<commit_before>/*!
 * Static Site Starter Kit | https://github.com/kriasoft/static-site-starter
 * Copyright (c) Konstantin Tarkus, KriaSoft LLC. All rights reserved. See COPYRIGHT.txt
 */

'use strict';

// Include Gulp and other build automation tools and utilities
// See: https://github.com/gulpjs/gulp/blob/master/docs/API.md
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var pagespeed = require('psi');
var argv = require('minimist')(process.argv.slice(2));

// Settings
var DEST = './build';
var RELEASE = Boolean(argv.release);
var GOOGLE_ANALYTICS_ID = 'UA-XXXXX-X';
var AUTOPREFIXER_BROWSERS = [
    'ie >= 10',
    'ie_mob >= 10',
    'ff >= 30',
    'chrome >= 34',
    'safari >= 7',
    'opera >= 23',
    'ios >= 7',
    'android >= 4.4',
    'bb >= 10'
];

var src = {};
var watch = false;
var reload = browserSync.reload;
var pkgs = (function () {
    var temp = {};
    var map = function (source) {
        for (var key in source) {
            temp[key.replace(/[^a-z0-9]/gi, '')] = source[key].substring(1);
        }
    };
    map(require('./package.json').dependencies);
    map(require('./bower.json').dependencies);
    return temp;
}());

// The default task
gulp.task('default', ['serve']);

// Clean up
gulp.task('clean', del.bind(null, [DEST]));

// 3rd party libraries
gulp.task('vendor', function () {
    var merge = require('merge-stream');
    return merge(
        gulp.src('bower_components/jquery/dist/**')
            .pipe(gulp.dest(DEST + '/vendor/jquery-' + pkgs.jquery)),
        gulp.src('bower_components/modernizr/modernizr.js')
            .pipe($.rename('modernizr.min.js'))
            .pipe($.uglify())
            .pipe(gulp.dest(DEST + '/vendor/modernizr-' + pkgs.modernizr))
    );
});

// Static files
gulp.task('assets', function () {
    src.assets = 'assets/**';
    return gulp.src(src.assets)
        .pipe(gulp.dest(DEST))
        .pipe($.if(watch, reload({stream: true})));
});

// Fonts
gulp.task('fonts', function () {
    return gulp.src('node_modules/bootstrap/fonts/**')
        .pipe(gulp.dest(DEST + '/fonts'));
});

// HTML pages
gulp.task('pages', function () {
    src.pages = ['pages/**/*', 'layouts/**/*', 'partials/**/*'];
    return gulp.src(src.pages[0])
        .pipe($.if('*.hbs', $.assemble({
            data: { pkgs: pkgs },
            partials: 'partials/**/*.hbs',
            layout: 'default',
            layoutext: '.hbs',
            layoutdir: 'layouts'
        })))
        .pipe($.if(RELEASE, $.htmlmin({
            removeComments: true,
            collapseWhitespace: true,
            minifyJS: true, minifyCSS: true
        })))
        .pipe($.replace('UA-XXXXX-X', GOOGLE_ANALYTICS_ID))
        .pipe(gulp.dest(DEST))
        .pipe($.if(watch, reload({stream: true})));
});

// CSS style sheets
gulp.task('styles', function () {
    src.styles = 'styles/**/*.{css,less}';
    return gulp.src('styles/bootstrap.less')
        .pipe($.less())
        .pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
        .pipe($.csscomb())
        .pipe(RELEASE ? $.cssmin() : $.util.noop())
        .pipe($.rename('style.css'))
        .pipe(gulp.dest(DEST + '/css'))
        .pipe($.if(watch, reload({stream: true})));
});

// JavaScript
gulp.task('scripts', function () {
    src.scripts = ['scripts/plugins.js', 'scripts/main.js'];
    return gulp.src(src.scripts)
        .pipe($.if(!RELEASE, $.sourcemaps.init()))
        .pipe($.concat('bundle.js'))
        .pipe($.if(RELEASE, $.uglify()))
        .pipe($.if(!RELEASE, $.sourcemaps.write()))
        .pipe(gulp.dest(DEST + '/js'))
        .pipe($.if(watch, reload({stream: true})));
});

// Build
gulp.task('build', ['clean'], function (cb) {
    runSequence(['vendor', 'assets', 'fonts', 'pages', 'styles', 'scripts'], cb);
});

// Run BrowserSync
gulp.task('serve', ['build'], function () {
    browserSync({
        notify: false,
        server: { baseDir: [DEST] }
    });

    gulp.watch(src.assets, ['assets']);
    gulp.watch(src.pages, ['pages']);
    gulp.watch(src.styles, ['styles']);
    gulp.watch(src.scripts, ['scripts']);
    watch = true;
});

// Publish to Amazon S3 / CloudFront
gulp.task('deploy', function () {
    var awspublish = require('gulp-awspublish');
    var aws = {
        "key": process.env.AWS_KEY,
        "secret": process.env.AWS_SECRET,
        "bucket": 'XXXXXXXX',
        "region": 'us-standard',
        "distributionId": 'XXXXXXXX'
    };
    var publisher = awspublish.create(aws);
    var headers = {
        'Cache-Control': 'max-age=315360000, no-transform, public'
    };

    return gulp.src('build/**')
        // Add a revisioned suffix to the filename for each static asset
        .pipe($.revAll({
            ignore: [
                /^\/apple-touch-icon-precomposed.png$/g,
                /^\/browserconfig.xml$/g,
                /^\/crossdomain.xml$/g,
                /^\/error.html$/g,
                /^\/humans.txt$/g,
                /^\/robots.txt$/g
            ]
        }))
        // Gzip, set Content-Encoding headers
        .pipe(awspublish.gzip())
        // Publisher will add Content-Length, Content-Type and headers specified above
        // If not specified it will set x-amz-acl to public-read by default
        .pipe(publisher.publish(headers))
        // Create a cache file to speed up consecutive uploads
        .pipe(publisher.cache())
        // Print upload updates to console
        .pipe(awspublish.reporter())
        // Updates the Default Root Object of a CloudFront distribution
        .pipe($.cloudfront(aws));
});

// Run PageSpeed Insights
// Update `url` below to the public URL for your site
gulp.task('pagespeed', pagespeed.bind(null, {
    // By default, we use the PageSpeed Insights free (no API key) tier.
    // You can use a Google Developer API key if you have one.
    // See http://goo.gl/RkN0vE for info key: 'YOUR_API_KEY'
    url: 'https://example.com',
    strategy: 'mobile'
}));<commit_msg>Copy images during a build<commit_after>/*!
 * Static Site Starter Kit | https://github.com/kriasoft/static-site-starter
 * Copyright (c) Konstantin Tarkus, KriaSoft LLC. All rights reserved. See COPYRIGHT.txt
 */

'use strict';

// Include Gulp and other build automation tools and utilities
// See: https://github.com/gulpjs/gulp/blob/master/docs/API.md
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var merge = require('merge-stream');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var pagespeed = require('psi');
var argv = require('minimist')(process.argv.slice(2));

// Settings
var DEST = './build';
var RELEASE = Boolean(argv.release);
var GOOGLE_ANALYTICS_ID = 'UA-XXXXX-X';
var AUTOPREFIXER_BROWSERS = [
    'ie >= 10',
    'ie_mob >= 10',
    'ff >= 30',
    'chrome >= 34',
    'safari >= 7',
    'opera >= 23',
    'ios >= 7',
    'android >= 4.4',
    'bb >= 10'
];

var src = {};
var watch = false;
var reload = browserSync.reload;
var pkgs = (function () {
    var temp = {};
    var map = function (source) {
        for (var key in source) {
            temp[key.replace(/[^a-z0-9]/gi, '')] = source[key].substring(1);
        }
    };
    map(require('./package.json').dependencies);
    map(require('./bower.json').dependencies);
    return temp;
}());

// The default task
gulp.task('default', ['serve']);

// Clean up
gulp.task('clean', del.bind(null, [DEST]));

// 3rd party libraries
gulp.task('vendor', function () {
    return merge(
        gulp.src('bower_components/jquery/dist/**')
            .pipe(gulp.dest(DEST + '/vendor/jquery-' + pkgs.jquery)),
        gulp.src('bower_components/modernizr/modernizr.js')
            .pipe($.rename('modernizr.min.js'))
            .pipe($.uglify())
            .pipe(gulp.dest(DEST + '/vendor/modernizr-' + pkgs.modernizr))
    );
});

// Static files
gulp.task('assets', function () {
    src.assets = 'assets/**';
    return gulp.src(src.assets)
        .pipe(gulp.dest(DEST))
        .pipe($.if(watch, reload({stream: true})));
});

// Images
gulp.task('images', function () {
    src.images = 'images/**';
    return gulp.src(src.images)
        .pipe(gulp.dest(DEST + '/img'))
        .pipe($.if(watch, reload({stream: true})));
});

// Fonts
gulp.task('fonts', function () {
    return gulp.src('node_modules/bootstrap/fonts/**')
        .pipe(gulp.dest(DEST + '/fonts'));
});

// HTML pages
gulp.task('pages', function () {
    src.pages = ['pages/**/*', 'layouts/**/*', 'partials/**/*'];
    return gulp.src(src.pages[0])
        .pipe($.if('*.hbs', $.assemble({
            data: { pkgs: pkgs },
            partials: 'partials/**/*.hbs',
            layout: 'default',
            layoutext: '.hbs',
            layoutdir: 'layouts'
        })))
        .pipe($.if(RELEASE, $.htmlmin({
            removeComments: true,
            collapseWhitespace: true,
            minifyJS: true, minifyCSS: true
        })))
        .pipe($.replace('UA-XXXXX-X', GOOGLE_ANALYTICS_ID))
        .pipe(gulp.dest(DEST))
        .pipe($.if(watch, reload({stream: true})));
});

// CSS style sheets
gulp.task('styles', function () {
    src.styles = 'styles/**/*.{css,less}';
    return gulp.src('styles/bootstrap.less')
        .pipe($.less())
        .pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
        .pipe($.csscomb())
        .pipe(RELEASE ? $.cssmin() : $.util.noop())
        .pipe($.rename('style.css'))
        .pipe(gulp.dest(DEST + '/css'))
        .pipe($.if(watch, reload({stream: true})));
});

// JavaScript
gulp.task('scripts', function () {
    src.scripts = ['scripts/plugins.js', 'scripts/main.js'];
    return gulp.src(src.scripts)
        .pipe($.if(!RELEASE, $.sourcemaps.init()))
        .pipe($.concat('bundle.js'))
        .pipe($.if(RELEASE, $.uglify()))
        .pipe($.if(!RELEASE, $.sourcemaps.write()))
        .pipe(gulp.dest(DEST + '/js'))
        .pipe($.if(watch, reload({stream: true})));
});

// Build
gulp.task('build', ['clean'], function (cb) {
    runSequence(['vendor', 'assets', 'images', 'fonts', 'pages', 'styles', 'scripts'], cb);
});

// Run BrowserSync
gulp.task('serve', ['build'], function () {
    browserSync({
        notify: false,
        server: { baseDir: [DEST] }
    });

    gulp.watch(src.assets, ['assets']);
    gulp.watch(src.images, ['images']);
    gulp.watch(src.pages, ['pages']);
    gulp.watch(src.styles, ['styles']);
    gulp.watch(src.scripts, ['scripts']);
    watch = true;
});

// Publish to Amazon S3 / CloudFront
gulp.task('deploy', function () {
    var awspublish = require('gulp-awspublish');
    var aws = {
        "key": process.env.AWS_KEY,
        "secret": process.env.AWS_SECRET,
        "bucket": 'XXXXXXXX',
        "region": 'us-standard',
        "distributionId": 'XXXXXXXX'
    };
    var publisher = awspublish.create(aws);
    var headers = {
        'Cache-Control': 'max-age=315360000, no-transform, public'
    };

    return gulp.src('build/**')
        // Add a revisioned suffix to the filename for each static asset
        .pipe($.revAll({
            ignore: [
                /^\/apple-touch-icon-precomposed.png$/g,
                /^\/browserconfig.xml$/g,
                /^\/crossdomain.xml$/g,
                /^\/error.html$/g,
                /^\/humans.txt$/g,
                /^\/robots.txt$/g
            ]
        }))
        // Gzip, set Content-Encoding headers
        .pipe(awspublish.gzip())
        // Publisher will add Content-Length, Content-Type and headers specified above
        // If not specified it will set x-amz-acl to public-read by default
        .pipe(publisher.publish(headers))
        // Create a cache file to speed up consecutive uploads
        .pipe(publisher.cache())
        // Print upload updates to console
        .pipe(awspublish.reporter())
        // Updates the Default Root Object of a CloudFront distribution
        .pipe($.cloudfront(aws));
});

// Run PageSpeed Insights
// Update `url` below to the public URL for your site
gulp.task('pagespeed', pagespeed.bind(null, {
    // By default, we use the PageSpeed Insights free (no API key) tier.
    // You can use a Google Developer API key if you have one.
    // See http://goo.gl/RkN0vE for info key: 'YOUR_API_KEY'
    url: 'https://example.com',
    strategy: 'mobile'
}));<|endoftext|>


<commit_before>var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var open = require('gulp-open');
var minifyCss = require('gulp-minify-css');
var rimraf = require('gulp-rimraf');
var inline = require('gulp-inline');
var template = require('gulp-template');
var minifyHTML = require('gulp-minify-html');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var browserSync = require('browser-sync');
var runSequence = require('run-sequence');

var staticAssets = [
	"index.html",
	"./assets/**",
	"./php/!(cache)**",
	"*.ico",
	".htaccess"
];

function compileJs(watch) {
	var bundler = watchify(browserify('./js/RegExr.js', {debug: true}));

	function rebundle() {
		bundler.bundle()
			.on('error', function (err) {
				console.error(err);
				this.emit('end');
			})
			.pipe(source('scripts.min.js'))
			.pipe(buffer())
			.pipe(sourcemaps.init({loadMaps: true}))
			.pipe(sourcemaps.write('./'))
			.pipe(gulp.dest('./build/js'));
	}

	if (watch) {
		bundler.on('update', function () {
			rebundle();
		});
	}

	rebundle();
}

gulp.task('sass', function () {
	return gulp.src('./scss/regexr.scss')
		.pipe(sass({includePaths: ["scss/third-party/compass-mixins"]}).on('error', sass.logError))
		.pipe(gulp.dest('./build/css'));
});

gulp.task('browser-sync', function () {
	return browserSync(
		{
			open: "local",
			server: {
				baseDir: "./build/"
			},
			files: "./build/**"
		});
});

gulp.task('watch-js-templates', function () {
	var assets = "js/*.template.js";
	return gulp.watch(assets, ['copy-js-templates']);
});

gulp.task('copy-js-templates', function () {
	var assets = "js/*.template.js";
	return gulp.src(assets, {base: './js'})
		.pipe(gulp.dest('build/js/'));
});

gulp.task('watch-assets', function () {
	return gulp.src(staticAssets, {base: './'})
		.pipe(watch(staticAssets))
		.pipe(gulp.dest('build/'));
});

gulp.task('watch-sass', function () {
	gulp.watch("./scss/**/*.scss", ['sass']);
});

gulp.task('copy-assets', function () {
	return gulp.src(staticAssets, {base: './'})
		.pipe(gulp.dest('build/'));
});

gulp.task('minify-js', function () {
	return gulp.src(['build/js/scripts.min.js', 'build/js/regExWorker.template.js'])
		.pipe(uglify({
			compress: {
				global_defs: {
					DEBUG: false
				},
				dead_code: true
			},
			ASCIIOnly: true
		}))
		.pipe(gulp.dest('build/js'));
});

gulp.task('build-js', function () {
	return compileJs();
});

gulp.task('watch-js', function () {
	return compileJs(true);
});

gulp.task('server', function () {
	connect.server({
		root: 'build'
	});
});

gulp.task('minify-css', function () {
	return gulp.src('build/css/regexr.css')
		.pipe(minifyCss())
		.pipe(gulp.dest('build/css'));
});

gulp.task('open-build', function () {
	gulp.src(__filename)
		.pipe(open({uri: 'http://localhost:8080'}));
});

gulp.task('clean-pre-build', function () {
	return gulp.src(['./build/!(v1|.git|sitemap.txt|*.md)'], {read: false})
		.pipe(rimraf());
});

gulp.task('clean-post-build', function () {
	return gulp.src(['./build/js/index.template.js', './build/js/scripts.min.js.map'], {read: false})
		.pipe(rimraf());
});

gulp.task('inline', function () {
	return gulp.src('build/index.html')
		.pipe(inline({
				base: 'build/', js: uglify, css: minifyCss
			}
		))
		.pipe(gulp.dest('build/'));
});

gulp.task('parse-index', function () {
	return gulp.src('build/index.html')
		.pipe(template({noCache: Date.now()}))
		.pipe(minifyHTML())
		.pipe(gulp.dest('build/'));
});

gulp.task('build', function (done) {
	runSequence(
		'clean-pre-build',
		['build-js', 'copy-assets', 'sass'],
		['minify-js', 'minify-css', 'inline'],
		['parse-index', 'clean-post-build'],
		'server', 'open-build',
		done
	);
});

gulp.task('default', function (done) {
	runSequence(
		['sass', 'watch-js', 'watch-sass', 'copy-js-templates'],
		'copy-assets',
		['watch-assets', 'watch-js-templates', 'browser-sync'],
		done
	);
});
<commit_msg>Fix copying certain static assets.<commit_after>var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var open = require('gulp-open');
var minifyCss = require('gulp-minify-css');
var rimraf = require('gulp-rimraf');
var inline = require('gulp-inline');
var template = require('gulp-template');
var minifyHTML = require('gulp-minify-html');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var browserSync = require('browser-sync');
var runSequence = require('run-sequence');

var staticAssets = [
	"index.html",
	"./assets/**",
	"./php/!(cache)**",
	"*.ico",
	".htaccess"
];

function compileJs(watch) {
	var bundler = watchify(browserify('./js/RegExr.js', {debug: true}));

	function rebundle() {
		bundler.bundle()
			.on('error', function (err) {
				console.error(err);
				this.emit('end');
			})
			.pipe(source('scripts.min.js'))
			.pipe(buffer())
			.pipe(sourcemaps.init({loadMaps: true}))
			.pipe(sourcemaps.write('./'))
			.pipe(gulp.dest('./build/js'));
	}

	if (watch) {
		bundler.on('update', function () {
			rebundle();
		});
	}

	rebundle();
}

gulp.task('sass', function () {
	return gulp.src('./scss/regexr.scss')
		.pipe(sass({includePaths: ["scss/third-party/compass-mixins"]}).on('error', sass.logError))
		.pipe(gulp.dest('./build/css'));
});

gulp.task('browser-sync', function () {
	return browserSync(
		{
			open: "local",
			server: {
				baseDir: "./build/"
			},
			files: "./build/**"
		});
});

gulp.task('watch-js-templates', function () {
	var assets = "js/*.template.js";
	return gulp.watch(assets, ['copy-js-templates']);
});

gulp.task('copy-js-templates', function () {
	var assets = "js/*.template.js";
	return gulp.src(assets, {base: './js'})
		.pipe(gulp.dest('build/js/'));
});

gulp.task('watch-assets', function () {
	return gulp.watch(staticAssets, ['copy-assets'])
});

gulp.task('watch-sass', function () {
	gulp.watch("./scss/**/*.scss", ['sass']);
});

gulp.task('copy-assets', function () {
	return gulp.src(staticAssets, {base: './'})
		.pipe(gulp.dest('build/'));
});

gulp.task('minify-js', function () {
	return gulp.src(['build/js/scripts.min.js', 'build/js/regExWorker.template.js'])
		.pipe(uglify({
			compress: {
				global_defs: {
					DEBUG: false
				},
				dead_code: true
			},
			ASCIIOnly: true
		}))
		.pipe(gulp.dest('build/js'));
});

gulp.task('build-js', function () {
	return compileJs();
});

gulp.task('watch-js', function () {
	return compileJs(true);
});

gulp.task('server', function () {
	connect.server({
		root: 'build'
	});
});

gulp.task('minify-css', function () {
	return gulp.src('build/css/regexr.css')
		.pipe(minifyCss())
		.pipe(gulp.dest('build/css'));
});

gulp.task('open-build', function () {
	gulp.src(__filename)
		.pipe(open({uri: 'http://localhost:8080'}));
});

gulp.task('clean-pre-build', function () {
	return gulp.src(['./build/!(v1|.git|sitemap.txt|*.md)'], {read: false})
		.pipe(rimraf());
});

gulp.task('clean-post-build', function () {
	return gulp.src(['./build/js/index.template.js', './build/js/scripts.min.js.map'], {read: false})
		.pipe(rimraf());
});

gulp.task('inline', function () {
	return gulp.src('build/index.html')
		.pipe(inline({
				base: 'build/', js: uglify, css: minifyCss
			}
		))
		.pipe(gulp.dest('build/'));
});

gulp.task('parse-index', function () {
	return gulp.src('build/index.html')
		.pipe(template({noCache: Date.now()}))
		.pipe(minifyHTML())
		.pipe(gulp.dest('build/'));
});

gulp.task('build', function (done) {
	runSequence(
		'clean-pre-build',
		['build-js', 'copy-assets', 'sass'],
		['minify-js', 'minify-css', 'inline'],
		['parse-index', 'clean-post-build'],
		'server', 'open-build',
		done
	);
});

gulp.task('default', function (done) {
	runSequence(
		['sass', 'watch-js', 'watch-sass', 'copy-js-templates'],
		'copy-assets',
		['watch-assets', 'watch-js-templates', 'browser-sync'],
		done
	);
});
<|endoftext|>


<commit_before>/*jshint node:true*/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var dest = 'extension';
var base = {base: 'src/'};

gulp.task('copy', () => gulp.src([
    'src/manifest.json',
    'src/icon_128.jpg',
    'src/*.css'], base)
    .pipe(gulp.dest(dest)));

gulp.task('html', () => gulp.src('src/*.html', base)
    .pipe($.htmlReplace({js: 'lib.js'}))
    .pipe(gulp.dest(dest)));

gulp.task('js', () => gulp.src('src/*.js', base)
    .pipe($.ngAnnotate())
    .pipe($.uglify())
    .pipe(gulp.dest(dest)));

gulp.task('lib', () => gulp.src('src/templates/*.html', base)
    .pipe($.angularTemplatecache())
    .pipe(gulp.src('src/common/*.js'))
    .pipe($.ngAnnotate())
    .pipe($.uglify())
    .pipe(gulp.src(['src/bower/angular/angular.min.js',
                   'src/bower/lodash/lodash.min.js']))
    .pipe($.concat('lib.js'))
    .pipe(gulp.dest(dest)));

gulp.task('default', ['copy', 'html', 'js', 'lib']);

gulp.task('clean', () => require('del')(dest));
<commit_msg>breaking apart lib task with merge-stream to accomidate multiple srcs<commit_after>/*jshint node:true*/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var merge = require('merge-stream');
var dest = 'extension';
var base = {base: 'src/'};

gulp.task('copy', () => gulp.src([
    'src/manifest.json',
    'src/icon_128.jpg',
    'src/*.css'], base)
    .pipe(gulp.dest(dest)));

gulp.task('html', () => gulp.src('src/*.html', base)
    .pipe($.htmlReplace({js: 'lib.js'}))
    .pipe(gulp.dest(dest)));

gulp.task('js', () => gulp.src('src/*.js', base)
    .pipe($.ngAnnotate())
    .pipe($.uglify())
    .pipe(gulp.dest(dest)));

var d = require('gulp-debug');

gulp.task('lib', () => merge(
    gulp.src('src/templates/*.html', base)
    .pipe(d())
    .pipe($.angularTemplatecache()),
    gulp.src('src/common/*.js')
    .pipe(d({title:'should have common'}))
    .pipe($.ngAnnotate())
    .pipe($.uglify()),
    gulp.src(['src/bower/angular/angular.min.js',
                   'src/bower/lodash/lodash.min.js'])
    .pipe($.concat('lib.js'))
    .pipe(gulp.dest(dest))));

gulp.task('default', ['copy', 'html', 'js', 'lib']);

gulp.task('clean', () => require('del')(dest));
<|endoftext|>


<commit_before>'use strict';

const es = require('event-stream');
const del = require('del');
const browserSync = require('browser-sync').create();

const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const mqpacker = require('css-mqpacker');
const csswring = require('csswring');

const gulp = require('gulp');
const aigis = require('gulp-aigis');
const concat = require('gulp-concat');
const consolidate = require('gulp-consolidate');
const iconfont = require('gulp-iconfont');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const watch = require('gulp-watch');
const awspublish = require('gulp-awspublish');

gulp.task('serve', function() {
  browserSync.init({
    server: {
      baseDir: './',
      directory: true,
    },
    files: ['build'],
    notify: false,
    open: false,
  });
});

gulp.task('clean', function() {
  return del('./build/');
});

x;
gulp.task('copy-font', function() {
  return gulp
    .src(['./src/assets2/font/zero-width.woff'])
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('copy-img', function() {
  return gulp
    .src(['./src/assets2/img/*/**'])
    .pipe(gulp.dest('./build/assets2/img/'));
});

gulp.task('copy-static', function() {
  return gulp.src(['./static/*/**']).pipe(gulp.dest('./build/'));
});

gulp.task('js', function() {
  return gulp
    .src([
      './src/assets2/js/vendor/EventDispatcher.js',
      './src/assets2/js/vendor/prism.js',
      './src/assets2/js/prism.extend.js',
      './src/assets2/js/CG2.js',
      './src/assets2/js/CG2-pageHeader.js',
      './src/assets2/js/CG2-drawer.js',
      './src/assets2/js/CG2-compactNav.js',
      './src/assets2/js/CG2-tab.js',
      './src/assets2/js/CG2-articleSeriesNav.js',
      './src/assets2/js/CG2-livecode.js',
      './src/assets2/js/CG2-forms.js',
      './src/assets2/js/old-jade-click-to-play.js',
      './src/assets2/js/old-jade-prism.js',
    ])
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(concat('codegrid-ui.js'))
    .pipe(gulp.dest('./build/assets2/js/'))
    .pipe(uglify())
    .pipe(rename({ extname: '.min.js' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./build/assets2/js/'));
});

gulp.task('css', function() {
  return gulp
    .src([
      './src/assets2/scss/codegrid-ui.scss',
      './src/assets2/scss/codegrid-ui-core.scss',
      './src/assets2/scss/codegrid-ui-www.scss',
    ])
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(postcss([autoprefixer({ supports: false })]))
    .pipe(gulp.dest('./build/assets2/css/'))
    .pipe(postcss([mqpacker(), csswring()]))
    .pipe(rename({ extname: '.min.css' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./build/assets2/css/'));
});

gulp.task('iconfont', function() {
  const fontName = 'codegrid-icon';

  return gulp
    .src(['./src/assets2/font/codegrid-icon/*.svg'])
    .pipe(
      iconfont({
        fontName: fontName,
        formats: ['woff', 'woff2'],
        appendCodepoints: true,
      })
    )
    .on('glyphs', function(glyphs, options) {
      gulp
        .src([
          './src/assets2/font/codegrid-icon/_icon.scss',
          './src/assets2/font/codegrid-icon/_icon-utils.scss',
        ])
        .pipe(
          consolidate('underscore', {
            glyphs: glyphs,
            fontName: fontName,
            fontPath: '../font/',
            prefix: 'CG2-icon',
          })
        )
        .pipe(gulp.dest('./src/assets2/scss/'));
    })
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('numfont', function() {
  const fontName = 'codegrid-num';

  return gulp
    .src(['./src/assets2/font/codegrid-num/*.svg'])
    .pipe(
      iconfont({
        fontName: fontName,
        formats: ['woff', 'woff2'],
        fontHeight: 256,
        descent: 24,
      })
    )
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('guide', function() {
  return gulp.src('./aigis_config.yml').pipe(aigis());
});

// todo: スタイルガイドのHTMLの変更を検知して更新するタスク
// todo: アイコンフォント用SVGファイルの変更を検知するタスク（要るかな）

gulp.task('watch:css', function() {
  return gulp.watch('./src/assets2/scss/**/*.scss', gulp.series('css'));
});

gulp.task('watch:js', function() {
  return gulp.watch('./src/assets2/js/**/*.js', gulp.series('js'));
});

gulp.task('watch', gulp.parallel('watch:css', 'watch:js'));

gulp.task(
  'default',
  gulp.series(
    'iconfont',
    gulp.parallel(
      'numfont',
      'copy-font',
      'copy-img',
      'copy-static',
      'js',
      'css'
    ),
    gulp.parallel('watch', 'serve')
  )
);

gulp.task(
  'build',
  gulp.series(
    'clean',
    'iconfont',
    gulp.parallel(
      'numfont',
      'copy-font',
      'copy-img',
      'copy-static',
      'js',
      'css'
    ),
    'guide'
  )
);

gulp.task('deploy', function() {
  const publisher = awspublish.create({
    params: {
      Bucket: 'ui.codegrid.net',
    },
    endpoint: 's3-ap-northeast-1.amazonaws.com',
  });

  gulp
    .src('./build/**/*')
    .pipe(publisher.publish())
    .pipe(publisher.sync())
    .pipe(awspublish.reporter());
});
<commit_msg>gulpfile: 使わなくなったgulp-watch削除<commit_after>'use strict';

const es = require('event-stream');
const del = require('del');
const browserSync = require('browser-sync').create();

const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const mqpacker = require('css-mqpacker');
const csswring = require('csswring');

const gulp = require('gulp');
const aigis = require('gulp-aigis');
const concat = require('gulp-concat');
const consolidate = require('gulp-consolidate');
const iconfont = require('gulp-iconfont');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const awspublish = require('gulp-awspublish');

gulp.task('serve', function() {
  browserSync.init({
    server: {
      baseDir: './',
      directory: true,
    },
    files: ['build'],
    notify: false,
    open: false,
  });
});

gulp.task('clean', function() {
  return del('./build/');
});

x;
gulp.task('copy-font', function() {
  return gulp
    .src(['./src/assets2/font/zero-width.woff'])
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('copy-img', function() {
  return gulp
    .src(['./src/assets2/img/*/**'])
    .pipe(gulp.dest('./build/assets2/img/'));
});

gulp.task('copy-static', function() {
  return gulp.src(['./static/*/**']).pipe(gulp.dest('./build/'));
});

gulp.task('js', function() {
  return gulp
    .src([
      './src/assets2/js/vendor/EventDispatcher.js',
      './src/assets2/js/vendor/prism.js',
      './src/assets2/js/prism.extend.js',
      './src/assets2/js/CG2.js',
      './src/assets2/js/CG2-pageHeader.js',
      './src/assets2/js/CG2-drawer.js',
      './src/assets2/js/CG2-compactNav.js',
      './src/assets2/js/CG2-tab.js',
      './src/assets2/js/CG2-articleSeriesNav.js',
      './src/assets2/js/CG2-livecode.js',
      './src/assets2/js/CG2-forms.js',
      './src/assets2/js/old-jade-click-to-play.js',
      './src/assets2/js/old-jade-prism.js',
    ])
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(concat('codegrid-ui.js'))
    .pipe(gulp.dest('./build/assets2/js/'))
    .pipe(uglify())
    .pipe(rename({ extname: '.min.js' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./build/assets2/js/'));
});

gulp.task('css', function() {
  return gulp
    .src([
      './src/assets2/scss/codegrid-ui.scss',
      './src/assets2/scss/codegrid-ui-core.scss',
      './src/assets2/scss/codegrid-ui-www.scss',
    ])
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(postcss([autoprefixer({ supports: false })]))
    .pipe(gulp.dest('./build/assets2/css/'))
    .pipe(postcss([mqpacker(), csswring()]))
    .pipe(rename({ extname: '.min.css' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./build/assets2/css/'));
});

gulp.task('iconfont', function() {
  const fontName = 'codegrid-icon';

  return gulp
    .src(['./src/assets2/font/codegrid-icon/*.svg'])
    .pipe(
      iconfont({
        fontName: fontName,
        formats: ['woff', 'woff2'],
        appendCodepoints: true,
      })
    )
    .on('glyphs', function(glyphs, options) {
      gulp
        .src([
          './src/assets2/font/codegrid-icon/_icon.scss',
          './src/assets2/font/codegrid-icon/_icon-utils.scss',
        ])
        .pipe(
          consolidate('underscore', {
            glyphs: glyphs,
            fontName: fontName,
            fontPath: '../font/',
            prefix: 'CG2-icon',
          })
        )
        .pipe(gulp.dest('./src/assets2/scss/'));
    })
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('numfont', function() {
  const fontName = 'codegrid-num';

  return gulp
    .src(['./src/assets2/font/codegrid-num/*.svg'])
    .pipe(
      iconfont({
        fontName: fontName,
        formats: ['woff', 'woff2'],
        fontHeight: 256,
        descent: 24,
      })
    )
    .pipe(gulp.dest('./build/assets2/font/'));
});

gulp.task('guide', function() {
  return gulp.src('./aigis_config.yml').pipe(aigis());
});

// todo: スタイルガイドのHTMLの変更を検知して更新するタスク
// todo: アイコンフォント用SVGファイルの変更を検知するタスク（要るかな）

gulp.task('watch:css', function() {
  return gulp.watch('./src/assets2/scss/**/*.scss', gulp.series('css'));
});

gulp.task('watch:js', function() {
  return gulp.watch('./src/assets2/js/**/*.js', gulp.series('js'));
});

gulp.task('watch', gulp.parallel('watch:css', 'watch:js'));

gulp.task(
  'default',
  gulp.series(
    'iconfont',
    gulp.parallel(
      'numfont',
      'copy-font',
      'copy-img',
      'copy-static',
      'js',
      'css'
    ),
    gulp.parallel('watch', 'serve')
  )
);

gulp.task(
  'build',
  gulp.series(
    'clean',
    'iconfont',
    gulp.parallel(
      'numfont',
      'copy-font',
      'copy-img',
      'copy-static',
      'js',
      'css'
    ),
    'guide'
  )
);

gulp.task('deploy', function() {
  const publisher = awspublish.create({
    params: {
      Bucket: 'ui.codegrid.net',
    },
    endpoint: 's3-ap-northeast-1.amazonaws.com',
  });

  gulp
    .src('./build/**/*')
    .pipe(publisher.publish())
    .pipe(publisher.sync())
    .pipe(awspublish.reporter());
});
<|endoftext|>


<commit_before>var del          = require("del");
var gulp         = require("gulp");
var autoprefixer = require("gulp-autoprefixer");
var babel        = require("gulp-babel");
var closure      = require("gulp-closurecompiler");
var concat       = require("gulp-concat");
var gulpif       = require("gulp-if");
var jade         = require("gulp-jade");
var mocha        = require("gulp-mocha");
var nodemon      = require("gulp-nodemon")
var rename       = require("gulp-rename");
var stylus       = require("gulp-stylus");
var uglify       = require("gulp-uglify");
var util         = require("gulp-util");
var mkdirp       = require("mkdirp");
var yargs        = require("yargs");

//=========================================================
// Arguments
//=========================================================

var argv = yargs.argv;
var enableAnalytics = argv.enableAnalytics === true;

if (enableAnalytics) {
    util.log("Google Analytics enabled");
}

//=========================================================
// Environments
//=========================================================

var environment = "production";

function production() {
    return environment === "production";
}

function development() {
    return environment === "development";
}

function envcase(productionValue, developmentValue) {
    return production() ? productionValue : developmentValue;
}

function envfile(developmentFile) {
    var productionFile = developmentFile.replace(".js", ".min.js")
                                        .replace(".css", ".min.css");
    return envcase(productionFile, developmentFile);
}

//=========================================================
// Library
//=========================================================

gulp.task("lib", function() {
    return gulp.src(["./src/lib/**/*.js", "!./src/lib/core/debug/**"])
        .pipe(closure({
                fileName: envfile("cfxnes.js")
            }, {
                create_source_map: "./dist/lib/" + envfile("cfxnes.js.map"),
                compilation_level: envcase("ADVANCED", "SIMPLE"),
                language_in: "ECMASCRIPT6",
                language_out: "ES5",
                externs: [
                    "./externs/JSZip.js",
                    "./externs/md5.js",
                    "./externs/screenfull.js",
                    "./externs/w3c_audio.js"
                ]
            }))
        .pipe(gulp.dest("./dist/lib/"))
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

//=========================================================
// Client
//=========================================================

gulp.task("scripts", function() {
    return gulp.src("./src/app/client/**/*.js")
        .pipe(babel())
        .pipe(gulpif(production(), uglify()))
        .pipe(concat(envfile("app.js")))
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

gulp.task("styles", function() {
    return gulp.src("./src/app/client/app.styl")
        .pipe(stylus({
            include: [
                "./bower_components/bootstrap-stylus/",
                "./bower_components/font-awesome-stylus/stylus/"
            ],
            compress: production()
        }))
        .pipe(autoprefixer({browsers: ['last 2 versions'], cascade: false}))
        .pipe(rename(envfile("app.css")))
        .pipe(gulp.dest("./dist/app/static/styles/"));
});

gulp.task("views", function() {
    return gulp.src("./src/app/client/**/*.jade")
        .pipe(jade({
            pretty: development(),
            compileDebug: development(),
            data: {
                environment: environment,
                enableAnalytics: enableAnalytics
            }
        }))
        .pipe(gulp.dest("./dist/app/static/"));
});

gulp.task("images", function() {
    return gulp.src("./src/app/client/**/*.{png,jpg,gif}")
        .pipe(gulp.dest("./dist/app/static/"));
});

//=========================================================
// Third party
//=========================================================

gulp.task("vendor-scripts", function() {
    return gulp.src([
                envcase("./bower_components/seiyria-bootstrap-slider/dist/bootstrap-slider.min.js",
                        "./bower_components/seiyria-bootstrap-slider/js/bootstrap-slider.js"), // Different .min file path
                envfile("./bower_components/jquery/dist/jquery.js"),
                envfile("./bower_components/angular/angular.js"),
                envfile("./bower_components/angular-ui-router/release/angular-ui-router.js"),
                envfile("./bower_components/angular-bootstrap/ui-bootstrap-tpls.js"),
                envfile("./bower_components/bootstrap/dist/js/bootstrap.js"),
                envfile("./bower_components/jquery.browser/dist/jquery.browser.js"),
                envfile("./bower_components/js-md5/js/md5.js"),
                envfile("./bower_components/jszip/dist/jszip.js"),
                "./bower_components/angular-bootstrap-slider/slider.js", // Missing .min file
                "./bower_components/screenfull/dist/screenfull.js", // Missing .min file
                "./node_modules/babel/node_modules/babel-core/browser-polyfill.js" // Already minified
            ])
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

gulp.task("vendor-styles", function() {
    return gulp.src([
                envfile("./bower_components/seiyria-bootstrap-slider/dist/css/bootstrap-slider.css")
            ])
        .pipe(gulp.dest("./dist/app/static/styles/"));
});

gulp.task("vendor-fonts", function() {
    return gulp.src("./bower_components/font-awesome-stylus/fonts/fontawesome-webfont.*")
        .pipe(gulp.dest("./dist/app/static/fonts/"));
});

//=========================================================
// Server
//=========================================================

gulp.task("server", function() {
    return gulp.src("./src/app/server/**/*.js")
        .pipe(babel())
        .pipe(gulp.dest("./dist/app/"));
})

//=========================================================
// Application
//=========================================================

gulp.task("init", function(done) {
    mkdirp.sync("./dist/");
    if (process.platform === "win32") {
        done(); // Common Windows user doesn't have right to create symbolic links
    } else {
        mkdirp.sync("./roms/");
        return gulp.src("./roms/")
            .pipe(gulp.symlink("./dist/app/"));
    }
});

gulp.task("build", gulp.parallel(
    "lib",
    "scripts",
    "styles",
    "views",
    "images",
    "vendor-scripts",
    "vendor-styles",
    "vendor-fonts",
    "server"
));

gulp.task("run", function(done) {
    nodemon({
        script: "./dist/app/app.js",
        env: {NODE_ENV: environment},
        ignore: ["./dist/app/static/", "./dist/app/roms/"]
    });
});

gulp.task("app", gulp.series("init", "build", "run"));

//=========================================================
// Tests
//=========================================================

gulp.task("test", function() {
    require("babel/register");
    return gulp.src("./test/**/*-test{,s}.js")
        .pipe(mocha({timeout: 60000}));
});

//=========================================================
// Development
//=========================================================

gulp.task("set-development", function(done) {
    environment = "development";
    done();
})

gulp.task("watch",  function() {
    gulp.watch("./src/lib/**/*.js", gulp.series("lib"));
    gulp.watch("./src/app/client/**/*.js", gulp.series("scripts"));
    gulp.watch("./src/app/client/**/*.styl", gulp.series("styles"));
    gulp.watch("./src/app/client/**/*.jade", gulp.series("views"));
    gulp.watch("./src/app/server/**/*.js", gulp.series("server"));
});

gulp.task("dev", gulp.series(
    "set-development",
    "init",
    "build",
    gulp.parallel("watch", "run")
));

//=========================================================
// Other
//=========================================================

gulp.task("clean", function(done) {
    del(["./dist/"], done);
});

gulp.task("default", gulp.series("init", "app"));
<commit_msg>Fixed nodemon configuration in gulpfile.<commit_after>var del          = require("del");
var gulp         = require("gulp");
var autoprefixer = require("gulp-autoprefixer");
var babel        = require("gulp-babel");
var closure      = require("gulp-closurecompiler");
var concat       = require("gulp-concat");
var gulpif       = require("gulp-if");
var jade         = require("gulp-jade");
var mocha        = require("gulp-mocha");
var nodemon      = require("gulp-nodemon")
var rename       = require("gulp-rename");
var stylus       = require("gulp-stylus");
var uglify       = require("gulp-uglify");
var util         = require("gulp-util");
var mkdirp       = require("mkdirp");
var yargs        = require("yargs");

//=========================================================
// Arguments
//=========================================================

var argv = yargs.argv;
var enableAnalytics = argv.enableAnalytics === true;

if (enableAnalytics) {
    util.log("Google Analytics enabled");
}

//=========================================================
// Environments
//=========================================================

var environment = "production";

function production() {
    return environment === "production";
}

function development() {
    return environment === "development";
}

function envcase(productionValue, developmentValue) {
    return production() ? productionValue : developmentValue;
}

function envfile(developmentFile) {
    var productionFile = developmentFile.replace(".js", ".min.js")
                                        .replace(".css", ".min.css");
    return envcase(productionFile, developmentFile);
}

//=========================================================
// Library
//=========================================================

gulp.task("lib", function() {
    return gulp.src(["./src/lib/**/*.js", "!./src/lib/core/debug/**"])
        .pipe(closure({
                fileName: envfile("cfxnes.js")
            }, {
                create_source_map: "./dist/lib/" + envfile("cfxnes.js.map"),
                compilation_level: envcase("ADVANCED", "SIMPLE"),
                language_in: "ECMASCRIPT6",
                language_out: "ES5",
                externs: [
                    "./externs/JSZip.js",
                    "./externs/md5.js",
                    "./externs/screenfull.js",
                    "./externs/w3c_audio.js"
                ]
            }))
        .pipe(gulp.dest("./dist/lib/"))
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

//=========================================================
// Client
//=========================================================

gulp.task("scripts", function() {
    return gulp.src("./src/app/client/**/*.js")
        .pipe(babel())
        .pipe(gulpif(production(), uglify()))
        .pipe(concat(envfile("app.js")))
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

gulp.task("styles", function() {
    return gulp.src("./src/app/client/app.styl")
        .pipe(stylus({
            include: [
                "./bower_components/bootstrap-stylus/",
                "./bower_components/font-awesome-stylus/stylus/"
            ],
            compress: production()
        }))
        .pipe(autoprefixer({browsers: ['last 2 versions'], cascade: false}))
        .pipe(rename(envfile("app.css")))
        .pipe(gulp.dest("./dist/app/static/styles/"));
});

gulp.task("views", function() {
    return gulp.src("./src/app/client/**/*.jade")
        .pipe(jade({
            pretty: development(),
            compileDebug: development(),
            data: {
                environment: environment,
                enableAnalytics: enableAnalytics
            }
        }))
        .pipe(gulp.dest("./dist/app/static/"));
});

gulp.task("images", function() {
    return gulp.src("./src/app/client/**/*.{png,jpg,gif}")
        .pipe(gulp.dest("./dist/app/static/"));
});

//=========================================================
// Third party
//=========================================================

gulp.task("vendor-scripts", function() {
    return gulp.src([
                envcase("./bower_components/seiyria-bootstrap-slider/dist/bootstrap-slider.min.js",
                        "./bower_components/seiyria-bootstrap-slider/js/bootstrap-slider.js"), // Different .min file path
                envfile("./bower_components/jquery/dist/jquery.js"),
                envfile("./bower_components/angular/angular.js"),
                envfile("./bower_components/angular-ui-router/release/angular-ui-router.js"),
                envfile("./bower_components/angular-bootstrap/ui-bootstrap-tpls.js"),
                envfile("./bower_components/bootstrap/dist/js/bootstrap.js"),
                envfile("./bower_components/jquery.browser/dist/jquery.browser.js"),
                envfile("./bower_components/js-md5/js/md5.js"),
                envfile("./bower_components/jszip/dist/jszip.js"),
                "./bower_components/angular-bootstrap-slider/slider.js", // Missing .min file
                "./bower_components/screenfull/dist/screenfull.js", // Missing .min file
                "./node_modules/babel/node_modules/babel-core/browser-polyfill.js" // Already minified
            ])
        .pipe(gulp.dest("./dist/app/static/scripts/"));
});

gulp.task("vendor-styles", function() {
    return gulp.src([
                envfile("./bower_components/seiyria-bootstrap-slider/dist/css/bootstrap-slider.css")
            ])
        .pipe(gulp.dest("./dist/app/static/styles/"));
});

gulp.task("vendor-fonts", function() {
    return gulp.src("./bower_components/font-awesome-stylus/fonts/fontawesome-webfont.*")
        .pipe(gulp.dest("./dist/app/static/fonts/"));
});

//=========================================================
// Server
//=========================================================

gulp.task("server", function() {
    return gulp.src("./src/app/server/**/*.js")
        .pipe(babel())
        .pipe(gulp.dest("./dist/app/"));
})

//=========================================================
// Application
//=========================================================

gulp.task("init", function(done) {
    mkdirp.sync("./dist/");
    if (process.platform === "win32") {
        done(); // Common Windows user doesn't have right to create symbolic links
    } else {
        mkdirp.sync("./roms/");
        return gulp.src("./roms/")
            .pipe(gulp.symlink("./dist/app/"));
    }
});

gulp.task("build", gulp.parallel(
    "lib",
    "scripts",
    "styles",
    "views",
    "images",
    "vendor-scripts",
    "vendor-styles",
    "vendor-fonts",
    "server"
));

gulp.task("run", function(done) {
    // We can't change nodemon working directory, because that would break
    // closure compiler paths in 'lib' task.
    nodemon({
        env: {NODE_ENV: environment},
        script: "./dist/app/app.js",
        watch: [ "dist/app/app.js", "dist/app/services/" ],
        ignore: [
            ".git/",
            "bin/",
            "bower_components/",
            "dist/lib/",
            "dist/app/roms/",
            "dist/app/static/",
            "externs/",
            "roms/",
            "node_modules/",
            "src/",
            "test/",
            ".gitignore",
            "bower.json",
            "CHANGELOG.md",
            "gulpfile.js",
            "LICENSE.txt",
            "package.json",
            "README.md"
        ]
    });
});

gulp.task("app", gulp.series("init", "build", "run"));

//=========================================================
// Tests
//=========================================================

gulp.task("test", function() {
    require("babel/register");
    return gulp.src("./test/**/*-test{,s}.js")
        .pipe(mocha({timeout: 60000}));
});

//=========================================================
// Development
//=========================================================

gulp.task("set-development", function(done) {
    environment = "development";
    done();
})

gulp.task("watch",  function() {
    gulp.watch("./src/lib/**/*.js", gulp.series("lib"));
    gulp.watch("./src/app/client/**/*.js", gulp.series("scripts"));
    gulp.watch("./src/app/client/**/*.styl", gulp.series("styles"));
    gulp.watch("./src/app/client/**/*.jade", gulp.series("views"));
    gulp.watch("./src/app/server/**/*.js", gulp.series("server"));
});

gulp.task("dev", gulp.series(
    "set-development",
    "init",
    "build",
    gulp.parallel("watch", "run")
));

//=========================================================
// Other
//=========================================================

gulp.task("clean", function(done) {
    del(["./dist/"], done);
});

gulp.task("default", gulp.series("init", "app"));
<|endoftext|>


<commit_before>var fs = require('fs')
  , gulp = require('gulp')
  , browserify = require('gulp-browserify')
  , rename = require('gulp-rename')
  , uglify = require('gulp-uglify');

gulp.task('browserify', function () {
  gulp.src('./client/config/app.js')
    .pipe(browserify())
    .pipe(uglify({ outSourceMap: true }))
    .pipe(gulp.dest('./client/assets/js/'))
});

gulp.task('config', function () {
  if (!fs.existsSync('./server/config/config.js')) {
    gulp.src('./server/config/config.default.js')
      .pipe(rename('config.js'))
      .pipe(gulp.dest('./server/config/'));
  }
});

gulp.task('watch', function () {
  gulp.watch(['./client/config/*.js', './client/app/*.js'], function () {
    gulp.run('browserify');
  });
});

gulp.task('default', function () {
  gulp.run('config', 'browserify');
});
<commit_msg>update gulpfile<commit_after>var fs = require('fs')
  , gulp = require('gulp')
  , browserify = require('gulp-browserify')
  , rename = require('gulp-rename')
  , uglify = require('gulp-uglify');

gulp.task('browserify', function () {
  gulp.src('./client/config/app.js')
    .pipe(browserify())
    .pipe(uglify({ outSourceMap: true }))
    .pipe(gulp.dest('./client/assets/js/'))
});

gulp.task('config', function () {
  if (!fs.existsSync('./server/config/config.js')) {
    gulp.src('./server/config/config.default.js')
      .pipe(rename('config.js'))
      .pipe(gulp.dest('./server/config/'));
  }
});

gulp.task('watch', function () {
  gulp.watch(['./client/config/*.js', './client/app/*.js'], ['browserify'])
});

gulp.task('default', ['config', 'browserify']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var webpack = require('webpack-stream');
var sass = require('gulp-sass');
var minifyCss = require('gulp-cssnano');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');

var paths = {
  css: ['app/**/*.scss'],
  html: ['app/**/*.html'],
  js: ['app/**/*.js'],
  test: ['test/testRoutes.js']
};

gulp.task('build:css', function() {
  gulp.src('app/scss/app.scss')
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(gulp.dest('app/css/'))
    .pipe(minifyCss())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/'));
});

gulp.task('build:html', function() {
  gulp.src('app/**/*.html')
  .pipe(gulp.dest('build/'));
});

gulp.task('build:js', function() {
  return gulp.src('app/js/entry.js')
  .pipe(webpack({
    output: {
      filename: 'bundle.js'
    }
  }))
  .pipe(gulp.dest('build/'));
});

gulp.task('build:static', function() {
  gulp.src('img/*')
  .pipe(gulp.dest('build/img'));

  gulp.src('vendor/*')
  .pipe(gulp.dest('build/vendor'));
});

gulp.task('watch:css', function() {
	gulp.watch(paths.css, ['build:css']);
});

gulp.task('watch:html', function() {
	gulp.watch(paths.html, ['build:html']);
});

gulp.task('watch:js', function() {
	gulp.watch(paths.js, ['build:js']);
});

gulp.task('build:all', ['build:css', 'build:html', 'build:js', 'build:static']);
gulp.task('test:all', ['test:mocha']);
gulp.task('watch:all', ['watch:css', 'watch:html', 'watch:js']);
gulp.task('default', ['build:all']);
<commit_msg>add watch to default gulp task<commit_after>var gulp = require('gulp');
var webpack = require('webpack-stream');
var sass = require('gulp-sass');
var minifyCss = require('gulp-cssnano');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');

var paths = {
  css: ['app/**/*.scss'],
  html: ['app/**/*.html'],
  js: ['app/**/*.js'],
  test: ['test/testRoutes.js']
};

gulp.task('build:css', function() {
  gulp.src('app/scss/app.scss')
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(gulp.dest('app/css/'))
    .pipe(minifyCss())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/'));
});

gulp.task('build:html', function() {
  gulp.src('app/**/*.html')
  .pipe(gulp.dest('build/'));
});

gulp.task('build:js', function() {
  return gulp.src('app/js/entry.js')
  .pipe(webpack({
    output: {
      filename: 'bundle.js'
    }
  }))
  .pipe(gulp.dest('build/'));
});

gulp.task('build:static', function() {
  gulp.src('img/*')
  .pipe(gulp.dest('build/img'));

  gulp.src('vendor/*')
  .pipe(gulp.dest('build/vendor'));
});

gulp.task('watch:css', function() {
	gulp.watch(paths.css, ['build:css']);
});

gulp.task('watch:html', function() {
	gulp.watch(paths.html, ['build:html']);
});

gulp.task('watch:js', function() {
	gulp.watch(paths.js, ['build:js']);
});

gulp.task('build:all', ['build:css', 'build:html', 'build:js', 'build:static']);
gulp.task('test:all', ['test:mocha']);
gulp.task('watch:all', ['watch:css', 'watch:html', 'watch:js']);
gulp.task('default', ['build:all', 'watch:all']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var notify = require('gulp-notify');
var autoprefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var nodemon = require('gulp-nodemon');

var paths = {
    scss: './sass/*.scss'
};

gulp.task('scripts', function() {
  return gulp.src([
    /* Add your JS files here, they will be combined in this order */
    'js/vendor/jquery-1.11.1.js',
    'js/app.js'
    ])
    .pipe(concat('main.js'))
    .pipe(gulp.dest('js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('js'));
});

gulp.task('sass', function () {
    gulp.src('scss/main.scss')
    .pipe(plumber())
    .pipe(sass({
        includePaths: ['scss']
    }))
    .pipe(gulp.dest('css'))
    .pipe(autoprefixer({
      browsers: ['> 1%']
    }))
    .pipe(minifycss())
    .pipe(gulp.dest('css'))
    /* Reload the browser CSS after every change */
    .pipe(reload({stream:true}));
});

gulp.task('bs-reload', function () {
  browserSync.reload();
});

gulp.task('browser-sync', ['nodemon'], function() {
  browserSync.init(['css/*.css', 'js/*.js'], {
    proxy: 'http://localhost:3000',
    port: 4000
  });
});

gulp.task('nodemon', function (cb) {
  var called = false;
  return nodemon({
    script: 'server.js',
    nodeArgs: ['--debug'],
    watch: ['models', 'routes', 'server.js', 'gulpfile.js']
  })
  .on('start', function onStart() {
    // ensure start only got called once
    if (!called) { cb(); }
    called = true;
  })
  .on('restart', function onRestart() {
    // reload connected browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, 500);
  });
});

/* Watch scss, js and html files, doing different things with each. */
gulp.task('watch', function () {
  /* Watch scss, run the sass task on change. */
  gulp.watch(['scss/*.scss', 'scss/**/*.scss'], ['sass']);
  /* Watch app.js file, run the scripts task on change. */
  // gulp.watch(['js/**/*.js'], ['bs-reload']);
  /* Watch .html files, run the bs-reload task on change. */
  gulp.watch(['*.html', '*.js'], ['bs-reload']);
});

/* Watch scss, js and html files, doing different things with each. */
gulp.task('default', ['sass', 'browser-sync', 'watch'], function () {});

gulp.task('serve', ['sass', 'watch'], function () {

});
<commit_msg>gulpfile improvements<commit_after>var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var notify = require('gulp-notify');
var autoprefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var nodemon = require('gulp-nodemon');

var paths = {
    scss: './sass/*.scss'
};

gulp.task('scripts', function() {
  return gulp.src([
    /* Add your JS files here, they will be combined in this order */
    'js/vendor/jquery-1.11.1.js',
    'js/app.js'
    ])
    .pipe(concat('main.js'))
    .pipe(gulp.dest('js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('js'));
});

gulp.task('sass', function () {
    gulp.src('scss/main.scss')
    .pipe(plumber())
    .pipe(sass({
        includePaths: ['scss']
    }))
    .pipe(gulp.dest('css'))
    .pipe(autoprefixer({
      browsers: ['> 1%']
    }))
    .pipe(minifycss())
    .pipe(gulp.dest('css'))
    /* Reload the browser CSS after every change */
    .pipe(reload({stream:true}));
});

gulp.task('bs-reload', function () {
  browserSync.reload();
});

gulp.task('browser-sync', ['nodemon'], function() {
  browserSync.init(['css/*.css', 'js/*.js', '*.html'], {
    proxy: 'http://localhost:3000',
    port: 4000
  });
});

gulp.task('nodemon', function (cb) {
  var called = false;
  return nodemon({
    script: 'server.js',
    nodeArgs: ['--debug'],
    watch: ['models', 'routes', 'server.js', 'gulpfile.js']
  })
  .on('start', function onStart() {
    // ensure start only got called once
    if (!called) { cb(); }
    called = true;
  })
  .on('restart', function onRestart() {
    // reload connected browsers after a slight delay
    setTimeout(function reload() {
      browserSync.reload({
        stream: false
      });
    }, 500);
  });
});

/* Watch scss, js and html files, doing different things with each. */
gulp.task('watch', function () {
  /* Watch scss, run the sass task on change. */
  gulp.watch(['scss/*.scss', 'scss/**/*.scss'], ['sass']);
  /* Watch app.js file, run the scripts task on change. */
  // gulp.watch(['js/**/*.js'], ['bs-reload']);
  /* Watch .html files, run the bs-reload task on change. */
  gulp.watch(['*.html', '*.js'], ['bs-reload']);
});

/* Watch scss, js and html files, doing different things with each. */
gulp.task('default', ['sass', 'browser-sync', 'watch'], function () {});

gulp.task('serve', ['sass', 'watch'], function () {

});
<|endoftext|>