<commit_before>'use strict'

const path = require('path')
const fs = require('fs-promise')

const gulp = require('gulp')
const execa = require('execa')
const lodash = require('lodash')
const request = require('request')
const revHash = require('rev-hash')
const archiver = require('archiver')
const uglifyJS = require('uglify-js')
const babelCore = require('babel-core')
const scriptTags = require('script-tags')
const prettyBytes = require('pretty-bytes')
const browserSync = require('browser-sync').create()
const htmlMinifier = require('html-minifier')
const minifyHtml = html => htmlMinifier.minify(html, {
  collapseWhitespace: true,
  conservativeCollapse: true,
  minifyCSS: true,
  minifyJS: true,
  removeComments: true,
  removeRedundantAttributes: true,
  sortAttributes: true,
  sortClassName: true
})

const debug = require('./src/compile/debug.js')
const paths = require('./src/compile/paths.js')
const config = require('./src/compile/config.js')
const articles = require('./src/compile/articles.js')
const nunjucksEnv = require('./src/compile/nunjucks/env.js')

if (!process.env.CI) { // Travis adds this env variable
  debug()
}

//
//
// Local state
//
//

let nunjucks = nunjucksEnv(false)
let productionBuild = false

//
//
// Site compilation
//
//

gulp.task('site:prepare-dirs', done => {
  fs.remove(paths.dist)
    .then(() => {
      return fs.mkdir(paths.dist)
    })
    .then(() => {
      return Promise.all([
        fs.mkdir(paths.distDrafts),
        fs.mkdir(paths.distStatic)
      ])
    })
    .then(() => {
      return Promise.all([
        fs.mkdir(paths.distImages),
        fs.mkdir(paths.distStyles),
        fs.mkdir(paths.distScripts)
      ])
    })
    .then(() => done())
})

gulp.task('site:static-pages', done => {
  const pages = [
    { from: '404.njk', to: '404.html' },
    { from: 'robots.txt.njk', to: 'robots.txt' }
  ]

  for (const page of pages) {
    let html = nunjucks.render(page.from)
    if (productionBuild) {
      html = minifyHtml(html)
    }

    fs.writeFile(path.join(paths.dist, page.to), html)
      .then(done)
  }
})

gulp.task('site:styles', done => {
  if (!productionBuild) {
    fs.remove(paths.distStyles)
      .then(() => fs.symlink(paths.styles, paths.distStyles))
      .then(() => done())
    return
  }

  var postCss = require('postcss')
  var postCssImport = require('postcss-import')
  var postCssNext = require('postcss-cssnext')
  var cssnano = require('cssnano')

  const from = path.join(paths.styles, 'styles.css')

  postCss([
    postCssImport(),
    postCssNext({ browsers: config.supportedBrowsers }),
    cssnano({ autoprefixer: false })
  ])
    .process(fs.readFileSync(from, 'utf8'), {
      from: from,
      map: {
        inline: false,
        annotation: 'styles.map.css'
      }
    })
    .then(function (result) {
      const hashCss = revHash(Buffer.from(result.css))
      nunjucks.addGlobal('hashCss', hashCss)

      fs.writeFileSync(path.join(paths.distStyles, `styles-${hashCss}.css`), result.css)
      fs.writeFileSync(path.join(paths.distStyles, 'styles.map.css'), result.map)

      done()
    })
})

gulp.task('site:scripts', done => {
  if (!productionBuild) {
    fs.remove(paths.distScripts)
      .then(() => fs.symlink(paths.scripts, paths.distScripts))
      .then(() => done())
    return
  }

  const baseTemplate = fs.readFileSync(path.join(paths.templates, '/extends/base.njk'), 'utf8')

  let code = scriptTags(baseTemplate)
  code = lodash.filter(code, script => script.attrs.src)
  code = lodash.filter(code, script => 'data-dev' in script.attrs)
  code = lodash.map(code, script => script.attrs.src)
  code = lodash.map(code, src => path.join(paths.src, src))
  code = lodash.map(code, path => fs.readFileSync(path, 'utf8'))
  code = lodash.join(code, ';\n')
  code = babelCore.transform(code, {
    presets: [
      ['env', {
        targets: { browsers: config.supportedBrowsers },
        loose: true
      }]
    ]
  }).code
  code = uglifyJS.minify(code, { fromString: true }).code

  const hashJs = revHash(Buffer.from(code))
  nunjucks.addGlobal('hashJs', hashJs)

  fs.writeFileSync(path.join(paths.distScripts, `scripts-${hashJs}.js`), code)

  done()
})

gulp.task('site:images', done => {
  if (productionBuild) {
    fs.copy(paths.images, paths.distImages)
      .then(() => done())
  } else {
    fs.remove(paths.distImages)
      .then(() => fs.symlink(paths.images, paths.distImages))
      .then(() => done())
  }
})

gulp.task('site:node-modules', done => {
  if (!productionBuild) {
    fs.symlink(paths.nodeModules, paths.distNodeModules)
      .then(() => done())
  } else {
    done()
  }
})

gulp.task('site:articles', done => {
  // gather articles data
  let articlesData = articles.getArticles(paths.articles, paths.articlesDrafts, nunjucks)
  articlesData = lodash.sortBy(articlesData, 'metadata.dateLastUpdate')
  articlesData = articlesData.reverse()

  let articlesPublishedData = lodash.filter(articlesData, article => article.metadata.published === true)
  articlesPublishedData = lodash.filter(articlesPublishedData, article => article.metadata.dateLastUpdate <= new Date())

  // index page
  const indexArticles = lodash.slice(articlesPublishedData, 0, config.articles.perPage)
  let htmlIndex = nunjucks.render('index.njk', {articles: indexArticles})
  if (productionBuild) {
    htmlIndex = minifyHtml(htmlIndex)
  }

  fs.writeFileSync(path.join(paths.dist, 'index.html'), htmlIndex)

  // articles
  const articlePromises = []
  for (const article of articlesData) {
    // article directory
    const folder = path.join(
      article.metadata.published ? paths.dist : paths.distDrafts,
      article.metadata.url
    )

    const promise = fs.mkdir(folder)
      .then(() => {
        // article html
        let htmlArticle = nunjucks.render('article.njk', article)
        if (productionBuild) {
          htmlArticle = minifyHtml(htmlArticle)
        }

        const promiseHtml = fs.writeFile(path.join(folder, 'index.html'), htmlArticle)
        let promiseImages
        let promiseSnippets
        if (productionBuild) {
          const imagesPath = path.join(article.fs.path, paths.articleImages)
          if (fs.existsSync(imagesPath)) {
            promiseImages = fs.copy(imagesPath, path.join(folder, paths.articleImages))
          }

          const snippetsPath = path.join(article.fs.path, paths.articleSnippets)
          if (fs.existsSync(snippetsPath)) {
            promiseSnippets = fs.copy(snippetsPath, path.join(folder, paths.articleSnippets))
          }
        } else {
          promiseImages = fs.symlink(
            path.join(article.fs.path, paths.articleImages),
            path.join(folder, paths.articleImages)
          )
          promiseSnippets = fs.symlink(
            path.join(article.fs.path, paths.articleSnippets),
            path.join(folder, paths.articleSnippets)
          )
        }

        return Promise.all([
          promiseHtml,
          promiseImages,
          promiseSnippets
        ])
      })

    articlePromises.push(promise)
  }

  const rssPromise = Promise.resolve()
    .then(() => {
      const rssArticles = lodash.slice(articlesData, 0, config.articles.perRssFeed)
      const rssFeed = nunjucks.render('rss.njk', {articles: rssArticles})

      return fs.writeFile(path.join(paths.dist, 'rss.xml'), rssFeed)
    })

  const humansTxtPromise = Promise.resolve()
    .then(() => {
      const lastUpdate = articlesPublishedData[0].metadata.dateLastUpdate
      const humansTxt = nunjucks.render('humans.txt.njk', {lastUpdate: lastUpdate})

      return fs.writeFileSync(path.join(paths.dist, 'humans.txt'), humansTxt)
    })

  Promise.all([
    articlePromises,
    rssPromise,
    humansTxtPromise
  ]).then(() => done())
})

gulp.task('site:deploy', done => {
  const archive = archiver('zip')

  archive.on('error', err => {
    console.error(err)
    done()
  })

  const logFileSize = archive => {
    console.log('archive size:', prettyBytes(archive.pointer()))
  }

  if (productionBuild) {
    archive.pipe(
      request({
        method: 'POST',
        url: 'https://api.netlify.com/api/v1/sites/hurtak.netlify.com/deploys',
        headers: {
          'Content-Type': 'application/zip',
          Authorization: `Bearer ${process.env.NETLIFY_ACCESS_TOKEN}`
        }
      }, (error, _, body) => {
        logFileSize(archive)
        if (error) {
          console.error('upload failed:', error)
        } else {
          console.log('upload successful, server responded with:', body)
        }
        done()
      })
    )
  } else {
    const writeStream = fs.createWriteStream(path.join(paths.dist, 'site.zip'))
    writeStream.on('close', () => {
      logFileSize(archive)
      done()
    })
    archive.pipe(writeStream)
  }

  archive.directory(paths.dist, '/')
  archive.finalize()
})

gulp.task('site:compile',
  gulp.series(
    'site:prepare-dirs',
    gulp.parallel(
      'site:static-pages',
      'site:styles',
      'site:scripts',
      'site:images',
      'site:node-modules',
      'site:articles'
    )
  )
)

gulp.task('site:compile:dist',
  gulp.series(
    'site:prepare-dirs',
    gulp.parallel(
      gulp.series(
        gulp.parallel(
          'site:styles',
          'site:scripts'
        ),
        gulp.parallel(
          'site:static-pages',
          'site:articles'
        )
      ),
      'site:images'
    )
  )
)

//
//
// Browser sync
//
//

gulp.task('browser-sync:server', done => {
  browserSync.init({
    server: './dist',
    port: 8000,
    open: false,
    https: true,
    reloadOnRestart: true
  }, done)
})

gulp.task('browser-sync:reload-browser', done => {
  browserSync.reload()
  done()
})

//
//
// Tests
//
//

gulp.task('test:unit', done => {
  execa.shell('ava src/test/**/*.js')
    .then(() => done())
    .catch((res) => {
      console.log(res.stderr)
      done()
    })
})

gulp.task('test:lint', done => {
  execa.shell('standard --verbose "scripts/**/*.js" "src/**/*.js"')
    .then(() => done())
    .catch((res) => {
      console.log(res.stdout)
      done()
    })
})

gulp.task('test:coverage', done => {
  execa.shell('nyc --all --include="src" --exclude="src/test" ava src/test/**/*.js')
    .then(() => done())
    .catch((res) => {
      console.log(res.stderr)
      done()
    })
})

gulp.task('test:coverage-report', done => {
  execa.shell('nyc report --reporter=lcov')
    .then(() => done())
})

gulp.task('test:coveralls', done => {
  execa.shell('nyc report --reporter=text-lcov | coveralls')
    .then(() => done())
})

gulp.task('test:collection:all', gulp.parallel(
  'test:lint',
  gulp.series('test:unit', 'test:coverage', 'test:coverage-report')
))

//
//
// Watches
//
//

gulp.task('watch:articles', () =>
  gulp.watch(['./articles/**/*', './src/**/*'],
    gulp.series(
      'site:compile',
      'browser-sync:reload-browser'
    )
))

gulp.task('watch:test', () =>
  gulp.watch(['./src/**/*.js'], gulp.series('test:collection:all')
))

//
//
// Main tasks
//
//

gulp.task('env:production', done => {
  productionBuild = true
  nunjucks = nunjucksEnv(productionBuild)
  done()
})

gulp.task('dev',
  gulp.parallel(
    gulp.series('site:compile', 'browser-sync:server'),
    'test:collection:all',
    'watch:articles',
    'watch:test'
  )
)

gulp.task('dist',
  gulp.series(
    'env:production',
    gulp.parallel(
      gulp.series('site:compile:dist', 'browser-sync:server'),
      'test:collection:all',
      'watch:articles',
      'watch:test'
    )
  )
)

gulp.task('default', gulp.series('dev'))

//
//
// Continuous integration tasks
//
//

gulp.task('ci:test', gulp.series(
  'test:unit',
  'site:compile'
))

gulp.task('ci:deploy', gulp.series(
  'env:production',
  'test:coverage',
  'site:compile:dist',
  'site:deploy',
  'test:coveralls'
))
<commit_msg>build: better name for test tasks<commit_after>'use strict'

const path = require('path')
const fs = require('fs-promise')

