<commit_before>// Load Gulp
const gulp = require('gulp');
// Load all npm modules that start with `gulp-`
const g = require('gulp-load-plugins')();
// Load Webpack (webpack-stream for gulp compatibility)
// const webpack = require('webpack-stream');
// Load BrowserSync (for livereloading w/ device sync)
const browserSync = require('browser-sync');

// `gulp` - Build everything
gulp.task('default', [
  'templates',
  'styles',
  // 'scripts', // Javascript isn't used in uTox.org at this time
  'images',
  'etc'
]);

// `gulp test` - Test everything
gulp.task('test', [
  'test:styles'
  // 'test:scripts' // Javascript isn't used in uTox.org at this time
]);

// `gulp serve` - Run a development server with auto-rebuilding
gulp.task('serve', () => {
  // Rebuild templates on change in src/
  gulp.watch(['src/*.njk', 'src/templates/**/*'], ['templates']);
  // Rebuild styles on change in src/styles/
  gulp.watch(['src/styles/**/*'], ['styles']);
  // Rebuild scripts on change in src/scripts/
  // gulp.watch(['src/scripts/**/*'], ['scripts']);
  // Rebuild images on change in src/images/
  gulp.watch(['src/images/**/*'], ['images']);
  // Copy over everything that isn't covered by an above task on change in src/
  gulp.watch(['src/**/*', '!src/{template,styles,scripts,images}/**/*'], ['etc']);

  return browserSync({
    // Options found here: https://browsersync.io/docs/options
    // Open control panel in browser
    open: 'ui',
    // Delay before reloading (milliseconds)
    reloadDelay: 2000,
    // Custom prefix for console.log messages sent by BrowserSync
    logPrefix: 'BrowserSync',
    // Run a development server
    server: {
      // Folder w/ our built files
      baseDir: './dist/',
      // Set to true for directory listings
      directory: false
    },
    // Set to true to use localtunnel.me service
    tunnel: true
  });
});

// `gulp templates` - Build HTML from Nunjucks source
gulp.task('templates', () =>
  gulp.src(['src/**/*.njk', '!src/{templates,templates/**/*}'])
    // Generate HTML from Nunjuck templates
    .pipe(g.nunjucks.compile())
    .pipe(g.rename({
      extname: ".html"
    }))
    // Write generated HTML code to dist/
    .pipe(gulp.dest('dist/'))
    // Reload the browser
    .pipe(browserSync.stream())
);

// `gulp test:styles` - Check SCSS code for errors (linter & style checker)
gulp.task('test:styles', () =>
  gulp.src(['src/styles/**/*.{scss,sass}'])
    // Lint & style check SCSS code
    // Config located in package.json under "stylelint"
    .pipe(g.stylelint({
      // Output results to CLI
      reporters: [
        {
          formatter: 'string',
          console: true
        }
      ]
    }))
);

// `gulp styles` - Build CSS from SCSS source
gulp.task('styles', ['test:styles'], () =>
  gulp.src(['src/styles/**/*.{scss,sass}'])
    // Start tracking sourcemap data
    .pipe(g.sourcemaps.init())
      // Generate CSS code from SCSS source
      .pipe(g.sass({
        // Generated CSS code should be readable if we disable CSS minification
        outputStyle: 'expanded',
        // Include these paths as shortcuts
        includePaths: [
          // Lets us leave off "node_modules/" when importing Sass from a module
          'node_modules'
        ]
      }))
      // Add vendor prefixed versions of CSS properties
      .pipe(g.autoprefixer({
        // Google's policy is last 2 versions of all major browsers
        browsers: ['last 2 versions']
      }))
      // Minify our generated CSS for a smaller output file
      .pipe(g.cleanCss({
        // Inline file contents when using @import (just like Sass @import)
        processImport: true,
        // Only inline local CSS, ignore remote CSS (e.g. fonts.googleapis.com)
        processImportFrom: ['local'],
        // Lets us leave off "node_modules/" when importing CSS from a module
        relativeTo: 'node_modules'
      }))
    // Write sourcemap to dist/sourcemaps/
    .pipe(g.sourcemaps.write('./'))
    // Write generated CSS code to dist/styles/
    .pipe(gulp.dest('dist/styles/'))
    // Reload/Inject into the browser
    .pipe(browserSync.stream())
);

// `gulp test:scripts` - Check JS code for errors (linter & style checker)
// gulp.task('test:scripts', () =>
//   gulp.src(['src/scripts/**/*.js'])
//     // Lint & style check JS code
//     // Config located in package.json under "xo"
//     .pipe(g.xo())
// );

// `gulp scripts` - Build browser JS code using webpack (v1)
// gulp.task('scripts', ['test:scripts'], () =>
//   gulp.src(['src/scripts/main.js'])
//     // Run Webpack with main.js as the entry point
//     .pipe(webpack({
//       // Add sourcemap to bundle.js
//       devtool: 'inline-source-map',
//       output: {
//         // Set filename of our JS output
//         filename: 'bundle.js'
//       }
//     }))
//     // Read webpack sourcemap and start tracking new sourcemap data
//     .pipe(g.sourcemaps.init({loadMaps: true}))
//       // Minify our generated JS for a smaller output file
//       .pipe(g.uglify())
//     // Write sourcemap to dist/sourcemaps/
//     .pipe(g.sourcemaps.write('./'))
//     // Write generated JS code to dist/scripts/
//     .pipe(gulp.dest('dist/scripts/'))
//     // Reload/Inject into the browser
//     .pipe(browserSync.stream())
// );

// `gulp images` - Build images
gulp.task('images', ['images:webp'], () =>
  gulp.src(['src/images/**/*.{png,jpg,gif,svg}'])
    // Only work on changed images
    .pipe(g.changed('dist/images/'))
    // Compresses (losslessly) PNG, JPG, GIF, & SVG images
    .pipe(g.imagemin())
    // Copy PNG, JPG, GIF, & SVG images to dist/images/
    .pipe(gulp.dest('dist/images/'))
);

// `gulp images:webp` - Build WEBP images
gulp.task('images:webp', () =>
  gulp.src(['src/images/**/*.{png,jpg}'])
    // Only work on changed images
    .pipe(g.changed('dist/images/'))
    // Convert PNG & JPG images to WEBP
    .pipe(g.webp({
      // Compression level (0 fastest, 4 default, 6 slowest)
      method: 6,
      // Encode losslessly
      lossless: true
    }))
    // Write WEBP converted files to dist/images/
    .pipe(gulp.dest('dist/images/'))
);

// `gulp etc` - Copy everything else
gulp.task('etc', () =>
  gulp.src([
    'src/**/*',
    '!src/{styles,images}/**/*',
    '!src/{scripts,scripts/**/*}',
    '!src/**/*.njk',
    '!src/{templates,templates/**/*}'
  ])
    // Only work on changed files
    .pipe(g.changed('dist/'))
    // Output files to the dist folder
    .pipe(gulp.dest('dist/'))
    // Reload/Inject into the browser
    .pipe(browserSync.stream())
);
<commit_msg>disabled localtunnel in browser-sync config<commit_after>// Load Gulp
const gulp = require('gulp');
// Load all npm modules that start with `gulp-`
const g = require('gulp-load-plugins')();
// Load Webpack (webpack-stream for gulp compatibility)
// const webpack = require('webpack-stream');
// Load BrowserSync (for livereloading w/ device sync)
const browserSync = require('browser-sync');

// `gulp` - Build everything
gulp.task('default', [
  'templates',
  'styles',
  // 'scripts', // Javascript isn't used in uTox.org at this time
  'images',
  'etc'
]);

// `gulp test` - Test everything
gulp.task('test', [
  'test:styles',
  // 'test:scripts' // Javascript isn't used in uTox.org at this time
]);

// `gulp serve` - Run a development server with auto-rebuilding
gulp.task('serve', () => {
  // Rebuild templates on change in src/
  gulp.watch(['src/*.njk', 'src/templates/**/*'], ['templates']);
  // Rebuild styles on change in src/styles/
  gulp.watch(['src/styles/**/*'], ['styles']);
  // Rebuild scripts on change in src/scripts/
  // gulp.watch(['src/scripts/**/*'], ['scripts']);
  // Rebuild images on change in src/images/
  gulp.watch(['src/images/**/*'], ['images']);
  // Copy over everything that isn't covered by an above task on change in src/
  gulp.watch(['src/**/*', '!src/{template,styles,scripts,images}/**/*'], ['etc']);

  return browserSync({
    // Options found here: https://browsersync.io/docs/options
    // Open control panel in browser
    open: 'ui',
    // Delay before reloading (milliseconds)
    reloadDelay: 2000,
    // Custom prefix for console.log messages sent by BrowserSync
    logPrefix: 'BrowserSync',
    // Run a development server
    server: {
      // Folder w/ our built files
      baseDir: './dist/',
      // Set to true for directory listings
      directory: false
    },
    // Set to true to use localtunnel.me service
    // tunnel: true
  });
});

// `gulp templates` - Build HTML from Nunjucks source
gulp.task('templates', () =>
  gulp.src(['src/**/*.njk', '!src/{templates,templates/**/*}'])
    // Generate HTML from Nunjuck templates
    .pipe(g.nunjucks.compile())
    .pipe(g.rename({
      extname: ".html"
    }))
    // Write generated HTML code to dist/
    .pipe(gulp.dest('dist/'))
    // Reload the browser
    .pipe(browserSync.stream())
);

// `gulp test:styles` - Check SCSS code for errors (linter & style checker)
gulp.task('test:styles', () =>
  gulp.src(['src/styles/**/*.{scss,sass}'])
    // Lint & style check SCSS code
    // Config located in package.json under "stylelint"
    .pipe(g.stylelint({
      // Output results to CLI
      reporters: [
        {
          formatter: 'string',
          console: true
        }
      ]
    }))
);

// `gulp styles` - Build CSS from SCSS source
gulp.task('styles', ['test:styles'], () =>
  gulp.src(['src/styles/**/*.{scss,sass}'])
    // Start tracking sourcemap data
    .pipe(g.sourcemaps.init())
      // Generate CSS code from SCSS source
      .pipe(g.sass({
        // Generated CSS code should be readable if we disable CSS minification
        outputStyle: 'expanded',
        // Include these paths as shortcuts
        includePaths: [
          // Lets us leave off "node_modules/" when importing Sass from a module
          'node_modules'
        ]
      }))
      // Add vendor prefixed versions of CSS properties
      .pipe(g.autoprefixer({
        // Google's policy is last 2 versions of all major browsers
        browsers: ['last 2 versions']
      }))
      // Minify our generated CSS for a smaller output file
      .pipe(g.cleanCss({
        // Inline file contents when using @import (just like Sass @import)
        processImport: true,
        // Only inline local CSS, ignore remote CSS (e.g. fonts.googleapis.com)
        processImportFrom: ['local'],
        // Lets us leave off "node_modules/" when importing CSS from a module
        relativeTo: 'node_modules'
      }))
    // Write sourcemap to dist/sourcemaps/
    .pipe(g.sourcemaps.write('./'))
    // Write generated CSS code to dist/styles/
    .pipe(gulp.dest('dist/styles/'))
    // Reload/Inject into the browser
    .pipe(browserSync.stream())
);

// `gulp test:scripts` - Check JS code for errors (linter & style checker)
// gulp.task('test:scripts', () =>
//   gulp.src(['src/scripts/**/*.js'])
//     // Lint & style check JS code
//     // Config located in package.json under "xo"
//     .pipe(g.xo())
// );

// `gulp scripts` - Build browser JS code using webpack (v1)
// gulp.task('scripts', ['test:scripts'], () =>
//   gulp.src(['src/scripts/main.js'])
//     // Run Webpack with main.js as the entry point
//     .pipe(webpack({
//       // Add sourcemap to bundle.js
//       devtool: 'inline-source-map',
//       output: {
//         // Set filename of our JS output
//         filename: 'bundle.js'
//       }
//     }))
//     // Read webpack sourcemap and start tracking new sourcemap data
//     .pipe(g.sourcemaps.init({loadMaps: true}))
//       // Minify our generated JS for a smaller output file
//       .pipe(g.uglify())
//     // Write sourcemap to dist/sourcemaps/
//     .pipe(g.sourcemaps.write('./'))
//     // Write generated JS code to dist/scripts/
//     .pipe(gulp.dest('dist/scripts/'))
//     // Reload/Inject into the browser
//     .pipe(browserSync.stream())
// );

// `gulp images` - Build images
gulp.task('images', ['images:webp'], () =>
  gulp.src(['src/images/**/*.{png,jpg,gif,svg}'])
    // Only work on changed images
    .pipe(g.changed('dist/images/'))
    // Compresses (losslessly) PNG, JPG, GIF, & SVG images
    .pipe(g.imagemin())
    // Copy PNG, JPG, GIF, & SVG images to dist/images/
    .pipe(gulp.dest('dist/images/'))
);

// `gulp images:webp` - Build WEBP images
gulp.task('images:webp', () =>
  gulp.src(['src/images/**/*.{png,jpg}'])
    // Only work on changed images
    .pipe(g.changed('dist/images/'))
    // Convert PNG & JPG images to WEBP
    .pipe(g.webp({
      // Compression level (0 fastest, 4 default, 6 slowest)
      method: 6,
      // Encode losslessly
      lossless: true
    }))
    // Write WEBP converted files to dist/images/
    .pipe(gulp.dest('dist/images/'))
);

// `gulp etc` - Copy everything else
gulp.task('etc', () =>
  gulp.src([
    'src/**/*',
    '!src/{styles,images}/**/*',
    '!src/{scripts,scripts/**/*}',
    '!src/**/*.njk',
    '!src/{templates,templates/**/*}'
  ])
    // Only work on changed files
    .pipe(g.changed('dist/'))
    // Output files to the dist folder
    .pipe(gulp.dest('dist/'))
    // Reload/Inject into the browser
    .pipe(browserSync.stream())
);
<|endoftext|>


<commit_before>/* global require */

