-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
216 lines (167 loc) · 5.19 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// ┏━━━━━━━━┓
// ┃ T E ┃
// ┃ N 4 ━┛
// ┗━━━━━┛
var gulp = require( 'gulp' );
var fs = require( 'fs' );
var PRODUCTION_MODE = false; // Production mode minifies output files and optimises images
var PATH_TEMPLATES = {
craft: './craft/templates/**/*.twig',
app: './app/templates/**/*.twig'
}[fs.existsSync( './craft' ) ? 'craft' : 'app'];
var TODO_FILE = './todo.txt';
function NOOP(){
return true;
}
function FILE_HEADER(){
return '/*\n┏━━━━━━━━┓\n┃ T E ┃\n┃ N 4 ━┛\n┗━━━━━┛\nLast updated on ' + ( new Date() ).toString() + '\n*/\n\n';
}
function SRC( path ){
return './raw' + ( path || '' );
}
function DEST( path ){
return './public_html/assets' + ( path || '' );
}
// To install new package: 'npm install --save-dev [package name e.g. gulp-concat]'
var gulpif = require( 'gulp-if' );
var livereload = require( 'gulp-livereload' );
var header = require( 'gulp-header' );
var sass = require( 'gulp-sass' );
var autoprefix = require( 'gulp-autoprefixer' );
var csslint = require( 'gulp-csslint' );
var jshint = require( 'gulp-jshint' );
var gconcat = require( 'gulp-concat' );
var watch = require( 'gulp-watch' );
if( PRODUCTION_MODE ){
var cssnano = require( 'gulp-cssnano' );
var uglify = require( 'gulp-uglify' );
var imagemin = require( 'gulp-imagemin' );
var svgmin = require( 'gulp-svgmin' );
}
else{
var cssnano = NOOP;
var uglify = NOOP;
var imagemin = NOOP;
var svgmin = NOOP;
}
gulp.task( 'todo', function(){
fs.readFile( TODO_FILE, function( error, buffer ){
if( error ){
console.log( '\nNo todo.txt file found\n' );
return;
}
var todo_list = buffer.toString().trim();
if( todo_list.length == 0 ){
console.log( '\nNo todos\n' );
return;
}
console.log( '\nTO DO:' );
console.log( '----------\n' );
console.log( todo_list );
console.log( '\n----------\n' );
} );
} );
gulp.task( 'js-lint', function(){
gulp.src( SRC( '/js/*.js' ) )
.pipe( jshint() )
.pipe( jshint.reporter( 'default' ) );
} );
gulp.task( 'css-lint', ['sass'], function(){
gulp.src( DEST( '/css/*.css' ) )
.pipe( csslint( {
'adjoining-classes': false,
'unique-headings': false,
'qualified-headings': false,
'compatible-vendor-prefixes': false,
'box-sizing': false,
'bulletproof-font-face': false
} ) )
.pipe( csslint.reporter( 'compact' ) );
} );
gulp.task( 'sass', function(){
gulp.src( SRC( '/sass/root.scss' ) )
.pipe( sass() )
.on( 'error', sass.logError )
.pipe( gconcat( 'main.css' ) )
.pipe( gulpif( PRODUCTION_MODE, cssnano() ) )
.pipe( autoprefix( 'last 2 versions', '> 1%', 'Explorer 8' ) )
.pipe( header( FILE_HEADER() ) )
.pipe( gulp.dest( DEST( '/css' ) ) );
gulp.src( SRC( '/sass/site/js-only.scss' ) )
.pipe( sass() )
.on( 'error', sass.logError )
.pipe( gconcat( 'js-only.css' ) )
.pipe( gulpif( PRODUCTION_MODE, cssnano() ) )
.pipe( autoprefix( 'last 2 versions', '> 1%', 'Explorer 8' ) )
.pipe( header( FILE_HEADER() ) )
.pipe( gulp.dest( DEST( '/css' ) ) );
gulp.src( SRC( '/sass/site/ie8.scss' ) )
.pipe( sass() )
.on( 'error', sass.logError )
.pipe( gconcat( 'ie8.css' ) )
.pipe( gulpif( PRODUCTION_MODE, cssnano() ) )
.pipe( autoprefix( 'Explorer 8' ) )
.pipe( header( FILE_HEADER() ) )
.pipe( gulp.dest( DEST( '/css' ) ) );
} );
gulp.task( 'css', ['css-lint'] );
gulp.task( 'js', ['js-lint'], function(){
var ordered_lib_filenames = fs.readFileSync( './raw/js/libs/_order.txt' ).toString().split( '\n' );
var ordered_lib_paths = [];
for( var i = 0; i < ordered_lib_filenames.length; i += 1 ){
ordered_lib_paths.push( SRC( '/js/libs/' + ordered_lib_filenames[i] ) );
}
gulp.src( ordered_lib_paths )
.pipe( gconcat( 'libs.js' ) )
.pipe( header( FILE_HEADER() ) )
.pipe( gulp.dest( DEST( '/js' ) ) );
gulp.src( SRC( '/js/libs-solo/*.js' ) )
.pipe( gulp.dest( DEST( '/js' ) ) );
gulp.src( SRC( '/js/*.js' ) )
.pipe( gulpif( PRODUCTION_MODE, uglify() ) )
.pipe( gconcat( 'main.js' ) )
.pipe( header( FILE_HEADER() ) )
.pipe( gulp.dest( DEST( '/js' ) ) );
} );
gulp.task( 'img', function(){
gulp.src( SRC( '/img/**/*.{jpg,jpeg,png,gif,ico}' ) )
.pipe( gulpif( PRODUCTION_MODE, imagemin( {
optimizationLevel: 3,
progressive: true,
interlaced: true
} ) ) )
.pipe( gulp.dest( DEST( '/img' ) ) );
gulp.src( SRC( '/img/**/*.svg' ) )
.pipe( gulpif( PRODUCTION_MODE, svgmin() ) )
.pipe( gulp.dest( DEST( '/img' ) ) );
} );
gulp.task( 'fonts', function(){
gulp.src( SRC( '/fonts/*' ) )
.pipe( gulp.dest( DEST( '/fonts' ) ) );
} );
gulp.task( 'watch', ['full'], function(){
livereload.listen();
watch( SRC( '/sass/**/*.scss' ), function(){
gulp.start( 'css' );
} );
watch( SRC( '/js/**/*' ), function(){
gulp.start( 'js' );
} );
watch( SRC( '/img/**/*' ), function(){
gulp.start( 'img' );
} );
watch( SRC( '/fonts/*' ), function(){
gulp.start( 'fonts' );
} );
watch( [
DEST( '/css/**/*' ),
DEST( '/js/**/*' ),
DEST( '/img/**/*' ),
DEST( '/fonts/*' ),
PATH_TEMPLATES
], function( file ){
livereload.changed( file.path );
} );
} );
gulp.task( 'default', ['watch'] ); // Ctrl-C in terminal to exit watch mode
gulp.task( 'full', ['css','js','img','fonts','todo'] );