<commit_before>const gulp = require('gulp')
const fs = require('fs')
const { spawn } = require('child_process')
const {sources, buildConfigFile, destinationFolder} = require('./core/gulp/utils/utils')
const setupWatchers = require('./core/gulp/utils/setup-watchers')
const tasks = [
  'clean-build',
  'copy-bower',
  'compile-index',
  'compile-404',
  'compile-manifest',
  'compile-shell',
  'compile-opts',
  'compile-modules-html',
  'generate-sw',
  'polymer-build',
  'browserify',
  'compile-sass',
  'copy-images',
  'compile-firebase',
  'compile-firebase-json'
]

const compilerTasks = []

const watchers = [
  {
    name: 'watch-bower',
    files: sources.bower,
    tasks: 'copy-bower'
  },
  {
    name: 'watch-images',
    files: sources.images,
    tasks: 'copy-images'
  },
  {
    name: 'watch-browserify',
    files: sources.browserify,
    tasks: 'browserify'
  },
  {
    name: 'watch-sass',
    files: sources.sass,
    tasks: 'compile-sass'
  },
  {
    name: 'watch-index',
    files: [sources.index, `src/${buildConfigFile()}`],
    tasks: 'compile-index'
  },
  {
    name: 'watch-manifest',
    files: `core/${buildConfigFile()}`,
    tasks: 'compile-manifest'
  },
  {
    name: 'watch-shell',
    files: [sources.appShell, `src/${buildConfigFile()}`],
    tasks: 'compile-shell'
  },
  {
    name: 'watch-opts',
    files: sources.opts,
    tasks: 'compile-opts'
  },
  {
    name: 'watch-modules-html',
    files: [sources.modulesHtml, `src/${buildConfigFile()}`],
    tasks: 'compile-modules-html'
  },
  {
    name: 'watch-firebase',
    files: `core/${buildConfigFile()}`,
    tasks: 'compile-firebase'
  }
]

for (var i in tasks) {
  require(`./core/gulp/tasks/${tasks[i]}`)
  if (tasks[i] !== 'clean-build' && tasks[i] !== 'generate-sw' && tasks[i] !== 'polymer-build' && tasks[i] !== 'bower-install' && tasks[i] !== 'compile-firebase-json') {
    compilerTasks.push(tasks[i])
  }
}

require('./core/gulp/tasks/create-module')
require('./core/gulp/tasks/delete-module')
require('./core/gulp/tasks/create-page')
require('./core/gulp/tasks/create-component')
require('./core/gulp/tasks/create-model')
require('./core/gulp/tasks/copy-config')

setupWatchers(watchers)

const createFolder = (done) => {
  fs.mkdirSync(destinationFolder())
  done()
}

const generateSW = (done) => {
  fs.writeFileSync(`${destinationFolder()}/service-worker.js`, 'console.log("Development version. Will not cache files")', 'utf8')
  done()
}

const checkDevJson = (done) => {
  if (!fs.existsSync(`src/${buildConfigFile()}`)) {
    console.log('copying from dev.sample.json in src/config')
    fs.writeFileSync(`src/${buildConfigFile()}`, JSON.stringify(JSON.parse(fs.readFileSync('src/config/dev.sample.json', 'utf8')), null, 2), 'utf8')
  }
  done()
}

const autoCopyProd = (done) => {
  fs.writeFileSync(`src/config/prod.json`, JSON.stringify(JSON.parse(fs.readFileSync('src/config/dev.json', 'utf8'), null, 2)), 'utf8')
  done()
}

const runServer = (done) => {
  const args = ['serve']
  if (process.argv.indexOf('-p') > 0 && process.argv.indexOf('-p') + 1 < process.argv.length) {
    args.push('-p')
    args.push(process.argv.indexOf('-p') + 1)
  } else if (process.argv.indexOf('--port') > 0 && process.argv.indexOf('--port') + 1 < process.argv.length) {
    args.push('-p')
    args.push(process.argv.indexOf('--port') + 1)
  } else if (process.argv.indexOf('-h') > 0 && process.argv.indexOf('-h') + 1 < process.argv.length) {
    args.push('-o')
    args.push(process.argv.indexOf('-h') + 1)
  } else if (process.argv.indexOf('--host') > 0 && process.argv.indexOf('-h') + 1 < process.argv.length) {
    args.push('-o')
    args.push(process.argv.indexOf('--host') + 1)
  }
  const fb = spawn('firebase', args)

  fb.stdout.on('data', (data) => {
    console.log(data.toString('utf8'))
  })

  fb.stderr.on('data', (data) => {
    console.log(`stderr: ${data.toString('utf8')}`)
  })

  fb.on('close', (code) => {
    console.log(`child process exited with code ${code}`)
    done()
  })
}

const series = gulp.series('clean-build', createFolder, gulp.parallel(compilerTasks))
const watch = gulp.series('clean-build', createFolder, generateSW, gulp.parallel(watchers.map((w) => (w.name))))

gulp.task('default', gulp.series(checkDevJson, 'compile-firebase-json', series, generateSW))
gulp.task('watch', gulp.series(checkDevJson, 'compile-firebase-json', watch, runServer))
gulp.task('build', gulp.series(autoCopyProd, 'compile-firebase-json', series, 'polymer-build', 'generate-sw'))
<commit_msg>edited gulpfile<commit_after>const gulp = require('gulp')
const fs = require('fs')
const { spawn } = require('child_process')
const {sources, buildConfigFile, destinationFolder} = require('./core/gulp/utils/utils')
const setupWatchers = require('./core/gulp/utils/setup-watchers')
const tasks = [
  'clean-build',
  'copy-bower',
  'compile-index',
  'compile-404',
  'compile-manifest',
  'compile-shell',
  'compile-opts',
  'compile-modules-html',
  'generate-sw',
  'polymer-build',
  'browserify',
  'compile-sass',
  'copy-images',
  'compile-firebase',
  'compile-firebase-json'
]

const compilerTasks = []

const watchers = [
  {
    name: 'watch-bower',
    files: sources.bower,
    tasks: 'copy-bower'
  },
  {
    name: 'watch-images',
    files: sources.images,
    tasks: 'copy-images'
  },
  {
    name: 'watch-browserify',
    files: sources.browserify,
    tasks: 'browserify'
  },
  {
    name: 'watch-sass',
    files: sources.sass,
    tasks: 'compile-sass'
  },
  {
    name: 'watch-index',
    files: [sources.index, `src/${buildConfigFile()}`],
    tasks: 'compile-index'
  },
  {
    name: 'watch-manifest',
    files: `core/${buildConfigFile()}`,
    tasks: 'compile-manifest'
  },
  {
    name: 'watch-shell',
    files: [sources.appShell, `src/${buildConfigFile()}`],
    tasks: 'compile-shell'
  },
  {
    name: 'watch-opts',
    files: sources.opts,
    tasks: 'compile-opts'
  },
  {
    name: 'watch-modules-html',
    files: [sources.modulesHtml, `src/${buildConfigFile()}`],
    tasks: 'compile-modules-html'
  },
  {
    name: 'watch-firebase',
    files: `core/${buildConfigFile()}`,
    tasks: 'compile-firebase'
  }
]

for (var i in tasks) {
  require(`./core/gulp/tasks/${tasks[i]}`)
  if (tasks[i] !== 'clean-build' && tasks[i] !== 'generate-sw' && tasks[i] !== 'polymer-build' && tasks[i] !== 'bower-install' && tasks[i] !== 'compile-firebase-json') {
    compilerTasks.push(tasks[i])
  }
}

require('./core/gulp/tasks/create-module')
require('./core/gulp/tasks/delete-module')
require('./core/gulp/tasks/create-page')
require('./core/gulp/tasks/create-component')
require('./core/gulp/tasks/create-model')
require('./core/gulp/tasks/copy-config')

setupWatchers(watchers)

const createFolder = (done) => {
  fs.mkdirSync(destinationFolder())
  done()
}

const generateSW = (done) => {
  fs.writeFileSync(`${destinationFolder()}/service-worker.js`, 'console.log("Development version. Will not cache files")', 'utf8')
  done()
}

const checkDevJson = (done) => {
  if (!fs.existsSync(`src/${buildConfigFile()}`)) {
    console.log('copying from dev.sample.json in src/config')
    fs.writeFileSync(`src/${buildConfigFile()}`, JSON.stringify(JSON.parse(fs.readFileSync('src/config/dev.sample.json', 'utf8')), null, 2), 'utf8')
  }
  done()
}

const autoCopyProd = (done) => {
  fs.writeFileSync(`src/config/prod.json`, JSON.stringify(JSON.parse(fs.readFileSync('src/config/dev.json', 'utf8'), null, 2)), 'utf8')
  done()
}

const runServer = (done) => {
  const args = ['serve']
  if (process.argv.indexOf('--port') > 0 && process.argv.indexOf('--port') + 1 < process.argv.length) {
    args.push('-p')
    args.push(process.argv.indexOf('--port') + 1)
  } else if (process.argv.indexOf('--host') > 0 && process.argv.indexOf('-h') + 1 < process.argv.length) {
    args.push('-o')
    args.push(process.argv.indexOf('--host') + 1)
  }
  const fb = spawn('firebase', args)

  fb.stdout.on('data', (data) => {
    console.log(data.toString('utf8'))
  })

  fb.stderr.on('data', (data) => {
    console.log(`stderr: ${data.toString('utf8')}`)
  })

  fb.on('close', (code) => {
    console.log(`child process exited with code ${code}`)
    done()
  })
}

const series = gulp.series('clean-build', createFolder, gulp.parallel(compilerTasks))
const watch = gulp.series('clean-build', createFolder, generateSW, gulp.parallel(watchers.map((w) => (w.name))))