const gulp = require('gulp')
const execa = require('execa')
const lodash = require('lodash')
const request = require('request')
const revHash = require('rev-hash')
const archiver = require('archiver')
const uglifyJS = require('uglify-js')
const babelCore = require('babel-core')
const scriptTags = require('script-tags')
const prettyBytes = require('pretty-bytes')
const browserSync = require('browser-sync').create()
const htmlMinifier = require('html-minifier')
const minifyHtml = html => htmlMinifier.minify(html, {
  collapseWhitespace: true,
  conservativeCollapse: true,
  minifyCSS: true,
  minifyJS: true,
  removeComments: true,
  removeRedundantAttributes: true,
  sortAttributes: true,
  sortClassName: true
})

const debug = require('./src/compile/debug.js')
const paths = require('./src/compile/paths.js')
const config = require('./src/compile/config.js')
const articles = require('./src/compile/articles.js')
const nunjucksEnv = require('./src/compile/nunjucks/env.js')

if (!process.env.CI) { // Travis adds this env variable
  debug()
}

//
//
// Local state
//
//

let nunjucks = nunjucksEnv(false)
let productionBuild = false

//
//
// Site compilation
//
//

gulp.task('site:prepare-dirs', done => {
  fs.remove(paths.dist)
    .then(() => {
      return fs.mkdir(paths.dist)
    })
    .then(() => {
      return Promise.all([
        fs.mkdir(paths.distDrafts),
        fs.mkdir(paths.distStatic)
      ])
    })
    .then(() => {
      return Promise.all([
        fs.mkdir(paths.distImages),
        fs.mkdir(paths.distStyles),
        fs.mkdir(paths.distScripts)
      ])
    })
    .then(() => done())
})

gulp.task('site:static-pages', done => {
  const pages = [
    { from: '404.njk', to: '404.html' },
    { from: 'robots.txt.njk', to: 'robots.txt' }
  ]

  for (const page of pages) {
    let html = nunjucks.render(page.from)
    if (productionBuild) {
      html = minifyHtml(html)
    }

    fs.writeFile(path.join(paths.dist, page.to), html)
      .then(done)
  }
})

gulp.task('site:styles', done => {
  if (!productionBuild) {
    fs.remove(paths.distStyles)
      .then(() => fs.symlink(paths.styles, paths.distStyles))
      .then(() => done())
    return
  }

  var postCss = require('postcss')
  var postCssImport = require('postcss-import')
  var postCssNext = require('postcss-cssnext')
  var cssnano = require('cssnano')

  const from = path.join(paths.styles, 'styles.css')

  postCss([
    postCssImport(),
    postCssNext({ browsers: config.supportedBrowsers }),
    cssnano({ autoprefixer: false })
  ])
    .process(fs.readFileSync(from, 'utf8'), {
      from: from,
      map: {
        inline: false,
        annotation: 'styles.map.css'
      }
    })
    .then(function (result) {
      const hashCss = revHash(Buffer.from(result.css))
      nunjucks.addGlobal('hashCss', hashCss)

      fs.writeFileSync(path.join(paths.distStyles, `styles-${hashCss}.css`), result.css)
      fs.writeFileSync(path.join(paths.distStyles, 'styles.map.css'), result.map)

      done()
    })
})

gulp.task('site:scripts', done => {
  if (!productionBuild) {
    fs.remove(paths.distScripts)
      .then(() => fs.symlink(paths.scripts, paths.distScripts))
      .then(() => done())
    return
  }

  const baseTemplate = fs.readFileSync(path.join(paths.templates, '/extends/base.njk'), 'utf8')

  let code = scriptTags(baseTemplate)
  code = lodash.filter(code, script => script.attrs.src)
  code = lodash.filter(code, script => 'data-dev' in script.attrs)
  code = lodash.map(code, script => script.attrs.src)
  code = lodash.map(code, src => path.join(paths.src, src))
  code = lodash.map(code, path => fs.readFileSync(path, 'utf8'))
  code = lodash.join(code, ';\n')
  code = babelCore.transform(code, {
    presets: [
      ['env', {
        targets: { browsers: config.supportedBrowsers },
        loose: true
      }]
    ]
  }).code
  code = uglifyJS.minify(code, { fromString: true }).code

  const hashJs = revHash(Buffer.from(code))
  nunjucks.addGlobal('hashJs', hashJs)

  fs.writeFileSync(path.join(paths.distScripts, `scripts-${hashJs}.js`), code)

  done()
})

gulp.task('site:images', done => {
  if (productionBuild) {
    fs.copy(paths.images, paths.distImages)
      .then(() => done())
  } else {
    fs.remove(paths.distImages)
      .then(() => fs.symlink(paths.images, paths.distImages))
      .then(() => done())
  }
})

gulp.task('site:node-modules', done => {
  if (!productionBuild) {
    fs.symlink(paths.nodeModules, paths.distNodeModules)
      .then(() => done())
  } else {
    done()
  }
})

gulp.task('site:articles', done => {
  // gather articles data
  let articlesData = articles.getArticles(paths.articles, paths.articlesDrafts, nunjucks)
  articlesData = lodash.sortBy(articlesData, 'metadata.dateLastUpdate')
  articlesData = articlesData.reverse()

  let articlesPublishedData = lodash.filter(articlesData, article => article.metadata.published === true)
  articlesPublishedData = lodash.filter(articlesPublishedData, article => article.metadata.dateLastUpdate <= new Date())

  // index page
  const indexArticles = lodash.slice(articlesPublishedData, 0, config.articles.perPage)
  let htmlIndex = nunjucks.render('index.njk', {articles: indexArticles})
  if (productionBuild) {
    htmlIndex = minifyHtml(htmlIndex)
  }

  fs.writeFileSync(path.join(paths.dist, 'index.html'), htmlIndex)

  // articles
  const articlePromises = []
  for (const article of articlesData) {
    // article directory
    const folder = path.join(
      article.metadata.published ? paths.dist : paths.distDrafts,
      article.metadata.url
    )

    const promise = fs.mkdir(folder)
      .then(() => {
        // article html
        let htmlArticle = nunjucks.render('article.njk', article)
        if (productionBuild) {
          htmlArticle = minifyHtml(htmlArticle)
        }

        const promiseHtml = fs.writeFile(path.join(folder, 'index.html'), htmlArticle)
        let promiseImages
        let promiseSnippets
        if (productionBuild) {
          const imagesPath = path.join(article.fs.path, paths.articleImages)
          if (fs.existsSync(imagesPath)) {
            promiseImages = fs.copy(imagesPath, path.join(folder, paths.articleImages))
          }

          const snippetsPath = path.join(article.fs.path, paths.articleSnippets)
          if (fs.existsSync(snippetsPath)) {
            promiseSnippets = fs.copy(snippetsPath, path.join(folder, paths.articleSnippets))
          }
        } else {
          promiseImages = fs.symlink(
            path.join(article.fs.path, paths.articleImages),
            path.join(folder, paths.articleImages)
          )
          promiseSnippets = fs.symlink(
            path.join(article.fs.path, paths.articleSnippets),
            path.join(folder, paths.articleSnippets)
          )
        }

        return Promise.all([
          promiseHtml,
          promiseImages,
          promiseSnippets
        ])
      })

    articlePromises.push(promise)
  }

  const rssPromise = Promise.resolve()
    .then(() => {
      const rssArticles = lodash.slice(articlesData, 0, config.articles.perRssFeed)
      const rssFeed = nunjucks.render('rss.njk', {articles: rssArticles})

      return fs.writeFile(path.join(paths.dist, 'rss.xml'), rssFeed)
    })

  const humansTxtPromise = Promise.resolve()
    .then(() => {
      const lastUpdate = articlesPublishedData[0].metadata.dateLastUpdate
      const humansTxt = nunjucks.render('humans.txt.njk', {lastUpdate: lastUpdate})

      return fs.writeFileSync(path.join(paths.dist, 'humans.txt'), humansTxt)
    })

  Promise.all([
    articlePromises,
    rssPromise,
    humansTxtPromise
  ]).then(() => done())
})

gulp.task('site:deploy', done => {
  const archive = archiver('zip')

  archive.on('error', err => {
    console.error(err)
    done()
  })

  const logFileSize = archive => {
    console.log('archive size:', prettyBytes(archive.pointer()))
  }

  if (productionBuild) {
    archive.pipe(
      request({
        method: 'POST',
        url: 'https://api.netlify.com/api/v1/sites/hurtak.netlify.com/deploys',
        headers: {
          'Content-Type': 'application/zip',
          Authorization: `Bearer ${process.env.NETLIFY_ACCESS_TOKEN}`
        }
      }, (error, _, body) => {
        logFileSize(archive)
        if (error) {
          console.error('upload failed:', error)
        } else {
          console.log('upload successful, server responded with:', body)
        }
        done()
      })
    )
  } else {
    const writeStream = fs.createWriteStream(path.join(paths.dist, 'site.zip'))
    writeStream.on('close', () => {
      logFileSize(archive)
      done()
    })
    archive.pipe(writeStream)
  }

  archive.directory(paths.dist, '/')
  archive.finalize()
})

gulp.task('site:compile',
  gulp.series(
    'site:prepare-dirs',
    gulp.parallel(
      'site:static-pages',
      'site:styles',
      'site:scripts',
      'site:images',
      'site:node-modules',
      'site:articles'
    )
  )
)

gulp.task('site:compile:dist',
  gulp.series(
    'site:prepare-dirs',
    gulp.parallel(
      gulp.series(
        gulp.parallel(
          'site:styles',
          'site:scripts'
        ),
        gulp.parallel(
          'site:static-pages',
          'site:articles'
        )
      ),
      'site:images'
    )
  )
)

//
//
// Browser sync
//
//

gulp.task('browser-sync:server', done => {
  browserSync.init({
    server: './dist',
    port: 8000,
    open: false,
    https: true,
    reloadOnRestart: true
  }, done)
})

gulp.task('browser-sync:reload-browser', done => {
  browserSync.reload()
  done()
})

//
//
// Tests
//
//

gulp.task('test:unit', done => {
  execa.shell('ava src/test/**/*.js')
    .then(() => done())
    .catch((res) => {
      console.log(res.stderr)
      done()
    })
})

gulp.task('test:lint', done => {
  execa.shell('standard --verbose "scripts/**/*.js" "src/**/*.js"')
    .then(() => done())
    .catch((res) => {
      console.log(res.stdout)
      done()
    })
})

gulp.task('test:coverage', done => {
  execa.shell('nyc --all --include="src" --exclude="src/test" ava src/test/**/*.js')
    .then(() => done())
    .catch((res) => {
      console.log(res.stderr)
      done()
    })
})

gulp.task('test:coverage-report', done => {
  execa.shell('nyc report --reporter=lcov')
    .then(() => done())
})

gulp.task('test:coveralls', done => {
  execa.shell('nyc report --reporter=text-lcov | coveralls')
    .then(() => done())
})

gulp.task('test:all', gulp.parallel(
  'test:lint',
  gulp.series('test:unit', 'test:coverage', 'test:coverage-report')
))

//
//
// Watches
//
//

gulp.task('watch:articles', () =>
  gulp.watch(['./articles/**/*', './src/**/*'],
    gulp.series(
      'site:compile',
      'browser-sync:reload-browser'
    )
))

gulp.task('watch:test', () =>
  gulp.watch(['./src/**/*.js'], gulp.series('test:all')
))

//
//
// Main tasks
//
//

gulp.task('env:production', done => {
  productionBuild = true
  nunjucks = nunjucksEnv(productionBuild)
  done()
})

gulp.task('dev',
  gulp.parallel(
    gulp.series('site:compile', 'browser-sync:server'),
    'test:all',
    'watch:articles',
    'watch:test'
  )
)

gulp.task('dist',
  gulp.series(
    'env:production',
    gulp.parallel(
      gulp.series('site:compile:dist', 'browser-sync:server'),
      'test:all',
      'watch:articles',
      'watch:test'
    )
  )
)

gulp.task('default', gulp.series('dev'))

//
//
// Continuous integration tasks
//
//

gulp.task('ci:test', gulp.series(
  'test:unit',
  'site:compile'
))

gulp.task('ci:deploy', gulp.series(
  'env:production',
  'test:coverage',
  'site:compile:dist',
  'site:deploy',
  'test:coveralls'
))
<|endoftext|>


<commit_before>/* global require, Promise, Buffer */
var gulp = require("gulp"),
	minify = require("gulp-uglify"),
	htmlmin = require("gulp-html-minifier2"),
	livereload = require("gulp-livereload"),
	iife = require("gulp-iife"),
	through2 = require("through2"),
	fs = require("fs-extra"),
	del = require("del");

gulp.task("build-popup.html", function(){
	gulp.src("src/popup.html").pipe(htmlmin({
		removeComments: true,
		removeCommentsFromCDATA: true,
		collapseWhitespace: true
	})).pipe(through2.obj(function(file, enc, callback){
		var text = file.contents.toString();
		text = text.replace("js/angular.js", "js/angular.min.js");
		file.contents = new Buffer(text);
		callback(null, file);
	})).pipe(gulp.dest("dist"));
});

