codemoji/gulpfile.js

179 строки
4.7 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

2016-03-02 18:48:59 +03:00
var fs = require('fs');
2016-02-18 22:10:21 +03:00
var gulp = require('gulp');
var usemin = require('gulp-usemin');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
2016-03-02 18:48:59 +03:00
var cleanCSS = require('gulp-clean-css');
2016-02-18 22:10:21 +03:00
var del = require('del')
var rev = require('gulp-rev')
2016-02-22 18:36:35 +03:00
var realFavicon = require('gulp-real-favicon');
var copy = require('gulp-copy');
2016-02-29 19:02:35 +03:00
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
2016-03-02 18:48:59 +03:00
var svgInject = require('svg-injectr');
var htmlmin = require('gulp-htmlmin');
var through = require('through2');
var processhtml = require('gulp-processhtml');
2016-03-03 01:44:31 +03:00
var replace = require('gulp-replace');
2016-02-22 18:36:35 +03:00
// File where the favicon markups are stored
var FAVICON_DATA_FILE = 'cache/faviconData.json';
2016-02-22 18:36:35 +03:00
gulp.task('copy:fonts', ['clean'], function() {
2016-03-02 18:48:59 +03:00
return gulp.src('assets/css/font/**/*.{ttf,woff,woff2,eot,svg}')
2016-02-22 18:36:35 +03:00
.pipe(gulp.dest('public/font'));
});
2016-05-26 20:13:23 +03:00
gulp.task('copy:cname', ['clean'], function() {
return gulp.src('assets/CNAME')
.pipe(gulp.dest('public/'));
});
gulp.task('copy:assets', ['clean'], function() {
2016-02-22 18:36:35 +03:00
var assets_paths = [
2016-03-02 18:48:59 +03:00
'assets/svg/*',
2016-02-22 18:36:35 +03:00
'assets/img/**/*',
2016-04-22 20:32:30 +03:00
'vendor/**/*',
2016-04-22 20:39:38 +03:00
'share.html',
'bower_components/youarei/dist/youarei.js'
2016-02-22 18:36:35 +03:00
]
return gulp.src(assets_paths)
.pipe(copy('public'));
});
2016-02-18 22:10:21 +03:00
gulp.task('copy:favicon', ['clean'], function() {
return gulp.src('cache/favicon/*')
.pipe(gulp.dest('public'));
});
2016-03-02 20:18:42 +03:00
2016-02-18 22:10:21 +03:00
gulp.task('minify', ['clean'], function() {
2016-02-29 19:02:35 +03:00
2016-03-02 20:18:42 +03:00
var cleancssOpt = {advanced:false, aggressiveMerging:false, restructuring:false}
2016-05-31 14:17:48 +03:00
var processors = [autoprefixer({browsers: ['last 3 version']})];
2016-02-29 19:02:35 +03:00
2016-02-22 18:36:35 +03:00
return gulp.src('index.html')
2016-02-18 22:10:21 +03:00
.pipe(usemin({
2016-03-03 01:44:31 +03:00
css: [ cleanCSS(cleancssOpt), postcss(processors) ],
vendorjs: [ uglify ]
2016-02-18 22:10:21 +03:00
}))
.pipe(gulp.dest('public'));
});
2016-02-29 19:02:35 +03:00
2016-02-18 22:10:21 +03:00
gulp.task('clean', function() {
return del([
2016-03-02 18:48:59 +03:00
'public/**/**/*',
2016-02-18 22:10:21 +03:00
// don't remove .gitkeep
'!public/.gitkeep'
]);
});
2016-02-22 18:36:35 +03:00
// Generate the icons. This task takes a few seconds to complete.
// You should run it at least once to create the icons. Then,
// you should run it whenever RealFaviconGenerator updates its
// package (see the check-for-favicon-update task below).
gulp.task('generate-favicon', function(done) {
realFavicon.generateFavicon({
masterPicture: 'favicon.svg',
dest: 'cache/favicon',
2016-02-22 18:36:35 +03:00
iconsPath: '/',
design: {
ios: {
pictureAspect: 'backgroundAndMargin',
backgroundColor: '#ffffff',
margin: '14%'
},
desktopBrowser: {},
windows: {
pictureAspect: 'noChange',
backgroundColor: '#da532c',
onConflict: 'override'
},
androidChrome: {
pictureAspect: 'shadow',
themeColor: '#ffffff',
manifest: {
name: 'Cryptoloji',
display: 'browser',
orientation: 'notSet',
onConflict: 'override',
declared: true
}
},
safariPinnedTab: {
pictureAspect: 'silhouette',
themeColor: '#5bbad5'
}
},
settings: {
compression: 2,
scalingAlgorithm: 'Mitchell',
errorOnImageTooSmall: false
},
markupFile: FAVICON_DATA_FILE
}, function() {
done();
});
});
2016-03-02 18:48:59 +03:00
2016-03-03 11:54:13 +03:00
gulp.task('finalhtml', ['copy:assets'], function(){
2016-04-23 10:53:00 +03:00
var htmlminopt = {collapseWhitespace: true, removeComments:true}
2016-06-30 21:13:54 +03:00
var env;
if (fs.existsSync('./env.json')) {
env = require('./env.json')
}
2016-06-30 21:39:14 +03:00
else if (process.env.DOMAIN) {
2016-06-30 21:13:54 +03:00
env = {
2016-06-30 21:39:14 +03:00
domain: process.env.DOMAIN
2016-06-30 21:13:54 +03:00
}
} else {
env = {
domain: 'http://localhost:8080'
}
}
2016-05-12 10:32:05 +03:00
gulp.src('public/share.html')
.pipe(processhtml({
commentMarker: 'process',
recursive:true,
data:{version:Math.random()*10000, env:env}
}))
.pipe(htmlmin(htmlminopt))
.pipe(gulp.dest('public/'))
2016-02-22 18:36:35 +03:00
gulp.src('public/index.html')
2016-03-03 01:02:19 +03:00
.pipe(through.obj(function (chunk, enc, cb) {
svgInject({source:chunk.path, selector:'data-svg'}, function(res){
chunk.contents = new Buffer('<!DOCTYPE html>' + res)
cb(null, chunk);
})
}))
2016-04-23 10:53:00 +03:00
// disabled since it strip the og:image FB tag
// favicon tag are put manually into html markup
//.pipe(realFavicon.injectFaviconMarkups(JSON.parse(fs.readFileSync(FAVICON_DATA_FILE)).favicon.html_code))
2016-03-02 18:48:59 +03:00
.pipe(processhtml({
commentMarker: 'process',
recursive:true,
2016-05-12 10:32:05 +03:00
data:{version:Math.random()*10000, env:env}
2016-03-02 18:48:59 +03:00
}))
2016-03-03 01:44:31 +03:00
.pipe(replace('<script src="app.js"></script>', ''))
.pipe(replace('<link rel="stylesheet" href="style.css">', ''))
2016-03-03 11:54:13 +03:00
.pipe(htmlmin(htmlminopt))
2016-03-02 18:48:59 +03:00
.pipe(gulp.dest('public/'))
})
2016-02-22 18:36:35 +03:00
2016-05-26 20:13:23 +03:00
gulp.task('build', ['clean', 'copy:fonts', 'copy:cname', 'copy:favicon', 'copy:assets', 'minify', 'finalhtml']);
gulp.task('favicon', ['generate-favicon']);