Commit 6bf45a7a authored by Rurik Bugdanov's avatar Rurik Bugdanov

gulpfile.js: convert tabs to spaces

parent e6f808cf
...@@ -3,23 +3,23 @@ ...@@ -3,23 +3,23 @@
var gulp=require('gulp'), var gulp=require('gulp'),
bower=require('gulp-bower'), bower=require('gulp-bower'),
wiredep=require('wiredep').stream, wiredep=require('wiredep').stream,
foreach=require('gulp-foreach'), foreach=require('gulp-foreach'),
usemin=require('gulp-usemin'), usemin=require('gulp-usemin'),
htmlmin=require('gulp-htmlmin'), htmlmin=require('gulp-htmlmin'),
sourcemaps=require('gulp-sourcemaps'), sourcemaps=require('gulp-sourcemaps'),
uglify=require('gulp-uglify'), uglify=require('gulp-uglify'),
cleanCss=require('gulp-clean-css'), cleanCss=require('gulp-clean-css'),
rev=require('gulp-rev'), rev=require('gulp-rev'),
connect=require('gulp-connect'), connect=require('gulp-connect'),
express=require('express'), express=require('express'),
php=require('node-php'), php=require('node-php'),
cors=require('cors'), cors=require('cors'),
opn=require('opn'), opn=require('opn'),
fs=require('fs'), fs=require('fs'),
path=require('path'), path=require('path'),
extend=require('extend'), extend=require('extend'),
Q=require('q'), Q=require('q'),
clean=require('gulp-clean'); clean=require('gulp-clean');
var app; var app;
var config={ var config={
...@@ -28,168 +28,168 @@ var config={ ...@@ -28,168 +28,168 @@ var config={
port: 8080, port: 8080,
home: 'index.html', home: 'index.html',
bowerDir: './bower_components', bowerDir: './bower_components',
dist: './dist', dist: './dist',
} }
function abort(err) { function abort(err) {
console.log(JSON.stringify(err,false,4)); console.log(JSON.stringify(err,false,4));
process.exit(1); process.exit(1);
} }
function getHtmlFiles() { function getHtmlFiles() {
return gulp.src('*.html'); return gulp.src('*.html');
} }
// handle error events and synchronous chaining using promises // handle error events and synchronous chaining using promises
function wrap(taskName,stream,q) { function wrap(taskName,stream,q) {
stream=stream.on('error',function errorHandler(err){ stream=stream.on('error',function errorHandler(err){
console.log('ERROR: '+taskName+' failed !'); console.log('ERROR: '+taskName+' failed !');
console.log(JSON.stringify(err,false,4)); console.log(JSON.stringify(err,false,4));
if (q) { if (q) {
q.reject(err); q.reject(err);
} else { } else {
process.exit(1); process.exit(1);
} }
}).on('end',function(){ }).on('end',function(){
if (q) if (q)
q.resolve(stream); q.resolve(stream);
}); });
if (q) return q.promise; if (q) return q.promise;
else return stream; else return stream;
} }
// download bower dependencies // download bower dependencies
gulp.task('bower', function(cb){ gulp.task('bower', function(cb){
return bower() return bower()
.pipe(gulp.dest(config.bowerDir)); .pipe(gulp.dest(config.bowerDir));
}); });
// merge bower.json with file specific options // merge bower.json with file specific options
function getBowerJson(srcFile) { function getBowerJson(srcFile) {
try { try {
var srcFileJson=require(srcFile+'.json'); var srcFileJson=require(srcFile+'.json');
} catch(e) {} } catch(e) {}
var options=(srcFileJson && srcFileJson.bower)||{}; var options=(srcFileJson && srcFileJson.bower)||{};
var bowerJson=extend(true,{},require('./bower.json'),options); var bowerJson=extend(true,{},require('./bower.json'),options);
return bowerJson; return bowerJson;
} }
// inject bower dependencies // inject bower dependencies
gulp.task('wiredep', function(cb){ gulp.task('wiredep', function(cb){
return getHtmlFiles() return getHtmlFiles()
.pipe(foreach(function(stream,file){ .pipe(foreach(function(stream,file){
var filepath=path.join(file.cwd,file.relative); var filepath=path.join(file.cwd,file.relative);
console.log('wiredep: '+filepath); console.log('wiredep: '+filepath);
return stream.pipe( return stream.pipe(
wrap('wiredep', wiredep({ wrap('wiredep', wiredep({
verbose: true, verbose: true,
bowerJson: getBowerJson(filepath) bowerJson: getBowerJson(filepath)
})) }))
); );
})) }))
.pipe( .pipe(
gulp.dest('.') gulp.dest('.')
); );
}); });
// replace references to scripts and stylesheets in html files // replace references to scripts and stylesheets in html files
// and store resulting files in directory "build" // and store resulting files in directory "build"
gulp.task('usemin', function(cb){ gulp.task('usemin', function(cb){
return getHtmlFiles() return getHtmlFiles()
.pipe(foreach(function(stream,file){ .pipe(foreach(function(stream,file){
console.log('usemin: '+path.join(file.cwd,file.relative)); console.log('usemin: '+path.join(file.cwd,file.relative));
return stream.pipe(usemin({ return stream.pipe(usemin({
css: [ css: [
// sourcemaps.init({ // sourcemaps.init({
// loadMaps: true // loadMaps: true
// }), // }),
wrap('cleanCss', cleanCss()), wrap('cleanCss', cleanCss()),
// 'concat', // 'concat',
rev(), rev(),
// sourcemaps.write() // sourcemaps.write()
], ],
html: [ html: [
function() { function() {
return wrap('htmlmin', htmlmin({ return wrap('htmlmin', htmlmin({
collapseWhitespace:true collapseWhitespace:true
})); }));
} }
], ],
js: [ js: [
sourcemaps.init({ sourcemaps.init({
loadMaps: true loadMaps: true
}), }),
wrap('uglify js', uglify()), wrap('uglify js', uglify()),
'concat', 'concat',
rev(), rev(),
sourcemaps.write() sourcemaps.write()
], ],
inlinejs: [ inlinejs: [
wrap('uglify inlinejs', uglify()) wrap('uglify inlinejs', uglify())
], ],
inlinecss: [ inlinecss: [
wrap('cleanCss', cleanCss()), wrap('cleanCss', cleanCss()),
'concat' 'concat'
] ]
})); }));
})) }))
.pipe(gulp.dest('build/')) .pipe(gulp.dest('build/'))
}); });
gulp.task('cleanbuild', function(){ gulp.task('cleanbuild', function(){
return gulp.src('./build', {read: false}) return gulp.src('./build', {read: false})
.pipe(clean()) .pipe(clean())
}); });
// copy files to directory "dist" // copy files to directory "dist"
gulp.task( gulp.task(
'dist', 'dist',
function(cb) { function(cb) {
var count=3; var count=3;
function goon(){ function goon(){
if (--count==0) { if (--count==0) {
cb(null); cb(null);
} }
} }
// copy assets // copy assets
wrap( wrap(
'copy assets', 'copy assets',
gulp.src('./assets/**/*') gulp.src('./assets/**/*')
.pipe(gulp.dest(config.dist)), .pipe(gulp.dest(config.dist)),
Q.defer() Q.defer()
) )
.catch(abort) .catch(abort)
.then(goon) .then(goon)
.done(); .done();
// copy files // copy files
wrap( wrap(
'copy files', 'copy files',
gulp.src([ gulp.src([
'./build/**/*', './build/**/*',
'*.php' '*.php'
]) ])
.pipe(gulp.dest(config.dist)), .pipe(gulp.dest(config.dist)),
Q.defer() Q.defer()
) )
.catch(abort) .catch(abort)
.then(goon) .then(goon)
.done(); .done();
// copy images // copy images
wrap( wrap(
'copy images', 'copy images',
gulp.src([ gulp.src([
'./js/**/*.png' './js/**/*.png'
]).pipe(gulp.dest(path.join(config.dist,'js'))), ]).pipe(gulp.dest(path.join(config.dist,'js'))),
Q.defer() Q.defer()
) )
.catch(abort) .catch(abort)
.then(goon) .then(goon)
.done(); .done();
} }
); );
// serve content through express and php-cgi // serve content through express and php-cgi
function php_cgi(connect,options) { function php_cgi(connect,options) {
...@@ -211,7 +211,7 @@ gulp.task('server',function(cb){ ...@@ -211,7 +211,7 @@ gulp.task('server',function(cb){
}, },
livereload: true livereload: true
}); });
cb(null); cb(null);
}); });
// watch for changes // watch for changes
...@@ -226,8 +226,8 @@ gulp.task('watch', function(cb){ ...@@ -226,8 +226,8 @@ gulp.task('watch', function(cb){
'**.js', '**.js',
'**.kml', '**.kml',
'**.x3d', '**.x3d',
'!build/**/*', '!build/**/*',
'!gulpfile.js' '!gulpfile.js'
], ],
gulp.series('html') gulp.series('html')
); );
...@@ -235,14 +235,14 @@ gulp.task('watch', function(cb){ ...@@ -235,14 +235,14 @@ gulp.task('watch', function(cb){
// trigger package injection/removal on bower.json change // trigger package injection/removal on bower.json change
gulp.watch('bower.json', gulp.series('inject')); gulp.watch('bower.json', gulp.series('inject'));
cb(null); cb(null);
}); });
// open browser // open browser
gulp.task('open', function(cb){ gulp.task('open', function(cb){
opn('http://'+config.host+':'+config.port+'/'+config.home); opn('http://'+config.host+':'+config.port+'/'+config.home);
cb(null); cb(null);
}); });
gulp.task('connect', gulp.series('server','watch','open')); gulp.task('connect', gulp.series('server','watch','open'));
...@@ -260,8 +260,8 @@ gulp.task('inject', gulp.series('bower','wiredep')); ...@@ -260,8 +260,8 @@ gulp.task('inject', gulp.series('bower','wiredep'));
gulp.task('build', gulp.series('bower','wiredep','usemin')); gulp.task('build', gulp.series('bower','wiredep','usemin'));
gulp.task('prod-root', function(cb){ gulp.task('prod-root', function(cb){
config.documentRoot=config.dist; config.documentRoot=config.dist;
cb(null); cb(null);
}); });
// start server with frorm "build" directory // start server with frorm "build" directory
...@@ -269,5 +269,5 @@ gulp.task('prod', gulp.series('prod-root','build','dist','connect')); ...@@ -269,5 +269,5 @@ gulp.task('prod', gulp.series('prod-root','build','dist','connect'));
gulp.task( gulp.task(
'default', 'default',
gulp.series('inject','connect') gulp.series('inject','connect')
); );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment