Skip to content

Instantly share code, notes, and snippets.

@shprink
Created February 15, 2016 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shprink/f0d199e02a5d46bb361e to your computer and use it in GitHub Desktop.
Save shprink/f0d199e02a5d46bb361e to your computer and use it in GitHub Desktop.
var gulp = require('gulp'),
runSequence = require('run-sequence'),
gulpif = require('gulp-if'),
argv = require('minimist')(process.argv.slice(2)),
uglify = require('gulp-uglify'),
clean = require('gulp-clean'),
minifyCss = require("gulp-minify-css"),
minifyHtml = require("gulp-minify-html"),
header = require("gulp-header"),
stripDebug = require('gulp-strip-debug'),
gutil = require('gulp-util'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
pngcrush = require('imagemin-pngcrush'),
rimraf = require('gulp-rimraf'),
ngAnnotate = require('gulp-ng-annotate'),
jshint = require('gulp-jshint'),
protractor = require("gulp-protractor").protractor,
merge = require('merge-stream'),
autoprefixer = require('gulp-autoprefixer');
var variables = require('../services/variables.js');
var services = require('../services/web.js');
var configService = require('../services/configService.js');
var IS_CANVAS = (typeof argv.canvas === 'undefined') ? false : true;
var IS_RELEASE_BUILD = (typeof argv.prod === 'undefined') ? false : true;
if (IS_RELEASE_BUILD) {
gutil.log(
gutil.colors.red('--prod'),
'Building release version (minified, debugs stripped)...'
);
}
var dest = IS_RELEASE_BUILD ? variables.dist.web : variables.sandbox.web;
if (IS_CANVAS) {
dest = IS_RELEASE_BUILD ? variables.dist.canvas : variables.sandbox.canvas;
}
gulp.task('WebJsHint', function() {
return services.getMpJsStream()
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
})
gulp.task('WebJs', function() {
services.getJsStream()
// .pipe(gulpif(IS_RELEASE_BUILD, stripDebug()))
.pipe(ngAnnotate())
.pipe(concat(IS_RELEASE_BUILD ? 'mateprofiler.min.js' : 'mateprofiler.js'))
.pipe(gulpif(IS_RELEASE_BUILD, uglify({})))
.pipe(gulpif(!IS_RELEASE_BUILD, uglify({ // removing comments to reduce file size
compress: false,
mangle: false, // For memory profiling
output: {
beautify: true
}
})))
.pipe(header(configService.getCopyright(), {
version: configService.getVersion()
}))
.pipe(gulp.dest(dest + 'js'));
});
gulp.task('WebCss', function() {
merge(merge(services.getCssStream(), services.getSassStream()), services.getLessStream())
.pipe(concat(IS_RELEASE_BUILD ? 'mateprofiler.min.css' : 'mateprofiler.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulpif(IS_RELEASE_BUILD, minifyCss({
keepSpecialComments: 0
})))
.pipe(header(configService.getCopyright(), {
version: configService.getVersion()
}))
.pipe(gulp.dest(dest + 'css'));
});
gulp.task('WebData', function() {
gulp.src(variables.lib.common + 'data/**/*')
.pipe(gulp.dest(dest + 'data'));
});
gulp.task('WebViews', function() {
gulp.src([variables.lib.common + 'views/**/*', variables.lib.web + 'views/**/*'])
.pipe(gulpif(IS_RELEASE_BUILD, minifyHtml({
quotes: true,
empty: true
})))
.pipe(gulp.dest(dest + 'views'));
});
gulp.task('WebIcons', function() {
services.getIonicIcons()
.pipe(gulp.dest(dest + 'fonts'));
});
gulp.task('WebImgClean', function() {
// empty folder
return gulp.src(dest + 'img/*').pipe(rimraf());
});
gulp.task('WebImg', function() {
// empty folder
return gulp.src([variables.lib.common + 'img/**/*',
variables.lib.web + 'img/**/*'
])
.pipe(gulp.dest(dest + 'img'));
});
gulp.task('WebImgOptim', function() {
gulp.src(variables.lib.web + 'img/**/*')
.pipe(imagemin({
progressive: true,
optimizationLevel: 3,
interlaced: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngcrush()]
}))
.pipe(gulp.dest(variables.lib.web + 'img'));
});
gulp.task('CommonImgOptim', function() {
gulp.src(variables.lib.common + 'img/**/*')
.pipe(imagemin({
progressive: true,
optimizationLevel: 3,
interlaced: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngcrush()]
}))
.pipe(gulp.dest(variables.lib.common + 'img'));
});
gulp.task('WebConf', function() {
configService.dumpConfig(dest, (IS_CANVAS) ? 'canvas' : 'web');
});
gulp.task('WebIndex', function() {
configService.dumpIndex(variables.lib.web, dest, IS_RELEASE_BUILD);
});
gulp.task('build_web', function(cb) {
// Run everything in parralel but 'WebImgClean' and 'WebImg'
runSequence('WebJsHint', ['WebJs', 'WebCss', 'WebViews', 'WebData', 'WebIcons'], 'WebIndex', 'WebConf', 'WebImgClean', 'WebImg', cb);
});
gulp.task('test:web', function() {
gulp.src([variables.lib.web + "tests/*.js"])
.pipe(protractor({
configFile: variables.lib.web + "protractor.js",
// args: ['debug']
}))
.on('end', function() {
})
.on('error', function(e) {
throw e
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment