1- var gulp = require ( 'gulp' ) ,
2- uglify = require ( 'gulp-uglify' ) ,
3- rename = require ( 'gulp-rename' ) ,
4- header = require ( 'gulp-header' ) ,
5- bump = require ( 'gulp-bump' ) ,
6- sass = require ( 'gulp-sass' ) ,
7- autoprefixer = require ( 'gulp-autoprefixer' ) ,
8- csscomb = require ( 'gulp-csscomb' ) ,
9- gutil = require ( 'gulp-util' ) ,
10- preprocess = require ( 'gulp-preprocess' ) ; ;
11-
12- var fs = require ( 'fs' ) ,
13- getPackageJson = function ( ) {
1+ var gulp = require ( 'gulp' ) ,
2+ $ = require ( 'gulp-load-plugins' ) ( ) ,
3+ fs = require ( 'fs' ) ;
4+
5+ var getPackageJson = function ( ) {
146 return JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) ;
157 } ;
168
9+ /*======================================
10+ Bump version
11+ ======================================*/
1712gulp . task ( 'bump' , function ( ) {
1813 var pkg = getPackageJson ( ) ,
19- newVersion = gutil . env . bump || pkg . version ;
14+ newVersion = $ . util . env . bump || pkg . version ;
2015
2116 return gulp . src ( [ './package.json' , './bower.json' , './selectric.jquery.json' ] )
22- . pipe ( bump ( {
17+ . pipe ( $ . bump ( {
2318 version : newVersion
2419 } ) )
2520 . pipe ( gulp . dest ( './' ) ) ;
2621} ) ;
2722
23+ /*======================================
24+ Javascript
25+ ======================================*/
2826gulp . task ( 'js' , [ 'bump' ] , function ( ) {
2927 var pkg = getPackageJson ( ) ,
3028 banner = [
@@ -47,42 +45,86 @@ gulp.task('js', ['bump'], function() {
4745 ] . join ( '\n' ) ;
4846
4947 return gulp . src ( 'src/jquery.selectric.js' )
50- . pipe ( header ( banner , { pkg : pkg } ) )
51- . pipe ( gulp . dest ( './dist' ) ) ;
48+ . pipe ( $ . header ( banner , { pkg : pkg } ) )
49+ . pipe ( gulp . dest ( './public' ) )
50+ . pipe ( $ . connect . reload ( ) ) ;
5251} ) ;
5352
5453gulp . task ( 'js-min' , [ 'bump' ] , function ( ) {
5554 var pkg = getPackageJson ( ) ;
5655
5756 return gulp . src ( 'src/jquery.selectric.js' )
58- . pipe ( uglify ( ) )
59- . pipe ( header ( '/*! Selectric ϟ v<%= pkg.version %> (<%= new Date().toJSON().slice(0,10) %>) - git.io/tjl9sQ - Copyright (c) <%= new Date().getFullYear() %> Leonardo Santos - Dual licensed: MIT/GPL */\n' , { pkg : pkg } ) )
60- . pipe ( rename ( {
61- suffix : '.min'
62- } ) )
63- . pipe ( gulp . dest ( './dist' ) ) ;
57+ . pipe ( $ . uglify ( ) )
58+ . pipe ( $ . header ( '/*! Selectric ϟ v<%= pkg.version %> (<%= new Date().toJSON().slice(0,10) %>) - git.io/tjl9sQ - Copyright (c) <%= new Date().getFullYear() %> Leonardo Santos - Dual licensed: MIT/GPL */\n' , { pkg : pkg } ) )
59+ . pipe ( $ . rename ( { suffix : '.min' } ) )
60+ . pipe ( gulp . dest ( './public' ) )
61+ . pipe ( $ . connect . reload ( ) ) ;
6462} ) ;
6563
64+ /*======================================
65+ CSS
66+ ======================================*/
6667gulp . task ( 'css' , function ( ) {
68+ var pkg = getPackageJson ( ) ;
69+
6770 return gulp . src ( './src/*.scss' )
68- . pipe ( sass ( ) )
69- . pipe ( autoprefixer ( {
71+ . pipe ( $ . sass ( ) )
72+ . pipe ( $ . autoprefixer ( {
7073 browsers : [ 'last 2 versions' , '> 1%' , 'ie 8' , 'ie 7' ]
7174 } ) )
72- . pipe ( csscomb ( ) )
73- . pipe ( gulp . dest ( './dist' ) ) ;
75+ . pipe ( $ . csscomb ( ) )
76+ . pipe ( $ . header ( '/*======================================\n Selectric v<%= pkg.version %>\n======================================*/\n\n' , { pkg : pkg } ) )
77+ . pipe ( gulp . dest ( './public' ) )
78+ . pipe ( $ . connect . reload ( ) ) ;
7479} ) ;
7580
76- gulp . task ( 'template' , function ( ) {
77- return gulp . src ( './template/*' )
78- . pipe ( preprocess ( ) )
79- . pipe ( gulp . dest ( './' ) )
81+ /*======================================
82+ Live preview
83+ ======================================*/
84+ gulp . task ( 'serve' , function ( ) {
85+ $ . connect . server ( {
86+ root : './public' ,
87+ livereload : true
88+ } ) ;
89+ } ) ;
90+
91+ gulp . task ( 'html' , function ( ) {
92+ return gulp . src ( './public/*.html' )
93+ . pipe ( $ . connect . reload ( ) ) ;
94+ } ) ;
95+
96+ /*======================================
97+ Watch
98+ ======================================*/
99+ gulp . task ( 'watch' , [ 'serve' ] , function ( ) {
100+ gulp . watch ( [ './src/*.js' ] , [ 'js' , 'js-min' ] ) ;
101+ gulp . watch ( [ './src/*.scss' ] , [ 'css' ] ) ;
102+ gulp . watch ( [ './public/*.html' ] , [ 'html' ] ) ;
103+ } ) ;
104+
105+ /*======================================
106+ ZIP
107+ ======================================*/
108+ gulp . task ( 'zip' , function ( ) {
109+ var pkg = getPackageJson ( ) ;
110+
111+ return gulp . src ( './public/*' )
112+ . pipe ( $ . zip ( 'selectric_v' + pkg . version + '.zip' ) )
113+ . pipe ( gulp . dest ( './' ) ) ;
80114} ) ;
81115
82- gulp . task ( 'watch' , function ( ) {
83- gulp . watch ( './src/*.js' , [ 'js' , 'js-min' ] ) ;
84- gulp . watch ( './src/*.scss' , [ 'css' ] ) ;
85- gulp . watch ( './template/*' , [ 'template' ] ) ;
116+ /*======================================
117+ GitHub Pages
118+ ======================================*/
119+ gulp . task ( 'gh-pages' , function ( ) {
120+ return gulp . src ( './public/**/*' )
121+ . pipe ( $ . ghPages ( ) ) ;
86122} ) ;
87123
88- gulp . task ( 'default' , [ 'bump' , 'js' , 'js-min' , 'css' , 'template' ] ) ;
124+ /*======================================
125+ Default tasks
126+ ======================================*/
127+ gulp . task ( 'build' , [ 'js' , 'js-min' , 'css' ] ) ;
128+ gulp . task ( 'default' , [ 'build' , 'watch' ] ) ;
129+ gulp . task ( 'release' , [ 'bump' , 'build' , 'zip' ] ) ;
130+ gulp . task ( 'publish' , [ 'gh-pages' ] ) ;
0 commit comments