gulp.task('default', gulp.series(checkDevJson, 'compile-firebase-json', series, generateSW))
gulp.task('watch', gulp.series(checkDevJson, 'compile-firebase-json', watch, runServer))
gulp.task('build', gulp.series('compile-firebase-json', series, 'polymer-build', 'generate-sw'))
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    gutil = require('gulp-util'),
    browserify = require('gulp-browserify'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    connect = require('gulp-connect'),
    gulpif = require('gulp-if'),
    uglify = require('gulp-uglify'),
    htmlmin = require('gulp-htmlmin'),
    jsonminify = require('gulp-jsonminify'),
    imagemin = require('gulp-imagemin'),
    pngquant = require('imagemin-pngquant'),
    autoprefixer = require('gulp-autoprefixer'),
    nunjucksRender = require('gulp-nunjucks-render'),
    data = require('gulp-data'),
    critical = require('critical'),
    fs = require('fs'),
    concat = require('gulp-concat');

var env,
    jsSources,
    sassSources,
    htmlSources,
    jsonSources,
    outputDir,
    sassStyle;

env = 'production';
// env = 'development';

if (env === 'development') {
    outputDir = 'builds/development/';
    sassStyle = 'expanded';
} else {
    outputDir = 'builds/production/';
    sassStyle = 'compressed';
}

//'components/scripts/fullPageScrolling.js',
jsSourcesIndex = [
    'components/scripts/modernizr-custom.js',
    'components/scripts/jquery.js',
    'components/scripts/velocity.js',
    'components/scripts/typed.js',
    'components/scripts/menu.js',
    'components/scripts/portfolio.js',
    'components/scripts/callsOnIndex.js',
    'components/scripts/google.js',
    'components/scripts/svgxuse.js'
];

jsSources = [
    'components/scripts/modernizr-custom.js',
    'components/scripts/jquery.js',
    'components/scripts/velocity.js',
    'components/scripts/menu.js',
    'components/scripts/google.js',
    'components/scripts/svgxuse.js'
];

sassSources = ['components/sass/style.scss'];
htmlSources = [outputDir + '*.html'];
jsonSources = ['components/json/*.json'];
imgSources = ['components/img/**/*.+(png|jpg|jpeg)'];
svgSources = ['components/img/**/*.+(svg)'];
nunjucksSources = ['components/pages/*.+(html|nunj)'];

gulp.task('connect', function () {
    connect.server({
        root: outputDir,
        livereload: true
    });
});

gulp.task('js', function () {
    return gulp.src(jsSources)
        .pipe(concat('script.js'))
        .pipe(browserify())
        .pipe(gulpif(env === 'production', uglify()))
        .pipe(gulp.dest(outputDir + 'js'))
        .pipe(connect.reload())
});

gulp.task('jsIndex', function () {
    return gulp.src(jsSourcesIndex)
        .pipe(concat('index.js'))
        .pipe(browserify())
        .pipe(gulpif(env === 'production', uglify()))
        .pipe(gulp.dest(outputDir + 'js'))
        .pipe(connect.reload())
});

gulp.task('sass', function () {
  return gulp.src(sassSources)
    .pipe(sourcemaps.init())
    .pipe(sass({outputStyle: 'compressed', includePaths: ['node_modules/foundation-sites/scss', 'node_modules/typi/scss']}))
    .pipe(autoprefixer({
        browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3']
    }).on('error', gutil.log))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(outputDir + 'css'))
    .pipe(connect.reload())
});

gulp.task('watch', function () {
    gulp.watch(jsSources, ['js']);
    gulp.watch(jsSourcesIndex, ['jsIndex']);
    gulp.watch('components/sass/*.scss', ['sass']);
    gulp.watch(imgSources, ['images']);
    gulp.watch(jsonSources, ['json', 'html']);
    gulp.watch(['components/pages/*.+(html|nunj)', 'components/templates/**/*.+(html|nunj)'], ['critical']);
});

//call html after nunjucks finished
gulp.task('html', ['nunjucks'], function () {
    return gulp.src(outputDir +'*.html')
        .pipe(gulpif(env === 'production', htmlmin(
            {
                collapseWhitespace: true,
                minifyJS: true,
                minifyCSS: true
            }
        )))
        .pipe(gulpif(env === 'production', gulp.dest(outputDir)))
        .pipe(connect.reload())
});

gulp.task('nunjucks', function() {
    return gulp.src(nunjucksSources)
        .pipe(data(function () {
            return JSON.parse(fs.readFileSync('./components/json/data.json', 'utf8'));
        }))
        .pipe(nunjucksRender({
            path: ['components/templates/']
        }).on('error', gutil.log))
        .pipe(gulp.dest(outputDir))
        .pipe(connect.reload())
});

gulp.task('images', function () {
    return gulp.src(imgSources)
        .pipe(gulpif(env === 'production', imagemin()))
        .pipe(gulp.dest(outputDir + 'images'))
        .pipe(connect.reload())
});

// copy svg files to build
gulp.task('svg', function () {
  return gulp.src(svgSources)
    .pipe(gulp.dest(outputDir + 'images'))
    .pipe(connect.reload())
});

gulp.task('json', function () {
    return gulp.src(jsonSources)
        .pipe(gulpif(env === 'production', jsonminify()))
        .pipe(gulp.dest(outputDir + 'json'))
        .pipe(connect.reload())
});

// TODO: only call task if env == production
gulp.task('critical', ['html'], function () {
    critical.generate({
        inline: true,
        base: 'builds/production',
        src: 'index.html',
        dest: 'builds/production/index.html',
        minify: true,
        width: 1300,
        height: 900
    });
});

gulp.task('default', ['json', 'js', 'jsIndex', 'sass', 'images', 'svg', 'nunjucks', 'html', 'critical', 'connect', 'watch']);<commit_msg>update critical task<commit_after>var gulp = require('gulp'),
    gutil = require('gulp-util'),
    browserify = require('gulp-browserify'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    connect = require('gulp-connect'),
    gulpif = require('gulp-if'),
    uglify = require('gulp-uglify'),
    htmlmin = require('gulp-htmlmin'),
    jsonminify = require('gulp-jsonminify'),
    imagemin = require('gulp-imagemin'),
    pngquant = require('imagemin-pngquant'),
    autoprefixer = require('gulp-autoprefixer'),
    nunjucksRender = require('gulp-nunjucks-render'),
    data = require('gulp-data'),
    critical = require('critical'),
    fs = require('fs'),
    concat = require('gulp-concat');

var env,
    jsSources,
    sassSources,
    htmlSources,
    jsonSources,
    outputDir,
    sassStyle;

env = 'production';
// env = 'development';

if (env === 'development') {
    outputDir = 'builds/development/';
    sassStyle = 'expanded';
} else {
    outputDir = 'builds/production/';
    sassStyle = 'compressed';
}

//'components/scripts/fullPageScrolling.js',
jsSourcesIndex = [
    'components/scripts/modernizr-custom.js',
    'components/scripts/jquery.js',
    'components/scripts/velocity.js',
    'components/scripts/typed.js',
    'components/scripts/menu.js',
    'components/scripts/portfolio.js',
    'components/scripts/callsOnIndex.js',
    'components/scripts/google.js',
    'components/scripts/svgxuse.js'
];

jsSources = [
    'components/scripts/modernizr-custom.js',
    'components/scripts/jquery.js',
    'components/scripts/velocity.js',
    'components/scripts/menu.js',
    'components/scripts/google.js',
    'components/scripts/svgxuse.js'
];

sassSources = ['components/sass/style.scss'];
htmlSources = [outputDir + '*.html'];
jsonSources = ['components/json/*.json'];
imgSources = ['components/img/**/*.+(png|jpg|jpeg)'];
svgSources = ['components/img/**/*.+(svg)'];
nunjucksSources = ['components/pages/*.+(html|nunj)'];

gulp.task('connect', function () {
    connect.server({
        root: outputDir,
        livereload: true
    });
});

gulp.task('js', function () {
    return gulp.src(jsSources)
        .pipe(concat('script.js'))
        .pipe(browserify())
        .pipe(gulpif(env === 'production', uglify()))
        .pipe(gulp.dest(outputDir + 'js'))
        .pipe(connect.reload())
});

gulp.task('jsIndex', function () {
    return gulp.src(jsSourcesIndex)
        .pipe(concat('index.js'))
        .pipe(browserify())
        .pipe(gulpif(env === 'production', uglify()))
        .pipe(gulp.dest(outputDir + 'js'))
        .pipe(connect.reload())
});

gulp.task('sass', function () {
    return gulp.src(sassSources)
        .pipe(sourcemaps.init())
        .pipe(sass({
            outputStyle: 'compressed',
            includePaths: ['node_modules/foundation-sites/scss', 'node_modules/typi/scss']
        }))
        .pipe(autoprefixer({
            browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3']
        }).on('error', gutil.log))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest(outputDir + 'css'))
        .pipe(connect.reload())
});

gulp.task('watch', function () {
    gulp.watch(jsSources, ['js']);
    gulp.watch(jsSourcesIndex, ['jsIndex']);
    gulp.watch('components/sass/*.scss', ['sass']);
    gulp.watch(imgSources, ['images']);
    gulp.watch(jsonSources, ['json', 'html']);
    gulp.watch(['components/pages/*.+(html|nunj)', 'components/templates/**/*.+(html|nunj)'], ['critical']);
});

//call html after nunjucks finished
gulp.task('html', ['nunjucks'], function () {
    return gulp.src(outputDir + '*.html')
        .pipe(gulpif(env === 'production', htmlmin(
            {
                collapseWhitespace: true,
                minifyJS: true,
                minifyCSS: true
            }
        )))
        .pipe(gulpif(env === 'production', gulp.dest(outputDir)))
        .pipe(connect.reload())
});

gulp.task('nunjucks', function () {
    return gulp.src(nunjucksSources)
        .pipe(data(function () {
            return JSON.parse(fs.readFileSync('./components/json/data.json', 'utf8'));
        }))
        .pipe(nunjucksRender({
            path: ['components/templates/']
        }).on('error', gutil.log))
        .pipe(gulp.dest(outputDir))
        .pipe(connect.reload())
});

gulp.task('images', function () {
    return gulp.src(imgSources)
        .pipe(gulpif(env === 'production', imagemin()))
        .pipe(gulp.dest(outputDir + 'images'))
        .pipe(connect.reload())
});

// copy svg files to build
gulp.task('svg', function () {
    return gulp.src(svgSources)
        .pipe(gulp.dest(outputDir + 'images'))
        .pipe(connect.reload())
});

gulp.task('json', function () {
    return gulp.src(jsonSources)
        .pipe(gulpif(env === 'production', jsonminify()))
        .pipe(gulp.dest(outputDir + 'json'))
        .pipe(connect.reload())
});

// generate critical css and inline it
gulp.task('critical', ['html'], function () {
    critical.generate(
        {
            inline: true,
            base: outputDir,
            src: 'index.html',
            dest: outputDir + 'index.html',
            minify: true,
            width: 1300,
            height: 900
        }
    )
});

gulp.task('default', ['json', 'js', 'jsIndex', 'sass', 'images',  'svg', 'nunjucks', 'html', 'critical', 'connect', 'watch']);<|endoftext|>


