var packageJson = require('./package.json') var gulp = require('gulp') var $ = require('gulp-load-plugins')({ lazy: false }) var path = require('path') var http = require('http') var st = require('st') var del = require('del') var swPrecache = require('sw-precache') var Server = require('karma').Server // The generated file is being created at src // so it can be fetched by usemin. gulp.task('templates', function () { return gulp.src('app/partials/**/*.html') .pipe($.angularTemplatecache('templates.js', { root: 'partials', module: 'myApp.templates', standalone: true })) .pipe(gulp.dest('app/js')) }) gulp.task('clean-templates', function () { return del(['app/js/templates.js']) }) gulp.task('usemin-index', function () { return gulp.src('app/index.html') .pipe($.usemin({ html: [$.minifyHtml({ empty: true })], js: ['concat', $.ngAnnotate(), $.uglify({ outSourceMap: false })], css: ['concat', $.minifyCss({ compatibility: true, keepBreaks: true })] })) .pipe(gulp.dest('dist')) }) gulp.task('usemin-badbrowser', function () { return gulp.src('app/badbrowser.html') .pipe($.usemin({ html: [$.minifyHtml({ empty: true })], css: ['concat', $.minifyCss({ compatibility: true, keepBreaks: true })] })) .pipe(gulp.dest('dist')) }) // ulimit -n 10240 on OS X gulp.task('imagemin', function () { return gulp.src(['app/img/**/*', '!app/img/screenshot*', '!app/img/*.wav']) .pipe($.imagemin()) .pipe(gulp.dest('dist/img')) }) gulp.task('standard', function () { return gulp.src(['app/**/*.js', '!app/vendor/**/*', 'gulpfile.js']) .pipe($.standard()) .pipe($.standard.reporter('default', { breakOnError: true })) }) gulp.task('copy-images', function () { return gulp.src(['app/img/**/*', '!app/img/screenshot*', '!app/img/*.wav']) .pipe(gulp.dest('dist/img')) }) gulp.task('copy', gulp.parallel( function () { return gulp.src(['app/favicon.ico', 'app/favicon_unread.ico', 'app/manifest.webapp', 'app/manifest.webapp.json', 'app/manifest.json', 'app/**/*worker.js']) .pipe(gulp.dest('dist')) }, function () { return gulp.src(['app/img/**/*.wav']) .pipe(gulp.dest('dist/img')) }, function () { return gulp.src(['app/js/lib/polyfill.js', 'app/js/lib/bin_utils.js']) .pipe(gulp.dest('dist/js/lib')) }, function () { return gulp.src('app/vendor/closure/long.js') .pipe(gulp.dest('dist/vendor/closure')) }, function () { return gulp.src(['app/css/desktop.css', 'app/css/mobile.css']) .pipe(gulp.dest('dist/css')) }, function () { return gulp.src('app/vendor/jsbn/jsbn_combined.js') .pipe(gulp.dest('dist/vendor/jsbn')) }, function () { return gulp.src('app/vendor/leemon_bigint/bigint.js') .pipe(gulp.dest('dist/vendor/leemon_bigint')) }, function () { return gulp.src('app/vendor/rusha/rusha.js') .pipe(gulp.dest('dist/vendor/rusha')) }, function () { return gulp.src('app/vendor/cryptoJS/crypto.js') .pipe(gulp.dest('dist/vendor/cryptoJS')) }, function () { return gulp.src(['app/nacl/mtproto_crypto.pexe', 'app/nacl/mtproto_crypto.nmf']) .pipe(gulp.dest('dist/nacl/')) }, function () { return gulp.src('app/js/background.js') .pipe(gulp.dest('dist/js')) } )) gulp.task('copy-locales', function (callback) { var langpackSrc = [] var ngSrc = [] packageJson.locales.forEach(function (locale) { langpackSrc.push('app/js/locales/' + locale + '.json') ngSrc.push('app/vendor/angular/i18n/angular-locale_' + locale + '.js') }) gulp.parallel( function () { return gulp.src(langpackSrc) .pipe(gulp.dest('dist/js/locales/')) }, function () { return gulp.src(ngSrc) .pipe(gulp.dest('dist/vendor/angular/i18n/')) } )(callback) }) gulp.task('clean', function () { return del(['dist/*', 'app/js/templates.js', 'app/css/*', '!dist/.git']) }) gulp.task('less', function () { return gulp.src('app/less/*.less') .pipe($.less({ paths: [path.join(__dirname, 'less', 'includes')], javascriptEnabled: true })) .pipe(gulp.dest('app/css')) }) gulp.task('disable-production', gulp.parallel( function () { return gulp.src('app/index.html') .pipe($.replace(/PRODUCTION_ONLY_BEGIN-->/g, 'PRODUCTION_ONLY_BEGIN')) .pipe($.replace(/')) .pipe($.replace(/PRODUCTION_ONLY_END/, '')) .pipe($.replace(/PRODUCTION_ONLY_END/, '