gulp.task("copy-static", function() {
	gulp.src("src/img/*").pipe(gulp.dest("dist/img"));
	gulp.src("src/css/*").pipe(gulp.dest("dist/css"));
	gulp.src("src/js/angular.min.js").pipe(gulp.dest("dist/js"));
});

gulp.task("build-popup.js", function(){
	gulp.src("src/js/popup.js")
		.pipe(iife())
		.pipe(minify())
		.pipe(gulp.dest("dist/js"));
});

gulp.task("build", ["copy-static", "build-popup.js", "build-popup.html"], function(){
	var manifest = fs.readJsonSync("src/manifest.json");
	// remove livereload.js
	manifest.background.scripts.pop();
	fs.writeJsonSync("dist/manifest.json", manifest);
	return gulp.src("src/js/background.js")
		.pipe(iife())
		.pipe(minify())
		.pipe(gulp.dest("dist/js"));
});

gulp.task("reload", function(){
	gulp.src("src/manifest.json").pipe(livereload());
});

gulp.task("watch", function() {
	livereload.listen();
	gulp.watch([
		"src/js/*.js",
		"src/css/*.css",
		"src/*.html",
		"src/manifest.json"
	], ["reload"]);
});

gulp.task("clean", function(){
	del.sync("dist/**/*");
});

gulp.task("default", ["watch"]);
<commit_msg>add disable max-len comment<commit_after>/* global require, Promise, Buffer */
var gulp = require("gulp"),
	minify = require("gulp-uglify"),
	htmlmin = require("gulp-html-minifier2"),
	livereload = require("gulp-livereload"),
	iife = require("gulp-iife"),
	through2 = require("through2"),
	fs = require("fs-extra"),
	del = require("del");

gulp.task("build-popup.html", function(){
	gulp.src("src/popup.html").pipe(htmlmin({
		removeComments: true,
		removeCommentsFromCDATA: true,
		collapseWhitespace: true
	})).pipe(through2.obj(function(file, enc, callback){
		var text = file.contents.toString();
		text = text.replace("js/angular.js", "js/angular.min.js");
		file.contents = new Buffer(text);
		callback(null, file);
	})).pipe(gulp.dest("dist"));
});

gulp.task("copy-static", function() {
	gulp.src("src/img/*").pipe(gulp.dest("dist/img"));
	gulp.src("src/css/*").pipe(gulp.dest("dist/css"));
	gulp.src("src/js/angular.min.js").pipe(gulp.dest("dist/js"));
});

gulp.task("build-popup.js", function(){
	gulp.src("src/js/popup.js")
		.pipe(iife())
		.pipe(minify())
		.pipe(gulp.dest("dist/js"));
});

// eslint-disable-next-line max-len
gulp.task("build", ["copy-static", "build-popup.js", "build-popup.html"], function(){
	var manifest = fs.readJsonSync("src/manifest.json");
	// remove livereload.js
	manifest.background.scripts.pop();
	fs.writeJsonSync("dist/manifest.json", manifest);
	return gulp.src("src/js/background.js")
		.pipe(iife())
		.pipe(minify())
		.pipe(gulp.dest("dist/js"));
});

gulp.task("reload", function(){
	gulp.src("src/manifest.json").pipe(livereload());
});

gulp.task("watch", function() {
	livereload.listen();
	gulp.watch([
		"src/js/*.js",
		"src/css/*.css",
		"src/*.html",
		"src/manifest.json"
	], ["reload"]);
});

gulp.task("clean", function(){
	del.sync("dist/**/*");
});

gulp.task("default", ["watch"]);
<|endoftext|>


<commit_before>var gulp = require( 'gulp' ),
    gutil = require('gulp-util'),
    huxley = require( './index' ),
    SeleniumServer = require('selenium-webdriver/remote').SeleniumServer,
    jar = require('selenium-server-standalone-jar'),
    HttpServer = require('http-server');

var selenium = null;

gulp.task('http', function() {
    HttpServer.createServer().listen(8000);
});

gulp.task('selenium', function() {
    selenium = new SeleniumServer(jar.path, {
        port: 4444
    });
    selenium.start();
});

gulp.task( 'test', ['selenium'], function() {
  gulp.src('./test/**/Huxleyfile.json')
    .pipe( huxley( {
        action: 'record',
        browser: 'chrome',
        server: selenium.address()
    } ) );
});

gulp.task( 'default', [ 'http', 'test' ] );
<commit_msg>Syntax inconsistencies.<commit_after>var gulp = require( 'gulp' ),
    gutil = require('gulp-util'),
    huxley = require( './index' ),
    SeleniumServer = require('selenium-webdriver/remote').SeleniumServer,
    jar = require('selenium-server-standalone-jar'),
    HttpServer = require('http-server');

var selenium = null;

gulp.task( 'http', function() {
  HttpServer.createServer().listen( 8000 );
} );

gulp.task( 'selenium', function() {
  selenium = new SeleniumServer( jar.path, { });
  selenium.start();
} );

gulp.task( 'test', [ 'selenium' ], function() {
  gulp.src( './test/**/Huxleyfile.json' )
  .pipe( huxley( {
    action: 'record',
    browser: 'chrome',
    server: selenium.address()
  } ) );
});

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


<commit_before>'use strict';

const gulp            = require('gulp');
const webpackStream   = require('webpack-stream');
const webpack         = require('webpack');
const webpackConfig   = require('./webpack.config.js');
const zip             = require('gulp-zip');
const clean           = require('gulp-clean');
const runSequence     = require('run-sequence');

const TARGET_DIR              = 'chrome';
const TARGET_UGLIFIED_DIR     = 'chrome_uglified';

// CLEAN
gulp.task('clean', function () {
  return gulp.src(`${TARGET_DIR}/`, {read: false})
    .pipe(clean());
});

// CLEAN UGLIFIED
gulp.task('clean-production', function () {
  return gulp.src(`${TARGET_UGLIFIED_DIR}/`, {read: false})
    .pipe(clean());
});

// IMAGES
gulp.task('images', function() {
  return gulp.src('./assets/images/**/*.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/images/`));
});

// IMAGES FOR UGLIFIED
gulp.task('images-production', function() {
  return gulp.src('./assets/images/**/*.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/images/`));
});

// LIB
gulp.task('lib', function() {
  return gulp.src('./assets/lib/**/*.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/lib/`));
});

// LIB FOR UGLIFIED
gulp.task('lib-production', function() {
  return gulp.src('./assets/lib/**/*.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/lib/`));
});

// HTML
gulp.task('html', function() {
  return gulp.src('./assets/**.html')
    .pipe(gulp.dest(`./${TARGET_DIR}`));
});

// HTML FOR UGLIFIED
gulp.task('html-production', function() {
  return gulp.src('./assets/*.html')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}`));
});

// FAVICON
gulp.task('favicon', function() {
  return gulp.src('./assets/images/favicon/dev/**.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/images/favicon/`));
});

// FAVICON FOR UGLIFIED
gulp.task('favicon-production', function() {
  return gulp.src('./assets/images/favicon/production/**.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/images/favicon/`));
});

// MANIFEST
gulp.task('manifest', function() {
  return gulp.src('./assets/manifest.json')
    .pipe(gulp.dest(`./${TARGET_DIR}`));
});

// MANIFEST FOR UGLIFIED
gulp.task('manifest-production', function() {
  return gulp.src('./assets/manifest.json')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}`));
});

// MOVE FOR DEV
gulp.task('move', ['images', 'lib', 'html', 'favicon', 'manifest']);

// MOVE FOR UGLIFIED
gulp.task('move-production', ['images-production', 'lib-production', 'html-production', 'favicon-production', 'manifest-production']);

// WEBPACK
gulp.task('webpack', function() {
  // PACK NON-UGLIFIED
  return gulp.src('./assets')
    .pipe(webpackStream(webpackConfig.debug, webpack))
    .pipe(gulp.dest(`./${TARGET_DIR}/public/js`));
});

// WEBPACK FOR UGLIFIED
gulp.task('webpack-production', function() {
  // PACK PROD UGLIFIED
  return gulp.src('./assets')
    .pipe(webpackStream(webpackConfig.uglified, webpack))
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/js`));
});

/*
* UNUGLIFIED BUILD PROCESS
*
* $ gulp dev
*/
gulp.task('dev', function() {
  runSequence('clean', 'move', 'webpack');

  gulp.watch('./assets/**/*', ['webpack']);
  gulp.watch('./assets/**.html', ['html']);
  gulp.watch('./assets/manifest.json', ['manifest']);

  console.log('Watching...');
});

/*
* UGLIFIED BUILD PROCESS
*
* $ gulp
*/
gulp.task('default', function() {
  runSequence('clean-production', 'move-production', 'webpack-production', 'zip');
});

// ZIP UP THE UGLIFIED VERSION
gulp.task('zip', function() {
  return gulp.src(`./${TARGET_UGLIFIED_DIR}/**/*`)
    .pipe(zip('chrome_extension.zip'))
    .pipe(gulp.dest('./'));
});

/*
* SET ENVIRONMENT
*
*/

// gulp.task('production-env', function() {
//   return process.env.NODE_ENV = 'production';
// });

module.exports = gulp;<commit_msg>zippable non-uglified<commit_after>'use strict';

const gulp            = require('gulp');
const webpackStream   = require('webpack-stream');
const webpack         = require('webpack');
const webpackConfig   = require('./webpack.config.js');
const zip             = require('gulp-zip');
const clean           = require('gulp-clean');
const runSequence     = require('run-sequence');

const TARGET_DIR              = 'chrome';
const TARGET_UGLIFIED_DIR     = 'chrome_uglified';

// CLEAN
gulp.task('clean', function () {
  return gulp.src(`${TARGET_DIR}/`, {read: false})
    .pipe(clean());
});

// CLEAN UGLIFIED
gulp.task('clean-uglified', function () {
  return gulp.src(`${TARGET_UGLIFIED_DIR}/`, {read: false})
    .pipe(clean());
});