<commit_before>// ------------------------------------------
// Require - sorted alphabetically after npm name
// ------------------------------------------
require('dotenv').config({silent: true});

var gulp = require('gulp')
var sequence = require('run-sequence')

// ------------------------------------------
// Get the gulp content from the main
// ------------------------------------------

require('collections-online/build/gulp')(gulp, __dirname);

// ------------------------------------------
// Combining tasks
// ------------------------------------------

gulp.task('build', function (callback) {
  // put stuff in arrays that you'd want to run in parallel
  sequence(['clean', 'bower'],
           ['css', 'js', 'svg'],
           callback)
})

// ------------------------------------------
// Default task
// ------------------------------------------

gulp.task('default', function (callback) {
  if (process.env.NODE_ENV === 'development') {
    sequence(['build'],
             ['watch'],
             callback)
  } else {
    sequence(['build'],
             callback)
  }
})
<commit_msg>Fix collections online reference.<commit_after>// ------------------------------------------
// Require - sorted alphabetically after npm name
// ------------------------------------------
require('dotenv').config({silent: true});

var gulp = require('gulp')
var sequence = require('run-sequence')

// ------------------------------------------
// Get the gulp content from the main
// ------------------------------------------

require('./collections-online/build/gulp')(gulp, __dirname);

// ------------------------------------------
// Combining tasks
// ------------------------------------------

gulp.task('build', function (callback) {
  // put stuff in arrays that you'd want to run in parallel
  sequence(['clean', 'bower'],
           ['css', 'js', 'svg'],
           callback)
})

// ------------------------------------------
// Default task
// ------------------------------------------

gulp.task('default', function (callback) {
  if (process.env.NODE_ENV === 'development') {
    sequence(['build'],
             ['watch'],
             callback)
  } else {
    sequence(['build'],
             callback)
  }
})
<|endoftext|>


<commit_before>const {series, watch, src, dest, parallel} = require('gulp');
const pump = require('pump');
const path = require('path');
const releaseUtils = require('@tryghost/release-utils');
const inquirer = require('inquirer');

// gulp plugins and utils
const livereload = require('gulp-livereload');
const postcss = require('gulp-postcss');
const zip = require('gulp-zip');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const beeper = require('beeper');
const fs = require('fs');

// postcss plugins
const autoprefixer = require('autoprefixer');
const colorFunction = require('postcss-color-function');
const cssnano = require('cssnano');
const customProperties = require('postcss-custom-properties');
const easyimport = require('postcss-easy-import');

const REPO = 'TryGhost/Casper';
const REPO_READONLY = 'TryGhost/Casper';
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');

function serve(done) {
    livereload.listen();
    done();
}

const handleError = (done) => {
    return function (err) {
        if (err) {
            beeper();
        }
        return done(err);
    };
};

function hbs(done) {
    pump([
        src(['*.hbs', 'partials/**/*.hbs']),
        livereload()
    ], handleError(done));
}

