-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
247 lines (206 loc) · 7.47 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* Created by ychen on 10/31/14.
*/
var gulp = require('gulp');
var to5 = require('gulp-6to5');
var sass = require('gulp-ruby-sass');
var mocha = require('gulp-mocha');
var regenerator = require('gulp-regenerator');
var yargs = require('yargs');
var plumber = require('gulp-plumber');
var debug = require('gulp-debug');
var rename = require('gulp-rename');
var vulcanize = require('gulp-vulcanize');
var uglify = require('gulp-uglify');
var amdOptimize = require("amd-optimize");
var concat = require('gulp-concat');
var order = require('gulp-order');
var livereload = require('gulp-livereload');
var arrayFromPoly = require('array.from');
var gulpif = require('gulp-if');
var sprite = require('css-sprite').stream;
const BUILD_DEST_DIR = 'resume';
const WEB_PATH = 'web';
const XAVIER_PATH = "../XavierPlay/public/";
const SCRIPT_BASE_URL = "dist";
const ICON_SET_SVG_PATH = "app/icons/svg";
gulp.task('refresh', ['6to5', 'es5', 'sass']);
gulp.task('6to5', function () {
var sourcemaps = require("gulp-sourcemaps");
return gulp.src(['app/**/*.js', 'app/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(regenerator({
includeRuntime: false
}))
.pipe(to5({
experimental: true,
modules: "amd"
}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest('dist/'));
});
gulp.task('es5', function () {
return gulp.src(['app/es6/**/*.es5.js'])
.pipe(plumber())
.pipe(rename(function(path){
path.basename = path.basename.replace(/.es5/,"");
}))
.pipe(gulp.dest('app/es5/'));
});
//gulp.task('reload', function () {
// return
//});
gulp.task('sass', function () {
gulp.src('sass/**/*.scss')
.pipe(plumber())
.pipe(sass({sourcemap: false, compass: true}))
.on('error', function (err) { console.log(err.message); })
.pipe(gulp.dest('stylesheets'));
});
gulp.task('icon-set', function () {
var svgstore = require('gulp-svgstore');
var svgmin = require('gulp-svgmin');
var inject = require('gulp-inject');
var replace = require('gulp-replace'); //This is an hack since polymer/icon doesn't support symbol mode
// So the viewbox size must be in sync with icon-set.html's iconSize
var svgs = gulp.src(ICON_SET_SVG_PATH+'/*.svg')
.pipe(svgmin())
.pipe(svgstore({ fileName: 'icons.svg', prefix: 'icon-', inlineSvg:true }))
function fileContents (filePath, file) {
return file.contents.toString('utf8')
}
return gulp
.src(ICON_SET_SVG_PATH+'/icon-set.html')
.pipe(inject(svgs, { transform: fileContents }))
.pipe(replace(/symbol/g, "g"))
.pipe(gulp.dest(ICON_SET_SVG_PATH));
});
//-----------------------------------------------------------------------------------------------
//
// UTILITIES
//
//-----------------------------------------------------------------------------------------------
gulp.task("imageList", function(){
var i=0;
gulp.src('web/images/samples/src/*')
.pipe(plumber())
.pipe(rename(function(path){
path.basename = (i++);
}))
.pipe(gulp.dest('web/images/samples/Cuties/'));
});
//gulp.task("imageMeta", function(){
//
// var aspectRatioList = [];
//
// function makeChange() {
// // you're going to receive Vinyl files as chunks
// function transform(file, cb) {
// // read and modify file contents
// file.contents = new Buffer(String(file.contents) + ' some modified content');
//
// console.log(aspectRatioList);
//
// // if there was some error, just pass as the first parameter here
// cb(null, file);
// }
//
// // returning the map will cause your transform function to be called
// // for each one of the chunks (files) you receive. And when this stream
// // receives a 'end' signal, it will end as well.
// //
// // Additionally, you want to require the `event-stream` somewhere else.
// return eventStream.map(transform);
// }
//
// gulp.src('web/images/samples/Cuties/*')
// .pipe(gm(function(gmfile, done){
//
// gmfile.size(function(err, sizes){
//
// aspectRatioList.push(sizes.width/sizes.height);
//
// done(null, gmfile);
// });
// }))
// .pipe(makeChange());
//});
//-----------------------------------------------------------------------------------------------
//
// BUILD
//
//-----------------------------------------------------------------------------------------------
gulp.task("vulcanize", function(){
return gulp.src('web/index.html')
.pipe(vulcanize({
dest: BUILD_DEST_DIR,
csp: true,
inline: true
}))
.pipe(gulp.dest(BUILD_DEST_DIR));
});
// generate sprite.png and _sprite.scss
gulp.task('sprites', function () {
return gulp.src('./'+BUILD_DEST_DIR+'/assets/skills/*.png')
.pipe(sprite({
name: 'sprite',
style: 'sprite.scss',
cssPath: '../../'+BUILD_DEST_DIR+'/assets/',
processor: 'scss'
}))
.pipe(gulpif('*.png', gulp.dest('./'+BUILD_DEST_DIR+'/assets'), gulp.dest('./sass')))
});
gulp.task("optimize", ['vulcanize'], function(){
var paths = require("./lib/lib");
return gulp.src('build/index.js')
// .pipe(amdOptimize('index', {
// paths: paths,
// baseUrl: 'dist'
// }))
// .pipe(order([
// "index.js"
// ]))
.pipe(concat("index.js"))
.pipe(uglify())
.pipe(gulp.dest(BUILD_DEST_DIR));
});
gulp.task("copy_to_xavier", ['optimize'], function(){
return gulp.src([BUILD_DEST_DIR+'/index.js', BUILD_DEST_DIR+'/index.html'], {"base": "."})
.pipe(gulp.dest(XAVIER_PATH));
});
gulp.task('build', ['vulcanize', 'optimize']);
//-----------------------------------------------------------------------------------------------
//
// TEST
//
//-----------------------------------------------------------------------------------------------
gulp.task('test', function () {
var testType = function(){return yargs.argv.functional ? "functional" : "unit"};
return gulp.src('test/'+ testType() +'/**/*.spec.js', {read: false})
.pipe(mocha({reporter: 'spec', grep: yargs.argv.grep}));
});
//-----------------------------------------------------------------------------------------------
//
// WATCH
//
//-----------------------------------------------------------------------------------------------
gulp.task('server', function(next) {
var connect = require('connect'),
serveStatic = require('serve-static'),
server = connect();
server.use(serveStatic(".")).listen(process.env.PORT || 9090, next);
});
// Rerun the task when a file changes
gulp.task('watch', ['server'], function() {
var server = livereload();
gulp.watch([WEB_PATH + '/**', "app/es5/**/*.js"]).on('change', server.changed);
var watcher = gulp.watch(['app/**/*.js', 'app/*.js'], ['6to5', 'es5']);
watcher.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
var stylesheetWatcher = gulp.watch('sass/**/*.scss', ['sass']);
stylesheetWatcher.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});