var gulp = require('gulp-npm-run')(require('gulp'), {
      exclude: ['test'],
      require: ['doc']
    }),
    del = require('del')
    bump = require('gulp-bump'),
    qunit = require('gulp-qunit'),
    jshint = require('gulp-jshint'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    replace = require('gulp-replace'),
    rename = require('gulp-rename'),
    minimist = require('minimist'),
    deploy = require('gulp-gh-pages');

// Passing a version number
var knownOptions = {
  string: 'ver'
};
var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('default', ['sass', 'test', 'docs']);
gulp.task('docs', ['doc', 'docs-rename']);
gulp.task('build', ['sass', 'build-rename']);

// Lint Task
gulp.task('lint', function() {
  return gulp.src('./lib/dropkick.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Compile Our Sass
gulp.task('sass', function() {
  return gulp.src('./lib/css/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('css'))
    .pipe(gulp.dest('dist/css'));
});

gulp.task('bump', function(){
  gulp.src('./*.json')
  .pipe(bump())
  .pipe(gulp.dest('./'));
});

// USEAGE: gulp build-rename --ver 2.x.x
gulp.task('build-rename', function() {
  return gulp.src('./lib/dropkick.js')
    .pipe(rename('dropkick.' + options.ver + '.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist/js/'));
});

gulp.task('deploy', function() {
  return gulp.src('./docs/**/*').pipe(deploy({
    cname: "dropkickjs.com"
  }));
});

// Watch Files For Changes
gulp.task('watch', function() {
  gulp.watch('/lib/dropkick.js', ['scripts', 'docs']);
  gulp.watch('css/*.scss', ['sass']);
});

gulp.task('docs-rename', function() {
  setTimeout(function() { //ugh
    return del(['./docs/index.html'], function () {
      return gulp.src('./docs/classes/Dropkick.html')
          .pipe(rename('index.html'))
          .pipe(replace('../', ''))
          .pipe(gulp.dest('./docs/'));
    });
  }, 4000);
});

gulp.task('test', function() {
  //TODO: fix
  // return gulp.src(['./tests/src/runner.html', './tests/src/iframe.html'])
  return gulp.src(['./tests/src/runner.html'])
    .pipe(qunit());
});
<commit_msg>Fix tests<commit_after>/* global require */

var gulp = require('gulp-npm-run')(require('gulp'), {
      exclude: ['test'],
      require: ['doc']
    }),
    del = require('del')
    bump = require('gulp-bump'),
    qunit = require('gulp-qunit'),
    jshint = require('gulp-jshint'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    replace = require('gulp-replace'),
    rename = require('gulp-rename'),
    minimist = require('minimist'),
    deploy = require('gulp-gh-pages-cname');

// Passing a version number
var knownOptions = {
  string: 'ver'
};
var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('default', ['sass', 'test', 'docs']);
gulp.task('docs', ['doc', 'docs-rename']);
gulp.task('build', ['sass', 'build-rename']);

// Lint Task
gulp.task('lint', function() {
  return gulp.src('./lib/dropkick.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// Compile Our Sass
gulp.task('sass', function() {
  return gulp.src('./lib/css/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('css'))
    .pipe(gulp.dest('dist/css'));
});

gulp.task('bump', function(){
  gulp.src('./*.json')
  .pipe(bump())
  .pipe(gulp.dest('./'));
});

// USEAGE: gulp build-rename --ver 2.x.x
gulp.task('build-rename', function() {
  return gulp.src('./lib/dropkick.js')
    .pipe(rename('dropkick.' + options.ver + '.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist/js/'));
});

gulp.task('deploy', function() {
  return gulp.src('./docs/**/*').pipe(deploy({
    cname: "dropkickjs.com"
  }));
});

// Watch Files For Changes
gulp.task('watch', function() {
  gulp.watch('/lib/dropkick.js', ['scripts', 'docs']);
  gulp.watch('css/*.scss', ['sass']);
});

gulp.task('docs-rename', function() {
  setTimeout(function() { //ugh
    return del(['./docs/index.html'], function () {
      return gulp.src('./docs/classes/Dropkick.html')
          .pipe(rename('index.html'))
          .pipe(replace('../', ''))
          .pipe(gulp.dest('./docs/'));
    });
  }, 4000);
});

gulp.task('test', function() {
  //TODO: fix
  // return gulp.src(['./tests/src/runner.html', './tests/src/iframe.html'])
  return gulp.src(['./tests/src/runner.html'])
    .pipe(qunit());
});
<|endoftext|>


<commit_before>'use strict';
var path = require('path');
var gulp = require('gulp');
var filter = require('gulp-filter');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var nsp = require('gulp-nsp');

gulp.task('publish', function() {
  var f = filter(['generatorsSrc/**/*.js', '!generatorsSrc/app/templates/**/*.js'], { restore: true });

  return gulp.src('generatorsSrc/**/*.js')
    .pipe(f)
    .pipe(babel({
      presets: ['es2015', 'stage-1']
    }))
    .pipe(f.restore)
    .pipe(gulp.dest('generators'));
});

gulp.task('eslint', function() {
  return gulp.src(['**/*.js', '!generators/app/templates/**/*.js'])
    .pipe(excludeGitignore())
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task('nsp', function(cb) {
  nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('default', ['eslint', 'nsp']);
<commit_msg>Fix negation glob on gulpfile<commit_after>'use strict';
var path = require('path');
var gulp = require('gulp');
var filter = require('gulp-filter');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var nsp = require('gulp-nsp');

gulp.task('publish', function() {
  var f = filter(['generatorsSrc/**/*.js', '!generatorsSrc/**/*/templates/**/*.js'], { restore: true });

  return gulp.src('generatorsSrc/**/*.js')
    .pipe(f)
    .pipe(babel({
      presets: ['es2015', 'stage-1']
    }))
    .pipe(f.restore)
    .pipe(gulp.dest('generators'));
});

gulp.task('eslint', function() {
  return gulp.src(['**/*.js', '!generators/app/templates/**/*.js'])
    .pipe(excludeGitignore())
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

gulp.task('nsp', function(cb) {
  nsp({package: path.resolve('package.json')}, cb);
});

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


<commit_before>var gulp = require('gulp'),
    argv = require('yargs').argv,
    replace = require('gulp-replace'),
    exec = require('child_process').exec,
    fs = require('fs-extra'),
    path = require('path'),
    archiver = require('archiver');

gulp.task('build', ['copyTemplate', 'copyGlobalData', 'copyLocales']);

gulp.task('package', ['release'], function () {
    const keepFiles = ['build', 'node_modules', 'appconfig.json', 'gulpfile.js', 'logconfig.json', 'mail.json', 'pm2.json', 'sample collection.json', 'tsconfig.json'];
    const files = fs.readdirSync(__dirname);
    files.forEach(f => {
        if (!keepFiles.find(fileName => f.endsWith(fileName))) {
            fs.removeSync(f)
        }
    });

    const zipPath = __dirname;
    const zipFile = `${zipPath}.zip`;
    if (fs.existsSync(zipFile)) {
        fs.unlinkSync(zipFile);
    }

    const output = fs.createWriteStream(zipFile);
    const archive = archiver('zip');
    let isClose = false;

    output.on('close', () => {
        isClose = true;
    });
    output.on('end', () => {
        isClose = true;
    });

    archive.pipe(output);
    archive.directory(zipPath, false);
    archive.finalize();
});

gulp.task('release', ['copy', 'copyTemplate', 'copyGlobalData', 'copyLocales']);

gulp.task('copy', ['compilerClient'], function () {
    return gulp.src('./client/build/**/*.*')
        .pipe(gulp.dest('./build/public'))
        .on('end', function () {
            gulp.src('./pm2.json')
                .pipe(gulp.dest('./build'))
        });
});

gulp.task('copyTemplate', function () {
    fs.removeSync(path.join(__dirname, 'build/mail/templates'));
    return gulp.src('./api/mail/templates/**/*.*')
        .pipe(gulp.dest('./build/mail/templates'));
});

gulp.task('copyGlobalData', function () {
    fs.removeSync(path.join(__dirname, 'build/global_data'));
    return gulp.src('./api/global_data/**/*.*')
        .pipe(gulp.dest('./build/global_data'));
});

gulp.task('copyLocales', function () {
    fs.removeSync(path.join(__dirname, 'build/locales'));
    return gulp.src('./api/locales/**/*.*')
        .pipe(gulp.dest('./build/locales'));
});

gulp.task('compilerClient', ['compilerServer'], function (cb) {
    process.chdir('./client');
    exec('yarn build', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        process.chdir('../');
        cb();
    });
});

gulp.task('compilerServer', ['config'], function (cb) {
    exec('tsc -p . -w false', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        cb();
    });
});

gulp.task('config', [], function () {
    return gulp.src('./client/src/utils/urls.ts')
        .pipe(replace('http://localhost:3000/', 'HITCHHIKER_APP_HOST'))
        .pipe(gulp.dest('./client/src/utils/'))
        .on('end', function () {
            gulp.src('./appconfig.json')
                .pipe(replace('localhost:3000', `localhost:8080`))
                .pipe(replace('localhost:81', `localhost:8080`))
                .pipe(replace('"database": "hitchhiker"', '"database": "hitchhiker-prod"'))
                .pipe(replace('DEV', `PROD`))
                .pipe(gulp.dest('./'))
                .on('end', function () {
                    gulp.src('./client/package.json')
                        .pipe(replace('localhost:81', `localhost:8080`))
                        .pipe(gulp.dest('./client/'));
                });
        });
});<commit_msg>create project folder<commit_after>var gulp = require('gulp'),
    argv = require('yargs').argv,
    replace = require('gulp-replace'),
    exec = require('child_process').exec,
    fs = require('fs-extra'),
    path = require('path'),
    archiver = require('archiver');

gulp.task('build', ['copyTemplate', 'copyGlobalData', 'copyLocales']);

gulp.task('package', ['release'], function () {
    const keepFiles = ['build', 'node_modules', 'appconfig.json', 'gulpfile.js', 'logconfig.json', 'mail.json', 'pm2.json', 'sample collection.json', 'tsconfig.json'];
    const files = fs.readdirSync(__dirname);
    files.forEach(f => {
        if (!keepFiles.find(fileName => f.endsWith(fileName))) {
            fs.removeSync(f)
        }
    });

    const zipPath = __dirname;
    const zipFile = `${zipPath}.zip`;
    if (fs.existsSync(zipFile)) {
        fs.unlinkSync(zipFile);
    }

    const output = fs.createWriteStream(zipFile);
    const archive = archiver('zip');
    let isClose = false;

    output.on('close', () => {
        isClose = true;
    });
    output.on('end', () => {
        isClose = true;
    });

    archive.pipe(output);
    archive.directory(zipPath, false);
    archive.finalize();
});

gulp.task('release', ['copy', 'copyTemplate', 'copyGlobalData', 'copyLocales']);

gulp.task('copy', ['compilerClient'], function () {
    return gulp.src('./client/build/**/*.*')
        .pipe(gulp.dest('./build/public'))
        .on('end', function () {
            gulp.src('./pm2.json')
                .pipe(gulp.dest('./build'))
        });
});

gulp.task('copyTemplate', function () {
    fs.removeSync(path.join(__dirname, 'build/mail/templates'));
    return gulp.src('./api/mail/templates/**/*.*')
        .pipe(gulp.dest('./build/mail/templates'));
});

gulp.task('copyGlobalData', function () {
    let globalPath = path.join(__dirname, 'build/global_data');
    fs.removeSync(globalPath);
    fs.mkdirpSync(`${globalPath}/project`);
    return gulp.src('./api/global_data/**/*.*')
        .pipe(gulp.dest('./build/global_data'));
});

gulp.task('copyLocales', function () {
    fs.removeSync(path.join(__dirname, 'build/locales'));
    return gulp.src('./api/locales/**/*.*')
        .pipe(gulp.dest('./build/locales'));
});

gulp.task('compilerClient', ['compilerServer'], function (cb) {
    process.chdir('./client');
    exec('yarn build', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        process.chdir('../');
        cb();
    });
});

gulp.task('compilerServer', ['config'], function (cb) {
    exec('tsc -p . -w false', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        cb();
    });
});

gulp.task('config', [], function () {
    return gulp.src('./client/src/utils/urls.ts')
        .pipe(replace('http://localhost:3000/', 'HITCHHIKER_APP_HOST'))
        .pipe(gulp.dest('./client/src/utils/'))
        .on('end', function () {
            gulp.src('./appconfig.json')
                .pipe(replace('localhost:3000', `localhost:8080`))
                .pipe(replace('localhost:81', `localhost:8080`))
                .pipe(replace('"database": "hitchhiker"', '"database": "hitchhiker-prod"'))
                .pipe(replace('DEV', `PROD`))
                .pipe(gulp.dest('./'))
                .on('end', function () {
                    gulp.src('./client/package.json')
                        .pipe(replace('localhost:81', `localhost:8080`))
                        .pipe(gulp.dest('./client/'));
                });
        });
});<|endoftext|>


<commit_before>var gulp = require('gulp'),
	sass = require('gulp-sass'),
	autoprefixer = require('gulp-autoprefixer'),
	minifycss = require('gulp-minify-css'),
	jshint = require('gulp-jshint'),
	uglify = require('gulp-uglify'),
	imagemin = require('gulp-imagemin'),
	rename = require('gulp-rename'),
	concat = require('gulp-concat'),
	cache = require('gulp-cache'),
	livereload = require('gulp-livereload'),
	sourcemaps = require('gulp-sourcemaps'),
	del = require('del');

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

	// List al your SASS files HERE
	var scss_files = [
	'assets/styles/main.scss'
	];

	//return sass(scss_files, { style: 'expanded' })
	gulp.src(scss_files)
	.pipe(sass())
	.pipe(autoprefixer('last 3 version'))
	.pipe(gulp.dest('dist/styles'))
	.pipe(rename({suffix: '.min'}))
	.pipe(minifycss())
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/styles'))
	.pipe(livereload());
});

gulp.task('rtl-styles', function() {

	// List al your SASS files HERE
	var scss_files = [
	'assets/styles/rtl.scss'
	];

	//return sass(scss_files, { style: 'expanded' })
	gulp.src(scss_files)
	.pipe(sass())
	.pipe(autoprefixer('last 3 version'))
	.pipe(gulp.dest('dist/styles'))
	.pipe(rename({suffix: '.min'}))
	.pipe(minifycss())
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/styles'))
	.pipe(livereload());
});

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

	// List all your JS files HERE
	var js_files = [
	'bower_components/jquery/dist/jquery.js',
	'bower_components/jquery.cookie/jquery.cookie.js',
	'bower_components/jquery-placeholder/jquery-placeholder.js',
	'bower_components/fastclick/lib/fastclick.js',
	'bower_components/foundation/js/foundation.js',
	'bower_components/angular/angular.js',
	'assets/scripts/**/*.js'
	];

	return gulp.src(js_files)
	.pipe(jshint('.jshintrc'))
	//.pipe(jshint.reporter('default'))
	.pipe(concat('main.js'))
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/scripts'))
	.pipe(rename({suffix: '.min'}))
	.pipe(uglify())
	.pipe(gulp.dest('dist/scripts'))
	.pipe(livereload());
});

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

	var img_files = [
	'assets/images/**/*'
	];

	return gulp.src(img_files)
	.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
	.pipe(gulp.dest('dist/images'))
	.pipe(livereload());
});

gulp.task('clean', function(cb) {
	del(['dist/css', 'dist/scripts', 'dist/images'], cb)
});

gulp.task('default', ['clean'], function() {
	gulp.start('styles', 'rtl-styles', 'scripts', 'images');
});

gulp.task('watch', function() {
  // Create LiveReload server
  livereload.listen();
  // Watch .scss files
  gulp.watch('assets/styles/**/*.scss', ['styles', 'rtl-styles']);
  // Watch .js files
  gulp.watch('assets/scripts/**/*.js', ['scripts']);
  // Watch image files
  gulp.watch('assets/images/**/*', ['images']);
  // Watch any files in dist/, reload on change
  gulp.watch(['dist/**', '**/*.php']).on('change', livereload.changed);
});
<commit_msg>fix sourcemap flow<commit_after>var gulp = require('gulp'),
	sass = require('gulp-sass'),
	autoprefixer = require('gulp-autoprefixer'),
	minifycss = require('gulp-minify-css'),
	jshint = require('gulp-jshint'),
	uglify = require('gulp-uglify'),
	imagemin = require('gulp-imagemin'),
	rename = require('gulp-rename'),
	concat = require('gulp-concat'),
	cache = require('gulp-cache'),
	livereload = require('gulp-livereload'),
	sourcemaps = require('gulp-sourcemaps'),
	del = require('del');

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

	// List al your SASS files HERE
	var scss_files = [
	'assets/styles/main.scss'
	];

	//return sass(scss_files, { style: 'expanded' })
	gulp.src(scss_files)
	.pipe(sourcemaps.init())
	.pipe(sass())
	.pipe(autoprefixer('last 3 version'))
	.pipe(gulp.dest('dist/styles'))
	.pipe(rename({suffix: '.min'}))
	.pipe(minifycss())
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/styles'))
	.pipe(livereload());
});

gulp.task('rtl-styles', function() {

	// List al your SASS files HERE
	var scss_files = [
	'assets/styles/rtl.scss'
	];

	//return sass(scss_files, { style: 'expanded' })
	gulp.src(scss_files)
	.pipe(sourcemaps.init())
	.pipe(sass())
	.pipe(autoprefixer('last 3 version'))
	.pipe(gulp.dest('dist/styles'))
	.pipe(rename({suffix: '.min'}))
	.pipe(minifycss())
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/styles'))
	.pipe(livereload());
});

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

	// List all your JS files HERE
	var js_files = [
	'bower_components/jquery/dist/jquery.js',
	'bower_components/jquery.cookie/jquery.cookie.js',
	'bower_components/jquery-placeholder/jquery-placeholder.js',
	'bower_components/fastclick/lib/fastclick.js',
	'bower_components/foundation/js/foundation.js',
	'bower_components/angular/angular.js',
	'assets/scripts/**/*.js'
	];

	return gulp.src(js_files)
	.pipe(sourcemaps.init())
	.pipe(jshint('.jshintrc'))
	//.pipe(jshint.reporter('default'))
	.pipe(concat('main.js'))
	.pipe(sourcemaps.write())
	.pipe(gulp.dest('dist/scripts'))
	.pipe(rename({suffix: '.min'}))
	.pipe(uglify())
	.pipe(gulp.dest('dist/scripts'))
	.pipe(livereload());
});

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

	var img_files = [
	'assets/images/**/*'
	];

	return gulp.src(img_files)
	.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
	.pipe(gulp.dest('dist/images'))
	.pipe(livereload());
});

gulp.task('clean', function(cb) {
	del(['dist/css', 'dist/scripts', 'dist/images'], cb)
});

gulp.task('default', ['clean'], function() {
	gulp.start('styles', 'rtl-styles', 'scripts', 'images');
});

gulp.task('watch', function() {
  // Create LiveReload server
  livereload.listen();
  // Watch .scss files
  gulp.watch('assets/styles/**/*.scss', ['styles', 'rtl-styles']);
  // Watch .js files
  gulp.watch('assets/scripts/**/*.js', ['scripts']);
  // Watch image files
  gulp.watch('assets/images/**/*', ['images']);
  // Watch any files in dist/, reload on change
  gulp.watch(['dist/**', '**/*.php']).on('change', livereload.changed);
});
<|endoftext|>


<commit_before>var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var NwBuilder = require('nw-builder');

gulp.task('sync', function() {
  var package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
  var srcPackage = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
  var srcBower = JSON.parse(fs.readFileSync('src/bower.json', 'utf8'));
  srcPackage.name = srcBower.name = package.name;
  srcPackage.version = srcBower.version = package.version;
  srcPackage.description = srcBower.description = package.description;
  try {
    fs.writeFileSync('src/package.json',
                     JSON.stringify(srcPackage, null, "  "), 'utf8');
    fs.writeFileSync('src/bower.json',
                     JSON.stringify(srcBower, null, "  "), 'utf8');
  } catch(ignore) {
  }
});

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