function css(done) {
    pump([
        src('assets/css/*.css', {sourcemaps: true}),
        postcss([
            easyimport,
            customProperties({preserve: false}),
            colorFunction(),
            autoprefixer(),
            cssnano()
        ]),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

function js(done) {
    pump([
        src([
            // pull in lib files first so our own code can depend on it
            'assets/js/lib/*.js',
            'assets/js/*.js'
        ], {sourcemaps: true}),
        concat('casper.js'),
        uglify(),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

function zipper(done) {
    const filename = require('./package.json').name + '.zip';

    pump([
        src([
            '**',
            '!node_modules', '!node_modules/**',
            '!dist', '!dist/**'
        ]),
        zip(filename),
        dest('dist/')
    ], handleError(done));
}

const cssWatcher = () => watch('assets/css/**', css);
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs'], hbs);
const watcher = parallel(cssWatcher, hbsWatcher);
const build = series(css, js);

exports.build = build;
exports.zip = series(build, zipper);
exports.default = series(build, serve, watcher);

exports.release = () => {
    // @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
    // require(./package.json) can run into caching issues, this re-reads from file everytime on release
    var packageJSON = JSON.parse(fs.readFileSync('./package.json'));
    const newVersion = packageJSON.version;

    if (!newVersion || newVersion === '') {
        console.log(`Invalid version: ${newVersion}`);
        return;
    }

    console.log(`\nCreating release for ${newVersion}...`);

    let config;
    try {
        config = require('./config');
    } catch (err) {
        config = null;
    }

    if (!config || !config.github || !config.github.token) {
        console.log('Please copy config.example.json and configure Github token.');
        return;
    }

    let compatibleWithGhost;

    return inquirer.prompt([{
        type: 'input',
        name: 'compatibleWithGhost',
        message: 'Which version of Ghost is it compatible with?',
        default: '3.0.0'
    }])
    .then(result => {
        compatibleWithGhost = result.compatibleWithGhost;
        return Promise.resolve();
    })
    .then(() => releaseUtils.releases.get({
        userAgent: 'Casper',
        uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
    }))
    .then((response) => {
        if (!response || !response.length) {
            console.log('No releases found. Skipping...');
            return;
        }

        let previousVersion = response[0].tag_name || response[0].name;
        console.log(`Previous version: ${previousVersion}`);
        return Promise.resolve(previousVersion);
    })
    .then((previousVersion) => {
        const changelog = new releaseUtils.Changelog({
            changelogPath: CHANGELOG_PATH,
            folder: path.join(process.cwd(), '.')
        });

        changelog
            .write({
                githubRepoPath: `https://github.com/${REPO}`,
                lastVersion: previousVersion
            })
            .sort()
            .clean();

        return Promise.resolve();
    })
    .then(() => releaseUtils.releases.create({
        draft: true,
        preRelease: false,
        tagName: newVersion,
        releaseName: newVersion,
        userAgent: 'Casper',
        uri: `https://api.github.com/repos/${REPO}/releases`,
        github: {
            token: config.github.token
        },
        content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
        changelogPath: CHANGELOG_PATH
    }))
    .then((response) => {
        console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
        return Promise.resolve();
    })
    .catch((err) => {
        console.error(err);
        process.exit(1);
    });
};
<commit_msg>Disabled yarn-error.log file export to zip (#725)<commit_after>const {series, watch, src, dest, parallel} = require('gulp');
const pump = require('pump');
const path = require('path');
const releaseUtils = require('@tryghost/release-utils');
const inquirer = require('inquirer');

// gulp plugins and utils
const livereload = require('gulp-livereload');
const postcss = require('gulp-postcss');
const zip = require('gulp-zip');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const beeper = require('beeper');
const fs = require('fs');

// postcss plugins
const autoprefixer = require('autoprefixer');
const colorFunction = require('postcss-color-function');
const cssnano = require('cssnano');
const customProperties = require('postcss-custom-properties');
const easyimport = require('postcss-easy-import');

const REPO = 'TryGhost/Casper';
const REPO_READONLY = 'TryGhost/Casper';
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');

function serve(done) {
    livereload.listen();
    done();
}

const handleError = (done) => {
    return function (err) {
        if (err) {
            beeper();
        }
        return done(err);
    };
};

function hbs(done) {
    pump([
        src(['*.hbs', 'partials/**/*.hbs']),
        livereload()
    ], handleError(done));
}

function css(done) {
    pump([
        src('assets/css/*.css', {sourcemaps: true}),
        postcss([
            easyimport,
            customProperties({preserve: false}),
            colorFunction(),
            autoprefixer(),
            cssnano()
        ]),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

function js(done) {
    pump([
        src([
            // pull in lib files first so our own code can depend on it
            'assets/js/lib/*.js',
            'assets/js/*.js'
        ], {sourcemaps: true}),
        concat('casper.js'),
        uglify(),
        dest('assets/built/', {sourcemaps: '.'}),
        livereload()
    ], handleError(done));
}

function zipper(done) {
    const filename = require('./package.json').name + '.zip';

    pump([
        src([
            '**',
            '!node_modules', '!node_modules/**',
            '!dist', '!dist/**',
            '!yarn-error.log'
        ]),
        zip(filename),
        dest('dist/')
    ], handleError(done));
}

const cssWatcher = () => watch('assets/css/**', css);
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs'], hbs);
const watcher = parallel(cssWatcher, hbsWatcher);
const build = series(css, js);

exports.build = build;
exports.zip = series(build, zipper);
exports.default = series(build, serve, watcher);

exports.release = () => {
    // @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
    // require(./package.json) can run into caching issues, this re-reads from file everytime on release
    var packageJSON = JSON.parse(fs.readFileSync('./package.json'));
    const newVersion = packageJSON.version;

    if (!newVersion || newVersion === '') {
        console.log(`Invalid version: ${newVersion}`);
        return;
    }

    console.log(`\nCreating release for ${newVersion}...`);

    let config;
    try {
        config = require('./config');
    } catch (err) {
        config = null;
    }

    if (!config || !config.github || !config.github.token) {
        console.log('Please copy config.example.json and configure Github token.');
        return;
    }

    let compatibleWithGhost;

    return inquirer.prompt([{
        type: 'input',
        name: 'compatibleWithGhost',
        message: 'Which version of Ghost is it compatible with?',
        default: '3.0.0'
    }])
    .then(result => {
        compatibleWithGhost = result.compatibleWithGhost;
        return Promise.resolve();
    })
    .then(() => releaseUtils.releases.get({
        userAgent: 'Casper',
        uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
    }))
    .then((response) => {
        if (!response || !response.length) {
            console.log('No releases found. Skipping...');
            return;
        }

        let previousVersion = response[0].tag_name || response[0].name;
        console.log(`Previous version: ${previousVersion}`);
        return Promise.resolve(previousVersion);
    })
    .then((previousVersion) => {
        const changelog = new releaseUtils.Changelog({
            changelogPath: CHANGELOG_PATH,
            folder: path.join(process.cwd(), '.')
        });

        changelog
            .write({
                githubRepoPath: `https://github.com/${REPO}`,
                lastVersion: previousVersion
            })
            .sort()
            .clean();

        return Promise.resolve();
    })
    .then(() => releaseUtils.releases.create({
        draft: true,
        preRelease: false,
        tagName: newVersion,
        releaseName: newVersion,
        userAgent: 'Casper',
        uri: `https://api.github.com/repos/${REPO}/releases`,
        github: {
            token: config.github.token
        },
        content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
        changelogPath: CHANGELOG_PATH
    }))
    .then((response) => {
        console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
        return Promise.resolve();
    })
    .catch((err) => {
        console.error(err);
        process.exit(1);
    });
};
<|endoftext|>


<commit_before>var fs = require('fs');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var cache = require('gulp-cache');
var path = require('path');
var stream = require("event-stream")
var replace = require('gulp-replace-task');
var neon = require('neon-js/src/neon.js');

var configRaw = fs.readFileSync('./app/config/config.local.neon', 'utf8');
var config = neon.decode(configRaw);

var buildDir = './www/build';
var libDir = './www/libs';
var bsDir = './www/libs/bootstrap/less/';
var jsDir = './www/js';
var jsFiles = [
	path.join(jsDir, 'app/*.js'),
	path.join(jsDir, 'services/*.js'),
	path.join(jsDir, 'snippets/*.js'),
	path.join(jsDir, 'components/*.js'),
	path.join(jsDir, 'components/controls/*.js'),
	path.join(jsDir, 'components/forms/*.js'),
	path.join(jsDir, 'components/exercises/*.js')
];
var jsLibFiles = [
	path.join(libDir, 'bootstrap/js/alert.js'),
	path.join(libDir, 'bootstrap/js/tab.js'),
	path.join(libDir, 'bootstrap/js/modal.js'),
	path.join(libDir, 'jquery-timeago/jquery.timeago.js'),
	path.join(libDir, 'jquery-timeago/locales/jquery.timeago.cs.js'),
	path.join(libDir, 'nette-forms/src/assets/netteForms.js'),
	path.join(libDir, 'typeahead.js/dist/typeahead.jquery.min.js'),
	path.join(libDir, 'smooth-scroll/dist/js/smooth-scroll.js'),
	path.join(libDir, 'isInViewport/lib/isInViewport.min.js')
];
var jsAdminFiles = [
	path.join(jsDir, 'admin/*.js')
];
var jsAdminLibFiles = [
	path.join(libDir, 'jquery-ui/jquery-ui.min.js'),
	path.join(libDir, 'chosen/chosen.jquery.min.js'),
	path.join(libDir, 'zeroclipboard/dist/ZeroClipboard.min.js'),
	path.join(libDir, 'handsontable/dist/handsontable.full.min.js')
];
var lessDir = './www/less';
var lessBootstrapFiles = [
	path.join(bsDir, 'variables.less'),
	path.join(lessDir, 'variables.less'),

	path.join(bsDir, 'mixins.less'),
	path.join(bsDir, 'normalize.less'),
	//path.join(bsDir, 'print.less'),
	//path.join(bsDir, 'glyphicons.less'),
	path.join(bsDir, 'scaffolding.less'),
	path.join(bsDir, 'type.less'),
	//path.join(bsDir, 'code.less'),
	path.join(bsDir, 'grid.less'),
	//path.join(bsDir, 'tables.less'),
	path.join(bsDir, 'forms.less'),
	path.join(bsDir, 'buttons.less'),
	path.join(bsDir, 'component-animations.less'),
	path.join(bsDir, 'dropdowns.less'),
	//path.join(bsDir, 'button-groups.less'),
	//path.join(bsDir, 'input-groups.less'),
	path.join(bsDir, 'navs.less'),
	//path.join(bsDir, 'navbar.less'),
	//path.join(bsDir, 'breadcrumbs.less'),
	//path.join(bsDir, 'pagination.less'),
	//path.join(bsDir, 'pager.less'),
	//path.join(bsDir, 'labels.less'),
	//path.join(bsDir, 'badges.less'),
	//path.join(bsDir, 'jumbotron.less'),
	//path.join(bsDir, 'thumbnails.less'),
	path.join(bsDir, 'alerts.less'),
	//path.join(bsDir, 'progress-bars.less'),
	//path.join(bsDir, 'media.less'),
	//path.join(bsDir, 'list-group.less'),
	//path.join(bsDir, 'panels.less'),
	//path.join(bsDir, 'responsive-embed.less'),
	//path.join(bsDir, 'wells.less'),
	path.join(bsDir, 'close.less'),
	path.join(bsDir, 'modals.less'),
	//path.join(bsDir, 'tooltip.less'),
	//path.join(bsDir, 'popovers.less'),
	//path.join(bsDir, 'carousel.less'),
	path.join(bsDir, 'utilities.less'),
	path.join(bsDir, 'responsive-utilities.less')
];
var lessFiles = [
	path.join(bsDir, 'variables.less'),
	path.join(bsDir, 'mixins.less'),

	path.join(lessDir, 'variables.less'),
	path.join(lessDir, 'mixins.less'),
	path.join(lessDir, 'main/fonts/*.less'),
	path.join(lessDir, 'main/base.less'),
	path.join(lessDir, 'main/components/*.less'),
	path.join(lessDir, 'main/pages/*.less')
];
var lessAdminLibFiles = [
	path.join(libDir, 'chosen/chosen.min.css'),
	path.join(libDir, 'handsontable/dist/handsontable.full.min.css')
];
var lessAdminFiles = [
	path.join(lessDir, 'variables.less'),
	path.join(lessDir, 'mixins.less'),
	path.join(lessDir, 'admin/*.less'),
	path.join(lessDir, 'admin/pages/*.less')
];
var lessExperimentFiles = [
	path.join(lessDir, 'experiments/*.less')
];

gulp.task('less-dev-main', function() {
	return stream.concat(
		gulp.src(lessBootstrapFiles)
			.pipe($.concat('bootstrap.less'))
			.pipe(cache($.less())),
		gulp.src(lessFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('main.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../less'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-dev-admin', function() {
	return stream.concat(
		gulp.src(lessAdminLibFiles),
		gulp.src(lessAdminFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('main.admin.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.admin.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../less'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-experiment', function() {
	return gulp.src(lessExperimentFiles)
		.pipe($.concat('experiment.search.always.visible.less'))
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-production-main', function() {
	return stream.concat(
		gulp.src(lessBootstrapFiles)
			.pipe($.concat('bootstrap.less'))
			.pipe($.less()),
		gulp.src(lessFiles)
			.pipe($.concat('main.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.css'))
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-production-admin', function() {
	return stream.concat(
		gulp.src(lessAdminLibFiles),
		gulp.src(lessAdminFiles)
			.pipe($.concat('main.admin.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
			.pipe($.cssmin())
	)
		.pipe($.concat('main.admin.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-dev-main', function() {
	return stream.concat(
		gulp.src(jsLibFiles),
		gulp.src(jsFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('app.min.js'))
			.pipe($.uglify())
			.pipe(replace({
				patterns: [{
					json: {
						elastic: {
							url: 'http://' + config.get('parameters').get('elastic').get('hosts').get(0) + ':9200',
							index: config.get('parameters').get('elastic').get('index')
						}
					}
				}]
			}))
	)
		.pipe($.concat('app.min.js'))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-dev-admin', function() {
	return stream.concat(
		gulp.src(jsAdminLibFiles),
		gulp.src(jsAdminFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('app.admin.min.js'))
			.pipe($.uglify())
	)
		.pipe($.concat('app.admin.min.js'))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-production-main', function() {
	return stream.concat(
		gulp.src(jsLibFiles),
		gulp.src(jsFiles)
			.pipe($.concat('app.min.js'))
			.pipe($.uglify())
			.pipe(replace({
				patterns: [{
					json: {
						elastic: {
							url: 'https://elastic.khanovaskola.cz',
							index: config.get('parameters').get('elastic').get('index')
						}
					}
				}]
			}))
	)
		.pipe($.concat('app.min.js'))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-production-admin', function() {
	return stream.concat(
		gulp.src(jsAdminLibFiles),
		gulp.src(jsAdminFiles)
			.pipe($.concat('app.admin.min.js'))
			.pipe($.uglify())
	)
		.pipe($.concat('app.admin.min.js'))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-dev', ['less-dev-main', 'less-dev-admin']);
gulp.task('less', ['less-dev-main', 'less-dev-admin']);
gulp.task('less-production', ['less-production-main', 'less-production-admin']);

gulp.task('js-dev', ['js-dev-main', 'js-dev-admin']);
gulp.task('js', ['js-dev-main', 'js-dev-admin']);
gulp.task('js-production', ['js-production-main', 'js-production-admin']);

gulp.task('dev', ['less-dev', 'js-dev']);

gulp.task('production', ['less-production', 'js-production']);

gulp.task('default', ['dev']);
<commit_msg>remove too slow dev less sourcemaps<commit_after>var fs = require('fs');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var cache = require('gulp-cache');
var path = require('path');
var stream = require("event-stream")
var replace = require('gulp-replace-task');
var neon = require('neon-js/src/neon.js');

var configRaw = fs.readFileSync('./app/config/config.local.neon', 'utf8');
var config = neon.decode(configRaw);

var buildDir = './www/build';
var libDir = './www/libs';
var bsDir = './www/libs/bootstrap/less/';
var jsDir = './www/js';
var jsFiles = [
	path.join(jsDir, 'app/*.js'),
	path.join(jsDir, 'services/*.js'),
	path.join(jsDir, 'snippets/*.js'),
	path.join(jsDir, 'components/*.js'),
	path.join(jsDir, 'components/controls/*.js'),
	path.join(jsDir, 'components/forms/*.js'),
	path.join(jsDir, 'components/exercises/*.js')
];
var jsLibFiles = [
	path.join(libDir, 'bootstrap/js/alert.js'),
	path.join(libDir, 'bootstrap/js/tab.js'),
	path.join(libDir, 'bootstrap/js/modal.js'),
	path.join(libDir, 'jquery-timeago/jquery.timeago.js'),
	path.join(libDir, 'jquery-timeago/locales/jquery.timeago.cs.js'),
	path.join(libDir, 'nette-forms/src/assets/netteForms.js'),
	path.join(libDir, 'typeahead.js/dist/typeahead.jquery.min.js'),
	path.join(libDir, 'smooth-scroll/dist/js/smooth-scroll.js'),
	path.join(libDir, 'isInViewport/lib/isInViewport.min.js')
];
var jsAdminFiles = [
	path.join(jsDir, 'admin/*.js')
];
var jsAdminLibFiles = [
	path.join(libDir, 'jquery-ui/jquery-ui.min.js'),
	path.join(libDir, 'chosen/chosen.jquery.min.js'),
	path.join(libDir, 'zeroclipboard/dist/ZeroClipboard.min.js'),
	path.join(libDir, 'handsontable/dist/handsontable.full.min.js')
];
var lessDir = './www/less';
var lessBootstrapFiles = [
	path.join(bsDir, 'variables.less'),
	path.join(lessDir, 'variables.less'),

	path.join(bsDir, 'mixins.less'),
	path.join(bsDir, 'normalize.less'),
	//path.join(bsDir, 'print.less'),
	//path.join(bsDir, 'glyphicons.less'),
	path.join(bsDir, 'scaffolding.less'),
	path.join(bsDir, 'type.less'),
	//path.join(bsDir, 'code.less'),
	path.join(bsDir, 'grid.less'),
	//path.join(bsDir, 'tables.less'),
	path.join(bsDir, 'forms.less'),
	path.join(bsDir, 'buttons.less'),
	path.join(bsDir, 'component-animations.less'),
	path.join(bsDir, 'dropdowns.less'),
	//path.join(bsDir, 'button-groups.less'),
	//path.join(bsDir, 'input-groups.less'),
	path.join(bsDir, 'navs.less'),
	//path.join(bsDir, 'navbar.less'),
	//path.join(bsDir, 'breadcrumbs.less'),
	//path.join(bsDir, 'pagination.less'),
	//path.join(bsDir, 'pager.less'),
	//path.join(bsDir, 'labels.less'),
	//path.join(bsDir, 'badges.less'),
	//path.join(bsDir, 'jumbotron.less'),
	//path.join(bsDir, 'thumbnails.less'),
	path.join(bsDir, 'alerts.less'),
	//path.join(bsDir, 'progress-bars.less'),
	//path.join(bsDir, 'media.less'),
	//path.join(bsDir, 'list-group.less'),
	//path.join(bsDir, 'panels.less'),
	//path.join(bsDir, 'responsive-embed.less'),
	//path.join(bsDir, 'wells.less'),
	path.join(bsDir, 'close.less'),
	path.join(bsDir, 'modals.less'),
	//path.join(bsDir, 'tooltip.less'),
	//path.join(bsDir, 'popovers.less'),
	//path.join(bsDir, 'carousel.less'),
	path.join(bsDir, 'utilities.less'),
	path.join(bsDir, 'responsive-utilities.less')
];
var lessFiles = [
	path.join(bsDir, 'variables.less'),
	path.join(bsDir, 'mixins.less'),

	path.join(lessDir, 'variables.less'),
	path.join(lessDir, 'mixins.less'),
	path.join(lessDir, 'main/fonts/*.less'),
	path.join(lessDir, 'main/base.less'),
	path.join(lessDir, 'main/components/*.less'),
	path.join(lessDir, 'main/pages/*.less')
];
var lessAdminLibFiles = [
	path.join(libDir, 'chosen/chosen.min.css'),
	path.join(libDir, 'handsontable/dist/handsontable.full.min.css')
];
var lessAdminFiles = [
	path.join(lessDir, 'variables.less'),
	path.join(lessDir, 'mixins.less'),
	path.join(lessDir, 'admin/*.less'),
	path.join(lessDir, 'admin/pages/*.less')
];
var lessExperimentFiles = [
	path.join(lessDir, 'experiments/*.less')
];

gulp.task('less-dev-main', function() {
	return stream.concat(
		gulp.src(lessBootstrapFiles)
			.pipe($.concat('bootstrap.less'))
			.pipe(cache($.less())),
		gulp.src(lessFiles)
			.pipe($.concat('main.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-dev-admin', function() {
	return stream.concat(
		gulp.src(lessAdminLibFiles),
		gulp.src(lessAdminFiles)
			.pipe($.concat('main.admin.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.admin.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-experiment', function() {
	return gulp.src(lessExperimentFiles)
		.pipe($.concat('experiment.search.always.visible.less'))
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-production-main', function() {
	return stream.concat(
		gulp.src(lessBootstrapFiles)
			.pipe($.concat('bootstrap.less'))
			.pipe($.less()),
		gulp.src(lessFiles)
			.pipe($.concat('main.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
	)
		.pipe($.concat('main.css'))
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-production-admin', function() {
	return stream.concat(
		gulp.src(lessAdminLibFiles),
		gulp.src(lessAdminFiles)
			.pipe($.concat('main.admin.less'))
			.pipe($.less())
			.pipe($.autoprefixer())
			.pipe($.cssmin())
	)
		.pipe($.concat('main.admin.css'))
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-dev-main', function() {
	return stream.concat(
		gulp.src(jsLibFiles),
		gulp.src(jsFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('app.min.js'))
			.pipe($.uglify())
			.pipe(replace({
				patterns: [{
					json: {
						elastic: {
							url: 'http://' + config.get('parameters').get('elastic').get('hosts').get(0) + ':9200',
							index: config.get('parameters').get('elastic').get('index')
						}
					}
				}]
			}))
	)
		.pipe($.concat('app.min.js'))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-dev-admin', function() {
	return stream.concat(
		gulp.src(jsAdminLibFiles),
		gulp.src(jsAdminFiles)
			.pipe($.sourcemaps.init())
			.pipe($.concat('app.admin.min.js'))
			.pipe($.uglify())
	)
		.pipe($.concat('app.admin.min.js'))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-production-main', function() {
	return stream.concat(
		gulp.src(jsLibFiles),
		gulp.src(jsFiles)
			.pipe($.concat('app.min.js'))
			.pipe($.uglify())
			.pipe(replace({
				patterns: [{
					json: {
						elastic: {
							url: 'https://elastic.khanovaskola.cz',
							index: config.get('parameters').get('elastic').get('index')
						}
					}
				}]
			}))
	)
		.pipe($.concat('app.min.js'))
		.pipe(gulp.dest(buildDir));
});

gulp.task('js-production-admin', function() {
	return stream.concat(
		gulp.src(jsAdminLibFiles),
		gulp.src(jsAdminFiles)
			.pipe($.concat('app.admin.min.js'))
			.pipe($.uglify())
	)
		.pipe($.concat('app.admin.min.js'))
		.pipe(gulp.dest(buildDir));
});

gulp.task('less-dev', ['less-dev-main', 'less-dev-admin']);
gulp.task('less', ['less-dev-main', 'less-dev-admin']);
gulp.task('less-production', ['less-production-main', 'less-production-admin']);

gulp.task('js-dev', ['js-dev-main', 'js-dev-admin']);
gulp.task('js', ['js-dev-main', 'js-dev-admin']);
gulp.task('js-production', ['js-production-main', 'js-production-admin']);

gulp.task('dev', ['less-dev', 'js-dev']);

gulp.task('production', ['less-production', 'js-production']);

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


<commit_before>'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var bs = require('browser-sync').create();
var del = require('del');

gulp.task('lint', function () {
  return gulp.src('app/js/**/*.js')
    .pipe($.eslint())
    .pipe($.eslint.format())
    .pipe($.eslint.failAfterError());
});

gulp.task('serve', ['styles'], function () {
  bs.init({
    notify: false,
    port: 9000,
    open: true,
    server: {
      baseDir: ['.tmp', 'app']
    }
  });
  gulp.watch([
    'app/**/*.html',
    'app/js/**/*.js'
  ]).on('change', bs.reload);
  gulp.watch('app/_sass/**/*.scss', ['styles', bs.reload]);
  gulp.watch('app/js/**/*.js', ['lint']);
});

gulp.task('clean', del.bind(null, ['dist']));

gulp.task('styles', function () {
  return gulp.src('app/_sass/*.scss')
    .pipe($.sourcemaps.init())
    .pipe($.sass().on('error', $.sass.logError))
    .pipe($.autoprefixer({
      browsers: [
        'last 2 versions',
        'Explorer >= 8',
        'Firefox ESR',
        'Android >= 2.3',
        'iOS >= 7'
      ]
    }))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/css'))
    .pipe($.minifyCss())
    .pipe(gulp.dest('dist/css'));
});

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

gulp.task('html', function () {
  return gulp.src('app/**/*.html')
    .pipe($.htmlmin({
      collapseWhitespace: true
    }))
    .pipe(gulp.dest('dist'));
});

gulp.task('build', ['clean'], function (callback) {
  runSequence(['styles', 'scripts', 'html'], callback);
});

gulp.task('default', function (callback) {
  runSequence('lint', 'build', callback);
});
<commit_msg>Clean up .tmp when build<commit_after>'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var bs = require('browser-sync').create();
var del = require('del');

gulp.task('lint', function () {
  return gulp.src('app/js/**/*.js')
    .pipe($.eslint())
    .pipe($.eslint.format())
    .pipe($.eslint.failAfterError());
});

gulp.task('serve', ['styles'], function () {
  bs.init({
    notify: false,
    port: 9000,
    open: true,
    server: {
      baseDir: ['.tmp', 'app']
    }
  });
  gulp.watch([
    'app/**/*.html',
    'app/js/**/*.js'
  ]).on('change', bs.reload);
  gulp.watch('app/_sass/**/*.scss', ['styles', bs.reload]);
  gulp.watch('app/js/**/*.js', ['lint']);
});

gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

gulp.task('styles', function () {
  return gulp.src('app/_sass/*.scss')
    .pipe($.sourcemaps.init())
    .pipe($.sass().on('error', $.sass.logError))
    .pipe($.autoprefixer({
      browsers: [
        'last 2 versions',
        'Explorer >= 8',
        'Firefox ESR',
        'Android >= 2.3',
        'iOS >= 7'
      ]
    }))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/css'))
    .pipe($.minifyCss())
    .pipe(gulp.dest('dist/css'));
});

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

gulp.task('html', function () {
  return gulp.src('app/**/*.html')
    .pipe($.htmlmin({
      collapseWhitespace: true
    }))
    .pipe(gulp.dest('dist'));
});

gulp.task('build', ['clean'], function (callback) {
  runSequence(['styles', 'scripts', 'html'], callback);
});

gulp.task('default', function (callback) {
  runSequence('lint', 'build', callback);
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    connect = require('gulp-connect'),
    manifest = require('gulp-manifest'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css');

gulp.task('manifest', function(){
  gulp.src(['./app/index.html',
            './app/app.css',
            './app/app.js',
            './app/companies.json'
            ])
    .pipe(manifest({
      hash: true,
      preferOnline: false,
      network: ['http://*', 'https://*', '*'],
      cache: [
              '//ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js',
              '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',
              'bower_components/html5-boilerplate/dist/css/normalize.css',
              'bower_components/html5-boilerplate/dist/css/main.css'
              ],
      filename: 'app.manifest',
      exclude: ['app.manifest', 'cache.appcache']
     }))
    .pipe(gulp.dest('app'));
});

gulp.task('connect', function() {
  connect.server({
    root: 'app',
    port: 8000,
    livereload: true
  });
});

gulp.task('sass', function () {
  gulp.src('./app/sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(minifyCss())
    .pipe(gulp.dest('./app/'))
    .pipe(connect.reload());
});

gulp.task('html', function () {
  gulp.src('./app/**/*.html')
    .pipe(connect.reload());
});

gulp.task('js', function() {
  return gulp.src('./app/js/*.js')
    .pipe(concat('app.js'))
    .pipe(uglify())
    .pipe(gulp.dest('./app/'))
    .pipe(connect.reload());
});

gulp.task('watch', function () {
  gulp.watch('./app/sass/**/*.scss', ['sass']);
  gulp.watch('./app/**/*.html', ['html']);
  gulp.watch('./app/js/*.js', ['js']);
  gulp.watch('./app/**/*', ['manifest']);
});

gulp.task('build', ['sass', 'js']);

gulp.task('serve', ['connect', 'watch']);
<commit_msg>Compilar os assets com o gulp serve<commit_after>var gulp = require('gulp'),
    sass = require('gulp-sass'),
    connect = require('gulp-connect'),
    manifest = require('gulp-manifest'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css');

gulp.task('manifest', function(){
  gulp.src(['./app/index.html',
            './app/app.css',
            './app/app.js',
            './app/companies.json'
            ])
    .pipe(manifest({
      hash: true,
      preferOnline: false,
      network: ['http://*', 'https://*', '*'],
      cache: [
              '//ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js',
              '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',
              'bower_components/html5-boilerplate/dist/css/normalize.css',
              'bower_components/html5-boilerplate/dist/css/main.css'
              ],
      filename: 'app.manifest',
      exclude: ['app.manifest', 'cache.appcache']
     }))
    .pipe(gulp.dest('app'));
});

gulp.task('connect', function() {
  connect.server({
    root: 'app',
    port: 8000,
    livereload: true
  });
});

gulp.task('sass', function () {
  gulp.src('./app/sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(minifyCss())
    .pipe(gulp.dest('./app/'))
    .pipe(connect.reload());
});

gulp.task('html', function () {
  gulp.src('./app/**/*.html')
    .pipe(connect.reload());
});

gulp.task('js', function() {
  return gulp.src('./app/js/*.js')
    .pipe(concat('app.js'))
    .pipe(uglify())
    .pipe(gulp.dest('./app/'))
    .pipe(connect.reload());
});

gulp.task('watch', function () {
  gulp.watch('./app/sass/**/*.scss', ['sass']);
  gulp.watch('./app/**/*.html', ['html']);
  gulp.watch('./app/js/*.js', ['js']);
  gulp.watch('./app/**/*', ['manifest']);
});

gulp.task('build', ['sass', 'js', 'manifest']);

gulp.task('serve', ['connect', 'build', 'watch']);
<|endoftext|>


<commit_before>"use strict";
/*global require*/
var _                = require("lodash");
var del              = require("del");
var path             = require("path");
var runSequence      = require("run-sequence");

var gulp             = require("gulp");
var harmonize        = require("harmonize");
var awspublish       = require("gulp-awspublish");
var rename           = require("gulp-rename");
var parallelize      = require("concurrent-transform");
var gutil            = require("gulp-util");
var deploy           = require("gulp-gh-pages");
var cloufront        = require('gulp-invalidate-cloudfront');
var notifier         = require("node-notifier");
var merge            = require('merge-stream');

var ngrok            = require('ngrok');
var webpack          = require("webpack");
var WebpackDevServer = require("webpack-dev-server");

// Get our Config.
var config           = require("./config");
var webpackConfig    = require("./webpack.config");

harmonize();

var notify = function(message){
  notifier.notify({title: config.displayName+" Gulp",message:message});
};

// Setup a Ngrok server
var ngrokServe = function(subdomain){
  var options = { port: config.serverPort };
  var env = process.env;
  if (env.NGROK_AUTHTOKEN) {
    options.authtoken = env.NGROK_AUTHTOKEN;

    if(env.NGROK_SUBDOMAIN || subdomain){
      options.subdomain = (env.NGROK_SUBDOMAIN || subdomain).replace(/-/g,'');
    }
  }
  ngrok.connect(options, function (error, url) {
    if (error) {
      throw new gutil.PluginError('ship:server', error);
    }

    url = url.replace('https', 'http');
    notify({message:"Ngrok Started on "+url});

    gutil.log('[ship:server]', url);
  });
}

gulp.task("default", ["server"]);
gulp.task("serve",   ["server"]);
gulp.task("clean",   function(callback) {del(["./"+config.outputFolder+"/**/*"], callback); });

gulp.task("server",  function(callback) {runSequence("clean", "copy-files:watch", "webpack:server", callback); });
gulp.task("build",   function(callback) {runSequence("clean", "copy-files", "webpack:build", callback); });
gulp.task("deploy",  function(callback) {runSequence("build", "publish:sha", callback); });
gulp.task("deploy:release",  function(callback) {runSequence("build", "publish:release", callback); });

var notify = function(message){
  notifier.notify({title: config.displayName+" Gulp", message: message});
};
var handleError = function(err, taskName){
  if(err){
    notify(taskName+" Error: "+ err);
    throw new gutil.PluginError("webpack:build", err);
  }
};
// Copy static files from the source to the destination
var copyFiles = function(callback){
  _.map(config.files, function(dest, src){
    gulp.src(src).pipe(gulp.dest(dest));
  });
  notify("Vendors Updated");
  if (_.isFunction(callback)){
    callback();
  }
};

gulp.task("copy-files", copyFiles);

gulp.task("copy-files:watch", function(){
  copyFiles();
  gulp.watch(_.keys(config.files), copyFiles);
});

//Production Build.
//Minified, clean code. No demo keys inside.
//demo.html WILL NOT WORK with this build.
//
//Webpack handles CSS/SCSS, JS, and HTML files.
var afterBuild = function(err, stats){
  if (!!err) {throw new gutil.PluginError("webpack:build", err); }

  var jsonStats = stats.toJson();

  if (jsonStats.errors.length > 0) {
    return new gutil.PluginError("webpack:build", JSON.stringify(jsonStats.errors));
  }

  if (jsonStats.warnings.length > 0) {
    new gutil.PluginError("webpack:build", JSON.stringify(jsonStats.warnings));
  }

  gutil.log("[webpack:build]", stats.toString({colors: true}));
  notify("App Built");
};
gulp.task("webpack:build", function(callback) {
  // Then, use Webpack to bundle all JS and html files to the destination folder
  notify("Building App");
  webpack(_.values(webpackConfig.production), function(err, stats) {
    afterBuild(err, stats);
    webpack(_.values(webpackConfig.debug), function(err, stats){
      afterBuild(err, stats);
      callback();
    });
  });
});

// Dev Build
// Create the webpack compiler here for caching and performance.
var devCompiler = webpack(webpackConfig.development.browser);

// Build a Dev version of the project. Launched once on startup so we can have eveything copied.
gulp.task("webpack:build:dev", function(callback) {
  // run webpack with Dev profile.
  // Embeds the Hull config keys, and the necessary stuff to make demo.html work
  devCompiler.run(function(err, stats) {
    if (err){
      throw new gutil.PluginError("webpack:build:dev", err);
    }

    var jsonStats = stats.toJson();

    if(jsonStats.errors.length > 0){
      return new gutil.PluginError("webpack:build:dev", JSON.stringify(jsonStats.errors));
    }

    if(jsonStats.warnings.length > 0){
      new gutil.PluginError("webpack:build:dev", JSON.stringify(jsonStats.warnings));
    }

    gutil.log("[webpack:build:dev]", stats.toString({colors: true}));
    notify({message: "Webpack Updated"});
    callback();
  });
});

// Launch webpack dev server.
gulp.task("webpack:server", function() {
  var taskName = "webpack:server";
  new WebpackDevServer(devCompiler, {
    contentBase: config.outputFolder,
    publicPath: config.assetsFolder+"/",
    hot: config.hotReload,
    stats: {colors: true }
  }).listen(config.serverPort, function(err) {
    handleError(err, taskName);
    // Dump the preview URL in the console, and open Chrome when launched for convenience.
    notify({message: "Dev Server Started"});
    var url = webpackConfig.development.browser.output.publicPath+"webpack-dev-server/";
    ngrokServe(config.libName)
    gutil.log("["+taskName+"]", url);
  });
});

var publish = function(versions){
  var aws = config.aws
  var publisher = awspublish.create(aws.config);
  var files  = path.join(config.outputFolder, config.assetsFolder, "*")
  var streams = [];
  var cloudfrontInvalidations = []
  for (var i = 0; i < versions.length; i++) {
    var version = versions[i];
    if(version){
      console.log('Deploying to ',version);
      var plain = gulp.src(files)
      .pipe(rename(function(p){
        p.dirname += '/'+version;
        console.log('Publishing '+path.join(p.dirname,p.basename+p.extname))
      }))
      var gzip = gulp.src(files)
      .pipe(rename(function(p){
        p.dirname += '/'+version;
        console.log('Publishing '+path.join(p.dirname,p.basename+p.extname))
      }))
      .pipe(awspublish.gzip(aws.gzip))
      cloudfrontInvalidations.push('/'+version+'/*');
      streams.push(plain);
      streams.push(gzip);
    }
  };

  var invalidationBatch = {
    CallerReference: new Date().toString(),
    Paths:{
      Quantity:1,
      Items:cloudfrontInvalidations
    }
  }
  return merge.apply(merge,streams)
  .pipe(parallelize(publisher.publish(aws.publish.headers,aws.publish.options)))
  .pipe(publisher.cache())
  .pipe(cloudfront(invalidationBatch, aws.cloudfront))
  .pipe(awspublish.reporter())
}

// Deploys to S3
gulp.task('publish:sha',function(){
  var SHA1 = process.env.CIRCLE_SHA1;
  if( !SHA1 ){ return; }
  return publish([SHA1]);
});

gulp.task('publish:release',function(){
  var SHA1 = process.env.CIRCLE_SHA1;
  var RELEASE = config.pkg.version;
  if( !SHA1 || !RELEASE ){ return; }
  return publish([SHA1,RELEASE]);
});
<commit_msg>damn typos<commit_after>"use strict";
/*global require*/
var _                = require("lodash");
var del              = require("del");
var path             = require("path");
var runSequence      = require("run-sequence");

var gulp             = require("gulp");
var harmonize        = require("harmonize");
var awspublish       = require("gulp-awspublish");
var rename           = require("gulp-rename");
var parallelize      = require("concurrent-transform");
var gutil            = require("gulp-util");
var deploy           = require("gulp-gh-pages");
var cloudfront       = require('gulp-invalidate-cloudfront');
var notifier         = require("node-notifier");
var merge            = require('merge-stream');

var ngrok            = require('ngrok');
var webpack          = require("webpack");
var WebpackDevServer = require("webpack-dev-server");

// Get our Config.
var config           = require("./config");
var webpackConfig    = require("./webpack.config");

harmonize();

var notify = function(message){
  notifier.notify({title: config.displayName+" Gulp",message:message});
};

// Setup a Ngrok server
var ngrokServe = function(subdomain){
  var options = { port: config.serverPort };
  var env = process.env;
  if (env.NGROK_AUTHTOKEN) {
    options.authtoken = env.NGROK_AUTHTOKEN;

    if(env.NGROK_SUBDOMAIN || subdomain){
      options.subdomain = (env.NGROK_SUBDOMAIN || subdomain).replace(/-/g,'');
    }
  }
  ngrok.connect(options, function (error, url) {
    if (error) {
      throw new gutil.PluginError('ship:server', error);
    }

    url = url.replace('https', 'http');
    notify({message:"Ngrok Started on "+url});

    gutil.log('[ship:server]', url);
  });
}

gulp.task("default", ["server"]);
gulp.task("serve",   ["server"]);
gulp.task("clean",   function(callback) {del(["./"+config.outputFolder+"/**/*"], callback); });

gulp.task("server",  function(callback) {runSequence("clean", "copy-files:watch", "webpack:server", callback); });
gulp.task("build",   function(callback) {runSequence("clean", "copy-files", "webpack:build", callback); });
gulp.task("deploy",  function(callback) {runSequence("build", "publish:sha", callback); });
gulp.task("deploy:release",  function(callback) {runSequence("build", "publish:release", callback); });

var notify = function(message){
  notifier.notify({title: config.displayName+" Gulp", message: message});
};
var handleError = function(err, taskName){
  if(err){
    notify(taskName+" Error: "+ err);
    throw new gutil.PluginError("webpack:build", err);
  }
};
// Copy static files from the source to the destination
var copyFiles = function(callback){
  _.map(config.files, function(dest, src){
    gulp.src(src).pipe(gulp.dest(dest));
  });
  notify("Vendors Updated");
  if (_.isFunction(callback)){
    callback();
  }
};

gulp.task("copy-files", copyFiles);

gulp.task("copy-files:watch", function(){
  copyFiles();
  gulp.watch(_.keys(config.files), copyFiles);
});

//Production Build.
//Minified, clean code. No demo keys inside.
//demo.html WILL NOT WORK with this build.
//
//Webpack handles CSS/SCSS, JS, and HTML files.
var afterBuild = function(err, stats){
  if (!!err) {throw new gutil.PluginError("webpack:build", err); }

  var jsonStats = stats.toJson();

  if (jsonStats.errors.length > 0) {
    return new gutil.PluginError("webpack:build", JSON.stringify(jsonStats.errors));
  }

  if (jsonStats.warnings.length > 0) {
    new gutil.PluginError("webpack:build", JSON.stringify(jsonStats.warnings));
  }

  gutil.log("[webpack:build]", stats.toString({colors: true}));
  notify("App Built");
};
gulp.task("webpack:build", function(callback) {
  // Then, use Webpack to bundle all JS and html files to the destination folder
  notify("Building App");
  webpack(_.values(webpackConfig.production), function(err, stats) {
    afterBuild(err, stats);
    webpack(_.values(webpackConfig.debug), function(err, stats){
      afterBuild(err, stats);
      callback();
    });
  });
});

// Dev Build
// Create the webpack compiler here for caching and performance.
var devCompiler = webpack(webpackConfig.development.browser);

// Build a Dev version of the project. Launched once on startup so we can have eveything copied.
gulp.task("webpack:build:dev", function(callback) {
  // run webpack with Dev profile.
  // Embeds the Hull config keys, and the necessary stuff to make demo.html work
  devCompiler.run(function(err, stats) {
    if (err){
      throw new gutil.PluginError("webpack:build:dev", err);
    }

    var jsonStats = stats.toJson();

    if(jsonStats.errors.length > 0){
      return new gutil.PluginError("webpack:build:dev", JSON.stringify(jsonStats.errors));
    }

    if(jsonStats.warnings.length > 0){
      new gutil.PluginError("webpack:build:dev", JSON.stringify(jsonStats.warnings));
    }

    gutil.log("[webpack:build:dev]", stats.toString({colors: true}));
    notify({message: "Webpack Updated"});
    callback();
  });
});

// Launch webpack dev server.
gulp.task("webpack:server", function() {
  var taskName = "webpack:server";
  new WebpackDevServer(devCompiler, {
    contentBase: config.outputFolder,
    publicPath: config.assetsFolder+"/",
    hot: config.hotReload,
    stats: {colors: true }
  }).listen(config.serverPort, function(err) {
    handleError(err, taskName);
    // Dump the preview URL in the console, and open Chrome when launched for convenience.
    notify({message: "Dev Server Started"});
    var url = webpackConfig.development.browser.output.publicPath+"webpack-dev-server/";
    ngrokServe(config.libName)
    gutil.log("["+taskName+"]", url);
  });
});

var publish = function(versions){
  var aws = config.aws
  var publisher = awspublish.create(aws.config);
  var files  = path.join(config.outputFolder, config.assetsFolder, "*")
  var streams = [];
  var cloudfrontInvalidations = []
  for (var i = 0; i < versions.length; i++) {
    var version = versions[i];
    if(version){
      console.log('Deploying to ',version);
      var plain = gulp.src(files)
      .pipe(rename(function(p){
        p.dirname += '/'+version;
        console.log('Publishing '+path.join(p.dirname,p.basename+p.extname))
      }))
      var gzip = gulp.src(files)
      .pipe(rename(function(p){
        p.dirname += '/'+version;
        console.log('Publishing '+path.join(p.dirname,p.basename+p.extname))
      }))
      .pipe(awspublish.gzip(aws.gzip))
      cloudfrontInvalidations.push('/'+version+'/*');
      streams.push(plain);
      streams.push(gzip);
    }
  };

  var invalidationBatch = {
    CallerReference: new Date().toString(),
    Paths:{
      Quantity:1,
      Items:cloudfrontInvalidations
    }
  }
  return merge.apply(merge,streams)
  .pipe(parallelize(publisher.publish(aws.publish.headers,aws.publish.options)))
  .pipe(publisher.cache())
  .pipe(cloudfront(invalidationBatch, aws.cloudfront))
  .pipe(awspublish.reporter())
}

// Deploys to S3
gulp.task('publish:sha',function(){
  var SHA1 = process.env.CIRCLE_SHA1;
  if( !SHA1 ){ return; }
  return publish([SHA1]);
});

gulp.task('publish:release',function(){
  var SHA1 = process.env.CIRCLE_SHA1;
  var RELEASE = config.pkg.version;
  if( !SHA1 || !RELEASE ){ return; }
  return publish([SHA1,RELEASE]);
});
<|endoftext|>


<commit_before>/*global -$ */
'use strict';
// generated on 2015-06-05 using generator-gulp-webapp 0.3.0
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var del = require('del');
var fs = require('fs');
var semver = require('semver');
var pkg = (function () {
  return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
})();

gulp.task('styles', function () {
  return gulp.src('app/styles/main.scss')
    .pipe($.sourcemaps.init())
    .pipe($.sass({
      outputStyle: 'nested', // libsass doesn't support expanded yet
      precision: 10,
      includePaths: ['.'],
      onError: console.error.bind(console, 'Sass error:')
    }))
    .pipe($.postcss([
      require('autoprefixer-core')({browsers: ['last 4 versions']})
    ]))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/styles'))
    .pipe(reload({stream: true}));
});

gulp.task('jshint', function () {
  return gulp.src('app/scripts/**/*.js')
    .pipe(reload({stream: true, once: true}))
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});

gulp.task('html', ['styles'], function () {
  var assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});

  return gulp.src('app/*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
    .pipe(gulp.dest('dist'));
});

gulp.task('images', function () {
  return gulp.src('app/images/**/*')
    .pipe($.cache($.imagemin({
      progressive: true,
      interlaced: true,
      // don't remove IDs from SVGs, they are often used
      // as hooks for embedding and styling
      svgoPlugins: [{cleanupIDs: false}]
    })))
    .pipe(gulp.dest('dist/images'));
});

gulp.task('fonts', function () {
  return gulp.src(require('main-bower-files')({
    filter: '**/*.{eot,svg,ttf,woff,woff2}'
  }).concat('app/fonts/**/*'))
    .pipe(gulp.dest('.tmp/fonts'))
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('extras', function () {
  return gulp.src([
    'app/*.*',
    'app/CNAME',
    '!app/*.html'
  ], {
    dot: true
  }).pipe(gulp.dest('dist'));
});

gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

gulp.task('serve', ['styles', 'fonts'], function () {
  browserSync({
    notify: false,
    port: 9000,
    server: {
      baseDir: ['.tmp', 'app'],
      routes: {
        '/bower_components': 'bower_components'
      }
    }
  });

  // watch for changes
  gulp.watch([
    'app/*.html',
    'app/scripts/**/*.js',
    'app/images/**/*',
    '.tmp/fonts/**/*'
  ]).on('change', reload);

  gulp.watch('app/styles/**/*.scss', ['styles']);
  gulp.watch('app/fonts/**/*', ['fonts']);
  gulp.watch('bower.json', ['wiredep', 'fonts']);
});

// inject bower components
gulp.task('wiredep', function () {
  var wiredep = require('wiredep').stream;

  gulp.src('app/styles/*.scss')
    .pipe(wiredep({
      ignorePath: /^(\.\.\/)+/
    }))
    .pipe(gulp.dest('app/styles'));

  gulp.src('app/*.html')
    .pipe(wiredep({
      ignorePath: /^(\.\.\/)*\.\./
    }))
    .pipe(gulp.dest('app'));
});

gulp.task('build', ['jshint', 'html', 'images', 'fonts', 'extras'], function () {
  return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});

gulp.task('default', ['clean'], function () {
  gulp.start('build');
});

gulp.task('gitSemver', function () {

  return gulp.src(['app/manifest.json', 'bower.json', 'package.json'])
    .pipe($.git.commit('Update semver to v'+pkg.version))
    .pipe($.git.push('origin', 'master'));
});

// bump versions on package/bower/manifest
gulp.task('bump', function () {

  // increment version
  var newVer = semver.inc(pkg.version, 'patch');

  pkg.version = newVer;

  // uses gulp-filter
  var manifestFilter = $.filter(['manifest.json']);
  var regularJsons = $.filter(['*', '!manifest.json']);

  return gulp.src(['./bower.json', './package.json', './app/manifest.json'])
    .pipe($.bump({
      version: newVer
    }))
    .pipe(manifestFilter)
    .pipe(gulp.dest('./app'))
    .pipe(manifestFilter.restore())
    .pipe(regularJsons)
    .pipe(gulp.dest('./'));
});

gulp.task('upstream', ['build'], function () {

  return gulp.src('dist')
    .pipe($.subtree({
      remote: 'upstream',
      branch: 'master',
      message: 'New build v'+pkg.version
    }))
    .pipe($.clean());
});

gulp.task('deploy', ['clean', 'bump', 'gitSemver'], function () {
  gulp.start('upstream');
});
<commit_msg>add debug for fonts task<commit_after>/*global -$ */
'use strict';
// generated on 2015-06-05 using generator-gulp-webapp 0.3.0
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var del = require('del');
var mainBowerFiles = require('main-bower-files');
var fs = require('fs');
var semver = require('semver');
var pkg = (function () {
  return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
})();

gulp.task('styles', function () {
  return gulp.src('app/styles/main.scss')
    .pipe($.sourcemaps.init())
    .pipe($.sass({
      outputStyle: 'nested', // libsass doesn't support expanded yet
      precision: 10,
      includePaths: ['.'],
      onError: console.error.bind(console, 'Sass error:')
    }))
    .pipe($.postcss([
      require('autoprefixer-core')({browsers: ['last 4 versions']})
    ]))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/styles'))
    .pipe(reload({stream: true}));
});

gulp.task('jshint', function () {
  return gulp.src('app/scripts/**/*.js')
    .pipe(reload({stream: true, once: true}))
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});

gulp.task('html', ['styles'], function () {
  var assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});

  return gulp.src('app/*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
    .pipe(gulp.dest('dist'));
});

gulp.task('images', function () {
  return gulp.src('app/images/**/*')
    .pipe($.cache($.imagemin({
      progressive: true,
      interlaced: true,
      // don't remove IDs from SVGs, they are often used
      // as hooks for embedding and styling
      svgoPlugins: [{cleanupIDs: false}]
    })))
    .pipe(gulp.dest('dist/images'));
});

gulp.task('fonts', function () {
  return gulp.src(mainBowerFiles({
    filter: '**/*.{eot,svg,ttf,woff,woff2}',
    debugging: false
  }).concat('app/fonts/**/*'))
    .pipe(gulp.dest('.tmp/fonts'))
    .pipe(gulp.dest('dist/fonts'));
});

gulp.task('extras', function () {
  return gulp.src([
    'app/*.*',
    'app/CNAME',
    '!app/*.html'
  ], {
    dot: true
  }).pipe(gulp.dest('dist'));
});

gulp.task('clean', del.bind(null, ['.tmp', 'dist']));

gulp.task('serve', ['styles', 'fonts'], function () {
  browserSync({
    notify: false,
    port: 9000,
    server: {
      baseDir: ['.tmp', 'app'],
      routes: {
        '/bower_components': 'bower_components'
      }
    }
  });

  // watch for changes
  gulp.watch([
    'app/*.html',
    'app/scripts/**/*.js',
    'app/images/**/*',
    '.tmp/fonts/**/*'
  ]).on('change', reload);

  gulp.watch('app/styles/**/*.scss', ['styles']);
  gulp.watch('app/fonts/**/*', ['fonts']);
  gulp.watch('bower.json', ['wiredep', 'fonts']);
});

// inject bower components
gulp.task('wiredep', function () {
  var wiredep = require('wiredep').stream;

  gulp.src('app/styles/*.scss')
    .pipe(wiredep({
      ignorePath: /^(\.\.\/)+/
    }))
    .pipe(gulp.dest('app/styles'));

  gulp.src('app/*.html')
    .pipe(wiredep({
      ignorePath: /^(\.\.\/)*\.\./
    }))
    .pipe(gulp.dest('app'));
});

gulp.task('build', ['jshint', 'html', 'images', 'fonts', 'extras'], function () {
  return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});

gulp.task('default', ['clean'], function () {
  gulp.start('build');
});

gulp.task('gitSemver', function () {

  return gulp.src(['app/manifest.json', 'bower.json', 'package.json'])
    .pipe($.git.commit('Update semver to v'+pkg.version))
    .pipe($.git.push('origin', 'master'));
});

// bump versions on package/bower/manifest
gulp.task('bump', function () {

  // increment version
  var newVer = semver.inc(pkg.version, 'patch');

  pkg.version = newVer;

  // uses gulp-filter
  var manifestFilter = $.filter(['manifest.json']);
  var regularJsons = $.filter(['*', '!manifest.json']);

  return gulp.src(['./bower.json', './package.json', './app/manifest.json'])
    .pipe($.bump({
      version: newVer
    }))
    .pipe(manifestFilter)
    .pipe(gulp.dest('./app'))
    .pipe(manifestFilter.restore())
    .pipe(regularJsons)
    .pipe(gulp.dest('./'));
});

gulp.task('upstream', ['build'], function () {

  return gulp.src('dist')
    .pipe($.subtree({
      remote: 'upstream',
      branch: 'master',
      message: 'New build v'+pkg.version
    }))
    .pipe($.clean());
});

gulp.task('deploy', ['clean', 'bump', 'gitSemver'], function () {
  gulp.start('upstream');
});
<|endoftext|>


<commit_before>const gulp = require('gulp');
const less = require('gulp-less');
const pug = require('gulp-pug');
const bower = require('gulp-bower');
const autoprefixer = require('autoprefixer');
const imagemin = require('gulp-imagemin');
const postcss = require('gulp-postcss');
const cleancss = require('gulp-clean-css');
const renamecss = require('gulp-rename');
const sync = require('browser-sync');
const colors = require('colors');
const deploy = "public";

gulp.task('less', function () {
  return gulp.src('views/less/*.less')
    .pipe(less())
    .pipe(gulp.dest('views/css'))
});

gulp.task('prefix', function () {
  return gulp.src('views/css/*.css')
    .pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] })] ))
    .pipe(gulp.dest('views/css'))
});

gulp.task('minify', function() {
  return gulp.src('views/css/*.css')
    .pipe(cleancss())
    .pipe(gulp.dest('views/css'));
});

gulp.task('renamecss', function () {
  return gulp.src('views/css/*.css')
    .pipe(renamecss({extname: ".min.css"}))
    .pipe(gulp.dest(deploy + '/css'))
});

gulp.task('img', function () {
    gulp.src('views/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest(deploy + '/img'))
});

gulp.task('pug', function () {
  return gulp.src('views/pug/*.pug')
    .pipe(pug())
    .pipe(gulp.dest(deploy))
});

gulp.task('bower', function() {
  return bower('bower_modules/')
    .pipe(gulp.dest(deploy))
});

gulp.task('sync', ['img', 'bower', 'less', 'prefix', 'minify', 'renamecss', 'pug'], function() {
  sync({
    server: {
      baseDir: deploy
    }
  });
  gulp.watch('views/img/*', ['img']);
  gulp.watch('views/less/*.less', ['less']);
  gulp.watch('views/css/*.css', ['prefix', 'minify', 'renamecss']);
  gulp.watch('views/pug/*', ['pug']);
  gulp.watch('views/pug/include/*', ['pug']);

  gulp.watch(deploy + '/css/*.css').on('change', sync.reload);
  gulp.watch(deploy + '/*.html').on('change', sync.reload);
  gulp.watch(deploy + '/img/*').on('change', sync.reload);

  return console.log("Sync Successful!".green);
});

gulp.task('build', ['img', 'bower', 'less', 'prefix', 'minify', 'renamecss', 'pug'], function() {
  return console.log("Build Successful!".green);
});
<commit_msg>Add Gulp-Nodemon Function<commit_after>const gulp = require('gulp');
const less = require('gulp-less');
const pug = require('gulp-pug');
const bower = require('gulp-bower');
const autoprefixer = require('autoprefixer');
const imagemin = require('gulp-imagemin');
const postcss = require('gulp-postcss');
const cleancss = require('gulp-clean-css');
const renamecss = require('gulp-rename');
const nodemon = require('gulp-nodemon');
const sync = require('browser-sync');
const colors = require('colors');
const deploy = "public";

gulp.task('pug', function () {
  return gulp.src('views/*.pug')
    .pipe(pug())
    .pipe(gulp.dest(deploy))
});

gulp.task('less', function () {
  return gulp.src('views/less/*.less')
    .pipe(less())
    .pipe(gulp.dest('views/css'))
});

gulp.task('prefix', function () {
  return gulp.src('views/css/*.css')
    .pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] })] ))
    .pipe(gulp.dest('views/css'))
});

gulp.task('minify', function() {
  return gulp.src('views/css/*.css')
    .pipe(cleancss())
    .pipe(gulp.dest('views/css'));
});

gulp.task('renamecss', function () {
  return gulp.src('views/css/*.css')
    .pipe(renamecss({extname: ".min.css"}))
    .pipe(gulp.dest(deploy + '/css'))
});

gulp.task('img', function () {
    gulp.src('views/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest(deploy + '/img'))
});

gulp.task('bower', function() {
  return bower('bower_modules/')
    .pipe(gulp.dest(deploy))
});

gulp.task('nodemon', function(cb) {
  return nodemon({
      script: './bin/www'
      // script: './bin/www/app.js'
    })
    .on('start', function () {
      cb();
    })
    .on('error', function(err) {
     throw err;
   });
});

gulp.task('sync', ['nodemon'], function() {
  sync({
    server: {
      baseDir: deploy
    }
  });
  gulp.watch('views/*.pug', ['pug']);
  gulp.watch('views/img/*', ['img']);
  gulp.watch('views/less/*.less', ['less']);
  gulp.watch('views/css/*.css', ['prefix', 'minify', 'renamecss']);
  gulp.watch(deploy + '/css/*.css').on('change', sync.reload);
  gulp.watch(deploy + '/*.html').on('change', sync.reload);
  gulp.watch(deploy + '/img/*').on('change', sync.reload);

  return console.log("Sync Successful!".green);
});

gulp.task('build', ['pug', 'img', 'bower', 'less', 'prefix', 'minify', 'renamecss'], function() {
  return console.log("Build Successful!".green);
});
<|endoftext|>