This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
178 lines (151 loc) · 4.66 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
var fs = require('fs');
var gulp = require('gulp');
var usemin = require('gulp-usemin');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var del = require('del')
var rev = require('gulp-rev')
var realFavicon = require('gulp-real-favicon');
var copy = require('gulp-copy');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var svgInject = require('svg-injectr');
var htmlmin = require('gulp-htmlmin');
var through = require('through2');
var processhtml = require('gulp-processhtml');
var replace = require('gulp-replace');
// File where the favicon markups are stored
var FAVICON_DATA_FILE = 'cache/faviconData.json';
gulp.task('copy:fonts', ['clean'], function() {
return gulp.src('assets/css/font/**/*.{ttf,woff,woff2,eot,svg}')
.pipe(gulp.dest('public/font'));
});
gulp.task('copy:cname', ['clean'], function() {
return gulp.src('assets/CNAME')
.pipe(gulp.dest('public/'));
});
gulp.task('copy:assets', ['clean'], function() {
var assets_paths = [
'assets/svg/*',
'assets/img/**/*',
'vendor/**/*',
'share.html',
'bower_components/youarei/dist/youarei.js'
]
return gulp.src(assets_paths)
.pipe(copy('public'));
});
gulp.task('copy:favicon', ['clean'], function() {
return gulp.src('cache/favicon/*')
.pipe(gulp.dest('public'));
});
gulp.task('minify', ['clean'], function() {
var cleancssOpt = {advanced:false, aggressiveMerging:false, restructuring:false}
var processors = [autoprefixer({browsers: ['last 3 version']})];
return gulp.src('index.html')
.pipe(usemin({
css: [ cleanCSS(cleancssOpt), postcss(processors) ],
vendorjs: [ uglify ]
}))
.pipe(gulp.dest('public'));
});
gulp.task('clean', function() {
return del([
'public/**/**/*',
// don't remove .gitkeep
'!public/.gitkeep'
]);
});
// 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',
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();
});
});
gulp.task('finalhtml', ['copy:assets'], function(){
var htmlminopt = {collapseWhitespace: true, removeComments:true}
var env;
if (fs.existsSync('./env.json')) {
env = require('./env.json')
}
else if (process.env.DOMAIN) {
env = {
domain: process.env.DOMAIN
}
} else {
env = {
domain: 'http://localhost:8080'
}
}
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/'))
gulp.src('public/index.html')
.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);
})
}))
// 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))
.pipe(processhtml({
commentMarker: 'process',
recursive:true,
data:{version:Math.random()*10000, env:env}
}))
.pipe(replace('<script src="app.js"></script>', ''))
.pipe(replace('<link rel="stylesheet" href="style.css">', ''))
.pipe(htmlmin(htmlminopt))
.pipe(gulp.dest('public/'))
})
gulp.task('build', ['clean', 'copy:fonts', 'copy:cname', 'copy:favicon', 'copy:assets', 'minify', 'finalhtml']);
gulp.task('favicon', ['generate-favicon']);