Skip to content

Instantly share code, notes, and snippets.

@sirgalleto
Created July 13, 2016 03:53
Show Gist options
  • Save sirgalleto/9508e4771cf0236c1871deb2209c043a to your computer and use it in GitHub Desktop.
Save sirgalleto/9508e4771cf0236c1871deb2209c043a to your computer and use it in GitHub Desktop.
Angular Gulp tasks
'use strict';
var gulp = require('gulp-help')(require('gulp'))
, templateCache = require('gulp-angular-templatecache')
, browserSync = require('browser-sync').create()
, uglify = require('gulp-uglify')
, gulpsync = require('gulp-sync')(gulp)
, cssmin = require('gulp-cssmin')
, rename = require('gulp-rename')
, concat = require('gulp-concat')
, ngmin = require('gulp-ngmin')
, useref = require('gulp-useref')
, gulpif = require('gulp-if')
, minifyCss = require('gulp-minify-css')
, argv = require('yargs').argv
, exec = require('gulp-exec')
, baseDistRoute = argv.prod ? '../public_html' : 'dist';
gulp.task(
'serve', 'Create a local serve in app/', function() {
browserSync.init({
server: argv.dist ? './dist' : './app'
});
gulp.watch('./app/views/**/*.tpl.html', ['templates']);
gulp.watch(argv.dist ? './dist/**' : './app/**').on('change', browserSync.reload);
},
{
options: {
'dist': 'Use dist folter'
}
}
);
gulp.task('templates', 'Compress all the views in a angular module', function () {
return gulp.src('./app/views/**/*.tpl.html')
.pipe(templateCache(
'views.js',
{
module: 'cityDrivePartners',
transformUrl: function(url){
return ['views/', url].join('');
}
}
))
.pipe(gulp.dest('app/js/core/'));
});
gulp.task(
'compress', 'Uglify and minify', function(){
return gulp.src('app/*.html')
.pipe(useref())
.pipe(
gulpif(
'*.js', uglify()
)
)
.pipe(
gulpif(
'*.css', minifyCss()
)
)
.pipe(gulp.dest(baseDistRoute));
},
{
options: {
'prod': 'Use in production serve'
}
}
);
gulp.task(
'copy', 'Copy necesary archives to dist', function(){
gulp.src('./app/images/**/*')
.pipe(gulp.dest(baseDistRoute + '/images'));
gulp.src('./app/font/**/*')
.pipe(gulp.dest(baseDistRoute + '/font'));
gulp.src('./app/js/mexico_estados.json')
.pipe(gulp.dest(baseDistRoute + '/js'));
},
{
options: {
'prod': 'Use in production serve'
}
}
);
gulp.task(
'upload', 'Upload git subtree to production branch', function(){
var v = argv.v;
var options = {
continueOnError: false,
pipeStdout: false,
customTemplatingThing: "test"
};
var reportOptions = {
err: true,
stderr: true,
stdout: true
};
gulp.src('./')
.pipe(exec(
'git add --all'
))
.pipe(exec.reporter(reportOptions))
.pipe(exec(
`git commit -m "Prepare v${v}"`
))
.pipe(exec.reporter(reportOptions))
.pipe(exec(
`git tag "v${v}"`
))
.pipe(exec.reporter(reportOptions))
.pipe(exec(
`git push origin v${v}`
))
.pipe(exec.reporter(reportOptions))
.pipe(exec(
'git subtree push --prefix dist origin production'
))
.pipe(exec.reporter(reportOptions));
},
{
options: {
'v': 'Deploy versio'
}
}
)
gulp.task(
'dist', 'Prepare project to production', gulpsync.sync(
['templates', 'compress', 'copy']
)
);
gulp.task(
'default', 'Create a developer environment', gulpsync.sync(
['templates', 'serve']
)
);
gulp.task(
'deploy', 'Create a deploy execution', gulpsync.sync(
['dist', 'upload']
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment