<commit_before>
require('babel/register');

var _ = require('lodash');

var gulp = require('gulp');
var del = require('del');
var source = require('vinyl-source-stream');
var vinylPaths = require('vinyl-paths');
var browserify = require('browserify');
var babelify = require('babelify');
var errorify = require('errorify');
var watchify = require('watchify');
var fs = require('fs');
var execSync = require('child_process').execSync;

var git = require('gulp-git');
var util = require('gulp-util');
var open = require('gulp-open');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var minifyCss = require('gulp-minify-css');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var jade = require('gulp-jade');
var sourcemaps = require('gulp-sourcemaps');
var connect = require('gulp-connect');
var gulpif = require('gulp-if');
var ghPages = require('gulp-gh-pages');
var bump = require('gulp-bump');
var tagVersion = require('gulp-tag-version');
var filter = require('gulp-filter');
var ngAnnotate = require('gulp-ng-annotate');
var uncss = require('gulp-uncss');
var eslint = require('gulp-eslint');
var autoprefixer = require('gulp-autoprefixer');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var mocha = require('gulp-mocha');
var changelog = require('conventional-changelog');
var nwBuilder = require('gulp-nw-builder');
var zip = require('gulp-zip');
var folders = require('gulp-folders');
var release = require('gulp-github-release');
var packageJson = require('./package.json');

var watching = false;

var getPaths = function() {
  return JSON.parse(fs.readFileSync('./package.json')).gulp;
};

var currentTag = function() {
  return execSync('git describe --abbrev=0').toString().trim();
};

gulp.task('deploy', function() {
  var paths = getPaths();

  return gulp.src(paths.dist + '/(css|js|favicon.ico|index.html)')
    .pipe(ghPages());
});

gulp.task('clean', function() {
  var paths = getPaths();

  return gulp.src(paths.dist)
    .pipe(vinylPaths(del))
    .on('error', util.log);
});

gulp.task('copy:favicon', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.favicon)
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('build:libcss', ['clean', 'compile:jade', 'compile:sass'], function() {
  var paths = getPaths();

  return gulp.src(paths.libcss)
    //.pipe(cached('libcss'))
    //.pipe(remember('libcss'))
    .pipe(concat('lib.min.css'))
    /*.pipe(uncss({
      html: paths.dist + 'index.html'
    }))*/
    .pipe(minifyCss({
      keepSpecialComments: false,
      removeEmpty: true
    }))
    .pipe(gulp.dest(paths.dist + 'css'))
    .on('error', util.log);
});

gulp.task('build:libjs', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.libjs)
    //.pipe(cached('libjs'))
    //.pipe(remember('libjs'))
    //.pipe(gulpif(!watching, uglify({ outSourceMaps: false })))
    .pipe(concat('lib.min.js'))
    .pipe(gulp.dest(paths.dist + 'js'))
    .on('error', util.log);
});

gulp.task('compile:js', ['eslint', 'clean'], function() {
  var paths = getPaths();

  var bundler = browserify({
    cache: {}, packageCache: {}, fullPaths: true,
    entries: [paths.entry],
    debug: watching
  })
    .transform(babelify);

  if(watching) {
    bundler.plugin(errorify);
  }

  var bundlee = function() {
    return bundler
      .bundle()
      .pipe(source('js/main.min.js'))
      //.pipe(gulpif(!watching, uglify({ outSourceMaps: false })))
      .pipe(ngAnnotate())
      .pipe(gulp.dest(paths.dist))
      .on('error', util.log);
  };

  if (watching) {
    bundler = watchify(bundler);
    bundler.on('update', bundlee);
  }

  return bundlee();
});