// IMAGES
gulp.task('images', function() {
  return gulp.src('./assets/images/**/*.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/images/`));
});

// IMAGES FOR UGLIFIED
gulp.task('images-uglified', function() {
  return gulp.src('./assets/images/**/*.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/images/`));
});

// LIB
gulp.task('lib', function() {
  return gulp.src('./assets/lib/**/*.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/lib/`));
});

// LIB FOR UGLIFIED
gulp.task('lib-uglified', function() {
  return gulp.src('./assets/lib/**/*.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/lib/`));
});

// HTML
gulp.task('html', function() {
  return gulp.src('./assets/**.html')
    .pipe(gulp.dest(`./${TARGET_DIR}`));
});

// HTML FOR UGLIFIED
gulp.task('html-uglified', function() {
  return gulp.src('./assets/*.html')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}`));
});

// FAVICON
gulp.task('favicon', function() {
  return gulp.src('./assets/images/favicon/dev/**.*')
    .pipe(gulp.dest(`./${TARGET_DIR}/public/images/favicon/`));
});

// FAVICON FOR UGLIFIED
gulp.task('favicon-uglified', function() {
  return gulp.src('./assets/images/favicon/production/**.*')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/images/favicon/`));
});

// MANIFEST
gulp.task('manifest', function() {
  return gulp.src('./assets/manifest.json')
    .pipe(gulp.dest(`./${TARGET_DIR}`));
});

// MANIFEST FOR UGLIFIED
gulp.task('manifest-uglified', function() {
  return gulp.src('./assets/manifest.json')
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}`));
});

// MOVE FOR DEV
gulp.task('move', ['images', 'lib', 'html', 'favicon', 'manifest']);

// MOVE FOR UGLIFIED
gulp.task('move-uglified', ['images-uglified', 'lib-uglified', 'html-uglified', 'favicon-uglified', 'manifest-uglified']);

// WEBPACK
gulp.task('webpack', function() {
  // PACK NON-UGLIFIED
  return gulp.src('./assets')
    .pipe(webpackStream(webpackConfig.debug, webpack))
    .pipe(gulp.dest(`./${TARGET_DIR}/public/js`));
});

// WEBPACK FOR UGLIFIED
gulp.task('webpack-uglified', function() {
  // PACK PROD UGLIFIED
  return gulp.src('./assets')
    .pipe(webpackStream(webpackConfig.uglified, webpack))
    .pipe(gulp.dest(`./${TARGET_UGLIFIED_DIR}/public/js`));
});

/*
* NON-UGLIFIED BUILD PROCESS
*
* $ gulp dev
*/
// BUILD AND WATCH NON-UGLIFIED
gulp.task('dev', function() {
  runSequence('clean', 'move', 'webpack');

  gulp.watch('./assets/**/*', ['webpack']);
  gulp.watch('./assets/**.html', ['html']);
  gulp.watch('./assets/manifest.json', ['manifest']);

  console.log('Watching...');
});

// BUILD AND ZIP NON-UGLIFIED
gulp.task('build', function() {
  runSequence('clean', 'move', 'webpack', 'zip');
});

/*
* UGLIFIED BUILD PROCESS
*
* $ gulp
*/
// BUILD AND ZIP UGLIFIED
gulp.task('default', function() {
  runSequence('clean-uglified', 'move-uglified', 'webpack-uglified', 'zip-uglified');
});

// ZIP
gulp.task('zip', function() {
  return gulp.src(`./${TARGET_DIR}/**/*`)
    .pipe(zip('chrome_extension.zip'))
    .pipe(gulp.dest('./'));
});

// ZIP UP THE UGLIFIED VERSION
gulp.task('zip-uglified', function() {
  return gulp.src(`./${TARGET_UGLIFIED_DIR}/**/*`)
    .pipe(zip('chrome_extension-uglified.zip'))
    .pipe(gulp.dest('./'));
});

/*
* SET ENVIRONMENT
*
*/

// gulp.task('production-env', function() {
//   return process.env.NODE_ENV = 'production';
// });

module.exports = gulp;<|endoftext|>


<commit_before>// GULP DEPENDENCIES
// ----------------------------------------------------------------------------
var gulp         = require('gulp');
var sass         = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifycss    = require('gulp-minify-css');
var jshint       = require('gulp-jshint');
var concat       = require('gulp-concat');
var uglify       = require('gulp-uglify');
var imageMin     = require('gulp-imagemin');
var notify       = require('gulp-notify');
var rename       = require('gulp-rename');
var cache        = require('gulp-cache');
var del          = require('del');

// GULP TASKS.
// ----------------------------------------------------------------------------
gulp.task('styles', function() {
    return sass('./resources/assets/scss/*.scss', { style: 'expanded' })
        .pipe(autoprefixer('last 2 version'))
        .pipe(gulp.dest('./public/css'))
        .pipe(rename({suffix: '.min'}))
        .pipe(minifycss())
        .pipe(gulp.dest('./public/css'))
        .pipe(notify({ message: 'Styles task complete' }));
});

<commit_msg>add gulp watcher<commit_after>// GULP DEPENDENCIES
// ----------------------------------------------------------------------------
var gulp         = require('gulp');
var sass         = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifycss    = require('gulp-minify-css');
var jshint       = require('gulp-jshint');
var concat       = require('gulp-concat');
var uglify       = require('gulp-uglify');
var imageMin     = require('gulp-imagemin');
var notify       = require('gulp-notify');
var rename       = require('gulp-rename');
var cache        = require('gulp-cache');
var del          = require('del');

// GULP TASKS.
// ----------------------------------------------------------------------------
gulp.task('styles', function() {
    return sass('./resources/assets/scss/*.scss', { style: 'expanded' })
        .pipe(autoprefixer('last 2 version'))
        .pipe(gulp.dest('./public/css'))
        .pipe(rename({suffix: '.min'}))
        .pipe(minifycss())
        .pipe(gulp.dest('./public/css'))
        .pipe(notify({ message: 'Styles task complete' }));
});

gulp.task('watch', function() {
    // Watch .scss files.
    gulp.watch('./resources/assets/scss/*.scss', ['styles']);
});

<|endoftext|>


<commit_before>var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var historyApiFallback = require('connect-history-api-fallback');
var browserify = require('browserify');
var watchify = require('watchify');
var resolve = require('resolve');
var glob = require('glob').sync;
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var rename = require('gulp-rename');
var ghPages = require('gulp-gh-pages');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var streamqueue = require('streamqueue');

var baseDir = './admin';
var srcDir = baseDir + '/src';
var distDir = baseDir + '/dist';
var stylesDir = srcDir + '/styles';
var scriptsDir = srcDir + '/scripts';

var frontendDependencies = [
  'jquery',
  'bootstrap',
  'superagent',
  'csv'
];

function scriptPipeline(bundle, outfile) {

  /**
   * Run and return the scripts pipeline on bundle
   */

  console.log('Bundling: ' + outfile);

  return bundle
           .pipe(source(outfile))
           .pipe(buffer())
           .pipe(uglify())
           .pipe(gulp.dest(distDir));

}

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

  /**
   * Write the dist files to a gh-pages branch and push to remote
   */

  return gulp.src(distDir + '/*')
    .pipe(ghPages({
      message: "Web App update. " + Date.now(),
      remoteUrl: "https://github.com/okfn/datapackagist"
    }));

});

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

  /**
   * Run a reloading server for local development.
   */

  browserSync({
    open: false,
    server: {
        baseDir: distDir
        // use this for apps with client side routing
        // middleware: [historyApiFallback]
    }
  });

});

gulp.task('vendor-scripts', function () {

  /**
   * Provide frontend dependencies as a single bundle.
   */

  var bundler = browserify({});

  frontendDependencies.forEach(function (id) {
    bundler.require(resolve.sync(id), {expose: id});
  });

  return scriptPipeline(bundler.bundle(), 'vendor.min.js');

});

gulp.task('app-scripts', function() {

  /**
   * Provide frontend app as a single bundle.
   */

  var bundler = browserify({
        entries: [
            scriptsDir + '/app.js',
            // glob(scriptsDir + '/components/*.js')
        ],
        // transform: [],
        debug: true,
        cache: {},
        packageCache: {},
        fullPaths: true
  });

  // Don't include vendor dependencies in this bundle
  bundler.external(frontendDependencies);

  var watcher  = watchify(bundler);

  watcher
    .on('update', function() {
      scriptPipeline(watcher.bundle(), 'app.min.js');
    });

  return scriptPipeline(watcher.bundle(), 'app.min.js')
           .pipe(reload({stream: true}));

});

gulp.task('styles', function () {
  /**
   * Provide frontend styles as a single bundle.
   */
  return streamqueue(
    {objectMode: true},
    gulp.src(stylesDir + '/app.css'),

    // WARN replace hardcoded value
    gulp.src('*/highlight.js/src/styles/default.css')
  )
    .pipe(concat('app.min.css'))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(gulp.dest(distDir));
});

gulp.task('default', ['vendor-scripts', 'app-scripts', 'styles', 'serve']);
<commit_msg>Formatting<commit_after>var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var historyApiFallback = require('connect-history-api-fallback');
var browserify = require('browserify');
var watchify = require('watchify');
var resolve = require('resolve');
var glob = require('glob').sync;
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var rename = require('gulp-rename');
var ghPages = require('gulp-gh-pages');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var streamqueue = require('streamqueue');

var baseDir = './admin';
var srcDir = baseDir + '/src';
var distDir = baseDir + '/dist';
var stylesDir = srcDir + '/styles';
var scriptsDir = srcDir + '/scripts';

var frontendDependencies = [
  'jquery',
  'bootstrap',
  'superagent',
  'csv'
];

function scriptPipeline(bundle, outfile) {

  /**
   * Run and return the scripts pipeline on bundle
   */

  console.log('Bundling: ' + outfile);

  return bundle
           .pipe(source(outfile))
           .pipe(buffer())
           .pipe(uglify())
           .pipe(gulp.dest(distDir));

}

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

  /**
   * Write the dist files to a gh-pages branch and push to remote
   */

  return gulp.src(distDir + '/*')
    .pipe(ghPages({
      message: "Web App update. " + Date.now(),
      remoteUrl: "https://github.com/okfn/datapackagist"
    }));

});

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

  /**
   * Run a reloading server for local development.
   */

  browserSync({
    open: false,
    server: {
        baseDir: distDir
        // use this for apps with client side routing
        // middleware: [historyApiFallback]
    }
  });

});

gulp.task('vendor-scripts', function () {

  /**
   * Provide frontend dependencies as a single bundle.
   */

  var bundler = browserify({});

  frontendDependencies.forEach(function (id) {
    bundler.require(resolve.sync(id), {expose: id});
  });

  return scriptPipeline(bundler.bundle(), 'vendor.min.js');

});

gulp.task('app-scripts', function() {

  /**
   * Provide frontend app as a single bundle.
   */

  var bundler = browserify({
        entries: [
            scriptsDir + '/app.js',
            // glob(scriptsDir + '/components/*.js')
        ],
        // transform: [],
        debug: true,
        cache: {},
        packageCache: {},
        fullPaths: true
  });

  // Don't include vendor dependencies in this bundle
  bundler.external(frontendDependencies);

  var watcher  = watchify(bundler);

  watcher
    .on('update', function() {
      scriptPipeline(watcher.bundle(), 'app.min.js');
    });

  return scriptPipeline(watcher.bundle(), 'app.min.js')
           .pipe(reload({stream: true}));

});

gulp.task('styles', function () {
  /**
   * Provide frontend styles as a single bundle.
   */
  return streamqueue(
    {objectMode: true},
    gulp.src(stylesDir + '/app.css'),

    // WARN replace hardcoded value
    gulp.src('*/highlight.js/src/styles/default.css')
  )
    .pipe(concat('app.min.css'))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(gulp.dest(distDir));
});

gulp.task('default', ['vendor-scripts', 'app-scripts', 'styles', 'serve']);
<|endoftext|>


<commit_before>'use strict';

var gulp       = require('gulp'),
    fs         = require('fs'),
    del        = require('del'),
    merge      = require('merge-stream'),
    modRewrite = require('connect-modrewrite'),
    liveReload = require('connect-livereload'),
    karma      = require('karma').server,

    rename     = require('gulp-rename'),
    sass       = require('gulp-sass'),
    uglify     = require('gulp-uglify'),
    concat     = require('gulp-concat'),
    annotate   = require('gulp-ng-annotate'),
    ngHtml2Js  = require('gulp-ng-html2js'),
    connect    = require('gulp-connect'),
    eslint     = require('gulp-eslint');

/**
 * Cleaning task, cleans out folders before a build
 */
gulp.task('clean', function (cb) {
  del([
    '.tmp/**',
    '.sass-cache/**',
    'dist/**'
  ], cb);
});

/**
 * Clean post dist files
 */
gulp.task('clean:postdist', ['concat'], function(cb) {
  del([
    'dist/bootstrap.css',
    'dist/font-awesome.css',
    'dist/templates-html.js',
    'dist/templates-svg.js'
  ], cb);
});

/**
 * Karma test
 */
gulp.task('test:unit', ['templates'], function (cb) {
  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, cb);
});

/**
 * Lint source code
 */
gulp.task('lint', function () {
  return gulp.src([
    'src/**/*.js',
    '!src/**/*.test.js'
  ])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

/**
 * Lint tests
 */
gulp.task('lint:tests', function () {
  return gulp.src([
    'src/**/*.test.js'
  ])
    .pipe(eslint({
      env: {
        jasmine: true
      },
      globals: {
        describe: false,
        expect: false,
        it: false,
        beforeEach: false,
        afterEach: false,
        inject: false,
        spyOn: false,
        waitsFor: false,
        runs: false,
        jasmine: false
      }
    }))
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

/**
 * SASS compile task
 * Uses libsass
 */
gulp.task('sass', function () {
    // CoreOS
    var coreOsStream = gulp.src('src/coreos.scss')
      .pipe(sass({
        includePaths: ['src/sass', 'src/sass/mixin'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    // Fontawesome
    var fontAwesomeStream = gulp.src('ext/style/font-awesome/font-awesome.scss')
      .pipe(sass({
        includePaths: ['bower_components/font-awesome/scss', 'src/sass'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    // Bootstrap
    var bootstrapStream = gulp.src('ext/style/bootstrap/bootstrap.scss')
      .pipe(sass({
        includePaths: ['bower_components/bootstrap-sass/assets/stylesheets/bootstrap', 'src/sass'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    return merge(coreOsStream, fontAwesomeStream, bootstrapStream);
});

/**
 * Uglify task
 */
gulp.task('uglify', ['annotate'], function() {
  return gulp.src('dist/coreos.min.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

/**
 * Concat CSS task
 */
gulp.task('concat:css', ['sass'], function() {
  return gulp.src('dist/*.css')
    .pipe(concat('coreos.css'))
    .pipe(gulp.dest('dist'));
});

/**
 * Concat JS task
 */
gulp.task('concat:js', ['templates'], function() {
  return gulp.src([
    'src/**/*.js',
    '!src/**/*.test.js',
    'dist/*.js'
  ])
    .pipe(concat('coreos.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Combined concat tasks
 */
gulp.task('concat', ['concat:css', 'concat:js']);

/**
 * ngAnnotate for Angular
 */
gulp.task('annotate', ['concat:js'], function() {
  return gulp.src('dist/coreos.js')
    .pipe(rename('coreos.min.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Copy fonts
 */
gulp.task('copy:fonts', function() {
  return gulp.src([
    'bower_components/font-awesome/fonts/*',
    'bower_components/bootstrap-sass/fonts/*',
    'src/fonts/*'
  ])
    .pipe(gulp.dest('dist/fonts'));
});

/**
 * Copy images
 */
gulp.task('copy:images', function() {
  return gulp.src('src/img/**', {
    base: 'src/img'
  })
    .pipe(gulp.dest('dist/img'));
});

/**
 * Copy SVG files
 */
gulp.task('copy:svg', function() {
  gulp.src('src/svg/**', {
    base: 'src/svg'
  })
    .pipe(gulp.dest('dist/img'));
});

/**
 * Copy SASS files
 */
gulp.task('copy:sass', function() {
  return gulp.src([
    '*.scss',
    'mixin/**/*.scss',
    'compass/**/*.scss'
  ], {
    cwd: 'src/sass',
    base: 'src/sass'
  })
    .pipe(gulp.dest('dist/sass'));
});

/**
 * Copy task (all copy tasks)
 */
gulp.task('copy', ['copy:sass', 'copy:fonts', 'copy:images', 'copy:svg']);

/**
 * Compile HTML templates to JS
 * using Angular's $templateCache
 */
gulp.task('html2js:coreos', function() {
  return gulp.src('src/ui/**/*.html')
    .pipe(ngHtml2Js({
      moduleName: 'coreos-templates-html',
      rename: function(moduleName) {
        return '/coreos.ui/' + moduleName;
      }
    }))
    .pipe(concat('templates-html.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Compile SVG templates to JS
 * using Angular's $templateCache
 */
gulp.task('html2js:svg', function() {
  return gulp.src('src/svg/*.svg')
    .pipe(ngHtml2Js({
      moduleName: 'coreos-templates-svg',
      rename: function(moduleName) {
        return '/coreos.svg/' + moduleName;
      }
    }))
    .pipe(concat('templates-svg.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Templates task (both html and svg)
 */
gulp.task('templates', ['html2js:coreos', 'html2js:svg']);

/**
 * Connect task
 * This task will spawn a web server on port 9001
 */
gulp.task('connect', ['watch'], function() {
  connect.server({
    port: 9001,
    host: '0.0.0.0',
    base: '.',
    livereload: true,
    // Middleware fix for using HTML5 push-state
    middleware: function (connect, options) {
      var optBase = (typeof options.base === 'string') ? [options.base] : options.base;
      return [
        liveReload(), // Required until this bug is fixed
                      // https://github.com/AveVlad/gulp-connect/pull/83
        modRewrite(['!(\\..+)$ /example/ [L]'])
      ].concat(
        optBase.map(function(path){ return connect.static(path); }));
    }
  });
});

/**
 * Gulp watcher to notify livereload
 */
gulp.task('watch', function () {

  gulp.watch([
    'example/**/*.js',
    'src/**/*.js'
  ], ['lint']);

  return gulp.watch([
    'example/**',
    'src/**'
  ], ['reload']);
});

/**
 * Reload task
 */
gulp.task('reload', function() {
  gulp.src([
      'example/**',
      'src/**'
    ])
      .pipe(connect.reload());
});

/**
 * Test task
 */
gulp.task('test', ['lint', 'lint:tests', 'test:unit']);

/**
 * Version task
 * Create a version.json file based on the bower config version.
 */
gulp.task('version', ['copy'], function() {
  var bowerFile   = require('./bower.json');
  var versionFile = __dirname + '/dist/version.json';

  // The data to inset into the version file
  var versionInfo = {
    version: bowerFile.version
  };

  return fs.writeFile(versionFile, JSON.stringify(versionInfo, null, 2) + '\n');
});

/**
 * Dev task
 */
gulp.task('dev', ['clean'], function() {
  gulp.start('compile:dev');
});
gulp.task('compile:dev', ['templates', 'copy', 'sass']);

/**
 * Server task
 */
gulp.task('serve', ['lint', 'watch', 'connect']);

/**
 * Default prod build task
 */
gulp.task('compile:prod', ['templates', 'sass', 'concat', 'annotate', 'uglify', 'copy', 'version', 'clean:postdist']);
gulp.task('default', ['compile:prod']);
<commit_msg>build: lint for prod builds<commit_after>'use strict';

var gulp       = require('gulp'),
    fs         = require('fs'),
    del        = require('del'),
    merge      = require('merge-stream'),
    modRewrite = require('connect-modrewrite'),
    liveReload = require('connect-livereload'),
    karma      = require('karma').server,

    rename     = require('gulp-rename'),
    sass       = require('gulp-sass'),
    uglify     = require('gulp-uglify'),
    concat     = require('gulp-concat'),
    annotate   = require('gulp-ng-annotate'),
    ngHtml2Js  = require('gulp-ng-html2js'),
    connect    = require('gulp-connect'),
    eslint     = require('gulp-eslint');

/**
 * Cleaning task, cleans out folders before a build
 */
gulp.task('clean', function (cb) {
  del([
    '.tmp/**',
    '.sass-cache/**',
    'dist/**'
  ], cb);
});

/**
 * Clean post dist files
 */
gulp.task('clean:postdist', ['concat'], function(cb) {
  del([
    'dist/bootstrap.css',
    'dist/font-awesome.css',
    'dist/templates-html.js',
    'dist/templates-svg.js'
  ], cb);
});

/**
 * Karma test
 */
gulp.task('test:unit', ['templates'], function (cb) {
  karma.start({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, cb);
});

/**
 * Lint source code
 */
gulp.task('lint', function () {
  return gulp.src([
    'src/**/*.js',
    '!src/**/*.test.js'
  ])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

/**
 * Lint tests
 */
gulp.task('lint:tests', function () {
  return gulp.src([
    'src/**/*.test.js'
  ])
    .pipe(eslint({
      env: {
        jasmine: true
      },
      globals: {
        describe: false,
        expect: false,
        it: false,
        beforeEach: false,
        afterEach: false,
        inject: false,
        spyOn: false,
        waitsFor: false,
        runs: false,
        jasmine: false
      }
    }))
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
});

/**
 * SASS compile task
 * Uses libsass
 */
gulp.task('sass', function () {
    // CoreOS
    var coreOsStream = gulp.src('src/coreos.scss')
      .pipe(sass({
        includePaths: ['src/sass', 'src/sass/mixin'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    // Fontawesome
    var fontAwesomeStream = gulp.src('ext/style/font-awesome/font-awesome.scss')
      .pipe(sass({
        includePaths: ['bower_components/font-awesome/scss', 'src/sass'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    // Bootstrap
    var bootstrapStream = gulp.src('ext/style/bootstrap/bootstrap.scss')
      .pipe(sass({
        includePaths: ['bower_components/bootstrap-sass/assets/stylesheets/bootstrap', 'src/sass'],
        outputStyle: 'nested'
      }))
      .pipe(gulp.dest('dist'));

    return merge(coreOsStream, fontAwesomeStream, bootstrapStream);
});

/**
 * Uglify task
 */
gulp.task('uglify', ['annotate'], function() {
  return gulp.src('dist/coreos.min.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

/**
 * Concat CSS task
 */
gulp.task('concat:css', ['sass'], function() {
  return gulp.src('dist/*.css')
    .pipe(concat('coreos.css'))
    .pipe(gulp.dest('dist'));
});

/**
 * Concat JS task
 */
gulp.task('concat:js', ['templates'], function() {
  return gulp.src([
    'src/**/*.js',
    '!src/**/*.test.js',
    'dist/*.js'
  ])
    .pipe(concat('coreos.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Combined concat tasks
 */
gulp.task('concat', ['concat:css', 'concat:js']);

/**
 * ngAnnotate for Angular
 */
gulp.task('annotate', ['concat:js'], function() {
  return gulp.src('dist/coreos.js')
    .pipe(rename('coreos.min.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Copy fonts
 */
gulp.task('copy:fonts', function() {
  return gulp.src([
    'bower_components/font-awesome/fonts/*',
    'bower_components/bootstrap-sass/fonts/*',
    'src/fonts/*'
  ])
    .pipe(gulp.dest('dist/fonts'));
});

/**
 * Copy images
 */
gulp.task('copy:images', function() {
  return gulp.src('src/img/**', {
    base: 'src/img'
  })
    .pipe(gulp.dest('dist/img'));
});

/**
 * Copy SVG files
 */
gulp.task('copy:svg', function() {
  gulp.src('src/svg/**', {
    base: 'src/svg'
  })
    .pipe(gulp.dest('dist/img'));
});

/**
 * Copy SASS files
 */
gulp.task('copy:sass', function() {
  return gulp.src([
    '*.scss',
    'mixin/**/*.scss',
    'compass/**/*.scss'
  ], {
    cwd: 'src/sass',
    base: 'src/sass'
  })
    .pipe(gulp.dest('dist/sass'));
});

/**
 * Copy task (all copy tasks)
 */
gulp.task('copy', ['copy:sass', 'copy:fonts', 'copy:images', 'copy:svg']);

/**
 * Compile HTML templates to JS
 * using Angular's $templateCache
 */
gulp.task('html2js:coreos', function() {
  return gulp.src('src/ui/**/*.html')
    .pipe(ngHtml2Js({
      moduleName: 'coreos-templates-html',
      rename: function(moduleName) {
        return '/coreos.ui/' + moduleName;
      }
    }))
    .pipe(concat('templates-html.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Compile SVG templates to JS
 * using Angular's $templateCache
 */
gulp.task('html2js:svg', function() {
  return gulp.src('src/svg/*.svg')
    .pipe(ngHtml2Js({
      moduleName: 'coreos-templates-svg',
      rename: function(moduleName) {
        return '/coreos.svg/' + moduleName;
      }
    }))
    .pipe(concat('templates-svg.js'))
    .pipe(gulp.dest('dist'));
});

/**
 * Templates task (both html and svg)
 */
gulp.task('templates', ['html2js:coreos', 'html2js:svg']);

/**
 * Connect task
 * This task will spawn a web server on port 9001
 */
gulp.task('connect', ['watch'], function() {
  connect.server({
    port: 9001,
    host: '0.0.0.0',
    base: '.',
    livereload: true,
    // Middleware fix for using HTML5 push-state
    middleware: function (connect, options) {
      var optBase = (typeof options.base === 'string') ? [options.base] : options.base;
      return [
        liveReload(), // Required until this bug is fixed
                      // https://github.com/AveVlad/gulp-connect/pull/83
        modRewrite(['!(\\..+)$ /example/ [L]'])
      ].concat(
        optBase.map(function(path){ return connect.static(path); }));
    }
  });
});

/**
 * Gulp watcher to notify livereload
 */
gulp.task('watch', function () {

  gulp.watch([
    'example/**/*.js',
    'src/**/*.js'
  ], ['lint']);

  return gulp.watch([
    'example/**',
    'src/**'
  ], ['reload']);
});

/**
 * Reload task
 */
gulp.task('reload', function() {
  gulp.src([
      'example/**',
      'src/**'
    ])
      .pipe(connect.reload());
});

/**
 * Test task
 */
gulp.task('test', ['lint', 'lint:tests', 'test:unit']);

/**
 * Version task
 * Create a version.json file based on the bower config version.
 */
gulp.task('version', ['copy'], function() {
  var bowerFile   = require('./bower.json');
  var versionFile = __dirname + '/dist/version.json';

  // The data to inset into the version file
  var versionInfo = {
    version: bowerFile.version
  };

  return fs.writeFile(versionFile, JSON.stringify(versionInfo, null, 2) + '\n');
});

/**
 * Dev task
 */
gulp.task('dev', ['clean'], function() {
  gulp.start('compile:dev');
});
gulp.task('compile:dev', ['templates', 'copy', 'sass']);

/**
 * Server task
 */
gulp.task('serve', ['lint', 'watch', 'connect']);

/**
 * Default prod build task
 */
gulp.task('compile:prod', ['lint', 'templates', 'sass', 'concat', 'annotate', 'uglify', 'copy', 'version', 'clean:postdist']);
gulp.task('default', ['compile:prod']);
<|endoftext|>


<commit_before>/**
 * gulpfile.js
 *
 * All the yummy build stuff!
 */

// Requirements
var gulp             = require('gulp'),
    gulpif           = require('gulp-if'),
    gutil            = require('gulp-util'),
    plumber          = require('gulp-plumber'),
    sourcemaps       = require('gulp-sourcemaps'),
    autoprefixer     = require('gulp-autoprefixer'),
    minifyCss        = require('gulp-minify-css'),
    concat           = require('gulp-concat'),
    uglify           = require('gulp-uglify'),
    postcss          = require('gulp-postcss'),
    watch            = require('gulp-watch'),
    customProperties = require('postcss-custom-properties'),
    ghPages          = require('gh-pages'),
    path             = require('path'),
    eslint           = require('gulp-eslint'),
    htmlhint         = require('gulp-htmlhint'),
    w3cjs            = require('gulp-w3cjs'),
    dirSync          = require('gulp-directory-sync'),
    webserver        = require('gulp-webserver');

// Configure paths
var paths = {

  // Inputs
  js: ['./src/js/**/*.js'],
  css: ['./src/css/**/*.css'],

  // Static assets
  images: './src/i/',

  // Outputs
  jsOutput: 'main.js',
  cssOutput: 'styles.css',

  // Destinations
  jsDest: './gui/js/',
  cssDest: './gui/css/',
  imgDest: './gui/i/',

};

// Error handler
var onError = function (err) {
  gutil.beep();
  console.log(err);
};

// Check for production
var isProduction = process.env.NODE_ENV === 'production';

// Process stylesheets
gulp.task('css', function () {
  return gulp.src(paths.css)
    .pipe(plumber({
      errorHandler: onError
    }))
    .pipe(sourcemaps.init())
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(postcss([customProperties()]))
    .pipe(concat(paths.cssOutput))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(gulpif(!isProduction, sourcemaps.write('.')))
    .pipe(gulp.dest(paths.cssDest));
});

// Concatenate and minify JavaScript
gulp.task('js', function () {
  return gulp.src(paths.js)
    .pipe(plumber({
      errorHandler: onError
    }))
    .pipe(sourcemaps.init())
    .pipe(concat(paths.jsOutput))
    .pipe(uglify())
    .pipe(gulpif(!isProduction, sourcemaps.write('.')))
    .pipe(gulp.dest(paths.jsDest));
});

// HTMLhint
gulp.task('htmlhint', function () {
//  return gulp.src(paths.templates)
//     .pipe(htmlhint('.htmlhintrc'))
//     .pipe(htmlhint.reporter('htmlhint-stylish'))
//     .pipe(htmlhint.failReporter({ suppress: true }));
});

// eslint
gulp.task('eslint', function () {
  return gulp.src(paths.js)
    .pipe(eslint())
    .pipe(eslint.format());
});

// Validation
gulp.task('validate', function () {
  // return gulp.src(paths.templates)
  //   .pipe(w3cjs());
});

// Linting task
gulp.task('lint', ['htmlhint', 'eslint', 'validate']);

// Watch for changes
gulp.task('watch', function() {
  watch(paths.css, function() {
    gulp.start(['css']);
  });
  watch(paths.js, function() {
    gulp.start(['js', 'eslint']);
  });
  watch(paths.images, function() {
    gulp.start(['images']);
  });
});

// Copy image assets into /gui
gulp.task('images', function(){
  gulp.src(paths.images)
    .pipe(dirSync(paths.images, paths.imgDest));
});

// Deploy to gh-pages
gulp.task('deploy', function (cb) {
  ghPages.publish(path.join(process.cwd(), paths.tplDest), cb);
});

gulp.task('default', ['watch', 'css', 'js', 'images', 'lint']);
<commit_msg>Add new build task<commit_after>/**
 * gulpfile.js
 *
 * All the yummy build stuff!
 */

// Requirements
var gulp             = require('gulp'),
    gulpif           = require('gulp-if'),
    gutil            = require('gulp-util'),
    plumber          = require('gulp-plumber'),
    sourcemaps       = require('gulp-sourcemaps'),
    autoprefixer     = require('gulp-autoprefixer'),
    minifyCss        = require('gulp-minify-css'),
    concat           = require('gulp-concat'),
    uglify           = require('gulp-uglify'),
    postcss          = require('gulp-postcss'),
    watch            = require('gulp-watch'),
    customProperties = require('postcss-custom-properties'),
    ghPages          = require('gh-pages'),
    path             = require('path'),
    eslint           = require('gulp-eslint'),
    htmlhint         = require('gulp-htmlhint'),
    w3cjs            = require('gulp-w3cjs'),
    dirSync          = require('gulp-directory-sync'),
    webserver        = require('gulp-webserver');

// Configure paths
var paths = {

  // Inputs
  js: ['./src/js/**/*.js'],
  css: ['./src/css/**/*.css'],

  // Static assets
  images: './src/i/',

  // Outputs
  jsOutput: 'main.js',
  cssOutput: 'styles.css',

  // Destinations
  jsDest: './gui/js/',
  cssDest: './gui/css/',
  imgDest: './gui/i/',

};

// Error handler
var onError = function (err) {
  gutil.beep();
  console.log(err);
};

// Check for production
var isProduction = process.env.NODE_ENV === 'production';

// Process stylesheets
gulp.task('css', function () {
  return gulp.src(paths.css)
    .pipe(plumber({
      errorHandler: onError
    }))
    .pipe(sourcemaps.init())
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(postcss([customProperties()]))
    .pipe(concat(paths.cssOutput))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(gulpif(!isProduction, sourcemaps.write('.')))
    .pipe(gulp.dest(paths.cssDest));
});

// Concatenate and minify JavaScript
gulp.task('js', function () {
  return gulp.src(paths.js)
    .pipe(plumber({
      errorHandler: onError
    }))
    .pipe(sourcemaps.init())
    .pipe(concat(paths.jsOutput))
    .pipe(uglify())
    .pipe(gulpif(!isProduction, sourcemaps.write('.')))
    .pipe(gulp.dest(paths.jsDest));
});

// HTMLhint
gulp.task('htmlhint', function () {
//  return gulp.src(paths.templates)
//     .pipe(htmlhint('.htmlhintrc'))
//     .pipe(htmlhint.reporter('htmlhint-stylish'))
//     .pipe(htmlhint.failReporter({ suppress: true }));
});

// eslint
gulp.task('eslint', function () {
  return gulp.src(paths.js)
    .pipe(eslint())
    .pipe(eslint.format());
});

// Validation
gulp.task('validate', function () {
  // return gulp.src(paths.templates)
  //   .pipe(w3cjs());
});

// Linting task
gulp.task('lint', ['htmlhint', 'eslint', 'validate']);

// Watch for changes
gulp.task('watch', function() {
  watch(paths.css, function() {
    gulp.start(['css']);
  });
  watch(paths.js, function() {
    gulp.start(['js', 'eslint']);
  });
  watch(paths.images, function() {
    gulp.start(['images']);
  });
});

// Copy image assets into /gui
gulp.task('images', function(){
  gulp.src(paths.images)
    .pipe(dirSync(paths.images, paths.imgDest));
});

// Deploy to gh-pages
gulp.task('deploy', function (cb) {
  ghPages.publish(path.join(process.cwd(), paths.tplDest), cb);
});

// Build
gulp.task('build', ['css', 'js', 'images']);

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


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

gulp.task('default',function(){
    console.log('Hello World');
});
<commit_msg>Add functionality to the gulpfile<commit_after>var gulp = require('gulp');
    uglify=require('gulp-uglify'),
    sass=require('sass')
    ;

//Scripts task
//Uglifies.
gulp.task('scripts', function(){
    gulp.src('src/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/js'))
});

//Styles task
//Uglifies
gulp.task('styles', function(){
    gulp.src('src/sass/**/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('css/'))

});

//Watch task
//Watches js
gulp.task('watch', function(){
    gulp.watch('src/*.js',['scripts'])
});

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


<commit_before>
const { watch, src } = require('gulp');

// Import Gulp plugins.
const eslint = require('gulp-eslint');
const scsslint = require('gulp-scss-lint');
const fs = require('fs');

const config = {
  scssSrc:            './scss/**/*.scss',
  jsSrc:              './js/**/*.js'
};

function lintJS(cb) {
  src(config.jsSrc)
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.format('checkstyle', fs.createWriteStream('jsLintReport.xml')))
    .pipe(eslint.failAfterError());

  cb();
}

function lintSCSS(cb) {
  src(config.scssSrc)
    .pipe(scsslint({
      'config': 'scssLint.yml',
      'reporterOutput': 'scssLintReport.json'
    }));

  cb();
}

exports.styles = lintSCSS;
exports.scripts = lintJS;
exports.default = function() {
  // Watch SCSS and lint if changes occur
  watch(config.scssSrc, { ignoreInitial: false }, exports.styles);

  // Watch JS and process if changes occur
  watch(config.jsSrc, { ignoreInitial: false }, exports.scripts);
};
<commit_msg>Removed fail from JS lint<commit_after>
const { watch, src } = require('gulp');

// Import Gulp plugins.
const eslint = require('gulp-eslint');
const scsslint = require('gulp-scss-lint');
const fs = require('fs');

const config = {
  scssSrc:            './scss/**/*.scss',
  jsSrc:              './js/**/*.js'
};

function lintJS(cb) {
  src(config.jsSrc)
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.format('checkstyle', fs.createWriteStream('jsLintReport.xml')));

  cb();
}

function lintSCSS(cb) {
  src(config.scssSrc)
    .pipe(scsslint({
      'config': 'scssLint.yml',
      'reporterOutput': 'scssLintReport.json'
    }));

  cb();
}

exports.styles = lintSCSS;
exports.scripts = lintJS;
exports.default = function() {
  // Watch SCSS and lint if changes occur
  watch(config.scssSrc, { ignoreInitial: false }, exports.styles);

  // Watch JS and process if changes occur
  watch(config.jsSrc, { ignoreInitial: false }, exports.scripts);
};
<|endoftext|>


<commit_before>/*
Copyright 2014 Spotify AB

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/* global require */

var gulp = require("gulp");
var qunit = require("gulp-qunit");
var eslint = require("gulp-eslint");
var htmlhint = require("gulp-htmlhint");
var csslint = require("gulp-csslint");

gulp.task("test", function() {
    return gulp.src("./test.html")
        .pipe(qunit({"phantomjs-options": ["--ignore-ssl-errors=true"]}));
});

gulp.task("eslint", function() {
    return gulp.src("*.js")
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

gulp.task("htmllint", function() {
    return gulp.src(["*.html"])
        .pipe(htmlhint())
        .pipe(htmlhint.reporter())
        .pipe(htmlhint.failReporter());
});

gulp.task("csslint", function() {
    return gulp.src("*.css")
        .pipe(csslint())
        .pipe(csslint.formatter())
        .pipe(csslint.failFormatter());
});
<commit_msg>Fix linter warning<commit_after>/*
Copyright 2014 Spotify AB

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var gulp = require("gulp");
var qunit = require("gulp-qunit");
var eslint = require("gulp-eslint");
var htmlhint = require("gulp-htmlhint");
var csslint = require("gulp-csslint");

gulp.task("test", function() {
  return gulp
    .src("./test.html")
    .pipe(qunit({ "phantomjs-options": ["--ignore-ssl-errors=true"] }));
});

gulp.task("eslint", function() {
  return gulp
    .src("*.js")
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task("htmllint", function() {
  return gulp
    .src(["*.html"])
    .pipe(htmlhint())
    .pipe(htmlhint.reporter())
    .pipe(htmlhint.failReporter());
});

gulp.task("csslint", function() {
  return gulp
    .src("*.css")
    .pipe(csslint())
    .pipe(csslint.formatter())
    .pipe(csslint.failFormatter());
});
<|endoftext|>


<commit_before>'use strict';
var
  gulp = require('gulp'),
  path = require('path'),
  sequence = require('run-sequence'),
  requireDir = require('require-dir');

requireDir('./gulp/tasks', {
  recurse: true
});

gulp.task('clean',function (done) {
  sequence(
    '_clean',
    done
  );
});

gulp.task('lint',function (done) {
  sequence(
    '_lint',
    done
  );
});

gulp.task('unit',function (done) {
  sequence(
    '_unit',
    done
  );
});

gulp.task('build',function(done) {
  sequence(
    '_clean',
    '_nsp',
    '_lint',
    '_unit',
    done
  );
});

gulp.task('test', function(done) {
  sequence(
    '_lint',
    '_unit',
    done
  );
});

gulp.task('default', ['_watch']);<commit_msg>chore (nems) remove unused dependency in gulpfile<commit_after>'use strict';
var
  gulp = require('gulp'),
  sequence = require('run-sequence'),
  requireDir = require('require-dir');

requireDir('./gulp/tasks', {
  recurse: true
});

gulp.task('clean',function (done) {
  sequence(
    '_clean',
    done
  );
});

gulp.task('lint',function (done) {
  sequence(
    '_lint',
    done
  );
});

gulp.task('unit',function (done) {
  sequence(
    '_unit',
    done
  );
});

gulp.task('build',function(done) {
  sequence(
    '_clean',
    '_nsp',
    '_lint',
    '_unit',
    done
  );
});

gulp.task('test', function(done) {
  sequence(
    '_lint',
    '_unit',
    done
  );
});

// release: build, spawn:gulp-release-easy, spawn:npm

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


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

gulp.task("build:test", function (done) {
  gulp.src(['test/**/*.ts'])
    .pipe(tsc())
    .pipe(gulp.dest('build-test/'))
    .on('end', done);
});
<commit_msg>Create build:test task<commit_after>var gulp = require('gulp');
var tsc = require('gulp-tsc');

gulp.task("build:test", function (done) {
  gulp.src(['test/**/*.ts'])
    .pipe(tsc())
    .pipe(gulp.dest('build-test/'))
    .on('end', done);
});
<|endoftext|>


<commit_before>const gulp = require("gulp")
	, mocha = require("gulp-mocha")
	, jsdoc = require("gulp-jsdoc")
	, config = {
		testDir: "./test/*.js",
		srcDir: "./src/",
		docDir: "./docs/"
	};

gulp.task("default", function() {
	gulp.start("test", "doc");
});

gulp.task("test", function(){
	return gulp.src(config.testDir, {read: false})
			   .pipe(mocha({reporter: "spec"}));
})

gulp.task("doc", function(){
	gulp.src(config.srcDir+"**/*.js")
		.pipe(jsdoc(config.docDir));
});<commit_msg>Fixed jsdoc overstepping its bounds.<commit_after>const gulp = require("gulp")
	, mocha = require("gulp-mocha")
	, jsdoc = require("gulp-jsdoc")
	, config = {
		testDir: "./test/*.js",
		srcDir: "./src/",
		docDir: "./docs/"
	};

gulp.task("default", function() {
	gulp.start("test", "doc");
});

gulp.task("test", function(){
	return gulp.src(config.testDir, {read: false})
			   .pipe(mocha({reporter: "spec"}));
})

gulp.task("doc", function(){
	gulp.src(config.srcDir+"*.js")
		.pipe(jsdoc(config.docDir));
});<|endoftext|>


<commit_before>/*eslint-env node*/

const fs = require('fs');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const useref = require('gulp-useref');
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const babelMinify = require('babel-minify');
const child_process = require('child_process');
const merge = require('merge-stream');

function minifyJs(fileName) {
	const content = fs.readFileSync(fileName, 'utf8');
	const minifiedContent = babelMinify(content).code;
	fs.writeFileSync(fileName, minifiedContent);
	console.log(
		`[${fileName}]: ${content.length}kb -> ${minifiedContent.length}kb`
	);
}
gulp.task('runWebpack', function() {
	return child_process.execSync('yarn run build');
});

gulp.task('copyFiles', function() {
	return merge(
		gulp
			.src('src/lib/codemirror/theme/*')
			.pipe(gulp.dest('app/lib/codemirror/theme')),
		gulp
			.src('src/lib/codemirror/mode/**/*')
			.pipe(gulp.dest('app/lib/codemirror/mode')),
		gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers')),
		gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib')),
		gulp
			.src([
				'src/preview.html',
				'src/detached-window.js',
				'src/icon-48.png',
				'src/icon-128.png',
				'src/patreon.png'
			])
			.pipe(gulp.dest('app')),

		gulp
			.src('build/bundle.*.js')
			.pipe(rename('script.js'))
			.pipe(gulp.dest('app')),
		gulp
			.src('build/vendor.*.js')
			.pipe(rename('vendor.js'))
			.pipe(gulp.dest('app')),

		// Following CSS are copied to build/ folder where they'll be referenced by
		// useRef plugin to concat into one.
		gulp
			.src('src/lib/codemirror/lib/codemirror.css')
			.pipe(gulp.dest('build/lib/codemirror/lib')),
		gulp
			.src('src/lib/codemirror/addon/hint/show-hint.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/hint')),
		gulp
			.src('src/lib/codemirror/addon/fold/foldgutter.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/fold')),
		gulp
			.src('src/lib/codemirror/addon/dialog/dialog.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/dialog')),
		gulp.src('src/lib/hint.min.css').pipe(gulp.dest('build/lib')),
		gulp.src('src/lib/inlet.css').pipe(gulp.dest('build/lib')),
		gulp.src('src/style.css').pipe(gulp.dest('build')),

		gulp
			.src([
				'src/FiraCode.ttf',
				'src/FixedSys.ttf',
				'src/Inconsolata.ttf',
				'src/Monoid.ttf'
			])
			.pipe(gulp.dest('app'))
	);
});

gulp.task('useRef', function() {
	return gulp
		.src('build/index.html')
		.pipe(useref())
		.pipe(gulp.dest('app'));
});

gulp.task('concatSwRegistration', function() {
	gulp
		.src(['app/service-worker-registration.js', 'app/script.js'])
		.pipe(concat('script.js'))
		.pipe(gulp.dest('app'));
});

gulp.task('minify', function() {
	minifyJs('app/script.js');
	// minifyJs('app/vendor.js');
	minifyJs('app/lib/screenlog.js');

	gulp
		.src('app/*.css')
		.pipe(
			cleanCSS(
				{
					debug: true
				},
				details => {
					console.log(`${details.name}: ${details.stats.originalSize}`);
					console.log(`${details.name}: ${details.stats.minifiedSize}`);
				}
			)
		)
		.pipe(gulp.dest('app'));
});

gulp.task('fixIndex', function() {
	var contents = fs.readFileSync('build/index.html', 'utf8');
	// Replace hashed-filename script tags with unhashed ones
	contents = contents.replace(
		/\<\!\-\- SCRIPT-TAGS \-\-\>[\S\s]*?\<\!\-\- END-SCRIPT-TAGS \-\-\>/,
		'<script defer src="vendor.js"></script><script defer src="script.js"></script>'
	);

	// vendor.hash.js gets created outside our markers, so remove it
	contents = contents.replace(
		/\<script src="\/vendor\.[\S\s]*?\<\/script\>/,
		''
	);

	fs.writeFileSync('build/index.html', contents, 'utf8');
});

gulp.task('generate-service-worker', function(callback) {
	var swPrecache = require('sw-precache');
	var rootDir = 'app';

	swPrecache.write(
		`${rootDir}/service-worker.js`,
		{
			staticFileGlobs: [
				rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'
			],
			stripPrefix: `${rootDir}/`,

			// has to be increased to around 2.8mb for sass.worker.js
			maximumFileSizeToCacheInBytes: 2900000
		},
		callback
	);
});

gulp.task('cleanup', function() {
	return child_process.execSync('rm -rf build');
});

gulp.task('release', function(callback) {
	runSequence(
		'runWebpack',
		'copyFiles',
		'fixIndex',
		'useRef',
		'concatSwRegistration',
		'minify',
		'generate-service-worker',
		'cleanup',
		function(error) {
			if (error) {
				console.log(error.message);
			} else {
				console.log('RELEASE FINISHED SUCCESSFULLY');
			}
			callback(error);
		}
	);
});

// gulp.task('default', ['generate-service-worker']);
<commit_msg>gulp: fix swconcat task<commit_after>/*eslint-env node*/

const fs = require('fs');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const useref = require('gulp-useref');
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const babelMinify = require('babel-minify');
const child_process = require('child_process');
const merge = require('merge-stream');

function minifyJs(fileName) {
	const content = fs.readFileSync(fileName, 'utf8');
	const minifiedContent = babelMinify(content).code;
	fs.writeFileSync(fileName, minifiedContent);
	console.log(
		`[${fileName}]: ${content.length}kb -> ${minifiedContent.length}kb`
	);
}
gulp.task('runWebpack', function() {
	return child_process.execSync('yarn run build');
});

gulp.task('copyFiles', function() {
	return merge(
		gulp
			.src('src/lib/codemirror/theme/*')
			.pipe(gulp.dest('app/lib/codemirror/theme')),
		gulp
			.src('src/lib/codemirror/mode/**/*')
			.pipe(gulp.dest('app/lib/codemirror/mode')),
		gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers')),
		gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib')),
		gulp
			.src([
				'src/preview.html',
				'src/detached-window.js',
				'src/icon-48.png',
				'src/icon-128.png',
				'src/patreon.png'
			])
			.pipe(gulp.dest('app')),

		gulp
			.src('build/bundle.*.js')
			.pipe(rename('script.js'))
			.pipe(gulp.dest('app')),
		gulp
			.src('build/vendor.*.js')
			.pipe(rename('vendor.js'))
			.pipe(gulp.dest('app')),

		// Following CSS are copied to build/ folder where they'll be referenced by
		// useRef plugin to concat into one.
		gulp
			.src('src/lib/codemirror/lib/codemirror.css')
			.pipe(gulp.dest('build/lib/codemirror/lib')),
		gulp
			.src('src/lib/codemirror/addon/hint/show-hint.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/hint')),
		gulp
			.src('src/lib/codemirror/addon/fold/foldgutter.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/fold')),
		gulp
			.src('src/lib/codemirror/addon/dialog/dialog.css')
			.pipe(gulp.dest('build/lib/codemirror/addon/dialog')),
		gulp.src('src/lib/hint.min.css').pipe(gulp.dest('build/lib')),
		gulp.src('src/lib/inlet.css').pipe(gulp.dest('build/lib')),
		gulp.src('src/style.css').pipe(gulp.dest('build')),

		gulp
			.src([
				'src/FiraCode.ttf',
				'src/FixedSys.ttf',
				'src/Inconsolata.ttf',
				'src/Monoid.ttf'
			])
			.pipe(gulp.dest('app'))
	);
});

gulp.task('useRef', function() {
	return gulp
		.src('build/index.html')
		.pipe(useref())
		.pipe(gulp.dest('app'));
});

gulp.task('concatSwRegistration', function() {
	gulp
		.src(['src/service-worker-registration.js', 'app/script.js'])
		.pipe(concat('script.js'))
		.pipe(gulp.dest('app'));
});

gulp.task('minify', function() {
	minifyJs('app/script.js');
	// minifyJs('app/vendor.js');
	minifyJs('app/lib/screenlog.js');

	gulp
		.src('app/*.css')
		.pipe(
			cleanCSS(
				{
					debug: true
				},
				details => {
					console.log(`${details.name}: ${details.stats.originalSize}`);
					console.log(`${details.name}: ${details.stats.minifiedSize}`);
				}
			)
		)
		.pipe(gulp.dest('app'));
});

gulp.task('fixIndex', function() {
	var contents = fs.readFileSync('build/index.html', 'utf8');
	// Replace hashed-filename script tags with unhashed ones
	contents = contents.replace(
		/\<\!\-\- SCRIPT-TAGS \-\-\>[\S\s]*?\<\!\-\- END-SCRIPT-TAGS \-\-\>/,
		'<script defer src="vendor.js"></script><script defer src="script.js"></script>'
	);

	// vendor.hash.js gets created outside our markers, so remove it
	contents = contents.replace(
		/\<script src="\/vendor\.[\S\s]*?\<\/script\>/,
		''
	);

	fs.writeFileSync('build/index.html', contents, 'utf8');
});

gulp.task('generate-service-worker', function(callback) {
	var swPrecache = require('sw-precache');
	var rootDir = 'app';

	swPrecache.write(
		`${rootDir}/service-worker.js`,
		{
			staticFileGlobs: [
				rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'
			],
			stripPrefix: `${rootDir}/`,

			// has to be increased to around 2.8mb for sass.worker.js
			maximumFileSizeToCacheInBytes: 2900000
		},
		callback
	);
});

gulp.task('cleanup', function() {
	return child_process.execSync('rm -rf build');
});

gulp.task('release', function(callback) {
	runSequence(
		'runWebpack',
		'copyFiles',
		'fixIndex',
		'useRef',
		'concatSwRegistration',
		'minify',
		'generate-service-worker',
		'cleanup',
		function(error) {
			if (error) {
				console.log(error.message);
			} else {
				console.log('RELEASE FINISHED SUCCESSFULLY');
			}
			callback(error);
		}
	);
});

// gulp.task('default', ['generate-service-worker']);
<|endoftext|>


<commit_before>var gulp        = require('gulp');
var karma       = require('karma').server;
var concat      = require('gulp-concat');
var uglify      = require('gulp-uglify');
var rename      = require('gulp-rename');
var path        = require('path');
var plumber     = require('gulp-plumber');
var runSequence = require('run-sequence');
var jshint      = require('gulp-jshint');

var rootDirectory   = path.resolve('./');
var sourceDirectory = path.join(rootDirectory, './src');
var sourceFiles = [
  path.join(sourceDirectory, '/**/*.module.js'),
  path.join(sourceDirectory, '/**/*.js')
];
var lintFiles = [
  'gulpfile.js',
  'karma-*.conf.js'
].concat(sourceFiles);

gulp.task('build', function() {
  gulp.src(sourceFiles)
    .pipe(plumber())
    .pipe(concat('ng-iso-constants.js'))
    .pipe(gulp.dest('./dist/'))
    .pipe(uglify())
    .pipe(rename('ng-iso-constants.min.js'))
    .pipe(gulp.dest('./dist'));
});

gulp.task('process-all', function (done) {
  runSequence('jshint', 'test-src', 'build', done);
});

gulp.task('watch', function () {
  gulp.watch(sourceFiles, ['process-all']);
});

gulp.task('jshint', function () {
  return gulp.src(lintFiles)
    .pipe(plumber())
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

gulp.task('test-src', function (done) {
  karma.start({
    configFile: __dirname + '/karma-src.conf.js',
    singleRun: true
  }, done);
});

gulp.task('test-dist-concatenated', function (done) {
  karma.start({
    configFile: __dirname + '/karma-dist-concatenated.conf.js',
    singleRun: true
  }, done);
});

gulp.task('test-dist-minified', function (done) {
  karma.start({
    configFile: __dirname + '/karma-dist-minified.conf.js',
    singleRun: true
  }, done);
});

gulp.task('default', function () {
  runSequence('process-all', 'watch');
});
<commit_msg>Fix spacing<commit_after>var gulp        = require('gulp');
var karma       = require('karma').server;
var concat      = require('gulp-concat');
var uglify      = require('gulp-uglify');
var rename      = require('gulp-rename');
var path        = require('path');
var plumber     = require('gulp-plumber');
var runSequence = require('run-sequence');
var jshint      = require('gulp-jshint');

var rootDirectory   = path.resolve('./');
var sourceDirectory = path.join(rootDirectory, './src');
var sourceFiles = [
  path.join(sourceDirectory, '/**/*.module.js'),
  path.join(sourceDirectory, '/**/*.js')
];
var lintFiles = [
  'gulpfile.js',
  'karma-*.conf.js'
].concat(sourceFiles);

gulp.task('build', function() {
  gulp.src(sourceFiles)
    .pipe(plumber())
    .pipe(concat('ng-iso-constants.js'))
    .pipe(gulp.dest('./dist/'))
    .pipe(uglify())
    .pipe(rename('ng-iso-constants.min.js'))
    .pipe(gulp.dest('./dist'));
});

gulp.task('process-all', function (done) {
  runSequence('jshint', 'test-src', 'build', done);
});

gulp.task('watch', function () {
  gulp.watch(sourceFiles, ['process-all']);
});

gulp.task('jshint', function () {
  return gulp.src(lintFiles)
    .pipe(plumber())
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(jshint.reporter('fail'));
});

gulp.task('test-src', function (done) {
  karma.start({
    configFile: __dirname + '/karma-src.conf.js',
    singleRun: true
  }, done);
});

gulp.task('test-dist-concatenated', function (done) {
  karma.start({
    configFile: __dirname + '/karma-dist-concatenated.conf.js',
    singleRun: true
  }, done);
});

gulp.task('test-dist-minified', function (done) {
  karma.start({
    configFile: __dirname + '/karma-dist-minified.conf.js',
    singleRun: true
  }, done);
});

gulp.task('default', function () {
  runSequence('process-all', 'watch');
});
<|endoftext|>


<commit_before>var gulp = require('gulp')
var g_if = require('gulp-if')
var react = require('gulp-react')
var less = require('gulp-less')
var cssmin = require('gulp-cssmin')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var imagemin = require('gulp-imagemin')
var sourcemaps = require('gulp-sourcemaps')
var connect = require('gulp-connect')
var rename = require('gulp-rename')
var source = require('vinyl-source-stream')
var browserify = require('browserify')
var reactify = require('reactify')
var del = require('del')
var NwBuilder = require('node-webkit-builder')

var paths = {
  build: 'build/',
  main: ['./js/main.js'],
  js: ['js/**/*.js', 'js/**/*.jsx'],
  img: ['static/**/*.png'],
  css: ['less/**/*.less'],
  html: ['html/**/*.html'],
}

gulp.task('clean', function(cb) {
  del([paths.build], cb)
})

gulp.task('js', function() {
  return browserify(paths.main)
    .transform(reactify)
    .bundle()
    .pipe(source('bundle.min.js'))
    // .pipe(sourcemaps.init())
    // .pipe(g_if('*.jsx', react()))
    // .pipe(uglify())
    // .pipe(concat('bundle.min.js'))
    // .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/static'))
})

gulp.task('css', function() {
  return gulp.src(paths.css)
    .pipe(sourcemaps.init())
      .pipe(less())
      .pipe(cssmin())
      .pipe(concat('bundle.min.css'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/static'))
})

gulp.task('img', function() {
  return gulp.src(paths.img)
    .pipe(imagemin({optimizationLevel: 5}))
    .pipe(gulp.dest('build/static'))
    .pipe(connect.reload())
})

gulp.task('html', function() {
  return gulp.src(paths.html)
    .pipe(gulp.dest('build/'))
})

gulp.task('compile', ['js', 'css', 'img', 'html'])

gulp.task('watch', function() {
  gulp.watch(paths.js, ['js'])
  gulp.watch(paths.css, ['css'])
  gulp.watch(paths.img, ['img'])
  gulp.watch(paths.html, ['html'])
})

gulp.task('server', function() {
  connect.server({
    root: 'build',
    fallback: 'build/index.html',
    port: 8000,
    livereload: true
  })
})

gulp.task('build', ['compile'], function() {
  var stream = gulp.src('nw-package.json')
    .pipe(rename('package.json'))
    .pipe(gulp.dest('build'))

  stream.on('end', function() {
    var nw = new NwBuilder({
      files: ['build/**', '!build/node-ipfs/**'],
      platforms: ['osx', 'win', 'linux32', 'linux64']
    })
    nw.build(function(err) {
      if(err) console.error(err)
    })
  })
})

gulp.task('default', ['watch', 'compile', 'server'])
<commit_msg>Fixed nw build task path typo<commit_after>var gulp = require('gulp')
var g_if = require('gulp-if')
var react = require('gulp-react')
var less = require('gulp-less')
var cssmin = require('gulp-cssmin')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var imagemin = require('gulp-imagemin')
var sourcemaps = require('gulp-sourcemaps')
var connect = require('gulp-connect')
var rename = require('gulp-rename')
var source = require('vinyl-source-stream')
var browserify = require('browserify')
var reactify = require('reactify')
var del = require('del')
var NwBuilder = require('node-webkit-builder')

var paths = {
  build: 'build/',
  main: ['./js/main.js'],
  js: ['js/**/*.js', 'js/**/*.jsx'],
  img: ['static/**/*.png'],
  css: ['less/**/*.less'],
  html: ['html/**/*.html'],
}

gulp.task('clean', function(cb) {
  del([paths.build], cb)
})

gulp.task('js', function() {
  return browserify(paths.main)
    .transform(reactify)
    .bundle()
    .pipe(source('bundle.min.js'))
    // .pipe(sourcemaps.init())
    // .pipe(g_if('*.jsx', react()))
    // .pipe(uglify())
    // .pipe(concat('bundle.min.js'))
    // .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/static'))
})

gulp.task('css', function() {
  return gulp.src(paths.css)
    .pipe(sourcemaps.init())
      .pipe(less())
      .pipe(cssmin())
      .pipe(concat('bundle.min.css'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/static'))
})

gulp.task('img', function() {
  return gulp.src(paths.img)
    .pipe(imagemin({optimizationLevel: 5}))
    .pipe(gulp.dest('build/static'))
    .pipe(connect.reload())
})

gulp.task('html', function() {
  return gulp.src(paths.html)
    .pipe(gulp.dest('build/'))
})

gulp.task('compile', ['js', 'css', 'img', 'html'])

gulp.task('watch', function() {
  gulp.watch(paths.js, ['js'])
  gulp.watch(paths.css, ['css'])
  gulp.watch(paths.img, ['img'])
  gulp.watch(paths.html, ['html'])
})

gulp.task('server', function() {
  connect.server({
    root: 'build',
    fallback: 'build/index.html',
    port: 8000,
    livereload: true
  })
})

gulp.task('build', ['compile'], function() {
  var stream = gulp.src('nw-package.json')
    .pipe(rename('package.json'))
    .pipe(gulp.dest('build'))

  stream.on('end', function() {
    var nw = new NwBuilder({
      files: ['build/**', '!build/ipfs-webui/**'],
      platforms: ['osx', 'win', 'linux32', 'linux64']
    })
    nw.build(function(err) {
      if(err) console.error(err)
    })
  })
})

gulp.task('default', ['watch', 'compile', 'server'])
<|endoftext|>


<commit_before>var gulp     = require('gulp'),
     plugins = require('gulp-load-plugins')({camelize: true});

// Lets us type "gulp" on the command line and run all of our tasks
gulp.task('default', ['jshint', 'vendor', 'scripts']);

// Hint all user-developed JS
gulp.task('jshint', function() {
  return gulp.src(['src/*.js'])
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'))
    .pipe(plugins.notify({ message: 'JS Hinting task complete' }));
});

// Combine, minify all vendor JS
gulp.task('vendor', function() {
  return gulp.src(['src/vendor/jquery.history.js', 'src/vendor/jquery.imagesloaded.js'])
    .pipe(plugins.concat('wpajax-vendor.min.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest('js/'))
    .pipe(plugins.notify({ message: 'Vendor JS task complete' }));
});

// JS concat, strip debugging and minify
gulp.task('scripts', function() {
  return gulp.src(['src/*.js', '!src/vendor{,/**}'])
    .pipe(plugins.concat('wpajax.min.js'))
    .pipe(plugins.stripDebug())
    .pipe(plugins.uglify())
    .pipe(gulp.dest('js/'))
    .pipe(plugins.notify({ message: 'Scripts task complete' }));
});
<commit_msg>Debugging<commit_after>var gulp     = require('gulp'),
     plugins = require('gulp-load-plugins')({camelize: true});

// Lets us type "gulp" on the command line and run all of our tasks
gulp.task('default', ['jshint', 'vendor', 'scripts']);

// Hint all user-developed JS
gulp.task('jshint', function() {
  return gulp.src(['src/*.js'])
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('default'))
    .pipe(plugins.notify({ message: 'JS Hinting task complete' }));
});

// Combine, minify all vendor JS
gulp.task('vendor', function() {
  return gulp.src(['src/vendor/jquery.history.js', 'src/vendor/jquery.imagesloaded.js'])
    .pipe(plugins.concat('wpajax-vendor.min.js'))
    .pipe(plugins.uglify())
    .pipe(gulp.dest('js/'))
    .pipe(plugins.notify({ message: 'Vendor JS task complete' }));
});

// JS concat, strip debugging and minify
gulp.task('scripts', function() {
  return gulp.src(['src/*.js', '!src/vendor{,/**}'])
    .pipe(plugins.concat('wpajax.min.js'))
    //.pipe(plugins.stripDebug())
    //.pipe(plugins.uglify())
    .pipe(gulp.dest('js/'))
    .pipe(plugins.notify({ message: 'Scripts task complete' }));
});
<|endoftext|>


<commit_before>const gulp = require('gulp');
const jshint = require('gulp-jshint');
const beautify = require('gulp-beautify');

const sources = ['./index.js', './src/js/*.js'];

gulp.task('beautify', function () {
    return gulp.src(sources)
        .pipe(beautify())
        .pipe(gulp.dest('.'));
});

gulp.task('jshint', function () {
    return gulp.src(sources)
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(jshint.reporter('fail'));
});

gulp.task('default', ['jshint', 'beautify']);
<commit_msg>Migrate beautify options<commit_after>const gulp = require('gulp');
const jshint = require('gulp-jshint');
const beautify = require('gulp-beautify');

const sources = ['./index.js', './src/js/*.js'];

gulp.task('beautify', function () {
    return gulp.src(sources)
        .pipe(beautify({
            'max-preserve-newlines': 3,
            'end-with-newline': true
        }))
        .pipe(gulp.dest('.'));
});

gulp.task('jshint', function () {
    return gulp.src(sources)
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(jshint.reporter('fail'));
});

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


<commit_before>var gulp = require('gulp')
var minifyCss = require('gulp-minify-css')
var uglify = require('gulp-uglify')

gulp.task('minify-css', function() {
  return gulp.src('src/*.css')
    .pipe(minifyCss())
    .pipe(gulp.dest('dist'))
})

gulp.task('compress', function() {
  return gulp.src('src/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'))
})

gulp.task('default', ['compress', 'minify-css'])<commit_msg>gulpfile:add watch task<commit_after>var gulp = require('gulp')
var minifyCss = require('gulp-minify-css')
var uglify = require('gulp-uglify')

gulp.task('minify-css', function() {
  return gulp.src('src/*.css')
    .pipe(minifyCss())
    .pipe(gulp.dest('dist'))
})

gulp.task('compress', function() {
  return gulp.src('src/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('dist'))
})

gulp.task('watch', ['compress', 'minify-css'], function(){
    gulp.watch(['./src/**/*'], ['compress', 'minify-css'])
})

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