var nw = function(cb, platforms) {
  var nw = new NwBuilder({
    files: 'src/**',
    version: '0.12.1',
    platforms: platforms,
    build: 'build',
    cacheDir: 'cache',
    macCredits: 'Credits.html',
    macIcns: 'src/images/jikkyo.icns',
    macZip: true,
    winIco: 'src/images/jikkyo.ico'
  });
  nw.on('log', function(msg) {
    gutil.log('node-webkit-builder', msg);
  });
  nw.build(cb);
};

gulp.task('nw:release', ['clean', 'sync'], function(cb) {
  nw(cb, ['win', 'osx', 'linux']);
});

gulp.task('nw:win32', function(cb) {
  nw(cb, ['win32']);
});

gulp.task('nw:win64', function(cb) {
  nw(cb, ['win64']);
});

gulp.task('nw:osx32', function(cb) {
  nw(cb, ['osx32']);
});

gulp.task('nw:osx64', function(cb) {
  nw(cb, ['osx64']);
});

gulp.task('nw:linux', function(cb) {
  nw(cb, ['linux']);
});

gulp.task('clean', ['clean:build']);
gulp.task('release', ['clean', 'sync', 'nw:release']);
gulp.task('default', ['build']);
<commit_msg>Modify build winZip option<commit_after>var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var NwBuilder = require('nw-builder');

gulp.task('sync', function() {
  var package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
  var srcPackage = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
  var srcBower = JSON.parse(fs.readFileSync('src/bower.json', 'utf8'));
  srcPackage.name = srcBower.name = package.name;
  srcPackage.version = srcBower.version = package.version;
  srcPackage.description = srcBower.description = package.description;
  try {
    fs.writeFileSync('src/package.json',
                     JSON.stringify(srcPackage, null, "  "), 'utf8');
    fs.writeFileSync('src/bower.json',
                     JSON.stringify(srcBower, null, "  "), 'utf8');
  } catch(ignore) {
  }
});

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

var nw = function(cb, platforms) {
  var nw = new NwBuilder({
    files: 'src/**',
    version: '0.12.1',
    platforms: platforms,
    build: 'build',
    cacheDir: 'cache',
    macCredits: 'Credits.html',
    macIcns: 'src/images/jikkyo.icns',
    macZip: true,
    winIco: 'src/images/jikkyo.ico',
    winZip: false
  });
  nw.on('log', function(msg) {
    gutil.log('node-webkit-builder', msg);
  });
  nw.build(cb);
};

gulp.task('nw:release', ['clean', 'sync'], function(cb) {
  nw(cb, ['win', 'osx', 'linux']);
});

gulp.task('nw:win32', function(cb) {
  nw(cb, ['win32']);
});

gulp.task('nw:win64', function(cb) {
  nw(cb, ['win64']);
});

gulp.task('nw:osx32', function(cb) {
  nw(cb, ['osx32']);
});

gulp.task('nw:osx64', function(cb) {
  nw(cb, ['osx64']);
});

gulp.task('nw:linux', function(cb) {
  nw(cb, ['linux']);
});

gulp.task('clean', ['clean:build']);
gulp.task('release', ['clean', 'sync', 'nw:release']);
gulp.task('default', ['build']);
<|endoftext|>


<commit_before>var bower = require('gulp-bower');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var del = require('del');
var ghPages = require('gulp-gh-pages');
var gulp = require('gulp');
var gutil = require('gulp-util');
var runSequence = require('run-sequence');
var size = require('gulp-size');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var spawn = require('child_process').spawn;
var vulcanize = require('gulp-vulcanize');
var watchify = require('watchify');

var DEV_DIR = 'dev/';
var DIST_DIR = 'dist/';

