-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
99 lines (90 loc) · 2.68 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Dependencies
*/
var PKG = require( './package.json' ),
gulp = require( 'gulp' ),
plumber = require( 'gulp-plumber' ),
sass = require( 'gulp-sass' ),
replace = require( 'gulp-replace' ),
prefix = require( 'gulp-autoprefixer' ),
cleancss = require( 'gulp-clean-css' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
header = require( 'gulp-header' ),
watch = require( 'gulp-watch' );
/**
* Header text to be added to output build files
*/
var getHeader = function()
{
return [
"/*!",
" * @Date: Compiled " + new Date() + ".",
" * @Description: " + String( PKG.description || 'No description' ),
" * @Author: " + String( PKG.author.name || PKG.author || 'No author' ) + " ("+String( PKG.author.email || PKG.email || 'no-email' )+")",
" * @Version: " + String( PKG.version || 'No version' ),
" * @License: " + String( PKG.license || 'No license' ),
" */"
].join( "\n" ) + "\r\n";
};
/**
* Send errors to console
*/
var toConsole = function( error )
{
error && console.log( error );
this.emit && this.emit( 'end' );
}
/**
* Used by rename() to build named css theme files
*/
var renameCss = function( path )
{
path.basename = path.basename.replace( 'theme', 'syntaxy' );
path.extname = ".min.css";
}
/**
* Build CSS file
*/
gulp.task( 'build_css', function()
{
var input = './src/scss/theme.*.scss',
path = './dist/css/';
return gulp.src( input )
.pipe( plumber( { errorHandler: toConsole } ) )
.pipe( sass().on( 'error', toConsole ) )
.pipe( prefix( { browsers: ['last 2 versions', '> 1%', 'opera 12.1', 'bb 10', 'android 4'] } ) )
.pipe( cleancss( { advanced: false, keepBreaks: false, keepSpecialComments: false } ) )
.pipe( replace( /[\t\r\n]+/g, '' ) )
.pipe( header( getHeader() ) )
.pipe( rename( renameCss ) )
.pipe( gulp.dest( path ) );
});
/**
* Build JS file
*/
gulp.task( 'build_js', function()
{
var input = './src/js/syntaxy.js',
path = './dist/js/';
return gulp.src( input )
.pipe( plumber( { errorHandler: toConsole } ) )
.pipe( uglify( { preserveComments: false } ).on( 'error', toConsole ) )
.pipe( replace( /[\t\r\n]+/g, '' ) )
.pipe( header( getHeader() ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( path ) )
});
/**
* Watch files
*/
gulp.task( 'watch', function()
{
var files = ['./src/scss/*.scss', './src/js/*.js'];
gulp.watch( files, ['build'] );
});
/**
* Build all files
*/
gulp.task( 'build', ['build_css','build_js'] );
gulp.task( 'default', ['build','watch'] );