gulp.task('eslint', function() {
  var paths = getPaths();

  return gulp.src(paths.js)
    .pipe(eslint({ useEslintrc: true }))
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

gulp.task('compile:sass', ['clean', 'compile:jade'], function() {
  var paths = getPaths();

  return gulp.src(paths.sass)
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(concat('css/main.css'))
    /*.pipe(uncss({
      html: paths.dist + 'index.html'
    }))*/
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(gulpif(!watching, minifyCss({
      keepSpecialComments: false,
      removeEmpty: true
    })))
    .pipe(rename({ suffix: '.min' }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('compile:jade', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.jade)
    .pipe(concat('index.html'))
    .pipe(jade({
      pretty: watching
    }))
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('reload', ['build'], function() {
  return gulp.src('dist/*.html')
    .pipe(connect.reload())
    .on('error', util.log);
});

gulp.task('connect', function() {
  connect.server({
    root: ['./dist'],
    port: 8000,
    livereload: true
  });
});

gulp.task('open', ['build'], function() {
  gulp.src('./dist/index.html')
    .pipe(open({
      uri: 'http://127.0.0.1:8000'
    }));
});

gulp.task('watch', function() {
  var paths = getPaths();

  watching = true;
  return gulp.watch([paths.sass, paths.jade, paths.js, 'package.json'], ['reload']);
});

var versionSources = ['./bower.json', './package.json'];

var versionStream = function(type) {
  return gulp.src(versionSources)
    .pipe(bump({ type: type }))
    .pipe(gulp.dest('./'))
    .pipe(filter('package.json'))
    .pipe(tagVersion({ prefix: '' }));
};

var commitStream = function(type) {
  var tag = currentTag();
  return gulp.src(versionSources.concat('CHANGELOG.md'))
    .pipe(git.commit('chore(version): release '+type+ ' version ' +tag, function() {
      git.push();
      git.push('origin', 'master', { args: '--tags' });
    }));
};

var pushStream = function() {
  git.push();
  git.push('origin', 'master', { args: '--tags' });
};

gulp.task('bump:patch:tag', function() {
  return versionStream('patch');
});

gulp.task('bump:minor:tag', function() {
  return versionStream('minor');
});

gulp.task('bump:major:tag', function() {
  return versionStream('major');
});

gulp.task('bump:patch:commit', ['bump:patch:tag', 'generate:changelog'], function() {
  return commitStream('patch') && pushStream();
});

gulp.task('bump:minor:commit', ['bump:minor:tag', 'generate:changelog'], function() {
  return commitStream('minor') && pushStream();
});

gulp.task('bump:major:commit', ['bump:major:tag', 'generate:changelog'], function() {
  return commitStream('major') && pushStream();
});

gulp.task('generate:changelog', function() {
  return changelog({
    releaseCount: 0,
    preset: 'angular'
  })
    .pipe(fs.createWriteStream('CHANGELOG.md'));
});

gulp.task('copy:nw', function() {
  var paths = getPaths();

  return gulp.src(['./package.json', 'nw-setup/**/*'])
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('generate:binaries', ['clean:binaries', 'copy:nw'], function() {
  execSync('npm install --prefix ./dist/ express');
  var paths = getPaths();

  return gulp.src(paths.dist+'/**/*')
    .pipe(nwBuilder({
      version: 'v0.12.2',
      platforms: ['osx64', 'win64', 'linux64'],
      appName: packageJson.name,
      appVersion: packageJson.version,
      buildDir: './bin-build',
      cacheDir: './bin-cache',
      macIcns: './favicon.icns',
      winIco: './favicon.ico'
    }));
});

gulp.task('clean:binaries', function() {
  return gulp.src(['./bin-build', './bin-release'])
    .pipe(vinylPaths(del))
    .on('error', util.log);
});

var binaryPath = './bin-build/OpenChallenge';
gulp.task('package:binaries', ['generate:binaries'], folders(binaryPath, function(folder) {
  return gulp.src(binaryPath + '/' + folder + '/**/*')
    .pipe(zip(folder + '.zip'))
    .pipe(gulp.dest('./bin-release'));
}));

gulp.task('upload:binaries', ['package:binaries'], function() {
  return gulp.src('./bin-release/*.zip')
    .pipe(release({
      repo: 'openchallenge',
      owner: 'seiyria',
      tag: currentTag(),
      manifest: packageJson
    }));
});

gulp.task('test', function() {
  var paths = getPaths();

  gulp.src(paths.testjs)
    .pipe(mocha());
});

gulp.task('bump:patch', ['bump:patch:tag', 'bump:patch:commit']);
gulp.task('bump:minor', ['bump:minor:tag', 'bump:minor:commit']);
gulp.task('bump:major', ['bump:major:tag', 'bump:major:commit']);

gulp.task('release:patch', ['bump:patch', 'upload:binaries', 'deploy']);
gulp.task('release:minor', ['bump:minor', 'upload:binaries', 'deploy']);
gulp.task('release:major', ['bump:major', 'upload:binaries', 'deploy']);

gulp.task('default', ['build', 'connect', 'open', 'watch']);
gulp.task('build', ['clean', 'copy:favicon', 'build:libjs', 'build:libcss', 'compile']);
gulp.task('compile', ['compile:js', 'compile:sass', 'compile:jade']);
gulp.task('check', ['test', 'build']);
<commit_msg>fix deploy task<commit_after>
require('babel/register');

var _ = require('lodash');

var gulp = require('gulp');
var del = require('del');
var source = require('vinyl-source-stream');
var vinylPaths = require('vinyl-paths');
var browserify = require('browserify');
var babelify = require('babelify');
var errorify = require('errorify');
var watchify = require('watchify');
var fs = require('fs');
var execSync = require('child_process').execSync;

var git = require('gulp-git');
var util = require('gulp-util');
var open = require('gulp-open');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var minifyCss = require('gulp-minify-css');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var jade = require('gulp-jade');
var sourcemaps = require('gulp-sourcemaps');
var connect = require('gulp-connect');
var gulpif = require('gulp-if');
var ghPages = require('gulp-gh-pages');
var bump = require('gulp-bump');
var tagVersion = require('gulp-tag-version');
var filter = require('gulp-filter');
var ngAnnotate = require('gulp-ng-annotate');
var uncss = require('gulp-uncss');
var eslint = require('gulp-eslint');
var autoprefixer = require('gulp-autoprefixer');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var mocha = require('gulp-mocha');
var changelog = require('conventional-changelog');
var nwBuilder = require('gulp-nw-builder');
var zip = require('gulp-zip');
var folders = require('gulp-folders');
var release = require('gulp-github-release');
var packageJson = require('./package.json');

var watching = false;

var getPaths = function() {
  return JSON.parse(fs.readFileSync('./package.json')).gulp;
};

var currentTag = function() {
  return execSync('git describe --abbrev=0').toString().trim();
};

gulp.task('deploy', function() {
  var paths = getPaths();

  return gulp.src(paths.dist+'/**/*', { base: paths.dist })
    .pipe(filter(function(file) {
      return !_.contains(file.path, 'node_modules');
    }))
    .pipe(ghPages());
});

gulp.task('clean', function() {
  var paths = getPaths();

  return gulp.src(paths.dist)
    .pipe(vinylPaths(del))
    .on('error', util.log);
});

gulp.task('copy:favicon', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.favicon)
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('build:libcss', ['clean', 'compile:jade', 'compile:sass'], function() {
  var paths = getPaths();

  return gulp.src(paths.libcss)
    //.pipe(cached('libcss'))
    //.pipe(remember('libcss'))
    .pipe(concat('lib.min.css'))
    /*.pipe(uncss({
      html: paths.dist + 'index.html'
    }))*/
    .pipe(minifyCss({
      keepSpecialComments: false,
      removeEmpty: true
    }))
    .pipe(gulp.dest(paths.dist + 'css'))
    .on('error', util.log);
});

gulp.task('build:libjs', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.libjs)
    //.pipe(cached('libjs'))
    //.pipe(remember('libjs'))
    //.pipe(gulpif(!watching, uglify({ outSourceMaps: false })))
    .pipe(concat('lib.min.js'))
    .pipe(gulp.dest(paths.dist + 'js'))
    .on('error', util.log);
});

gulp.task('compile:js', ['eslint', 'clean'], function() {
  var paths = getPaths();

  var bundler = browserify({
    cache: {}, packageCache: {}, fullPaths: true,
    entries: [paths.entry],
    debug: watching
  })
    .transform(babelify);

  if(watching) {
    bundler.plugin(errorify);
  }

  var bundlee = function() {
    return bundler
      .bundle()
      .pipe(source('js/main.min.js'))
      //.pipe(gulpif(!watching, uglify({ outSourceMaps: false })))
      .pipe(ngAnnotate())
      .pipe(gulp.dest(paths.dist))
      .on('error', util.log);
  };

  if (watching) {
    bundler = watchify(bundler);
    bundler.on('update', bundlee);
  }

  return bundlee();
});

gulp.task('eslint', function() {
  var paths = getPaths();

  return gulp.src(paths.js)
    .pipe(eslint({ useEslintrc: true }))
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

gulp.task('compile:sass', ['clean', 'compile:jade'], function() {
  var paths = getPaths();

  return gulp.src(paths.sass)
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(concat('css/main.css'))
    /*.pipe(uncss({
      html: paths.dist + 'index.html'
    }))*/
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(gulpif(!watching, minifyCss({
      keepSpecialComments: false,
      removeEmpty: true
    })))
    .pipe(rename({ suffix: '.min' }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('compile:jade', ['clean'], function() {
  var paths = getPaths();

  return gulp.src(paths.jade)
    .pipe(concat('index.html'))
    .pipe(jade({
      pretty: watching
    }))
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('reload', ['build'], function() {
  return gulp.src('dist/*.html')
    .pipe(connect.reload())
    .on('error', util.log);
});

gulp.task('connect', function() {
  connect.server({
    root: ['./dist'],
    port: 8000,
    livereload: true
  });
});

gulp.task('open', ['build'], function() {
  gulp.src('./dist/index.html')
    .pipe(open({
      uri: 'http://127.0.0.1:8000'
    }));
});

gulp.task('watch', function() {
  var paths = getPaths();

  watching = true;
  return gulp.watch([paths.sass, paths.jade, paths.js, 'package.json'], ['reload']);
});

var versionSources = ['./bower.json', './package.json'];

var versionStream = function(type) {
  return gulp.src(versionSources)
    .pipe(bump({ type: type }))
    .pipe(gulp.dest('./'))
    .pipe(filter('package.json'))
    .pipe(tagVersion({ prefix: '' }));
};

var commitStream = function(type) {
  var tag = currentTag();
  return gulp.src(versionSources.concat('CHANGELOG.md'))
    .pipe(git.commit('chore(version): release '+type+ ' version ' +tag, function() {
      git.push();
      git.push('origin', 'master', { args: '--tags' });
    }));
};

var pushStream = function() {
  git.push();
  git.push('origin', 'master', { args: '--tags' });
};

gulp.task('bump:patch:tag', function() {
  return versionStream('patch');
});

gulp.task('bump:minor:tag', function() {
  return versionStream('minor');
});

gulp.task('bump:major:tag', function() {
  return versionStream('major');
});

gulp.task('bump:patch:commit', ['bump:patch:tag', 'generate:changelog'], function() {
  return commitStream('patch') && pushStream();
});

gulp.task('bump:minor:commit', ['bump:minor:tag', 'generate:changelog'], function() {
  return commitStream('minor') && pushStream();
});

gulp.task('bump:major:commit', ['bump:major:tag', 'generate:changelog'], function() {
  return commitStream('major') && pushStream();
});

gulp.task('generate:changelog', function() {
  return changelog({
    releaseCount: 0,
    preset: 'angular'
  })
    .pipe(fs.createWriteStream('CHANGELOG.md'));
});

gulp.task('copy:nw', function() {
  var paths = getPaths();

  return gulp.src(['./package.json', 'nw-setup/**/*'])
    .pipe(gulp.dest(paths.dist))
    .on('error', util.log);
});

gulp.task('generate:binaries', ['clean:binaries', 'copy:nw'], function() {
  execSync('npm install --prefix ./dist/ express');
  var paths = getPaths();

  return gulp.src(paths.dist+'/**/*')
    .pipe(nwBuilder({
      version: 'v0.12.2',
      platforms: ['osx64', 'win64', 'linux64'],
      appName: packageJson.name,
      appVersion: packageJson.version,
      buildDir: './bin-build',
      cacheDir: './bin-cache',
      macIcns: './favicon.icns',
      winIco: './favicon.ico'
    }));
});

gulp.task('clean:binaries', function() {
  return gulp.src(['./bin-build', './bin-release'])
    .pipe(vinylPaths(del))
    .on('error', util.log);
});

var binaryPath = './bin-build/OpenChallenge';
gulp.task('package:binaries', ['generate:binaries'], folders(binaryPath, function(folder) {
  return gulp.src(binaryPath + '/' + folder + '/**/*')
    .pipe(zip(folder + '.zip'))
    .pipe(gulp.dest('./bin-release'));
}));

gulp.task('upload:binaries', ['package:binaries'], function() {
  return gulp.src('./bin-release/*.zip')
    .pipe(release({
      repo: 'openchallenge',
      owner: 'seiyria',
      tag: currentTag(),
      manifest: packageJson
    }));
});

gulp.task('test', function() {
  var paths = getPaths();

  gulp.src(paths.testjs)
    .pipe(mocha());
});

gulp.task('bump:patch', ['bump:patch:tag', 'bump:patch:commit']);
gulp.task('bump:minor', ['bump:minor:tag', 'bump:minor:commit']);
gulp.task('bump:major', ['bump:major:tag', 'bump:major:commit']);

gulp.task('release:patch', ['bump:patch', 'upload:binaries', 'deploy']);
gulp.task('release:minor', ['bump:minor', 'upload:binaries', 'deploy']);
gulp.task('release:major', ['bump:major', 'upload:binaries', 'deploy']);

gulp.task('default', ['build', 'connect', 'open', 'watch']);
gulp.task('build', ['clean', 'copy:favicon', 'build:libjs', 'build:libcss', 'compile']);
gulp.task('compile', ['compile:js', 'compile:sass', 'compile:jade']);
gulp.task('check', ['test', 'build']);
<|endoftext|>


<commit_before>/******************************************************
* PATTERN LAB NODE
* EDITION-NODE-GULP
* The gulp wrapper around patternlab-node core, providing tasks to interact with the core library and move supporting frontend assets.
******************************************************/
var gulp = require('gulp');
var path = require('path');
var browserSync = require('browser-sync').create();
var argv = require('minimist')(process.argv.slice(2));

var projectConfig = require('./project.config.js');

//read all paths from our namespaced config file
var config = require('./patternlab-config');
var patternlab = require('patternlab-node');

var sgc = require('gulp-sass-generate-contents');
var sass  = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var gap = require('gulp-append-prepend');
var rename = require("gulp-rename");

var del = require('del');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

function resolvePath(pathInput) {
  return path.resolve(pathInput).replace(/\\/g,"/");
}

gulp.task('clean', function () {
	return del([
    projectConfig.dest.root,
    config.patternExportDirectory
  ]);
});

/******************************************************
* COPY TASKS - stream assets from source to destination
******************************************************/
// JS copy
gulp.task('pl-copy:js', function(){
  return gulp.src('**/*.js', {cwd: resolvePath(paths().source.js)} )
    .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(gulp.dest(resolvePath(projectConfig.dest.scripts)));
});

// Images copy
gulp.task('pl-copy:img', function(){
  return gulp.src('**/*.*',{cwd: resolvePath(paths().source.images)} )
    .pipe(gulp.dest(resolvePath(projectConfig.dest.images)));
});

// Favicon copy
gulp.task('pl-copy:favicon', function(){
  return gulp.src(paths().source.images + '/favicon.ico')
    .pipe(gulp.dest(resolvePath(projectConfig.dest.root)));
});

// Fonts copy
gulp.task('pl-copy:font', function(){
  return gulp.src('*', {cwd: resolvePath(paths().source.fonts)})
    .pipe(gulp.dest(resolvePath(projectConfig.dest.fonts)));
});

// Styleguide Copy everything but css
gulp.task('pl-copy:styleguide', function(){
  return gulp.src(resolvePath(paths().source.styleguide) + '/**/!(*.css)')
    .pipe(gulp.dest(resolvePath(paths().public.root)))
    .pipe(browserSync.stream());
});

// Styleguide Copy and flatten css
gulp.task('pl-copy:patternlab-css', function(){
  return gulp.src(resolvePath(paths().source.styleguide) + '/**/*.css')
    .pipe(gulp.dest(function(file){
      //flatten anything inside the styleguide into a single output dir per http://stackoverflow.com/a/34317320/1790362
      file.path = path.join(file.base, path.basename(file.path));
      return resolvePath(path.join(paths().public.styleguide, '/css'));
    }))
    .pipe(browserSync.stream());
});

// Styleguide Copy and flatten css
gulp.task('pl-copy:styleguide-css', function(){
  return gulp.src(resolvePath(paths().source.css))
    .pipe(gulp.dest(paths().public.root))
    .pipe(browserSync.stream());
});

/******************************************************
* Generate build HTML pages
******************************************************/

gulp.task('compile-homepage', function(done){
  return gulp.src('./pattern_exports/pages-homepage.html')
    .pipe(rename('index.html'))
    .pipe(gulp.dest(projectConfig.dest.root))
});

gulp.task('compile-html-pages', gulp.series('compile-homepage'));

/******************************************************
* PATTERN LAB CONFIGURATION - API with core library
******************************************************/
function paths() {
  return config.paths;
}

function getConfiguredCleanOption() {
  return config.cleanPublic;
}

function build(done) {
  var hbs = require('./node_modules/patternengine-node-handlebars/lib/engine_handlebars.js');
  var helpers = require('./handlebarsHelpers.js');

  Object.keys(helpers).forEach(function(helperName) {
    hbs.engine.registerHelper(helperName, helpers[helperName]);
  });

  patternlab(config).build(done, getConfiguredCleanOption());
}

gulp.task('sass-generate-contents', function () {
  return gulp.src(projectConfig.itcss)
    .pipe(sgc(projectConfig.src.sass , '', {forceComments: false }))
    .pipe(gulp.dest(projectConfig.src.styles));
});

gulp.task('sass',function () {
  var processors = [
    autoprefixer({
      browsers: 'last 1 version'
    })
  ];

  return gulp.src(projectConfig.src.styles + 'main.scss')
    .pipe(sass())
    .pipe(postcss(processors))
    .pipe(gulp.dest(projectConfig.dest.styles));
});

gulp.task('pl-assets', gulp.series(
  gulp.parallel(
    'pl-copy:js',
    'pl-copy:img',
    'pl-copy:favicon',
    'pl-copy:font',
    'pl-copy:styleguide',
    'pl-copy:styleguide-css',
    'pl-copy:patternlab-css'
  ),
  function(done){
    done();
  })
);

// gulp.task('patternlab:version', function (done) {
//   patternlab.version();
//   done();
// });
//
// gulp.task('patternlab:help', function (done) {
//   patternlab.help();
//   done();
// });
//
// gulp.task('patternlab:patternsonly', function (done) {
//   patternlab.patternsonly(done, getConfiguredCleanOption());
// });
//
// gulp.task('patternlab:liststarterkits', function (done) {
//   patternlab.liststarterkits();
//   done();
// });
//
// gulp.task('patternlab:loadstarterkit', function (done) {
//   patternlab.loadstarterkit(argv.kit, argv.clean);
//   done();
// });
//
// gulp.task('patternlab:installplugin', function (done) {
//   patternlab.installplugin(argv.plugin);
//   done();
// });

gulp.task('patternlab:build', gulp.series('clean', 'sass-generate-contents', 'sass', 'pl-assets', build, 'compile-html-pages', function(done){
  done();
}));

/******************************************************
* SERVER AND WATCH TASKS
******************************************************/

// watch task utility functions
function getSupportedTemplateExtensions() {
  var engines = require('./node_modules/patternlab-node/core/lib/pattern_engines');

  return engines.getSupportedFileExtensions();
}
function getTemplateWatches() {
  return getSupportedTemplateExtensions().map(function (dotExtension) {
    return resolvePath(paths().source.patterns) + '/**/*' + dotExtension;
  });
}

function reload() {
  browserSync.reload();
}

function reloadCSS() {
  browserSync.reload('*.css');
}

function watch() {
  gulp.watch(projectConfig.itcss, { awaitWriteFinish: true })
    .on('change', gulp.series('sass-generate-contents', 'sass', reloadCSS));

  gulp.watch(resolvePath(paths().source.styleguide) + '/**/*.*', { awaitWriteFinish: true })
    .on('change', gulp.series('pl-copy:styleguide', 'pl-copy:styleguide-css', 'pl-copy:patternlab-css', reloadCSS));

  var patternWatches = [
    resolvePath(paths().source.patterns) + '/**/*.json',
    resolvePath(paths().source.patterns) + '/**/*.md',
    resolvePath(paths().source.data) + '/*.json',
    resolvePath(paths().source.js) + '/*',
    resolvePath(paths().source.fonts) + '/*',
    resolvePath(paths().source.images) + '/*',
    resolvePath(paths().source.meta) + '/*',
    resolvePath(paths().source.annotations) + '/*'
  ].concat(getTemplateWatches());

  gulp.watch(patternWatches, { awaitWriteFinish: true }).on('change', gulp.series('patternlab:build', reload));
}

gulp.task('patternlab:connect', gulp.series(function(done) {
  browserSync.init({
    port: 8080,
    server: {
      baseDir: projectConfig.dest.root
    },
    snippetOptions: {
      // Ignore all HTML files within the templates folder
      blacklist: ['/index.html', '/', '/?*']
    },
    notify: {
      styles: [
        'display: none',
        'padding: 15px',
        'font-family: sans-serif',
        'position: fixed',
        'font-size: 1em',
        'z-index: 9999',
        'bottom: 0px',
        'right: 0px',
        'border-top-left-radius: 5px',
        'background-color: #1B2032',
        'opacity: 0.4',
        'margin: 0',
        'color: white',
        'text-align: center'
      ]
    }
  }, function(){
    done();
  });
}));

/******************************************************
* COMPOUND TASKS
******************************************************/
gulp.task('default', gulp.series('patternlab:build'));
gulp.task('patternlab:watch', gulp.series('patternlab:build', watch));
gulp.task('patternlab:serve', gulp.series('patternlab:build', 'patternlab:connect', watch));
<commit_msg>refactor: remove unused gulp code<commit_after>/******************************************************
* PATTERN LAB NODE
* EDITION-NODE-GULP
* The gulp wrapper around patternlab-node core, providing tasks to interact with the core library and move supporting frontend assets.
******************************************************/
var gulp = require('gulp');
var path = require('path');
var browserSync = require('browser-sync').create();
var argv = require('minimist')(process.argv.slice(2));

var projectConfig = require('./project.config.js');

//read all paths from our namespaced config file
var config = require('./patternlab-config');
var patternlab = require('patternlab-node');

var sgc = require('gulp-sass-generate-contents');
var sass  = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var gap = require('gulp-append-prepend');
var rename = require("gulp-rename");

var del = require('del');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

function resolvePath(pathInput) {
  return path.resolve(pathInput).replace(/\\/g,"/");
}

gulp.task('clean', function () {
	return del([
    projectConfig.dest.root,
    config.patternExportDirectory
  ]);
});

/******************************************************
* COPY TASKS - stream assets from source to destination
******************************************************/
// JS copy
gulp.task('pl-copy:js', function(){
  return gulp.src('**/*.js', {cwd: resolvePath(paths().source.js)} )
    .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(gulp.dest(resolvePath(projectConfig.dest.scripts)));
});

// Images copy
gulp.task('pl-copy:img', function(){
  return gulp.src('**/*.*',{cwd: resolvePath(paths().source.images)} )
    .pipe(gulp.dest(resolvePath(projectConfig.dest.images)));
});

// Favicon copy
gulp.task('pl-copy:favicon', function(){
  return gulp.src(paths().source.images + '/favicon.ico')
    .pipe(gulp.dest(resolvePath(projectConfig.dest.root)));
});

// Fonts copy
gulp.task('pl-copy:font', function(){
  return gulp.src('*', {cwd: resolvePath(paths().source.fonts)})
    .pipe(gulp.dest(resolvePath(projectConfig.dest.fonts)));
});

// Styleguide Copy everything but css
gulp.task('pl-copy:styleguide', function(){
  return gulp.src(resolvePath(paths().source.styleguide) + '/**/!(*.css)')
    .pipe(gulp.dest(resolvePath(paths().public.root)))
    .pipe(browserSync.stream());
});

// Styleguide Copy and flatten css
gulp.task('pl-copy:patternlab-css', function(){
  return gulp.src(resolvePath(paths().source.styleguide) + '/**/*.css')
    .pipe(gulp.dest(function(file){
      //flatten anything inside the styleguide into a single output dir per http://stackoverflow.com/a/34317320/1790362
      file.path = path.join(file.base, path.basename(file.path));
      return resolvePath(path.join(paths().public.styleguide, '/css'));
    }))
    .pipe(browserSync.stream());
});

// Styleguide Copy and flatten css
gulp.task('pl-copy:styleguide-css', function(){
  return gulp.src(resolvePath(paths().source.css))
    .pipe(gulp.dest(paths().public.root))
    .pipe(browserSync.stream());
});

/******************************************************
* Generate build HTML pages
******************************************************/

gulp.task('compile-homepage', function(done){
  return gulp.src('./pattern_exports/pages-homepage.html')
    .pipe(rename('index.html'))
    .pipe(gulp.dest(projectConfig.dest.root))
});

gulp.task('compile-html-pages', gulp.series('compile-homepage'));

/******************************************************
* PATTERN LAB CONFIGURATION - API with core library
******************************************************/
function paths() {
  return config.paths;
}

function getConfiguredCleanOption() {
  return config.cleanPublic;
}

function build(done) {
  var hbs = require('./node_modules/patternengine-node-handlebars/lib/engine_handlebars.js');
  var helpers = require('./handlebarsHelpers.js');

  Object.keys(helpers).forEach(function(helperName) {
    hbs.engine.registerHelper(helperName, helpers[helperName]);
  });

  patternlab(config).build(done, getConfiguredCleanOption());
}

gulp.task('sass-generate-contents', function () {
  return gulp.src(projectConfig.itcss)
    .pipe(sgc(projectConfig.src.sass , '', {forceComments: false }))
    .pipe(gulp.dest(projectConfig.src.styles));
});

gulp.task('sass',function () {
  var processors = [
    autoprefixer({
      browsers: 'last 1 version'
    })
  ];

  return gulp.src(projectConfig.src.styles + 'main.scss')
    .pipe(sass())
    .pipe(postcss(processors))
    .pipe(gulp.dest(projectConfig.dest.styles));
});

gulp.task('pl-assets', gulp.series(
  gulp.parallel(
    'pl-copy:js',
    'pl-copy:img',
    'pl-copy:favicon',
    'pl-copy:font',
    'pl-copy:styleguide',
    'pl-copy:styleguide-css',
    'pl-copy:patternlab-css'
  ),
  function(done){
    done();
  })
);

gulp.task('patternlab:build', gulp.series('clean', 'sass-generate-contents', 'sass', 'pl-assets', build, 'compile-html-pages', function(done){
  done();
}));

/******************************************************
* SERVER AND WATCH TASKS
******************************************************/

// watch task utility functions
function getSupportedTemplateExtensions() {
  var engines = require('./node_modules/patternlab-node/core/lib/pattern_engines');

  return engines.getSupportedFileExtensions();
}
function getTemplateWatches() {
  return getSupportedTemplateExtensions().map(function (dotExtension) {
    return resolvePath(paths().source.patterns) + '/**/*' + dotExtension;
  });
}

function reload() {
  browserSync.reload();
}

function reloadCSS() {
  browserSync.reload('*.css');
}

function watch() {
  gulp.watch(projectConfig.itcss, { awaitWriteFinish: true })
    .on('change', gulp.series('sass-generate-contents', 'sass', reloadCSS));

  gulp.watch(resolvePath(paths().source.styleguide) + '/**/*.*', { awaitWriteFinish: true })
    .on('change', gulp.series('pl-copy:styleguide', 'pl-copy:styleguide-css', 'pl-copy:patternlab-css', reloadCSS));

  var patternWatches = [
    resolvePath(paths().source.patterns) + '/**/*.json',
    resolvePath(paths().source.patterns) + '/**/*.md',
    resolvePath(paths().source.data) + '/*.json',
    resolvePath(paths().source.js) + '/*',
    resolvePath(paths().source.fonts) + '/*',
    resolvePath(paths().source.images) + '/*',
    resolvePath(paths().source.meta) + '/*',
    resolvePath(paths().source.annotations) + '/*'
  ].concat(getTemplateWatches());

  gulp.watch(patternWatches, { awaitWriteFinish: true }).on('change', gulp.series('patternlab:build', reload));
}

gulp.task('patternlab:connect', gulp.series(function(done) {
  browserSync.init({
    port: 8080,
    server: {
      baseDir: projectConfig.dest.root
    },
    snippetOptions: {
      // Ignore all HTML files within the templates folder
      blacklist: ['/index.html', '/', '/?*']
    },
    notify: {
      styles: [
        'display: none',
        'padding: 15px',
        'font-family: sans-serif',
        'position: fixed',
        'font-size: 1em',
        'z-index: 9999',
        'bottom: 0px',
        'right: 0px',
        'border-top-left-radius: 5px',
        'background-color: #1B2032',
        'opacity: 0.4',
        'margin: 0',
        'color: white',
        'text-align: center'
      ]
    }
  }, function(){
    done();
  });
}));

/******************************************************
* COMPOUND TASKS
******************************************************/
gulp.task('default', gulp.series('patternlab:build'));
gulp.task('patternlab:watch', gulp.series('patternlab:build', watch));
gulp.task('patternlab:serve', gulp.series('patternlab:build', 'patternlab:connect', watch));
<|endoftext|>


<commit_before>var gulp       = require('gulp');
var fs         = require('fs');
var sourcemaps = require('gulp-sourcemaps');
var babel      = require('gulp-babel');
var eslint     = require('gulp-eslint');
var jscs       = require('gulp-jscs');

gulp.task('build-npm', [ 'setupNpm', 'babel', 'lint' ]);

// -----------------------------------------------------------------------------
// setup for development use
gulp.task('setupDev', () => {
  getDevPluginXML();
  setIosNpmOrDev('dev');
})

// setup for npm deployment
gulp.task('setupNpm', () => {
  genNpmPluginXML();
  setIosNpmOrDev('npm');
});

// generate plugin.xml for use as a cordova plugin
// here we explode the contents of the frameworks
function genNpmPluginXML() {
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

  var files = [];
  var root = 'src/ios/dependencies/';
  files = files.concat(emitFiles(root + 'Fabric/'));
  files = files.concat(emitFiles(root + 'Branch-SDK/'));
  files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));

  var newLineIndent = '\n        ';
  xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent
    + files.join(newLineIndent));

  fs.writeFileSync('plugin.xml', xml);
};

// generate plugin.xml for local development
// here we reference the frameworks instead of all the files directly
function getDevPluginXML() {
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

  xml = xml.replace('<!--[Branch Framework Reference]-->',
    '<framework custom="true" src="src/ios/dependencies/Branch.framework" />');

  fs.writeFileSync('plugin.xml', xml);
};

function setIosNpmOrDev(npmOrDev) {
  if (npmOrDev === 'npm') {
    content = '#define BRANCH_NPM true';
  }
else if (npmOrDev === 'dev') {
    content = '//empty';
  }
else {
    throw new Error('expected deployed|local, not ' + deployedOrLocal);
  }
  fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
}

// emit array of cordova file references for all .h/.m files in path
function emitFiles(path) {
  var ret = [];
  for (filename of fs.readdirSync(path)) {
    var fileType = null;
    if (filename.match(/\.m$/)) {
      fileType = 'source';
    }
else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
      fileType = 'header';
    }
    if (fileType) {
      ret.push('<' + fileType + '-file src="' + path + filename + '" />');
    }
  }
  ret.push('');
  return ret;
}

// -----------------------------------------------------------------------------
// copy resources and compile es6 from corresponding directories
babelTasks = []; // list of all babel tasks so we can build all of them
function babelize(taskName, dir) {
  babelTasks.push(taskName + '-babel');
  if (!dir) {
    dir = taskName;
  }
  var srcDir = dir + '.es6/';
  var srcPattern = dir + '.es6/**/*.js'
  var destDir = dir + '/';
  gulp.task(taskName + '-copy', () => {
    return gulp.src(srcDir + '**/*.*').pipe(gulp.dest(destDir));
  });
  gulp.task(taskName + '-babel', [ taskName + '-copy' ], () => {
    return gulp.src(srcPattern)
      .pipe(sourcemaps.init())
      .pipe(babel({
        presets: [ 'es2015', 'stage-2' ],
        plugins: [ 'transform-runtime' ] // needed for generators etc
      }))
      .pipe(sourcemaps.write('.'))
      .pipe(gulp.dest(destDir));
  });
}

babelize('hooks');
babelize('www');
babelize('tests');
babelize('testbed', 'testbed/www/js');
gulp.task('babel', babelTasks);

// -----------------------------------------------------------------------------
// linting

gulp.task('lint', [ 'eslint', 'jscs-lint' ]);

var srcs = [
  '**/*.js',
  '!node_modules/**',
  '!testbed/platforms/ios/cordova/node_modules/**'
];

gulp.task('eslint', () => {
  return gulp.src(srcs)
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

function jscsTask(fix) {
  var ret = gulp.src('gulpfile.js')
    .pipe(jscs({ fix: fix }))
    .pipe(jscs.reporter())
    .pipe(jscs.reporter('fail'));

  if (fix) {
    ret.pipe(gulp.dest('.'));
  }
  return ret;
}

gulp.task('jscs-fix', jscsTask.bind(null, true));
gulp.task('jscs-lint', jscsTask.bind(null, false));
<commit_msg>chore(gulpfile): whitespace<commit_after>var gulp       = require('gulp');
var fs         = require('fs');
var sourcemaps = require('gulp-sourcemaps');
var babel      = require('gulp-babel');
var eslint     = require('gulp-eslint');
var jscs       = require('gulp-jscs');

gulp.task('build-npm', [ 'setupNpm', 'babel', 'lint' ]);

// -----------------------------------------------------------------------------
// setup for development use
gulp.task('setupDev', () => {
  getDevPluginXML();
  setIosNpmOrDev('dev');
})

// setup for npm deployment
gulp.task('setupNpm', () => {
  genNpmPluginXML();
  setIosNpmOrDev('npm');
});

// generate plugin.xml for use as a cordova plugin
// here we explode the contents of the frameworks
function genNpmPluginXML() {
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

  var files = [];
  var root = 'src/ios/dependencies/';
  files = files.concat(emitFiles(root + 'Fabric/'));
  files = files.concat(emitFiles(root + 'Branch-SDK/'));
  files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));

  var newLineIndent = '\n        ';
  xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent
    + files.join(newLineIndent));

  fs.writeFileSync('plugin.xml', xml);
};

// generate plugin.xml for local development
// here we reference the frameworks instead of all the files directly
function getDevPluginXML() {
  var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

  xml = xml.replace('<!--[Branch Framework Reference]-->',
    '<framework custom="true" src="src/ios/dependencies/Branch.framework" />');

  fs.writeFileSync('plugin.xml', xml);
};

function setIosNpmOrDev(npmOrDev) {
  if (npmOrDev === 'npm') {
    content = '#define BRANCH_NPM true';
  }
else if (npmOrDev === 'dev') {
    content = '//empty';
  }
else {
    throw new Error('expected deployed|local, not ' + deployedOrLocal);
  }
  fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
}

// emit array of cordova file references for all .h/.m files in path
function emitFiles(path) {
  var ret = [];
  for (filename of fs.readdirSync(path)) {
    var fileType = null;
    if (filename.match(/\.m$/)) {
      fileType = 'source';
    }
else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
      fileType = 'header';
    }
    if (fileType) {
      ret.push('<' + fileType + '-file src="' + path + filename + '" />');
    }
  }
  ret.push('');
  return ret;
}

// -----------------------------------------------------------------------------
// copy resources and compile es6 from corresponding directories
babelTasks = []; // list of all babel tasks so we can build all of them
function babelize(taskName, dir) {
  babelTasks.push(taskName + '-babel');
  if (!dir) {
    dir = taskName;
  }
  var srcDir = dir + '.es6/';
  var srcPattern = dir + '.es6/**/*.js'
  var destDir = dir + '/';
  gulp.task(taskName + '-copy', () => {
    return gulp.src(srcDir + '**/*.*').pipe(gulp.dest(destDir));
  });
  gulp.task(taskName + '-babel', [ taskName + '-copy' ], () => {
    return gulp.src(srcPattern)
      .pipe(sourcemaps.init())
      .pipe(babel({
        presets: [ 'es2015', 'stage-2' ],
        plugins: [ 'transform-runtime' ] // needed for generators etc
      }))
      .pipe(sourcemaps.write('.'))
      .pipe(gulp.dest(destDir));
  });
}

babelize('hooks');
babelize('www');
babelize('tests');
babelize('testbed', 'testbed/www/js');
gulp.task('babel', babelTasks);

// -----------------------------------------------------------------------------
// linting

gulp.task('lint', [ 'eslint', 'jscs-lint' ]);

var srcs = [
  '**/*.js',
  '!node_modules/**',
  '!testbed/platforms/ios/cordova/node_modules/**'
];

gulp.task('eslint', () => {
  return gulp.src(srcs)
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

function jscsTask(fix) {
  var ret = gulp.src('gulpfile.js')
    .pipe(jscs({ fix: fix }))
    .pipe(jscs.reporter())
    .pipe(jscs.reporter('fail'));

  if (fix) {
    ret.pipe(gulp.dest('.'));
  }
  return ret;
}

gulp.task('jscs-fix', jscsTask.bind(null, true));
gulp.task('jscs-lint', jscsTask.bind(null, false));<|endoftext|>


<commit_before>"use strict";

// Gulp
var gulp = require('gulp');

// Plugins
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var prefix = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var livereload = require('gulp-livereload');
var nodemon = require('gulp-nodemon');
var path = require('path');
var tinylr = require('tiny-lr');
var WritableStream = require('stream').Writable;
var svgSprites = require('gulp-svg-sprites');
var svg = svgSprites.svg;
var png = svgSprites.png;

var outputDir = 'website/dist';

// Paths
var paths = {
  scripts: ['assets/js/*.js'],
  images: ['assets/img/**'],
  icons: ['assets/icons/*.svg']
};

// Compile Sass
gulp.task('sass', function () {
  return gulp.src(['assets/scss/*.scss', '!assets/scss/_variables.scss'])
    .pipe(plumber())
    .pipe(sass({
      sourceComments: 'map'
    }))
    .pipe(prefix(
      "last 1 version", "> 1%", "ie 8", "ie 7"
    ))
    .pipe(gulp.dest(outputDir + '/assets/css'))
    .pipe(minifycss())
    .pipe(gulp.dest(outputDir + '/assets/css'))
});

// Uglify JS
gulp.task('uglify', function () {
  return gulp.src(paths.scripts)
    .pipe(plumber())
    .pipe(uglify({
      outSourceMap: false
    }))
    .pipe(gulp.dest(outputDir + '/assets/js'))
});

// Copy images.
gulp.task('copyimages', function () {
  return gulp.src(paths.images)
    .pipe(gulp.dest(outputDir + '/assets/img'));
});

gulp.task('sprites', function () {
  return gulp.src(paths.icons)
    .pipe(svg({
      className: ".%f-icon",
      cssFile: "_sprites.scss"
    }))
    .pipe(gulp.dest('assets/scss'))
    .pipe(png())
});

// Watch files
gulp.task('watch', function (event) {
  gulp.watch('assets/scss/*.scss', ['sass']);
  gulp.watch(paths.images, ['copyimages']);
  gulp.watch(paths.icons, ['sprites']);
  gulp.watch(paths.scripts, ['uglify']);
});

gulp.task('server', ['watch'], function (cb) {
  var productConfig = require('./development-config.json');

  if (productConfig['port'] === -1) {
      console.log('You need to have a product config defined');
      process.exit(-1);
  }

  nodemon({
    script: 'server.js',
    env: productConfig
  })
    .on('restart', function () {
      console.log('restarted node');
    });
});

gulp.task('azure-exit', ['build'], function (cb) {
	process.exit(0);
	cb(err);
});

gulp.task('build', ['sass', 'uglify', 'copyimages']);
gulp.task('azure', ['azure-exit']);
gulp.task('default', ['sprites', 'build', 'watch', 'server']); //there is a race condition here so it will probably fail the first time<commit_msg>Fix up deps<commit_after>"use strict";

// Gulp
var gulp = require('gulp');

// Plugins
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var prefix = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var livereload = require('gulp-livereload');
var nodemon = require('gulp-nodemon');
var path = require('path');
var tinylr = require('tiny-lr');
var WritableStream = require('stream').Writable;
var svgSprites = require('gulp-svg-sprites');
var svg = svgSprites.svg;
var png = svgSprites.png;

var outputDir = 'website/dist';

// Paths
var paths = {
  scripts: ['assets/js/*.js'],
  images: ['assets/img/**'],
  icons: ['assets/icons/*.svg']
};

// Compile Sass
gulp.task('sass', function () {
  return gulp.src(['assets/scss/*.scss', '!assets/scss/_variables.scss'])
    .pipe(plumber())
    .pipe(sass({
      sourceComments: 'map'
    }))
    .pipe(prefix(
      "last 1 version", "> 1%", "ie 8", "ie 7"
    ))
    .pipe(gulp.dest(outputDir + '/assets/css'))
    .pipe(minifycss())
    .pipe(gulp.dest(outputDir + '/assets/css'))
});

// Uglify JS
gulp.task('uglify', function () {
  return gulp.src(paths.scripts)
    .pipe(plumber())
    .pipe(uglify({
      outSourceMap: false
    }))
    .pipe(gulp.dest(outputDir + '/assets/js'))
});

// Copy images.
gulp.task('copyimages', function () {
  return gulp.src(paths.images)
    .pipe(gulp.dest(outputDir + '/assets/img'));
});

gulp.task('sprites', function () {
  return gulp.src(paths.icons)
    .pipe(svg({
      className: ".%f-icon",
      cssFile: "_sprites.scss"
    }))
    .pipe(gulp.dest('assets/scss'))
    .pipe(png())
});

// Watch files
gulp.task('watch', function (event) {
  gulp.watch('assets/scss/*.scss', ['sass']);
  gulp.watch(paths.images, ['copyimages']);
  gulp.watch(paths.icons, ['sprites']);
  gulp.watch(paths.scripts, ['uglify']);
});

gulp.task('server', ['build'], function (cb) {
  var productConfig = require('./development-config.json');

  if (productConfig['port'] === -1) {
      console.log('You need to have a product config defined');
      process.exit(-1);
  }

  nodemon({
    script: 'server.js',
    env: productConfig
  })
    .on('restart', function () {
      console.log('restarted node');
    });
});

gulp.task('azure-exit', ['build'], function (cb) {
	process.exit(0);
	cb(err);
});

gulp.task('build', ['sass', 'uglify', 'copyimages']);
gulp.task('azure', ['azure-exit']);
gulp.task('default', ['sprites', 'server', 'watch']); //there is a race condition here so it will probably fail the first time<|endoftext|>


<commit_before>var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
var del = require('del');
var uglify = require('gulp-uglify');
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = ['/**',
    ' * <%= pkg.name %> - <%= pkg.description %>',
    ' * @version v<%= pkg.version %>',
    ' * @link <%= pkg.homepage %>',
    ' * @license <%= pkg.license %>',
    ' */',
    ''].join('\n');

// Develop build
// ============================================================================
gulp.task('js', function () {
    gulp.src([
            'src/js/elasticslider.js',
        ])
        .pipe(sourcemaps.init())
        .pipe(babel())
        .pipe(concat('elasticslider.min.js'))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('src/js/'));
});

gulp.task('watch', function () {
    gulp.watch('src/elasticslider.js', ['js']);
});

// Dist build
// ============================================================================
gulp.task('clean', function (cb) {
    return del(['dist'], cb);
});

gulp.task('build', ['clean'], function () {
    return gulp.src('src/elasticslider.js')
        .pipe(concat('elasticslider.min.js'))
        .pipe(babel())
        .pipe(uglify())
        .pipe(header(banner, { pkg : pkg } ))
        .pipe(gulp.dest('dist'))
});

// Tasks
// ============================================================================
gulp.task('serve', ['js', 'watch']);
gulp.task('default', ['build']);
<commit_msg>Rename tasks<commit_after>var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
var del = require('del');
var uglify = require('gulp-uglify');
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = ['/**',
    ' * <%= pkg.name %> - <%= pkg.description %>',
    ' * @version v<%= pkg.version %>',
    ' * @link <%= pkg.homepage %>',
    ' * @license <%= pkg.license %>',
    ' */',
    ''].join('\n');

// Develop build
// ============================================================================
gulp.task('js', function () {
    gulp.src([
            'src/js/elasticslider.js',
        ])
        .pipe(sourcemaps.init())
        .pipe(babel())
        .pipe(concat('elasticslider.min.js'))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('src/js/'));
});

gulp.task('watch', function () {
    gulp.watch('src/elasticslider.js', ['js']);
});

// Dist build
// ============================================================================
gulp.task('dist:clean', function (cb) {
    return del(['dist'], cb);
});

gulp.task('dist:build', ['dist:clean'], function () {
    return gulp.src('src/elasticslider.js')
        .pipe(concat('elasticslider.min.js'))
        .pipe(babel())
        .pipe(uglify())
        .pipe(header(banner, { pkg : pkg } ))
        .pipe(gulp.dest('dist'))
});

// Tasks
// ============================================================================
gulp.task('serve', ['js', 'watch']);
gulp.task('default', ['dist:build']);
<|endoftext|>


<commit_before>var gulp = require('gulp');

var concat = require('gulp-concat');
var stylish = require('jshint-stylish');
var jshint = require('gulp-jshint');
var clean = require('gulp-clean');
var cache = require('gulp-cached');
var runSequence = require('run-sequence');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var _ = require('lodash-node');
var browserSync = require('browser-sync');

var paths = {
  scripts: ['app/scripts/**/*.js'],
  appScripts: ['app/scripts/**/*.js', '!app/scripts/**/*.spec.js', '!app/scripts/inject/inject.js'],
  images: 'app/images/**/*',
  html: 'app/**/*.html',
  styles: {
    sass: 'app/styles/**/*.scss',
    css: 'app/styles/*.css'
  },
  notLinted: ['!app/scripts/templates.js']
};

var options = {
  errorHandler: function(title) {
    return function(err) {
      gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
      this.emit('end');
    };
  },
  paths: paths
};

require('./gulp/release-tasks');
// require('./gulp/versioning');

require('./gulp/styles')(options);
require('./gulp/inject')(options);
require('./gulp/server')(options);
require('./gulp/unit-tests')(options);
require('./gulp/changelog')(options);
require('./gulp/unit-tests')(options);

/**
 * Development tasks
 */
var developTasks = ['preprocess', 'watch', 'serve', 'test'];
gulp.task('develop', developTasks);

gulp.task('no-karma', function() {
  _.remove(developTasks, 'karma');
  gulp.start('develop');
});

gulp.task('scripts', ['preprocess', 'lint']);

gulp.task('preprocess', ['inject', 'sass']);

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

gulp.task('lint', function() {
  return gulp.src(paths.scripts.concat(paths.notLinted))
    .pipe(cache('lint'))
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('jshint-stylish'));
});

// Rerun the task when a file changes
gulp.task('watch', function() {

  gulp.watch(paths.styles.sass, ['sass']);

  gulp.watch(paths.scripts).on('change', browserSync.reload);
  gulp.watch(paths.html).on('change', browserSync.reload);

  gulp.watch(paths.appScripts, function(event) {
    if (event.type === 'added' || event.type === 'deleted') {
      gulp.start('inject');
    }
  });
});
<commit_msg>run karma test with watchers<commit_after>var gulp = require('gulp');

var concat = require('gulp-concat');
var stylish = require('jshint-stylish');
var jshint = require('gulp-jshint');
var clean = require('gulp-clean');
var cache = require('gulp-cached');
var runSequence = require('run-sequence');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var _ = require('lodash-node');
var browserSync = require('browser-sync');

var paths = {
  scripts: ['app/scripts/**/*.js'],
  appScripts: ['app/scripts/**/*.js', '!app/scripts/**/*.spec.js', '!app/scripts/inject/inject.js'],
  images: 'app/images/**/*',
  html: 'app/**/*.html',
  styles: {
    sass: 'app/styles/**/*.scss',
    css: 'app/styles/*.css'
  },
  notLinted: ['!app/scripts/templates.js']
};

var options = {
  errorHandler: function(title) {
    return function(err) {
      gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
      this.emit('end');
    };
  },
  paths: paths
};

require('./gulp/release-tasks');
// require('./gulp/versioning');

require('./gulp/styles')(options);
require('./gulp/inject')(options);
require('./gulp/server')(options);
require('./gulp/unit-tests')(options);
require('./gulp/changelog')(options);
require('./gulp/unit-tests')(options);

/**
 * Development tasks
 */
var developTasks = ['preprocess', 'watch', 'serve', 'test:auto'];
gulp.task('develop', developTasks);

gulp.task('no-karma', function() {
  _.remove(developTasks, 'karma');
  gulp.start('develop');
});

gulp.task('scripts', ['preprocess', 'lint']);

gulp.task('preprocess', ['inject', 'sass']);

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

gulp.task('lint', function() {
  return gulp.src(paths.scripts.concat(paths.notLinted))
    .pipe(cache('lint'))
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('jshint-stylish'));
});

// Rerun the task when a file changes
gulp.task('watch', function() {

  gulp.watch(paths.styles.sass, ['sass']);

  gulp.watch(paths.scripts).on('change', browserSync.reload);
  gulp.watch(paths.html).on('change', browserSync.reload);

  gulp.watch(paths.appScripts, function(event) {
    if (event.type === 'added' || event.type === 'deleted') {
      gulp.start('inject');
    }
  });
});
<|endoftext|>


<commit_before>var autoprefixer = require('gulp-autoprefixer');
var debug = require('gulp-debug');
var del = require('del');
var es = require('event-stream');
var exec = require('child_process').exec;
var favicons = require('gulp-favicons');
var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var minifyJS = require('gulp-minify');
var minifyCSS = require('gulp-clean-css');
var minifyHTML = require('gulp-htmlmin');
var sass = require('gulp-sass');
var symlink = require('gulp-sym');
var twig = require('gulp-twig');
var vulcanize = require('gulp-vulcanize');

var abspath = '';
var data = {};

// remove dist directory
gulp.task('clean', function(cb) {
  return del('dist');
});

gulp.task('data', function(cb) {
  exec('php app/index.php', function (err, stdout, stderr) {
    data = JSON.parse(fs.readFileSync('./data.json'));
    cb(err);
  });
});

gulp.task('favicons', ['data'], function() {
  gulp.src("graphics/ni4ce-stream.png").pipe(favicons({
    appName: "My App",
    appDescription: data.site.description,
    developerName: data.site.title,
    developerURL: data.site.url,
    background: "#020307",
    path: "favicons/",
    url: data.site.url,
    display: "standalone",
    orientation: "portrait",
    version: 1.0,
    logging: false,
    online: false,
    html: "index.html",
    pipeHTML: true,
    replace: true,
  })).pipe(gulp.dest("static/favicons"));
});

// twig rendering
gulp.task('site', ['data'], function() {
  'use strict';
  data.abspath = abspath;
  return gulp.src('site/pages/**/*.twig')
    .pipe(twig({
      errorLogToConsole: true,
      base: 'site',
      data: data,
    }))
    .pipe(gulp.dest('dist'));
});

// styles
gulp.task('styles', function(cb) {
  return gulp.src('styles/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false,
    }))
    .pipe(gulp.dest('dist/styles/'));
});

// scripts
gulp.task('scripts', function(cb) {
  return gulp.src('scripts/**/*.js')
    .pipe(gulp.dest('dist/scripts/'));
});

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

// minimize
gulp.task('minimize', ['default'], function(cb) {
  return es.merge([
    gulp.src('dist/styles/**')
      .pipe(minifyCSS())
      .pipe(gulp.dest('dist/styles')),
    gulp.src('dist/scripts/**')
      .pipe(minifyJS({
        ext: {
          min: '.js',
        },
        noSource: true,
      }))
      .pipe(gulp.dest('dist/scripts')),
    gulp.src('dist/**/*.html')
      .pipe(minifyHTML({
        collapseWhitespace: true,
      }))
      .pipe(gulp.dest('dist')),
  ]);
});

// vulcanize
gulp.task('vulcanize', ['minimize'], function() {
  return gulp.src(['dist/**/*.html', '!dist/components'])
    .pipe(vulcanize({
      abspath: '',
      inlineCss: true,
      inlineScripts: true,
    }))
    .pipe(gulp.dest('dist'));
});

// clean dist
gulp.task('clean_dist', ['vulcanize'], function () {
  del('dist/styles');
  del('dist/scripts');
});

gulp.task('dist', function() {
  abspath = __dirname + '/dist';
  gulp.start('clean_dist');
});

// dist
// gulp.task('dist', ['clean_dist']);

// // symlinks
// gulp.task('symlinks', ['minify'], function (cb) {
//   return gulp.src(['bower_components', 'wl/static', 'creatives'])
//     .pipe(symlink(['dist/components', 'dist/static/wl', 'dist/creatives']));
// })

gulp.task('default', ['static', 'styles', 'scripts', 'site',]);

gulp.task('watch', ['default'], function() {
  gulp.watch('styles/**/*.scss', ['styles']);
  gulp.watch('scripts/**/*.js', ['scripts']);
  gulp.watch(['views/**/*.twig', 'site', 'public'], ['site']);
});

<commit_msg>manifest app<commit_after>var autoprefixer = require('gulp-autoprefixer');
var debug = require('gulp-debug');
var del = require('del');
var es = require('event-stream');
var exec = require('child_process').exec;
var favicons = require('gulp-favicons');
var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var minifyJS = require('gulp-minify');
var minifyCSS = require('gulp-clean-css');
var minifyHTML = require('gulp-htmlmin');
var sass = require('gulp-sass');
var symlink = require('gulp-sym');
var twig = require('gulp-twig');
var vulcanize = require('gulp-vulcanize');

var abspath = '';
var data = {};

// remove dist directory
gulp.task('clean', function(cb) {
  return del('dist');
});

gulp.task('data', function(cb) {
  exec('php app/index.php', function (err, stdout, stderr) {
    data = JSON.parse(fs.readFileSync('./data.json'));
    cb(err);
  });
});

gulp.task('favicons', ['data'], function() {
  gulp.src("graphics/ni4ce-stream.png").pipe(favicons({
    appName: data.site.title,
    appDescription: data.site.description,
    developerName: data.site.author,
    developerURL: data.site.url,
    background: "#020307",
    path: "favicons/",
    url: data.site.url,
    display: "standalone",
    orientation: "portrait",
    version: 1.0,
    logging: false,
    online: false,
    html: "index.html",
    pipeHTML: true,
    replace: true,
  })).pipe(gulp.dest("static/favicons"));
});

// twig rendering
gulp.task('site', ['data'], function() {
  'use strict';
  data.abspath = abspath;
  return gulp.src('site/pages/**/*.twig')
    .pipe(twig({
      errorLogToConsole: true,
      base: 'site',
      data: data,
    }))
    .pipe(gulp.dest('dist'));
});

// styles
gulp.task('styles', function(cb) {
  return gulp.src('styles/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false,
    }))
    .pipe(gulp.dest('dist/styles/'));
});

// scripts
gulp.task('scripts', function(cb) {
  return gulp.src('scripts/**/*.js')
    .pipe(gulp.dest('dist/scripts/'));
});

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

// minimize
gulp.task('minimize', ['default'], function(cb) {
  return es.merge([
    gulp.src('dist/styles/**')
      .pipe(minifyCSS())
      .pipe(gulp.dest('dist/styles')),
    gulp.src('dist/scripts/**')
      .pipe(minifyJS({
        ext: {
          min: '.js',
        },
        noSource: true,
      }))
      .pipe(gulp.dest('dist/scripts')),
    gulp.src('dist/**/*.html')
      .pipe(minifyHTML({
        collapseWhitespace: true,
      }))
      .pipe(gulp.dest('dist')),
  ]);
});

// vulcanize
gulp.task('vulcanize', ['minimize'], function() {
  return gulp.src(['dist/**/*.html', '!dist/components'])
    .pipe(vulcanize({
      abspath: '',
      inlineCss: true,
      inlineScripts: true,
    }))
    .pipe(gulp.dest('dist'));
});

// clean dist
gulp.task('clean_dist', ['vulcanize'], function () {
  del('dist/styles');
  del('dist/scripts');
});

gulp.task('dist', function() {
  abspath = __dirname + '/dist';
  gulp.start('clean_dist');
});

// dist
// gulp.task('dist', ['clean_dist']);

// // symlinks
// gulp.task('symlinks', ['minify'], function (cb) {
//   return gulp.src(['bower_components', 'wl/static', 'creatives'])
//     .pipe(symlink(['dist/components', 'dist/static/wl', 'dist/creatives']));
// })

gulp.task('default', ['static', 'styles', 'scripts', 'site',]);

gulp.task('watch', ['default'], function() {
  gulp.watch('styles/**/*.scss', ['styles']);
  gulp.watch('scripts/**/*.js', ['scripts']);
  gulp.watch(['views/**/*.twig', 'site', 'public'], ['site']);
});

<|endoftext|>


<commit_before>(function() {
    'use strict';

    var gulp = require('gulp'),
        rename = require('gulp-rename'),
        eslint = require('gulp-eslint'),
        uglify = require('gulp-uglify'),
        karma = require('gulp-karma'),
        concat = require('gulp-concat-util'),
        project = require('./package.json');

    // project paths
    var paths = {
        src: './src/' + project.name + '.js',
        spec: './test/' + project.name + '.spec.js',
        output: './dist'
    }

    // banner with project info
    var banner = '/*' +
        '\n * ' + project.title + ' - v' + project.version +
        '\n * ' + project.url +
        '\n * ' + project.copyright + ' (c) ' + project.author + ' - ' + project.license + ' License' +
        '\n*/\n\n';

    // tasks
    gulp.task('hint:src', function() {
        return gulp.src(paths.src)
            .pipe(eslint())
            // outputs the lint results to the console.
            .pipe(eslint.format())
            // To have the process exit with an error code (1) on
            // lint error, return the stream and pipe to failOnError last.
            .pipe(eslint.failOnError());
    });

    gulp.task('hint:spec', function() {
        return gulp.src(paths.spec)
            .pipe(eslint())
            // outputs the lint results to the console.
            .pipe(eslint.format())
            // To have the process exit with an error code (1) on
            // lint error, return the stream and pipe to failOnError last.
            .pipe(eslint.failOnError());
    });

    gulp.task('hint', [ 'hint:src', 'hint:spec' ]);

    gulp.task('test', [ 'hint' ], function() {
        return gulp.src([ paths.spec, paths.src ])
            .pipe(karma({configFile: 'test/karma.conf.js'}));
    });

    gulp.task('build', [ 'test' ], function () {
        return gulp.src(paths.src)
            .pipe(concat.header(banner))
            .pipe(gulp.dest(paths.output))
            .pipe(uglify())
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(paths.output));
    });

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

})();<commit_msg>Update Karma server start call<commit_after>(function() {
    'use strict';

    /*
     * aliasses
     * gulp: gulp streaming build system
     * $: namespace for gulp plugins
     */
    var gulp = require('gulp'),
        $ = require('gulp-load-plugins')(),
        // project information
        project = require('./package.json'),
        // karma test server
        karmaServer = require('karma').Server;

    /*
     * gulp plugins available
     *
     * $.rename: gulp-rename
     * $.uglify: gulp-uglify
     * $.karma: gulp-karma
     * $.concatUtil: gulp-concat-util
     * $.eslint: gulp-eslint
     */

    /*
     * project paths
     */
    var paths = {
        src: './src/' + project.name + '.js',
        spec: './test/' + project.name + '.spec.js',
        output: './dist'
    }

    /*
     * project banner for dist version
     */
    var banner = '/*' +
        '\n * ' + project.title + ' - v' + project.version +
        '\n * ' + project.url +
        '\n * ' + project.copyright + ' (c) ' + project.author + ' - ' + project.license + ' License' +
        '\n*/\n\n';

    /*
     * checks syntax in source files
     *
     * gulp lint:src
     */
    gulp.task('lint:src', function() {
        return gulp.src(paths.src)
            .pipe($.eslint())
            .pipe($.eslint.format())
            .pipe($.eslint.failAfterError());
    });

    /*
     * checks syntax in test files
     *
     * gulp lint:src
     */
    gulp.task('lint:spec', function() {
        return gulp.src(paths.spec)
            .pipe($.eslint())
            .pipe($.eslint.format())
            .pipe($.eslint.failAfterError());
    });

    /*
     * groups lint tasks
     *
     * gulp lint
     */
    gulp.task('lint', [ 'lint:src', 'lint:spec' ]);

    /*
     * checks general syntax and run tests on source files
     *
     * gulp test
     */
    gulp.task('test', [ 'lint' ], function(done) {
        var server = new karmaServer({
            configFile: __dirname + '/test/karma.conf.js',
            singleRun: true
        }, done);

        return server.start();
    });

    /*
     * run tests and creates distribution files
     *
     * gulp build
     */
    gulp.task('build', [ 'test' ], function () {
        return gulp.src(paths.src)
            .pipe($.concatUtil.header(banner))
            .pipe(gulp.dest(paths.output))
            .pipe($.uglify())
            .pipe($.rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest(paths.output));
    });

    /*
     * default task */
    gulp.task('default', [ 'build' ]);

})();<|endoftext|>


<commit_before>'use strict';

const _ = require('lodash');
const gulp = require('gulp');
const babel = require('gulp-babel');
const clean = require('gulp-clean');
const less = require('gulp-less');
const cssmin = require('gulp-cssmin');
const concat = require('gulp-concat');
const packager = require('electron-packager');
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const replace = require('gulp-replace');

const grunt = require('gulp-grunt');

const paths = {
  internalScripts: ['src/**/*.js'],
  externalScripts: ['node_modules/gmusic.js/dist/gmusic.min.js',
                    'node_modules/gmusic-theme.js/dist/gmusic-theme.min.js',
                    'node_modules/gmusic-mini-player.js/dist/gmusic-mini-player.min.js'],
  utilityScripts: ['node_modules/jquery/dist/jquery.min.js',
                    'node_modules/materialize-css/dist/js/materialize.min.js',
                    'node_modules/materialize-css/extras/noUiSlider/nouislider.min.js'],
  html: 'src/public_html/**/*.html',
  less: 'src/assets/less/**/*.less',
  fonts: ['node_modules/materialize-css/dist/font/**/*',
          '!node_modules/materialize-css/dist/font/material-design-icons/*',
          'node_modules/material-design-icons-iconfont/dist/fonts/**/*'],
  images: ['src/assets/icons/**/*', 'src/assets/img/**/*'],
};

const packageJSON = require('./package.json');
let version = packageJSON.dependencies['electron-prebuilt'];
if (version.substr(0, 1) !== '0') {
  version = version.substr(1);
}

const defaultPackageConf = {
  dir: '.',
  name: packageJSON.productName,
  'build-version': packageJSON.version,
  version,
  platform: 'all',
  arch: 'all',
  'app-bundle-id': packageJSON.name,
  'app-version': packageJSON.version,
  icon: './build/assets/img/main',
  out: './dist/',
  overwrite: true,
  prune: true,
  ignore: /(?!node_modules).*\/(vendor|dist|sig|docs|src|.cert.pfx|.eslintignore|.eslintrc|.gitignore|.travis.yml|appveyor.yml|circle.yml|Gruntfile.js|gulpfile.js|ISSUE_TEMPLATE.md|LICENSE|MR_CHANGELOG.html|README.md)(\/|$)/g, // eslint-disable-line
  'version-string': {
    CompanyName: 'Samuel Attard',
    LegalCopyright: 'Copyright © 2016 Samuel Attard, All rights reserved.',
    FileDescription: 'Google Play Music Desktop Player by Samuel Attard',
    ProductName: 'Google Play Music Desktop Player',
    InternalName: 'Google Play Music Desktop Player',
  },
};

const cleanGlob = (glob) => {
  return () => {
    return gulp.src(glob, { read: false })
      .pipe(clean({ force: true }));
  };
};

gulp.task('clean', cleanGlob(['./build', './dist']));
gulp.task('clean-dist-win', cleanGlob(`./dist/${packageJSON.productName}-win32-ia32`));
gulp.task('clean-dist-darwin', cleanGlob(`./dist/${packageJSON.productName}-darwin-ia32`));
gulp.task('clean-dist-linux', cleanGlob([
  `./dist/${packageJSON.productName}-linux-ia32`,
  `./dist/${packageJSON.productName}-linux-x64`,
]));
gulp.task('clean-external', cleanGlob('./build/external.js'));
gulp.task('clean-material', cleanGlob('./build/assets/material'));
gulp.task('clean-utility', cleanGlob('./build/assets/util'));
gulp.task('clean-html', cleanGlob('./build/public_html'));
gulp.task('clean-internal', cleanGlob(['./build/*.js', './build/**/*.js', '!./build/assets/**/*']));
gulp.task('clean-fonts', cleanGlob('./build/assets/font'));
gulp.task('clean-less', cleanGlob('./build/assets/css'));
gulp.task('clean-images', cleanGlob('./build/assets/img'));

gulp.task('external', ['clean-external'], () => {
  return gulp.src(paths.externalScripts)
    .pipe(concat('external.js'))
    .pipe(gulp.dest('./build/assets'));
});

gulp.task('materialize-js', ['clean-material'], () => {
  return gulp.src('node_modules/materialize-css/dist/js/materialize.min.js')
    .pipe(gulp.dest('./build/assets/material'));
});

gulp.task('utility-js', ['clean-utility'], () => {
  return gulp.src(paths.utilityScripts)
    .pipe(gulp.dest('./build/assets/util'));
});

gulp.task('html', ['clean-html'], () => {
  return gulp.src(paths.html)
    .pipe(gulp.dest('./build/public_html'));
});

gulp.task('transpile', ['clean-internal'], () => {
  gulp.src(paths.internalScripts)
    .pipe(babel({
      presets: ['es2015'],
    }))
    .on('error', (err) => { console.error(err); }) // eslint-disable-line
    .pipe(replace(/process\.env\.(.+)\;/gi, (envCall, envKey) => {
      return `'${process.env[envKey]}'`;
    }))
    .pipe(gulp.dest('./build/'));
});

gulp.task('fonts', ['clean-fonts'], () => {
  return gulp.src(paths.fonts)
    .pipe(gulp.dest('./build/assets/font'));
});

gulp.task('less', ['clean-less'], () => {
  gulp.src(paths.less)
    .pipe(less())
    .on('error', (err) => { console.error(err); }) // eslint-disable-line
    .pipe(cssmin())
    .pipe(concat('core.css'))
    .pipe(gulp.dest('./build/assets/css'));
});

// Copy all static images
gulp.task('images', ['clean-images'], () => {
  return gulp.src(paths.images)
    .pipe(gulp.dest('./build/assets/img/'));
});

// Rerun the task when a file changes
gulp.task('watch', ['build'], () => {
  gulp.watch(paths.internalScripts, ['transpile']);
  gulp.watch(paths.html, ['html']);
  gulp.watch(paths.images, ['images']);
  gulp.watch(paths.less, ['less']);
});

gulp.task('package:win', ['clean-dist-win', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'win32', arch: 'ia32' }), () => {
    setTimeout(() => {
      exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha1 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/${packageJSON.productName}-win32-ia32/${packageJSON.productName}.exe"`, {}, () => {
        exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha256 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/${packageJSON.productName}-win32-ia32/${packageJSON.productName}.exe"`, {}, () => {
          done();
        });
      });
    }, 1000);
  });
});