gulp.task('js', bundle);
var bundler = watchify(browserify('./dev/scripts/main.js', watchify.args));
bundler.on('update', bundle);
function bundle() {
  return bundler.bundle()
    .on('error', gutil.log.bind(gutil, 'Browserify Error'))
    .pipe(source('bundle.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(DEV_DIR + 'bundled_scripts'))
    .pipe(size({title: 'Bundled JavaScript'}));
}

gulp.task('bower', function() {
  return bower({
    cwd: DEV_DIR
  });
});

gulp.task('npm-install', function(callback) {
  var backend = spawn('npm', ['install']);
  backend.on('exit', function(code) {
    callback(code === 0 ? null : 'Error status from spawned process: ' + code);
  });
});

gulp.task('serve-frontend', ['js'], function() {
  browserSync({
    server: {
      baseDir: DEV_DIR
    },
    notify: false,
    open: false
  });

  gulp.watch(DEV_DIR + '**/*.{html,css,png}', browserSync.reload);
  gulp.watch(DEV_DIR + 'bundled_scripts/bundle.js', browserSync.reload);
  gulp.watch(DEV_DIR + 'bower.json', ['bower']);
});

gulp.task('serve-backend', function(callback) {
  var backend = spawn('node', ['server.js'], {stdio: 'inherit'});
  backend.on('exit', function(code) {
    callback(code === 0 ? null : 'Error status from spawned process: ' + code);
  });
});

gulp.task('serve', ['serve-frontend', 'serve-backend']);

gulp.task('vulcanize', function() {
  return gulp.src(DEV_DIR + 'elements.html')
    .pipe(vulcanize({
      dest: DEV_DIR,
      inline: true,
      strip: true
    }))
    .pipe(gulp.dest(DIST_DIR));
});

gulp.task('clean', function(callback) {
  del(DIST_DIR, callback);
});

gulp.task('copy-assets', function() {
  return gulp.src([
    DEV_DIR + '{bundled_scripts,fonts,images,styles}/**/*',
    DEV_DIR + 'index.html',
    DEV_DIR + 'manifest.json',
    DEV_DIR + 'service-worker.js',
    DEV_DIR + '**/webcomponents.min.js'
  ]).pipe(gulp.dest(DIST_DIR));
});

gulp.task('build', function(callback) {
  runSequence('clean', ['vulcanize', 'js'], 'copy-assets', callback);
});

gulp.task('gh-pages', ['build'], function() {
  return gulp.src(DIST_DIR + '**/*').pipe(ghPages());
});

gulp.task('default', function() {
  runSequence(['npm-install', 'bower'], 'serve');
});
<commit_msg>Refactored JS watching.<commit_after>var bower = require('gulp-bower');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var del = require('del');
var ghPages = require('gulp-gh-pages');
var gulp = require('gulp');
var gutil = require('gulp-util');
var runSequence = require('run-sequence');
var size = require('gulp-size');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var spawn = require('child_process').spawn;
var vulcanize = require('gulp-vulcanize');
var watchify = require('watchify');

var DEV_DIR = 'dev/';
var DIST_DIR = 'dist/';

function bundle(bundler) {
  return bundler.bundle()
    .on('error', gutil.log.bind(gutil, 'Browserify Error'))
    .pipe(source('bundle.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(DEV_DIR + 'bundled_scripts'))
    .pipe(size({title: 'Bundled JavaScript'}));
}

gulp.task('js', function() {
  var bundler = browserify('./dev/scripts/main.js');
  bundle(bundler);
});

gulp.task('js-watch', function() {
  var bundler = watchify(browserify('./dev/scripts/main.js', watchify.args));
  bundle(bundler);
  bundler.on('update', bundle);
});

gulp.task('bower', function() {
  return bower({
    cwd: DEV_DIR
  });
});

gulp.task('npm-install', function(callback) {
  var backend = spawn('npm', ['install']);
  backend.on('exit', function(code) {
    callback(code === 0 ? null : 'Error status from spawned process: ' + code);
  });
});

gulp.task('serve-frontend', ['js-watch'], function() {
  browserSync({
    server: {
      baseDir: DEV_DIR
    },
    notify: false,
    open: false
  });

  gulp.watch(DEV_DIR + '**/*.{html,css,png}', browserSync.reload);
  gulp.watch(DEV_DIR + 'bundled_scripts/bundle.js', browserSync.reload);
  gulp.watch(DEV_DIR + 'bower.json', ['bower']);
});

gulp.task('serve-backend', function(callback) {
  var backend = spawn('node', ['server.js'], {stdio: 'inherit'});
  backend.on('exit', function(code) {
    callback(code === 0 ? null : 'Error status from spawned process: ' + code);
  });
});

gulp.task('serve', ['serve-frontend', 'serve-backend']);

gulp.task('vulcanize', function() {
  return gulp.src(DEV_DIR + 'elements.html')
    .pipe(vulcanize({
      dest: DEV_DIR,
      inline: true,
      strip: true
    }))
    .pipe(gulp.dest(DIST_DIR));
});

gulp.task('clean', function(callback) {
  del(DIST_DIR, callback);
});

gulp.task('copy-assets', function() {
  return gulp.src([
    DEV_DIR + '{bundled_scripts,fonts,images,styles}/**/*',
    DEV_DIR + 'index.html',
    DEV_DIR + 'manifest.json',
    DEV_DIR + 'service-worker.js',
    DEV_DIR + '**/webcomponents.min.js'
  ]).pipe(gulp.dest(DIST_DIR));
});

gulp.task('build', function(callback) {
  runSequence('clean', ['vulcanize', 'js'], 'copy-assets', callback);
});

gulp.task('gh-pages', ['build'], function() {
  return gulp.src(DIST_DIR + '**/*').pipe(ghPages());
});

gulp.task('default', function() {
  runSequence(['npm-install', 'bower'], 'serve');
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
  mocha = require('gulp-mocha'),
  runSequence = require('gulp-run-sequence'),
  rimraf = require('rimraf'),
  fs = require('fs-extra'),
  replace = require('gulp-replace');

var gutil = require("gulp-util"),
  webpack = require("webpack"),
  webpackConfig = require("./webpack.config.js"),
  packageConfig = require('./package.json');

gulp.task("dist", function(cb) {
  runSequence(
    'dist:clean',
    'dist:package:debug',
    'dist:package:release',
    'dist:package:latest-entry',
    cb);
});

gulp.task("npm:pre-publish", function(cb) {
  return gulp.src('./package.json')
    .pipe(replace(/latest.js/g, packageConfig.name + "-" + packageConfig.version + ".js"))
    .pipe(gulp.dest('./'));
});

gulp.task("dist:package:release", function(cb) {
  // modify some webpack config options
  var myConfig = Object.create(webpackConfig);
  myConfig.plugins = myConfig.plugins || [];
  myConfig.plugins = myConfig.plugins.concat(
    new webpack.DefinePlugin({
      "process.env": {
        // This has effect on the react lib size
        "NODE_ENV": JSON.stringify("production")
      }
    }),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.UglifyJsPlugin()
  );
  myConfig.output.filename = "dist/" + packageConfig.name + "-" + packageConfig.version + ".js";

  // run webpack
  webpack(myConfig, function(err, stats) {
    if (err) throw new gutil.PluginError("webpack:build", err);
    gutil.log("[webpack:build]", stats.toString({
      colors: true
    }));
    cb();
  });
});

gulp.task("dist:package:debug", function(cb) {
  // modify some webpack config options
  var myDevConfig = Object.create(webpackConfig);
  myDevConfig.devtool = "sourcemap";
  myDevConfig.debug = true;
  myDevConfig.output.filename = "dist/" + packageConfig.name + "-" + packageConfig.version + ".debug.js";

  // create a single instance of the compiler to allow caching
  var devCompiler = webpack(myDevConfig);

  // run webpack
  devCompiler.run(function(err, stats) {
    if (err) throw new gutil.PluginError("webpack:build-dev", err);
    gutil.log("[webpack:build-dev]", stats.toString({
      colors: true
    }));
    cb();
  });
});

gulp.task("test", function() {
  return gulp.src('test/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("test:integration", function() {
  return gulp.src('test/integration/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("test:unit", function() {
  return gulp.src('test/unit/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("dist:clean", function(cb) {
  rimraf('./dist', cb);
});
<commit_msg>bugfix for extra gulp entry<commit_after>var gulp = require('gulp'),
  mocha = require('gulp-mocha'),
  runSequence = require('gulp-run-sequence'),
  rimraf = require('rimraf'),
  fs = require('fs-extra'),
  replace = require('gulp-replace');

var gutil = require("gulp-util"),
  webpack = require("webpack"),
  webpackConfig = require("./webpack.config.js"),
  packageConfig = require('./package.json');

gulp.task("dist", function(cb) {
  runSequence(
    'dist:clean',
    'dist:package:debug',
    'dist:package:release'
    cb);
});

gulp.task("npm:pre-publish", function(cb) {
  return gulp.src('./package.json')
    .pipe(replace(/latest.js/g, packageConfig.name + "-" + packageConfig.version + ".js"))
    .pipe(gulp.dest('./'));
});

gulp.task("dist:package:release", function(cb) {
  // modify some webpack config options
  var myConfig = Object.create(webpackConfig);
  myConfig.plugins = myConfig.plugins || [];
  myConfig.plugins = myConfig.plugins.concat(
    new webpack.DefinePlugin({
      "process.env": {
        // This has effect on the react lib size
        "NODE_ENV": JSON.stringify("production")
      }
    }),
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.UglifyJsPlugin()
  );
  myConfig.output.filename = "dist/" + packageConfig.name + "-" + packageConfig.version + ".js";

  // run webpack
  webpack(myConfig, function(err, stats) {
    if (err) throw new gutil.PluginError("webpack:build", err);
    gutil.log("[webpack:build]", stats.toString({
      colors: true
    }));
    cb();
  });
});

gulp.task("dist:package:debug", function(cb) {
  // modify some webpack config options
  var myDevConfig = Object.create(webpackConfig);
  myDevConfig.devtool = "sourcemap";
  myDevConfig.debug = true;
  myDevConfig.output.filename = "dist/" + packageConfig.name + "-" + packageConfig.version + ".debug.js";

  // create a single instance of the compiler to allow caching
  var devCompiler = webpack(myDevConfig);

  // run webpack
  devCompiler.run(function(err, stats) {
    if (err) throw new gutil.PluginError("webpack:build-dev", err);
    gutil.log("[webpack:build-dev]", stats.toString({
      colors: true
    }));
    cb();
  });
});

gulp.task("test", function() {
  return gulp.src('test/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("test:integration", function() {
  return gulp.src('test/integration/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("test:unit", function() {
  return gulp.src('test/unit/**/*.js', {
      read: false
    })
    .pipe(mocha({
      reporter: 'spec',
      timeout: 60000
    }));
});

gulp.task("dist:clean", function(cb) {
  rimraf('./dist', cb);
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    gls = require('gulp-live-server'),
    uglify = require('gulp-uglifyjs'),
    rename = require("gulp-rename");
//___________________________________________________
/*
gulp.task('default', ['lint']);
gulp.task('lint', ['jslint']);
gulp.task('build', ['lint', 'browserify', 'uglify']);

//___________________________________________________
// npm i --save-dev gulp-jshint jshint-stylish
var jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish');

gulp.task('jslint', function() {
    gulp.src('./index.js')
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});*/
//___________________________________________________
gulp.task('serve-test', function() {
    var server = gls.static(".", 8287);
    server.start();
    //live reload changed resource(s)
    gulp.watch(['dist/**/*.js', 'test/**/*.js'], server.notify);
});

//___________________________________________________
gulp.task('uglify', function() {
    gulp.src('dist/yamvish.js')
        .pipe(uglify())
        .pipe(rename('yamvish.min.js'))
        .pipe(gulp.dest('./dist'))
});

//___________________ browserify
/*
var browserify = require('gulp-browserify');
gulp.task('browserify', function() {
    // Single entry point to browserify
    gulp.src('index.js')
        .pipe(browserify({
            standalone: true,
            insertGlobals: false,
            debug: false // !gulp.env.production
        }))
        .pipe(rename('yamvish.js'))
        .pipe(gulp.dest('./dist'))
});
*/
<commit_msg>work on gulpfile<commit_after>var gulp = require('gulp'),
    uglify = require('gulp-uglifyjs'),
    rename = require("gulp-rename");
//___________________________________________________

gulp.task('default', ['lint']);
gulp.task('lint', ['jslint']);
gulp.task('build', ['lint', 'uglify']);

//___________________________________________________
// npm i --save-dev gulp-jshint jshint-stylish
var jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish');

gulp.task('jslint', function() {
    gulp.src(['./index.js', './core.js', './full.js', './lib/**.js', './plugins/**.js'])
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
});

//___________________________________________________
gulp.task('uglify', function() {
    gulp.src('dist/yamvish.js')
        .pipe(uglify())
        .pipe(rename('yamvish.min.js'))
        .pipe(gulp.dest('./dist'));
    gulp.src('dist/yamvish.core.js')
        .pipe(uglify())
        .pipe(rename('yamvish.core.min.js'))
        .pipe(gulp.dest('./dist'));
});

//___________________ browserify
/*
var browserify = require('gulp-browserify');
gulp.task('browserify', function() {
    // Single entry point to browserify
    gulp.src('index.js')
        .pipe(browserify({
            standalone: true,
            insertGlobals: false,
            debug: false // !gulp.env.production
        }))
        .pipe(rename('yamvish.js'))
        .pipe(gulp.dest('./dist'))
});
*/
<|endoftext|>


<commit_before>var gulp 	= require('gulp');
var	pkg		= require('./package.json');
var concat	= require('gulp-concat');
var uglify	= require('gulp-uglify');
var concat 	= require('gulp-concat');
var jshint	= require('gulp-jshint');

gulp.task('public', function() {
	return gulp.src([
		'src/**/*.html'
		], { "base": "src" })
		.pipe(gulp.dest("public/"));
});

gulp.task('libs', function() {
	return gulp.src(['src/lib/**/*.js'])
				.pipe(concat(pkg.name+'-libs.min.js'))
				.pipe(uglify())
				.pipe(gulp.dest("public/lib/"));
});

gulp.task('app', function() {
	return gulp.src(['src/js/**/*.js'])
			.pipe(jshint())
			.pipe(jshint.reporter('jshint-stylish'))
			.pipe(concat(pkg.name+'.min.js'))
			// .pipe(uglify())  // TODO: uncomment this later, easier to debug this way
			.pipe(gulp.dest("public/js/"));
})

gulp.task('watch', function() {
	gulp.watch(['src/js/**/*.js'], ['app']);
	gulp.watch(['src/**/*.html'], ['public']);
});

gulp.task('default', ['public','libs','app']);
<commit_msg>removed gulpfile. Not enought time to cover it in class<commit_after><|endoftext|>


<commit_before>const gulp = require('gulp');
const axios = require('axios');
const fs = require('fs');
const del = require('del');

const nodejsLink86 = 'https://nodejs.org/download/release/v14.19.2/node-v14.19.2-x86.msi';
const nodejsLink64 = 'https://nodejs.org/download/release/v14.19.2/node-v14.19.2-x64.msi';

function download(url, file) {
    return axios(url, {responseType: 'arraybuffer'})
        .then(response => fs.writeFileSync(file, response.data));
}

gulp.task('0-clean', () => del(['tmp/**/*', 'build/.windows-ready/**/*']));
gulp.task('1-nodex86', async () => download(nodejsLink86, __dirname + '/build/windows/nodejs/node.msi'));
gulp.task('2-nodex64', async () => download(nodejsLink64, __dirname + '/build/windows/nodejs/node-x64.msi'));
gulp.task('3-0-replaceWindowsVersion', async () => {
    const version = require('./package.json').version;
    !fs.existsSync(__dirname + '/build/.windows-ready') && fs.mkdirSync(__dirname + '/build/.windows-ready');

    let iss = fs.readFileSync(__dirname + '/build/windows/ioBroker.iss').toString('utf8');
    iss = iss.replace('@@version', version)
    fs.writeFileSync(__dirname + '/build/.windows-ready/ioBroker.iss', iss);

    fs.writeFileSync(`${__dirname}/build/.windows-ready/createSetup.bat`, `"${__dirname}/build/windows/InnoSetup6/ISCC.exe" "${__dirname}/build/.windows-ready/ioBroker.iss"`);
});

gulp.task('3-1-copy', async () =>
    gulp.src([
        'build/windows/*.js',
        'build/windows/*.ico',
        'build/windows/*.bat',
        'build/windows/*.json',
        '!service_ioBroker.bat',
        '!_service_ioBroker.bat',
        '!*.iss'
    ])
        .pipe(gulp.dest('build/.windows-ready')));

gulp.task('3-2-copy-nodejs', async () =>
    gulp.src([
        'build/windows/nodejs/**/*',
    ])
        .pipe(gulp.dest('build/.windows-ready/nodejs')));

function _checkFiles(callback, index) {
    index = index || 0;
    const files = [
        'build/.windows-ready/ioBroker.iss',
        'build/.windows-ready/nodejs/node.msi',
        'build/.windows-ready/nodejs/node-x64.msi',
        'build/.windows-ready/ioBroker.ico'
    ];

    if (files.find(file => !fs.existsSync(__dirname + '/' + file))) {
        if (index < 5) {
            setTimeout(() => _checkFiles(callback, index + 1), 3000);
        } else {
            callback('timeout');
        }
    } else {
        callback(null);
    }
}

function checkFiles() {
    return new Promise((resolve, reject) => _checkFiles(error => error ? reject(error) : resolve()));
}

function runMSI() {
    return new Promise((resolve, reject) => {
        checkFiles()
            .then(() => {
                // Install node modules
                const cwd = __dirname.replace(/\\/g, '/') + '/build/windows/';

                const cmd = `"${__dirname}\\build\\windows\\InnoSetup6\\ISCC.exe" "${__dirname}\\build\\.windows-ready\\ioBroker.iss"`;
                console.log(`"${cmd} in ${cwd}`);

                // System call used for update of js-controller itself,
                // because during installation npm packet will be deleted too, but some files must be loaded even during the install process.
                const exec = require('child_process').exec;
                const child = exec(cmd, {cwd});

                child.stderr.pipe(process.stderr);
                child.stdout.pipe(process.stdout);

                child.on('exit', (code /* , signal */) => {
                    // code 1 is strange error that cannot be explained. Everything is installed but error :(
                    if (code && code !== 1) {
                        reject(new Error('Cannot install: ' + code));
                    } else {
                        console.log(`"${cmd} in ${cwd} finished.`);
                        // command succeeded
                        resolve();
                    }
                });
            })
            .catch(error => reject(error));
    });
}

gulp.task('3-3-runMSI', runMSI);

if (/^win/.test(process.platform)) {
    gulp.task('3-windows-msi', gulp.series(['3-0-replaceWindowsVersion', '3-1-copy', '3-2-copy-nodejs', '3-3-runMSI']));
} else {
    gulp.task('3-windows-msi', async () => console.warn('Cannot create windows setup, while host is not windows'));
}

gulp.task('default',  gulp.series(['0-clean', '1-nodex86', '2-nodex64', '3-windows-msi']));
<commit_msg>Fix pipeline<commit_after>const gulp = require('gulp');
const axios = require('axios');
const fs = require('fs');
const del = require('del');
const path = require('path');

const nodejsLink86 = 'https://nodejs.org/download/release/v14.19.2/node-v14.19.2-x86.msi';
const nodejsLink64 = 'https://nodejs.org/download/release/v14.19.2/node-v14.19.2-x64.msi';

function download(url, file) {
    const directoryName = path.dirname(file);
    if (!fs.existsSync(directoryName)) {
        fs.mkdirSync(directoryName);
    }

    return axios(url, {responseType: 'arraybuffer'})
        .then(response => fs.writeFileSync(file, response.data));
}

gulp.task('0-clean', () => del(['tmp/**/*', 'build/.windows-ready/**/*', 'delivery/**/*']));
gulp.task('1-nodex86', () => download(nodejsLink86, __dirname + '/build/windows/nodejs/node.msi'));
gulp.task('2-nodex64', () => download(nodejsLink64, __dirname + '/build/windows/nodejs/node-x64.msi'));
gulp.task('3-0-replaceWindowsVersion', async () => {
    await checkFiles(['build/windows/nodejs/node.msi', 'build/windows/nodejs/node-x64.msi']);

    const version = require('./package.json').version;
    !fs.existsSync(__dirname + '/build/.windows-ready') && fs.mkdirSync(__dirname + '/build/.windows-ready');

    let iss = fs.readFileSync(__dirname + '/build/windows/ioBroker.iss').toString('utf8');
    iss = iss.replace('@@version', version)
    fs.writeFileSync(__dirname + '/build/.windows-ready/ioBroker.iss', iss);

    fs.writeFileSync(`${__dirname}/build/.windows-ready/createSetup.bat`, `"${__dirname}/build/windows/InnoSetup6/ISCC.exe" "${__dirname}/build/.windows-ready/ioBroker.iss"`);
});

gulp.task('3-1-copy', async () =>
    gulp.src([
        'build/windows/*.js',
        'build/windows/*.ico',
        'build/windows/*.bat',
        'build/windows/*.json',
        '!service_ioBroker.bat',
        '!_service_ioBroker.bat',
        '!*.iss'
    ])
        .pipe(gulp.dest('build/.windows-ready')));

gulp.task('3-2-copy-nodejs', async () =>
    gulp.src([
        'build/windows/nodejs/**/*',
    ])
        .pipe(gulp.dest('build/.windows-ready/nodejs')));

function _checkFiles(files, callback, index) {
    index = index || 0;

    if (files.find(file => !fs.existsSync(__dirname + '/' + file))) {
        if (index < 5) {
            setTimeout(() => _checkFiles(files, callback, index + 1), 3000);
        } else {
            callback('timeout');
        }
    } else {
        callback(null);
    }
}

function checkFiles(files) {
    return new Promise((resolve, reject) => _checkFiles(files, error => error ? reject(error) : resolve()));
}

function runMSI() {
    return new Promise((resolve, reject) => {
        checkFiles([
            'build/.windows-ready/ioBroker.iss',
            'build/.windows-ready/nodejs/node.msi',
            'build/.windows-ready/nodejs/node-x64.msi',
            'build/.windows-ready/ioBroker.ico'
        ])
            .then(() => {
                // Install node modules
                const cwd = __dirname.replace(/\\/g, '/') + '/build/windows/';

                const cmd = `"${__dirname}\\build\\windows\\InnoSetup6\\ISCC.exe" "${__dirname}\\build\\.windows-ready\\ioBroker.iss"`;
                console.log(`"${cmd} in ${cwd}`);

                // System call used for update of js-controller itself,
                // because during installation npm packet will be deleted too, but some files must be loaded even during the install process.
                const exec = require('child_process').exec;
                const child = exec(cmd, {cwd});

                child.stderr.pipe(process.stderr);
                child.stdout.pipe(process.stdout);

                child.on('exit', (code /* , signal */) => {
                    // code 1 is strange error that cannot be explained. Everything is installed but error :(
                    if (code && code !== 1) {
                        reject(new Error('Cannot install: ' + code));
                    } else {
                        console.log(`"${cmd} in ${cwd} finished.`);
                        // command succeeded
                        resolve();
                    }
                });
            })
            .catch(error => reject(error));
    });
}

gulp.task('3-3-runMSI', runMSI);

if (/^win/.test(process.platform)) {
    gulp.task('3-windows-msi', gulp.series(['3-0-replaceWindowsVersion', '3-1-copy', '3-2-copy-nodejs', '3-3-runMSI']));
} else {
    gulp.task('3-windows-msi', async () => console.warn('Cannot create windows setup, while host is not windows'));
}

gulp.task('default',  gulp.series(['0-clean', '1-nodex86', '2-nodex64', '3-windows-msi']));
<|endoftext|>


<commit_before>'use strict';

var config = require('./build/build.config.js');
var karmaConfig = require('./build/karma.config.js');
var protractorConfig = require('./build/protractor.config.js');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var pagespeed = require('psi');
var reload = browserSync.reload;
var pkg = require('./package');
var moment = require("moment");
var karma = require('karma').server;
var _ = require('lodash');
var fs = require('fs');
	var url = require('url');
  var webdriverStandalone = require('gulp-protractor').webdriver_standalone;
  var webdriverUpdate = require('gulp-protractor').webdriver_update;
// Run e2e tests using protractor.
// Make sure server task is running.
gulp.task('protractor', ['webdriver:update'], function() {
  return gulp.src("webapp/test/e2e/**/*.scenario.js")
    .pipe(plugins.protractor.protractor({
        configFile: "build/protractor.config.js"
    }))
    .on('error', function(e) {throw e});
});

gulp.task('webdriver:update', webdriverUpdate);

// Run webdriver standalone server indefinitely.
// Usually not required.
gulp.task('webdriver:standalone', ['webdriver:update'], webdriverStandalone);
/**
 * Run test once and exit
 */
gulp.task('test:unit', ["generated"], function(done) {
    karma.start(_.assign({}, karmaConfig, {
        singleRun: true
    }), done);
});

/**
 * Watch for file changes and re-run tests on each change
 */
gulp.task('tdd', function(done) {
    karma.start(karmaConfig, done);
});
// Lint JavaScript
gulp.task('jshint', function() {
    return gulp.src("webapp/src/**/*.js")
        .pipe(reload({
            stream: true,
            once: true
        }))
        .pipe(plugins.jshint())
        .pipe(plugins.jshint.reporter('jshint-stylish'))
        .pipe(plugins.if(!browserSync.active, plugins.jshint.reporter('fail')));
});

// Optimize Images
gulp.task('images', function() {
    return gulp.src('webapp/assets/images/**')
        .pipe(plugins.cache(plugins.imagemin({
            progressive: true,
            interlaced: true
        })))
        .pipe(gulp.dest('build/dist/assets/images'))
        .pipe(plugins.size({
            title: 'images'
        }));
});

gulp.task('copy', ['copy:root', 'copy:assets']);
gulp.task('generated', ['html2js', 'scss']);

// Copy All Files At The Root Level (app)
gulp.task('copy:root', function() {
    return gulp.src([
            'webapp/*.*',
            '!webapp/*.html'
        ], {
            dot: true
        })
        .pipe(gulp.dest(config.distDir))
        .pipe(plugins.size({
            title: 'copy:root'
        }));
});

// Copy All Files At The Root Level (app)
gulp.task('copy:assets', function() {
    return gulp.src(['webapp/assets/**', '!webapp/assets/images'])
        .pipe(gulp.dest(config.distDir + "/assets"))
        .pipe(plugins.size({
            title: 'copy:assets'
        }));
});

gulp.task('html2js', function() {
    return gulp.src('webapp/src/**/*.tpl.html')
        .pipe(plugins.ngHtml2js({
            moduleName: "templates",
            prefix: "app/"
        }))
        .pipe(plugins.concat("templates.js"))
        .pipe(gulp.dest("webapp/tmp"));
});

gulp.task('html', function() {
    return gulp.src('webapp/*.html')
        .pipe(plugins.useref.assets())
        .pipe(plugins.if(/main.js/, plugins.ngAnnotate()))
        .pipe(plugins.if('*.js', plugins.uglify({
            mangle: false
        })))
        .pipe(plugins.if('*.css', plugins.csso()))

    .pipe(plugins.rev())
        .pipe(plugins.header(config.banner, {
            version: pkg.version,
            name: pkg.name,
            date: moment().format("YYYY-MM-DD")
        }))
        .pipe(plugins.useref.restore())
        .pipe(plugins.useref())
        .pipe(plugins.if('*.html', plugins.minifyHtml({empty:true})))
        .pipe(plugins.revReplace())
        .pipe(gulp.dest('build/dist'))
        .pipe(plugins.size({
            title: 'html'
        }));
});

gulp.task('scss', function() {
    return gulp.src(['webapp/src/scss/main.scss'])
        .pipe(plugins.rubySass({
            style: 'expanded',
            precision: 10
        }))
        .on('error', console.error.bind(console))
        .pipe(gulp.dest('webapp/tmp'))
        .pipe(plugins.size({
            title: 'scss'
        }));
});

gulp.task('serve', function() {
    browserSync({
        notify: false,
        server: {
            baseDir: ['webapp']
        }
    });
    gulp.watch(['webapp/**/*.html'], reload);
    gulp.watch(['webapp/src/scss**/*.scss'], ['scss']);
    gulp.watch(['webapp/src/**/*.js'], ['jshint']);
    gulp.watch(['webapp/assets/**/*'], reload);
});

// Build and serve the output from the dist build
gulp.task('serve:dist', ['default'], function() {
    browserSync({
        notify: false,
        server: {
            baseDir: 'build/dist',
            middleware: function(req, res, next) {
                var indexFile = "index.html";
                var rootDir = 'build/dist';
                    var path = url.parse(req.url).pathname;

                    fs.readFile('./' + rootDir + path, function(err, buffer) {
                        if (!err) {
                            return next();
                        }

                        fs.readFile('./' + rootDir + '/' + indexFile, function(err, buffer) {
                            if (err) {
                                return next(err);
                            }

                            var resp = {
                                headers: {
                                    'Content-Type': 'text/html'
                                },
                                body: buffer
                            };
                            res.writeHead(200, resp.headers);
                            res.end(resp.body);
                        });
                    });

            }
        }
    });
});

/*
// Update/install webdriver.
gulp.task('webdriver:update', webdriverUpdate);

// Run webdriver standalone server indefinitely.
// Usually not required.
gulp.task('webdriver:standalone', ['webdriver:update'], webdriverStandalone);

// Run unit tests using karma.
gulp.task('karma', function () {
	return gulp.src(files.test.unit)
		.pipe(karma({
			configFile: 'karma.conf.js',
			action: 'run'
		}))
		.on('error', function (e) {
			throw e
		});
});

// Run e2e tests using protractor.
// Make sure server task is running.
gulp.task('protractor', ['webdriver:update'], function () {
	return gulp.src(files.test.e2e)
		.pipe(protractor({
			configFile: 'protractor.conf.js',
		}))
		.on('error', function (e) {
			throw e
		});
});

gulp.task('test', ['karma', 'protractor']);
*/

// Clean Output Directory
gulp.task('clean', function() {
    return gulp.src('build/dist', {
            read: false
        }) // much faster
        .pipe(plugins.rimraf());
});

gulp.task('default', ['clean'], function(cb) {
    runSequence('generated', ['copy', 'jshint', 'images', 'html'], cb);
});

/*
.pipe(concat("ng-quick-date.js"))   // Combine into 1 file
	.pipe(gulp.dest("dist"))            // Write non-minified to disk
	.pipe(uglify())                     // Minify
	.pipe(rename({extname: ".min.js"})) // Rename to ng-quick-date.min.js
	.pipe(gulp.dest("dist"))
 */
/*

grunt.registerTask('unit', 'karma:unit');

grunt.registerTask('default', 'serve');
*/
<commit_msg>fluff<commit_after>'use strict';

var config = require('./build/build.config.js');
var karmaConfig = require('./build/karma.config.js');
var protractorConfig = require('./build/protractor.config.js');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var pagespeed = require('psi');
var reload = browserSync.reload;
var pkg = require('./package');
var moment = require("moment");
var karma = require('karma').server;
var _ = require('lodash');
var fs = require('fs');
var url = require('url');
var webdriverStandalone = require('gulp-protractor').webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;
// Run e2e tests using protractor.
// Make sure server task is running.
gulp.task('protractor', ['webdriver:update'], function() {
  return gulp.src("webapp/test/e2e/**/*.scenario.js")
    .pipe(plugins.protractor.protractor({
      configFile: "build/protractor.config.js"
    }))
    .on('error', function(e) {
      throw e
    });
});

gulp.task('webdriver:update', webdriverUpdate);

// Run webdriver standalone server indefinitely.
// Usually not required.
gulp.task('webdriver:standalone', ['webdriver:update'], webdriverStandalone);
/**
 * Run test once and exit
 */
gulp.task('test:unit', ["generated"], function(done) {
  karma.start(_.assign({}, karmaConfig, {
    singleRun: true
  }), done);
});

/**
 * Watch for file changes and re-run tests on each change
 */
gulp.task('tdd', function(done) {
  karma.start(karmaConfig, done);
});
// Lint JavaScript
gulp.task('jshint', function() {
  return gulp.src("webapp/src/**/*.js")
    .pipe(reload({
      stream: true,
      once: true
    }))
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter('jshint-stylish'))
    .pipe(plugins.if(!browserSync.active, plugins.jshint.reporter('fail')));
});

// Optimize Images
gulp.task('images', function() {
  return gulp.src('webapp/assets/images/**')
    .pipe(plugins.cache(plugins.imagemin({
      progressive: true,
      interlaced: true
    })))
    .pipe(gulp.dest('build/dist/assets/images'))
    .pipe(plugins.size({
      title: 'images'
    }));
});

gulp.task('copy', ['copy:root', 'copy:assets']);
gulp.task('generated', ['html2js', 'scss']);

// Copy All Files At The Root Level (app)
gulp.task('copy:root', function() {
  return gulp.src([
      'webapp/*.*',
      '!webapp/*.html'
    ], {
      dot: true
    })
    .pipe(gulp.dest(config.distDir))
    .pipe(plugins.size({
      title: 'copy:root'
    }));
});

// Copy All Files At The Root Level (app)
gulp.task('copy:assets', function() {
  return gulp.src(['webapp/assets/**', '!webapp/assets/images'])
    .pipe(gulp.dest(config.distDir + "/assets"))
    .pipe(plugins.size({
      title: 'copy:assets'
    }));
});

gulp.task('html2js', function() {
  return gulp.src('webapp/src/**/*.tpl.html')
    .pipe(plugins.ngHtml2js({
      moduleName: "templates",
      prefix: "app/"
    }))
    .pipe(plugins.concat("templates.js"))
    .pipe(gulp.dest("webapp/tmp"));
});

gulp.task('html', function() {
  return gulp.src('webapp/*.html')
    .pipe(plugins.useref.assets())
    .pipe(plugins.if(/main.js/, plugins.ngAnnotate()))
    .pipe(plugins.if('*.js', plugins.uglify({
      mangle: false
    })))
    .pipe(plugins.if('*.css', plugins.csso()))

  .pipe(plugins.rev())
    .pipe(plugins.header(config.banner, {
      version: pkg.version,
      name: pkg.name,
      date: moment().format("YYYY-MM-DD")
    }))
    .pipe(plugins.useref.restore())
    .pipe(plugins.useref())
    .pipe(plugins.if('*.html', plugins.minifyHtml({
      empty: true
    })))
    .pipe(plugins.revReplace())
    .pipe(gulp.dest('build/dist'))
    .pipe(plugins.size({
      title: 'html'
    }));
});

gulp.task('scss', function() {
  return gulp.src(['webapp/src/scss/main.scss'])
    .pipe(plugins.rubySass({
      style: 'expanded',
      precision: 10
    }))
    .on('error', console.error.bind(console))
    .pipe(gulp.dest('webapp/tmp'))
    .pipe(plugins.size({
      title: 'scss'
    }));
});

gulp.task('serve', function() {
  browserSync({
    notify: false,
    server: {
      baseDir: ['webapp']
    }
  });
  gulp.watch(['webapp/**/*.html'], reload);
  gulp.watch(['webapp/src/scss**/*.scss'], ['scss']);
  gulp.watch(['webapp/src/**/*.js'], ['jshint']);
  gulp.watch(['webapp/assets/**/*'], reload);
});

// Build and serve the output from the dist build
gulp.task('serve:dist', ['default'], function() {
  browserSync({
    notify: false,
    server: {
      baseDir: 'build/dist',
      middleware: function(req, res, next) {
        var indexFile = "index.html";
        var rootDir = 'build/dist';
        var path = url.parse(req.url).pathname;

        fs.readFile('./' + rootDir + path, function(err, buffer) {
          if (!err) {
            return next();
          }

          fs.readFile('./' + rootDir + '/' + indexFile, function(err, buffer) {
            if (err) {
              return next(err);
            }

            var resp = {
              headers: {
                'Content-Type': 'text/html'
              },
              body: buffer
            };
            res.writeHead(200, resp.headers);
            res.end(resp.body);
          });
        });

      }
    }
  });
});

/*
// Update/install webdriver.
gulp.task('webdriver:update', webdriverUpdate);

// Run webdriver standalone server indefinitely.
// Usually not required.
gulp.task('webdriver:standalone', ['webdriver:update'], webdriverStandalone);

// Run unit tests using karma.
gulp.task('karma', function () {
	return gulp.src(files.test.unit)
		.pipe(karma({
			configFile: 'karma.conf.js',
			action: 'run'
		}))
		.on('error', function (e) {
			throw e
		});
});

// Run e2e tests using protractor.
// Make sure server task is running.
gulp.task('protractor', ['webdriver:update'], function () {
	return gulp.src(files.test.e2e)
		.pipe(protractor({
			configFile: 'protractor.conf.js',
		}))
		.on('error', function (e) {
			throw e
		});
});

gulp.task('test', ['karma', 'protractor']);
*/

// Clean Output Directory
gulp.task('clean', function() {
  return gulp.src('build/dist', {
      read: false
    }) // much faster
    .pipe(plugins.rimraf());
});

gulp.task('default', ['clean'], function(cb) {
  runSequence('generated', ['copy', 'jshint', 'images', 'html'], cb);
});

/*
.pipe(concat("ng-quick-date.js"))   // Combine into 1 file
	.pipe(gulp.dest("dist"))            // Write non-minified to disk
	.pipe(uglify())                     // Minify
	.pipe(rename({extname: ".min.js"})) // Rename to ng-quick-date.min.js
	.pipe(gulp.dest("dist"))
 */
/*

grunt.registerTask('unit', 'karma:unit');

grunt.registerTask('default', 'serve');
*/
* *
var gulp = require('gulp'),
  $ = require('gulp-load-plugins')(),
  del = require('del'),
  browserSync = require('browser-sync'),
  reload = browserSync.reload,
  buildFolder = 'presentation',
  assetsFolder = 'assets',
  srcPaths = {
    scss: assetsFolder + '/styles/main.scss',
    theme: assetsFolder + '/theme/*.scss',
    css: assetsFolder + '/styles/main.css',
    scripts: assetsFolder + '/scripts/{,*/}*.js',
    images: assetsFolder + '/images/*.*'
  };

gulp.task('clean', function(cb) {
  del([buildFolder], cb);
});

gulp.task('styles', function() {
  gulp.src(srcPaths.scss)
    .pipe($.sass({
      errLogToConsole: true
    }))
    .pipe($.autoprefixer('last 2 version'))
    .pipe(gulp.dest(assetsFolder + '/styles'))
    .pipe(reload({
      stream: true
    }));
});

gulp.task('theme', function() {
  gulp.src(srcPaths.theme)
    .pipe($.sass({
      errLogToConsole: true
    }))
    .pipe($.autoprefixer('last 2 version'))
    .pipe(gulp.dest(assetsFolder + '/theme'))
    .pipe(reload({
      stream: true
    }));
});

gulp.task('scripts', function() {
  gulp.src([srcPaths.scripts, 'gulpfile.js', '!assets/scripts/vendor/*.js'])
    .pipe($.jshint('.jshintrc'))
    .pipe($.jshint.reporter(require('jshint-stylish')));
});

gulp.task('fonts', function() {
  gulp.src('theme/fonts/*.*')
    .pipe(gulp.dest('presentation/theme/fonts'));
});

gulp.task('images', function() {
  gulp.src('assets/images/*.*')
    .pipe(gulp.dest('presentation/assets/images'));
});

gulp.task('themeMove', function() {
  gulp.src('assets/theme/**/*.*')
    .pipe(gulp.dest('presentation/assets/theme'));
});

gulp.task('prepare', ['styles', 'scripts'], function() {
  var assets = $.useref.assets();

  gulp.src('*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.ngAnnotate()))
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe(gulp.dest(buildFolder));
});

gulp.task('browserSync', function() {
  browserSync({
    server: {
      baseDir: './'
    }
  });
});

gulp.task('bump', function() {
  gulp.src(['./bower.json', './package.json', './bower-dist.json'])
    .pipe($.bump())
    .pipe(gulp.dest('./'));
});

gulp.task('tag', ['bump'], function() {
  var version = require('./bower.json').version;
  $.git.tag('v' + version, function(err) {
    if (err) {
      throw err;
    } else {
      console.log('tag created');
    }
  });
});

gulp.task('bowerDist', function() {
  gulp.src('bower-dist.json')
    .pipe($.rename('bower.json'))
    .pipe(gulp.dest('presentation'));
});

gulp.task('push', ['tag'], function() {
  $.git.push('bower', 'master', {
    args: ' --tags --dry-run'
  }, function(err) {
    if (err) {
      throw err;
    } else {
      console.log('pushed to repo');
    }
  });
});

gulp.task('build', ['clean'], function() {
  gulp.start(['prepare', 'images', 'fonts', 'themeMove']);
});

gulp.task('bower', ['build'], function() {
  gulp.start(['tag', 'push']);
});

gulp.task('watch', function() {
  gulp.start(['browserSync', 'styles', 'theme', 'scripts']);
  gulp.watch(srcPaths.scss, ['styles']);
  gulp.watch(srcPaths.theme, ['theme']);
  gulp.watch(srcPaths.scripts, ['scripts', browserSync.reload]);
});
<|endoftext|>


<commit_before>var gulp        = require('gulp');
var browserSync = require('browser-sync');
var sass        = require('gulp-sass');
var prefix      = require('gulp-autoprefixer');
var cp          = require('child_process');

var messages = {
    jekyllBuild: 'Running: $ jekyll build'
};

/**
 * Build the Jekyll Site
 */
gulp.task('jekyll-build', function (done) {
    browserSync.notify(messages.jekyllBuild);
    return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
        .on('close', done);
});

/**
 * Rebuild Jekyll & do page reload
 */
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});

/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() {
    browserSync.init(null, {
        server: {
            baseDir: '_site'
        },
        host: "0.0.0.0"
    });
});

/**
 * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
 */
gulp.task('sass', function () {
    gulp.src('_scss/main.scss')
        .pipe(sass({includePaths: ['scss']}))
        .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
        .pipe(gulp.dest('_site/css'))
        .pipe(browserSync.reload({stream:true}))
        .pipe(gulp.dest('css'));
});

/**
 * Watch scss files for changes & recompile
 * Watch html/md files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('_scss/*.scss', ['sass']);
    gulp.watch(['_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
});

/**
 * Default task, running just `gulp` will compile the sass,
 * compile the jekyll site, launch BrowserSync & watch files.
 */
gulp.task('default', ['browser-sync', 'watch']);
<commit_msg>Added in-browser notifications for SASS errors<commit_after>var gulp        = require('gulp');
var browserSync = require('browser-sync');
var sass        = require('gulp-sass');
var prefix      = require('gulp-autoprefixer');
var cp          = require('child_process');

var messages = {
    jekyllBuild: 'Running: $ jekyll build'
};

/**
 * Build the Jekyll Site
 */
gulp.task('jekyll-build', function (done) {
    browserSync.notify(messages.jekyllBuild);
    return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
        .on('close', done);
});

/**
 * Rebuild Jekyll & do page reload
 */
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});

/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() {
    browserSync.init(null, {
        server: {
            baseDir: '_site'
        },
        host: "localhost"
    });
});

/**
 * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
 */
gulp.task('sass', function () {
    gulp.src('_scss/main.scss')
        .pipe(sass({
            includePaths: ['scss'],
            onError: browserSync.notify
        }))
        .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
        .pipe(gulp.dest('_site/css'))
        .pipe(browserSync.reload({stream:true}))
        .pipe(gulp.dest('css'));
});

/**
 * Watch scss files for changes & recompile
 * Watch html/md files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('_scss/*.scss', ['sass']);
    gulp.watch(['_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
});

/**
 * Default task, running just `gulp` will compile the sass,
 * compile the jekyll site, launch BrowserSync & watch files.
 */
gulp.task('default', ['browser-sync', 'watch']);
<|endoftext|>


<commit_before>var fs = require('fs');
var path = require('path');

var gulp = require('gulp');

var connect = require('gulp-connect');

var sass = require('gulp-sass');
var jshint = require('gulp-jshint');
var packageJSON  = require('./package');
var jshintConfig = packageJSON.jshintConfig;

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

var jade = require('gulp-jade');

// test images
var testData = require('./test/data');

var version = '1.0.0';
var dir = {
    ui: './ui',
    assets: './ui/assets',
    scss: './ui/*/*.scss',
    script: ['./ui/*/*.js', '!./ui/assets/*.js'],

    jade2watch: './ui/*/*.jade',

    build: {
        ui: 'build/easy/ui/1.0.0/',
        base: 'build/easy/base/1.0.0',
        combo: 'build/easy/lib/1.0.0'
    }
};

gulp.task('compress_js', function() {
    gulp.src(dir.script)
      .pipe(uglify())
      .pipe(gulp.dest(dir.build.ui))
});

gulp.task('compile_jade', function() {
    var dirs = fs.readdirSync(dir.ui);

    function compileJade(jadePath, data) {
        data.imgs = testData.imgs;
        data.slides = testData.slides;
        gulp.src(jadePath)
            .pipe(jade({
                locals: data,
                pretty: true
            }))
            .pipe(gulp.dest(path.join(dir.ui, data.name)))
    }

    dirs.forEach(function(file) {
        var configFilePath = path.join(dir.ui, file, 'config.json');
        var jadeFilePath = path.join(dir.ui, file, 'index.jade');

        if (/^E/.test(file) && fs.existsSync(configFilePath) && fs.existsSync(jadeFilePath)) {
            var config = require('./' + configFilePath);

            compileJade(jadeFilePath, config);
        } else {
            console.log('config file not found.')
        }
    });
});

gulp.task('compile_sass', function() {
    gulp.src(dir.scss)
        .pipe(sass())
        .pipe(gulp.dest(dir.ui));
});

// lint 单个文件
gulp.task('lint', function() {
    var path = process.argv[4];

    gulp.src(path)
        .pipe(jshint(jshintConfig))
        .pipe(jshint.reporter('default'));
});

gulp.task('default', function() {
    gulp.src(dir.script)
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('watch', function() {
    gulp.watch(dir.jade2watch, ['compile_jade']);

    gulp.watch(dir.scss, ['compile_sass']);
});

gulp.task('server', function() {
    connect.server({
        port: 1024,
        root: dir.ui,
        livereload: false
    });
});

gulp.task('dev', ['watch', 'server', 'compile_sass', 'compile_jade']);
<commit_msg>add gulp task rebuild_dir<commit_after>var fs = require('fs');
var path = require('path');

var gulp = require('gulp');

var connect = require('gulp-connect');

var sass = require('gulp-sass');
var jshint = require('gulp-jshint');
var packageJSON  = require('./package');
var jshintConfig = packageJSON.jshintConfig;

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

var jade = require('gulp-jade');

// test images
var testData = require('./test/data');

var BASE_VERSION = '1.0.0';

var UI_CONFIG_LIST = [{
    name: 'EDropdown',
    version: '1.0.0',
    hasCSS: false
},{
    name: 'ELazyload',
    version: '1.0.0',
    hasCSS: false
},{
    name: 'ESlide',
    version: '1.0.0',
    hasCSS: true
},{
    name: 'ETab',
    version: '1.0.0',
    hasCSS: false
},{
    name: 'EModal',
    version: '1.0.0',
    hasCSS: true
},{
    name: 'ETips',
    version: '1.0.0',
    hasCSS: true
}];

var DIR = {
    ui: './ui',
    assets: './ui/assets',
    scss: './ui/*/*.scss',
    script: ['./ui/*/*.js', '!./ui/assets/*.js'],

    jade2watch: './ui/*/*.jade',

    build: {
        combo : 'build/E/1.0.0',
        ui    : 'build/E/ui/1.0.0/',
        biz   : 'build/E/biz/1.0.0/',
        base  : 'build/E/base/1.0.0'
    }
};

gulp.task('rebuild_dir', function() {
    var configContent = '';
    var jsContent = fs.readFileSync(path.join(DIR.assets, 'template.js'), 'utf8');
    var cssContent = '';
    var readmeContent = '';

    function writeFile (filename, content) {
        fs.writeFile(filename, content, 'utf-8', function(err) {
            if (err) {
                console.error('=> File write failed: ' + err);
            } else {
                console.log('==> Created success. [' + filename + '].');
            }
        });
    }

    function loopCheckFile (dir, ui) {
        var configFile = dir + '/' + 'config.json';
        var jsFile     = dir + '/' + ui.name + '.js';
        var cssFile    = dir + '/' + ui.name + '.scss';
        var readmeFile = dir + '/README.md';

        if ( !fs.existsSync(configFile) ) {
            configContent = JSON.stringify(ui, null, '    ');

            writeFile(configFile, configContent);
        }
        if ( !fs.existsSync(jsFile) ) {
            writeFile(jsFile, jsContent);
        }
        if ( !fs.existsSync(cssFile) && ui.hasCSS ) {
            writeFile(cssFile, cssContent);
        }
        if ( !fs.existsSync(readmeFile) ) {
            readmeContent = '#' + ui.name + '@' + ui.version;
            writeFile(readmeFile, readmeContent);
        }
    }

    function loopCheckDir (ui) {
        var dirname    = path.join(DIR.ui, ui.name);

        var dirExists  = fs.existsSync(dirname);

        if ( !dirExists ) {
            fs.mkdirSync(dirname);
        }

        loopCheckFile(dirname, ui);
    }

    UI_CONFIG_LIST.forEach(function(item) {
        loopCheckDir(item);
    });
});

gulp.task('compress_js', function() {
    gulp.src(DIR.script)
      .pipe(uglify())
      .pipe(gulp.dest(DIR.build.ui))
});

gulp.task('compile_jade', function() {
    var dirs = fs.readdirSync(DIR.ui);

    function compileJade(jadePath, data) {
        data.imgs = testData.imgs;
        data.slides = testData.slides;
        gulp.src(jadePath)
            .pipe(jade({
                locals: data,
                pretty: true
            }))
            .pipe(gulp.dest(path.join(DIR.ui, data.name)))
    }

    dirs.forEach(function(file) {
        var configFilePath = path.join(DIR.ui, file, 'config.json');
        var jadeFilePath = path.join(DIR.ui, file, 'index.jade');

        if (/^E/.test(file) && fs.existsSync(configFilePath) && fs.existsSync(jadeFilePath)) {
            var config = require('./' + configFilePath);

            compileJade(jadeFilePath, config);
        } else {
            console.log('config file not found.')
        }
    });
});

gulp.task('compile_sass', function() {
    gulp.src(DIR.scss)
        .pipe(sass())
        .pipe(gulp.dest(DIR.ui));
});

// lint 单个文件
gulp.task('lint', function() {
    var path = process.argv[4];

    gulp.src(path)
        .pipe(jshint(jshintConfig))
        .pipe(jshint.reporter('default'));
});

gulp.task('default', function() {
    gulp.src(DIR.script)
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('watch', function() {
    gulp.watch(DIR.jade2watch, ['compile_jade']);

    gulp.watch(DIR.scss, ['compile_sass']);
});

gulp.task('server', function() {
    connect.server({
        port: 1024,
        root: DIR.ui,
        livereload: false
    });
});

gulp.task('dev', ['watch', 'server', 'compile_sass', 'compile_jade']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');

gulp.task('build', function () {
  return browserify({entries: './js/examples/main.jsx', extensions: ['.jsx'], debug: true})
    .transform('babelify', {presets: ['es2015', 'stage-1', 'react']})
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('public/examples'));
});

gulp.task('watch', ['build'], function () {
    gulp.watch('*.jsx', ['build']);
});

gulp.task('default', ['watch']);
<commit_msg>fix spacing in gulpfile<commit_after>var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');

gulp.task('build', function () {
  return browserify({entries: './js/examples/main.jsx', extensions: ['.jsx'], debug: true})
    .transform('babelify', {presets: ['es2015', 'stage-1', 'react']})
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('public/examples'));
});

gulp.task('watch', ['build'], function () {
  gulp.watch('*.jsx', ['build']);
});

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