forked from ericyd/gdrive-transfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
216 lines (161 loc) · 6.37 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
"use strict";
var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var insert = require('gulp-insert');
var autoprefixer = require('gulp-autoprefixer');
var browserify = require('browserify');
var changed = require('gulp-changed');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var globby = require('globby');
var svg2png = require("svg2png");
var fs = require('fs');
var gulpHogan = require('gulp-hogan');
var hoganCompile = require('gulp-hogan-compile');
var hogan = require('hogan.js');
var gulpif = require('gulp-if');
var isProd = false; // true for production; controls minification of JS, CSS, HTML, and building of images with `build`
gulp.task('default', function(){
// Default task
});
gulp.task('build', ['templates', 'jslint', 'js','gs', 'html','css', 'cutestrap'], function() {
if (isProd) {
buildImages();
}
});
gulp.task('watch', function(){
var watcher = gulp.watch(['./src/**/*'], ['build']);
watcher.on('change', function (event) {
console.log('Event type: ' + event.type); // added, changed, or deleted
console.log('Event path: ' + event.path);
});
});
gulp.task('templates', function() {
return gulp.src(['src/templates/forms/*.html', 'src/templates/icons/*.html'])
.pipe(hoganCompile('templates.js', {wrapper: 'commonjs', hoganModule: 'hogan.js'}))
.pipe(gulp.dest('src/js/'));
});
// gulp.task('generate-test-site', ['build'], function() {
// return gulp.src('src/templates/test.html')
// .pipe(gulpHogan())
// .pipe(concat('index.html'))
// .pipe(gulp.dest('test'));
// });
gulp.task('js', ['templates'], function() {
globby(['./src/js/*.js']).then(function(entries) {
var b = browserify({
entries: entries,
baseDir: './src/js',
debug: false
});
return b.bundle()
.pipe(source('js.html'))
.pipe(buffer())
.pipe(gulpif(isProd, uglify(), uglify({
mangle: false,
output: {
indent_start : 0, // start indentation on every line (only when `beautify`)
indent_level : 2,
beautify : true, // beautify output?
bracketize : true, // use brackets every time?
comments : false // output comments?
},
compressor: {
sequences : false, // join consecutive statemets with the “comma operator”
conditionals : false, // optimize if-s and conditional expressions
comparisons : false, // optimize comparisons
evaluate : false, // evaluate constant expressions
booleans : true, // optimize boolean expressions
loops : false, // optimize loops
join_vars : false // join var declarations
}
}))) // GAS doesn't like the huge files that it creates without uglifying
.pipe(insert.wrap('<script>', '</script>'))
.pipe(gulp.dest('dist'));
});
})
gulp.task('gs', function() {
// jshint and minify Code.gs
return gulp.src('./src/application/**/*.js')
.pipe(changed('dist'))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('application.gs'))
.pipe(gulp.dest('dist'));
})
gulp.task('css', function() {
// process css
return gulp.src('./src/css/main.scss')
.pipe(sass({outputStyle: isProd ? 'compressed' : 'compact'}).on('error', sass.logError))
.pipe(autoprefixer({browsers: ['last 10 versions']}))
.pipe(concat('css.html'))
.pipe(insert.wrap('<style>', '</style>'))
.pipe(gulp.dest('dist'));
});
gulp.task('cutestrap', function() {
return gulp.src('./src/css/my-cutestrap.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer({browsers: ['last 2 versions']}))
.pipe(concat('cutestrap.html'))
.pipe(insert.wrap('<style>', '</style>'))
.pipe(gulp.dest('dist'));
});
gulp.task('html', function() {
// process html
return gulp.src('src/templates/complete.html')
.pipe(changed('dist'))
.pipe(gulpHogan({'isProd': isProd}))
.pipe(concat('Index.html'))
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
removeCommentsFromCDATA: true,
conservativeCollapse: true,
minifyJS: true
}))
.pipe(gulp.dest('dist'));
});
gulp.task('img', buildImages);
gulp.task('jslint', function() {
return /*gulp.src('./src/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));*/
})
function buildImages() {
let img_path = "./dist/icons/";
// TODO: Update image paths so this function works
fs.stat(img_path, (err, stat) => {
if (err) fs.mkdir(img_path);
});
fs.readFile("./images/svg/small-banner.svg", (err, data) => {
if (err) throw err;
svg2png(data, { width: 440, height: 280 })
.then(buffer => fs.writeFile(img_path + "small-banner.png", buffer, (err) => {
if (err) throw err;
}))
.catch(e => console.error(e));
});
fs.readFile("./images/svg/large-banner.svg", (err, data) => {
if (err) throw err;
svg2png(data, { width: 920, height: 680 })
.then(buffer => fs.writeFile(img_path + "large-banner.png", buffer, (err) => {
if (err) throw err;
}))
.catch(e => console.error(e));
});
let sizes = ['256','128','96','64','48','32','16'];
for (let i = 0; i < sizes.length; i++) {
fs.readFile("./images/svg/transfer-icon.svg", (err, data) => {
if (err) throw err;
svg2png(data, { width: sizes[i], height: sizes[i] })
.then(buffer => fs.writeFile(img_path + "cp-icon-" + sizes[i] + ".png", buffer, (err) => {
if (err) throw (err);
}))
.catch(e => console.error(e));
});
}
}