gulp.task('make:win', ['package:win'], (done) => {
  grunt.tasks()['grunt-build:win32'](() => {
    exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha1 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/win32/${packageJSON.productName}Setup.exe"`, {}, () => {
      exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha256 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/win32/${packageJSON.productName}Setup.exe"`, {}, () => {
        done();
      });
    });
  });
});

gulp.task('package:darwin', ['clean-dist-darwin', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'darwin', sign: 'Developer ID Application: Samuel Attard (S7WPQ45ZU2)' }), done); // eslint-disable-line
});

gulp.task('make:darwin', ['package:darwin'], (done) => {
  const pathEscapedName = packageJSON.productName.replace(/ /gi, '\ ');
  const child = spawn('zip', ['-r', '-y',
    `${pathEscapedName}.zip`,
    `${pathEscapedName}.app`],
    {
      cwd: `./dist/${packageJSON.productName}-darwin-x64`,
    });

  console.log(`Zipping "${packageJSON.productName}.app"`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('package:linux', ['clean-dist-linux', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'linux' }), done);
});

gulp.task('deb:linux', ['package:linux'], (done) => {
  const debian = require('electron-installer-debian');

  const defaults = {
    bin: packageJSON.productName,
    dest: 'dist/installers/debian',
    depends: ['libappindicator1'],
    maintainer: 'Samuel Attard <samuel.r.attard@gmail.com>',
    homepage: 'http://www.googleplaymusicdesktopplayer.com',
    icon: 'build/assets/img/main.png',
  };

  debian(_.extend({}, defaults, {
    src: `dist/${packageJSON.productName}-linux-ia32`,
    arch: 'i386',
  }), (err) => {
    console.log('32bit deb package built');
    if (err) return done(err);

    debian(_.extend({}, defaults, {
      src: `dist/${packageJSON.productName}-linux-x64`,
      arch: 'amd64',
    }), (err2) => {
      console.log('64bit deb package built');
      if (err2) return done(err2);
      done();
    });
  });
});

gulp.task('rpm:linux', ['package:linux'], (done) => {
  const redhat = require('electron-installer-redhat');

  const defaults = {
    bin: packageJSON.productName,
    dest: 'dist/installers/fedora',
    depends: ['libappindicator1'],
    maintainer: 'Samuel Attard <samuel.r.attard@gmail.com>',
    homepage: 'http://www.googleplaymusicdesktopplayer.com',
    icon: 'build/assets/img/main.png',
  };

  redhat(_.extend({}, defaults, {
    src: `dist/${packageJSON.productName}-linux-ia32`,
    arch: 'i386',
  }), (err) => {
    console.log('32bit rpm package built');
    if (err) return done(err);

    redhat(_.extend({}, defaults, {
      src: `dist/${packageJSON.productName}-linux-x64`,
      arch: 'amd64',
    }), (err2) => {
      console.log('64bit rpm package built');
      if (err2) return done(err2);
      done();
    });
  });
});

gulp.task('make:linux', ['deb:linux', 'rpm:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers`,
    });

  console.log(`Zipping the linux Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('make:deb', ['deb:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers/debian`,
    });

  console.log(`Zipping the linux Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('make:rpm', ['rpm:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers/fedora`,
    });

  console.log(`Zipping the RPM Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'transpile', 'images']);
gulp.task('build', ['external', 'materialize-js', 'utility-js', 'transpile', 'images', 'less',
                    'fonts', 'html']);
gulp.task('package', ['package:win', 'package:darwin', 'package:linux']);
<commit_msg>Fix packaging issues to do with excluding vendor files<commit_after>'use strict';

const _ = require('lodash');
const gulp = require('gulp');
const babel = require('gulp-babel');
const clean = require('gulp-clean');
const less = require('gulp-less');
const cssmin = require('gulp-cssmin');
const concat = require('gulp-concat');
const packager = require('electron-packager');
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const replace = require('gulp-replace');

const grunt = require('gulp-grunt');

const paths = {
  internalScripts: ['src/**/*.js'],
  externalScripts: ['node_modules/gmusic.js/dist/gmusic.min.js',
                    'node_modules/gmusic-theme.js/dist/gmusic-theme.min.js',
                    'node_modules/gmusic-mini-player.js/dist/gmusic-mini-player.min.js'],
  utilityScripts: ['node_modules/jquery/dist/jquery.min.js',
                    'node_modules/materialize-css/dist/js/materialize.min.js',
                    'node_modules/materialize-css/extras/noUiSlider/nouislider.min.js'],
  html: 'src/public_html/**/*.html',
  less: 'src/assets/less/**/*.less',
  fonts: ['node_modules/materialize-css/dist/font/**/*',
          '!node_modules/materialize-css/dist/font/material-design-icons/*',
          'node_modules/material-design-icons-iconfont/dist/fonts/**/*'],
  images: ['src/assets/icons/**/*', 'src/assets/img/**/*'],
};

const packageJSON = require('./package.json');
let version = packageJSON.dependencies['electron-prebuilt'];
if (version.substr(0, 1) !== '0') {
  version = version.substr(1);
}

const defaultPackageConf = {
  dir: '.',
  name: packageJSON.productName,
  'build-version': packageJSON.version,
  version,
  platform: 'all',
  arch: 'all',
  'app-bundle-id': packageJSON.name,
  'app-version': packageJSON.version,
  icon: './build/assets/img/main',
  out: './dist/',
  overwrite: true,
  prune: true,
  ignore: /^(?!.*node_modules).*\/(vendor|dist|sig|docs|src|.cert.pfx|.eslintignore|.eslintrc|.gitignore|.travis.yml|appveyor.yml|circle.yml|Gruntfile.js|gulpfile.js|ISSUE_TEMPLATE.md|LICENSE|MR_CHANGELOG.html|README.md)(\/|$)/g, // eslint-disable-line
  'version-string': {
    CompanyName: 'Samuel Attard',
    LegalCopyright: 'Copyright © 2016 Samuel Attard, All rights reserved.',
    FileDescription: 'Google Play Music Desktop Player by Samuel Attard',
    ProductName: 'Google Play Music Desktop Player',
    InternalName: 'Google Play Music Desktop Player',
  },
};

const cleanGlob = (glob) => {
  return () => {
    return gulp.src(glob, { read: false })
      .pipe(clean({ force: true }));
  };
};

gulp.task('clean', cleanGlob(['./build', './dist']));
gulp.task('clean-dist-win', cleanGlob(`./dist/${packageJSON.productName}-win32-ia32`));
gulp.task('clean-dist-darwin', cleanGlob(`./dist/${packageJSON.productName}-darwin-ia32`));
gulp.task('clean-dist-linux', cleanGlob([
  `./dist/${packageJSON.productName}-linux-ia32`,
  `./dist/${packageJSON.productName}-linux-x64`,
]));
gulp.task('clean-external', cleanGlob('./build/external.js'));
gulp.task('clean-material', cleanGlob('./build/assets/material'));
gulp.task('clean-utility', cleanGlob('./build/assets/util'));
gulp.task('clean-html', cleanGlob('./build/public_html'));
gulp.task('clean-internal', cleanGlob(['./build/*.js', './build/**/*.js', '!./build/assets/**/*']));
gulp.task('clean-fonts', cleanGlob('./build/assets/font'));
gulp.task('clean-less', cleanGlob('./build/assets/css'));
gulp.task('clean-images', cleanGlob('./build/assets/img'));

gulp.task('external', ['clean-external'], () => {
  return gulp.src(paths.externalScripts)
    .pipe(concat('external.js'))
    .pipe(gulp.dest('./build/assets'));
});

gulp.task('materialize-js', ['clean-material'], () => {
  return gulp.src('node_modules/materialize-css/dist/js/materialize.min.js')
    .pipe(gulp.dest('./build/assets/material'));
});

gulp.task('utility-js', ['clean-utility'], () => {
  return gulp.src(paths.utilityScripts)
    .pipe(gulp.dest('./build/assets/util'));
});

gulp.task('html', ['clean-html'], () => {
  return gulp.src(paths.html)
    .pipe(gulp.dest('./build/public_html'));
});

gulp.task('transpile', ['clean-internal'], () => {
  gulp.src(paths.internalScripts)
    .pipe(babel({
      presets: ['es2015'],
    }))
    .on('error', (err) => { console.error(err); }) // eslint-disable-line
    .pipe(replace(/process\.env\.(.+)\;/gi, (envCall, envKey) => {
      return `'${process.env[envKey]}'`;
    }))
    .pipe(gulp.dest('./build/'));
});

gulp.task('fonts', ['clean-fonts'], () => {
  return gulp.src(paths.fonts)
    .pipe(gulp.dest('./build/assets/font'));
});

gulp.task('less', ['clean-less'], () => {
  gulp.src(paths.less)
    .pipe(less())
    .on('error', (err) => { console.error(err); }) // eslint-disable-line
    .pipe(cssmin())
    .pipe(concat('core.css'))
    .pipe(gulp.dest('./build/assets/css'));
});

// Copy all static images
gulp.task('images', ['clean-images'], () => {
  return gulp.src(paths.images)
    .pipe(gulp.dest('./build/assets/img/'));
});

// Rerun the task when a file changes
gulp.task('watch', ['build'], () => {
  gulp.watch(paths.internalScripts, ['transpile']);
  gulp.watch(paths.html, ['html']);
  gulp.watch(paths.images, ['images']);
  gulp.watch(paths.less, ['less']);
});

gulp.task('package:win', ['clean-dist-win', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'win32', arch: 'ia32' }), () => {
    setTimeout(() => {
      exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha1 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/${packageJSON.productName}-win32-ia32/${packageJSON.productName}.exe"`, {}, () => {
        exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha256 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/${packageJSON.productName}-win32-ia32/${packageJSON.productName}.exe"`, {}, () => {
          done();
        });
      });
    }, 1000);
  });
});

gulp.task('make:win', ['package:win'], (done) => {
  grunt.tasks()['grunt-build:win32'](() => {
    exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha1 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/win32/${packageJSON.productName}Setup.exe"`, {}, () => {
      exec(`vendor\\signtool sign /f ".cert.pfx" /p ${process.env.SIGN_CERT_PASS} /fd sha256 /tr "http://timestamp.geotrust.com/tsa" /v /as "dist/win32/${packageJSON.productName}Setup.exe"`, {}, () => {
        done();
      });
    });
  });
});

gulp.task('package:darwin', ['clean-dist-darwin', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'darwin', sign: 'Developer ID Application: Samuel Attard (S7WPQ45ZU2)' }), done); // eslint-disable-line
});

gulp.task('make:darwin', ['package:darwin'], (done) => {
  const pathEscapedName = packageJSON.productName.replace(/ /gi, '\ ');
  const child = spawn('zip', ['-r', '-y',
    `${pathEscapedName}.zip`,
    `${pathEscapedName}.app`],
    {
      cwd: `./dist/${packageJSON.productName}-darwin-x64`,
    });

  console.log(`Zipping "${packageJSON.productName}.app"`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('package:linux', ['clean-dist-linux', 'build'], (done) => {
  packager(_.extend({}, defaultPackageConf, { platform: 'linux' }), done);
});

gulp.task('deb:linux', ['package:linux'], (done) => {
  const debian = require('electron-installer-debian');

  const defaults = {
    bin: packageJSON.productName,
    dest: 'dist/installers/debian',
    depends: ['libappindicator1'],
    maintainer: 'Samuel Attard <samuel.r.attard@gmail.com>',
    homepage: 'http://www.googleplaymusicdesktopplayer.com',
    icon: 'build/assets/img/main.png',
  };

  debian(_.extend({}, defaults, {
    src: `dist/${packageJSON.productName}-linux-ia32`,
    arch: 'i386',
  }), (err) => {
    console.log('32bit deb package built');
    if (err) return done(err);

    debian(_.extend({}, defaults, {
      src: `dist/${packageJSON.productName}-linux-x64`,
      arch: 'amd64',
    }), (err2) => {
      console.log('64bit deb package built');
      if (err2) return done(err2);
      done();
    });
  });
});

gulp.task('rpm:linux', ['package:linux'], (done) => {
  const redhat = require('electron-installer-redhat');

  const defaults = {
    bin: packageJSON.productName,
    dest: 'dist/installers/fedora',
    depends: ['libappindicator1'],
    maintainer: 'Samuel Attard <samuel.r.attard@gmail.com>',
    homepage: 'http://www.googleplaymusicdesktopplayer.com',
    icon: 'build/assets/img/main.png',
  };

  redhat(_.extend({}, defaults, {
    src: `dist/${packageJSON.productName}-linux-ia32`,
    arch: 'i386',
  }), (err) => {
    console.log('32bit rpm package built');
    if (err) return done(err);

    redhat(_.extend({}, defaults, {
      src: `dist/${packageJSON.productName}-linux-x64`,
      arch: 'amd64',
    }), (err2) => {
      console.log('64bit rpm package built');
      if (err2) return done(err2);
      done();
    });
  });
});

gulp.task('make:linux', ['deb:linux', 'rpm:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers`,
    });

  console.log(`Zipping the linux Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('make:deb', ['deb:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers/debian`,
    });

  console.log(`Zipping the linux Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

gulp.task('make:rpm', ['rpm:linux'], (done) => {
  // Zip Linux x86
  const child = spawn('zip', ['-r', '-y',
    `installers.zip`,
    `.`],
    {
      cwd: `./dist/installers/fedora`,
    });

  console.log(`Zipping the RPM Installers`); // eslint-disable-line

  // spit stdout to screen
  child.stdout.on('data', (data) => { process.stdout.write(data.toString()); });

  // Send stderr to the main console
  child.stderr.on('data', (data) => {
    process.stdout.write(data.toString());
  });

  child.on('close', (code) => {
    console.log('Finished zipping with code ' + code); // eslint-disable-line
    done();
  });
});

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'transpile', 'images']);
gulp.task('build', ['external', 'materialize-js', 'utility-js', 'transpile', 'images', 'less',
                    'fonts', 'html']);
gulp.task('package', ['package:win', 'package:darwin', 'package:linux']);
<|endoftext|>