scratch – Blame information for rev 117
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
117 | office | 1 | (function(){ |
2 | 'use strict'; |
||
3 | var gulp = require('gulp'), |
||
4 | connect = require('gulp-connect'), |
||
5 | open = require('gulp-open'), |
||
6 | less = require('gulp-less'), |
||
7 | rename = require('gulp-rename'), |
||
8 | header = require('gulp-header'), |
||
9 | path = require('path'), |
||
10 | uglify = require('gulp-uglify'), |
||
11 | sourcemaps = require('gulp-sourcemaps'), |
||
12 | cleanCSS = require('gulp-clean-css'), |
||
13 | tap = require('gulp-tap'), |
||
14 | concat = require('gulp-concat'), |
||
15 | jshint = require('gulp-jshint'), |
||
16 | stylish = require('jshint-stylish'), |
||
17 | fs = require('fs'), |
||
18 | paths = { |
||
19 | root: './', |
||
20 | build: { |
||
21 | root: 'build/', |
||
22 | styles: 'build/css/', |
||
23 | scripts: 'build/js/' |
||
24 | }, |
||
25 | custom: { |
||
26 | root: 'custom/', |
||
27 | styles: 'custom/css/', |
||
28 | scripts: 'custom/js/' |
||
29 | }, |
||
30 | dist: { |
||
31 | root: 'dist/', |
||
32 | styles: 'dist/css/', |
||
33 | scripts: 'dist/js/' |
||
34 | }, |
||
35 | playground: { |
||
36 | root: 'playground/' |
||
37 | }, |
||
38 | source: { |
||
39 | root: 'src/', |
||
40 | styles: 'src/less/', |
||
41 | scripts: 'src/js/*.js' |
||
42 | }, |
||
43 | }, |
||
44 | swiper = { |
||
45 | filename: 'swiper', |
||
46 | jsFiles: [ |
||
47 | 'src/js/wrap-start.js', |
||
48 | 'src/js/swiper-intro.js', |
||
49 | 'src/js/core.js', |
||
50 | 'src/js/effects.js', |
||
51 | 'src/js/lazy-load.js', |
||
52 | 'src/js/scrollbar.js', |
||
53 | 'src/js/controller.js', |
||
54 | 'src/js/hashnav.js', |
||
55 | 'src/js/history.js', |
||
56 | 'src/js/keyboard.js', |
||
57 | 'src/js/mousewheel.js', |
||
58 | 'src/js/parallax.js', |
||
59 | 'src/js/zoom.js', |
||
60 | 'src/js/plugins.js', |
||
61 | 'src/js/emitter.js', |
||
62 | 'src/js/a11y.js', |
||
63 | 'src/js/init.js', |
||
64 | 'src/js/swiper-outro.js', |
||
65 | 'src/js/swiper-proto.js', |
||
66 | 'src/js/dom.js', |
||
67 | 'src/js/get-dom-lib.js', |
||
68 | 'src/js/dom-plugins.js', |
||
69 | 'src/js/wrap-end.js', |
||
70 | 'src/js/amd.js' |
||
71 | ], |
||
72 | jQueryFiles : [ |
||
73 | 'src/js/wrap-start.js', |
||
74 | 'src/js/swiper-intro.js', |
||
75 | 'src/js/core.js', |
||
76 | 'src/js/effects.js', |
||
77 | 'src/js/lazy-load.js', |
||
78 | 'src/js/scrollbar.js', |
||
79 | 'src/js/controller.js', |
||
80 | 'src/js/hashnav.js', |
||
81 | 'src/js/history.js', |
||
82 | 'src/js/keyboard.js', |
||
83 | 'src/js/mousewheel.js', |
||
84 | 'src/js/parallax.js', |
||
85 | 'src/js/zoom.js', |
||
86 | 'src/js/plugins.js', |
||
87 | 'src/js/emitter.js', |
||
88 | 'src/js/a11y.js', |
||
89 | 'src/js/init.js', |
||
90 | 'src/js/swiper-outro.js', |
||
91 | 'src/js/swiper-proto.js', |
||
92 | 'src/js/get-dom-lib.js', |
||
93 | 'src/js/dom-plugins.js', |
||
94 | 'src/js/wrap-end.js', |
||
95 | 'src/js/amd.js' |
||
96 | ], |
||
97 | jQueryUMDFiles : [ |
||
98 | 'src/js/wrap-start-umd.js', |
||
99 | 'src/js/swiper-intro.js', |
||
100 | 'src/js/core.js', |
||
101 | 'src/js/effects.js', |
||
102 | 'src/js/lazy-load.js', |
||
103 | 'src/js/scrollbar.js', |
||
104 | 'src/js/controller.js', |
||
105 | 'src/js/hashnav.js', |
||
106 | 'src/js/history.js', |
||
107 | 'src/js/keyboard.js', |
||
108 | 'src/js/mousewheel.js', |
||
109 | 'src/js/parallax.js', |
||
110 | 'src/js/zoom.js', |
||
111 | 'src/js/plugins.js', |
||
112 | 'src/js/emitter.js', |
||
113 | 'src/js/a11y.js', |
||
114 | 'src/js/init.js', |
||
115 | 'src/js/swiper-outro.js', |
||
116 | 'src/js/swiper-proto.js', |
||
117 | 'src/js/get-jquery.js', |
||
118 | 'src/js/dom-plugins.js', |
||
119 | 'src/js/wrap-end-umd.js', |
||
120 | ], |
||
121 | Framework7Files : [ |
||
122 | 'src/js/swiper-intro-f7.js', |
||
123 | 'src/js/core.js', |
||
124 | 'src/js/effects.js', |
||
125 | 'src/js/lazy-load.js', |
||
126 | 'src/js/scrollbar.js', |
||
127 | 'src/js/controller.js', |
||
128 | 'src/js/parallax.js', |
||
129 | 'src/js/zoom.js', |
||
130 | 'src/js/plugins.js', |
||
131 | 'src/js/emitter.js', |
||
132 | 'src/js/a11y.js', |
||
133 | 'src/js/init.js', |
||
134 | 'src/js/swiper-outro.js', |
||
135 | 'src/js/swiper-proto.js', |
||
136 | ], |
||
137 | pkg: require('./bower.json'), |
||
138 | modules: require('./modules.json'), |
||
139 | banner: [ |
||
140 | '/**', |
||
141 | ' * Swiper <%= pkg.version %>', |
||
142 | ' * <%= pkg.description %>', |
||
143 | ' * ', |
||
144 | ' * <%= pkg.homepage %>', |
||
145 | ' * ', |
||
146 | ' * Copyright <%= date.year %>, <%= pkg.author %>', |
||
147 | ' * The iDangero.us', |
||
148 | ' * http://www.idangero.us/', |
||
149 | ' * ', |
||
150 | ' * Licensed under <%= pkg.license.join(" & ") %>', |
||
151 | ' * ', |
||
152 | ' * Released on: <%= date.month %> <%= date.day %>, <%= date.year %>', |
||
153 | ' */', |
||
154 | ''].join('\n'), |
||
155 | customBanner: [ |
||
156 | '/**', |
||
157 | ' * Swiper <%= pkg.version %> - Custom Build', |
||
158 | ' * <%= pkg.description %>', |
||
159 | ' * ', |
||
160 | ' * Included modules: <%= modulesList %>', |
||
161 | ' * ', |
||
162 | ' * <%= pkg.homepage %>', |
||
163 | ' * ', |
||
164 | ' * Copyright <%= date.year %>, <%= pkg.author %>', |
||
165 | ' * The iDangero.us', |
||
166 | ' * http://www.idangero.us/', |
||
167 | ' * ', |
||
168 | ' * Licensed under <%= pkg.license.join(" & ") %>', |
||
169 | ' * ', |
||
170 | ' * Released on: <%= date.month %> <%= date.day %>, <%= date.year %>', |
||
171 | ' */', |
||
172 | ''].join('\n'), |
||
173 | date: { |
||
174 | year: new Date().getFullYear(), |
||
175 | month: ('January February March April May June July August September October November December').split(' ')[new Date().getMonth()], |
||
176 | day: new Date().getDate() |
||
177 | } |
||
178 | }; |
||
179 | |||
180 | function addJSIndent (file, t, minusIndent) { |
||
181 | var addIndent = ' '; |
||
182 | var filename = file.path.split('src/js/')[1]; |
||
183 | if (['wrap-start.js', 'wrap-start-umd.js', 'wrap-end.js', 'wrap-end-umd.js', 'amd.js'].indexOf(filename) !== -1) { |
||
184 | addIndent = ''; |
||
185 | } |
||
186 | if (filename === 'swiper-intro.js' || filename === 'swiper-intro-f7.js' || filename === 'swiper-outro.js' || filename === 'dom.js' || filename === 'get-dom-lib.js' || filename === 'get-jquery.js' || filename === 'dom-plugins.js' || filename === 'swiper-proto.js') addIndent = ' '; |
||
187 | if (minusIndent) { |
||
188 | addIndent = addIndent.substring(4); |
||
189 | } |
||
190 | if (addIndent !== '') { |
||
191 | var fileLines = fs.readFileSync(file.path).toString().split('\n'); |
||
192 | var newFileContents = ''; |
||
193 | for (var i = 0; i < fileLines.length; i++) { |
||
194 | newFileContents += addIndent + fileLines[i] + (i === fileLines.length ? '' : '\n'); |
||
195 | } |
||
196 | file.contents = new Buffer(newFileContents); |
||
197 | } |
||
198 | } |
||
199 | gulp.task('scripts', function (cb) { |
||
200 | gulp.src(swiper.jsFiles) |
||
201 | .pipe(tap(function (file, t){ |
||
202 | addJSIndent (file, t); |
||
203 | })) |
||
204 | .pipe(sourcemaps.init()) |
||
205 | .pipe(concat(swiper.filename + '.js')) |
||
206 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
207 | .pipe(jshint()) |
||
208 | .pipe(jshint.reporter(stylish)) |
||
209 | .pipe(sourcemaps.write('./maps/')) |
||
210 | .pipe(gulp.dest(paths.build.scripts)); |
||
211 | |||
212 | |||
213 | gulp.src(swiper.jQueryFiles) |
||
214 | .pipe(tap(function (file, t){ |
||
215 | addJSIndent (file, t); |
||
216 | })) |
||
217 | .pipe(sourcemaps.init()) |
||
218 | .pipe(concat(swiper.filename + '.jquery.js')) |
||
219 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
220 | .pipe(sourcemaps.write('./maps/')) |
||
221 | .pipe(gulp.dest(paths.build.scripts)); |
||
222 | gulp.src(swiper.jQueryUMDFiles) |
||
223 | .pipe(tap(function (file, t){ |
||
224 | addJSIndent (file, t); |
||
225 | })) |
||
226 | .pipe(sourcemaps.init()) |
||
227 | .pipe(concat(swiper.filename + '.jquery.umd.js')) |
||
228 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
229 | .pipe(sourcemaps.write('./maps/')) |
||
230 | .pipe(gulp.dest(paths.build.scripts)); |
||
231 | gulp.src(swiper.Framework7Files) |
||
232 | .pipe(tap(function (file, t){ |
||
233 | addJSIndent (file, t, true); |
||
234 | })) |
||
235 | .pipe(sourcemaps.init()) |
||
236 | .pipe(concat(swiper.filename + '.framework7.js')) |
||
237 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
238 | .pipe(sourcemaps.write('./maps/')) |
||
239 | .pipe(gulp.dest(paths.build.scripts)) |
||
240 | .pipe(connect.reload()); |
||
241 | cb(); |
||
242 | }); |
||
243 | gulp.task('styles', function (cb) { |
||
244 | |||
245 | gulp.src(paths.source.styles + 'swiper.less') |
||
246 | .pipe(less({ |
||
247 | paths: [ path.join(__dirname, 'less', 'includes') ] |
||
248 | })) |
||
249 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date })) |
||
250 | .pipe(rename(function(path) { |
||
251 | path.basename = swiper.filename; |
||
252 | })) |
||
253 | .pipe(gulp.dest(paths.build.styles)) |
||
254 | .pipe(connect.reload()); |
||
255 | |||
256 | gulp.src([ |
||
257 | paths.source.styles + 'core.less', |
||
258 | paths.source.styles + 'navigation-f7.less', |
||
259 | paths.source.styles + 'effects.less', |
||
260 | paths.source.styles + 'zoom.less', |
||
261 | paths.source.styles + 'scrollbar.less', |
||
262 | paths.source.styles + 'preloader-f7.less' |
||
263 | ]) |
||
264 | .pipe(concat(swiper.filename + '.framework7.less')) |
||
265 | .pipe(header('/* === Swiper === */\n')) |
||
266 | .pipe(gulp.dest(paths.build.styles)); |
||
267 | cb(); |
||
268 | }); |
||
269 | gulp.task('build', ['scripts', 'styles'], function (cb) { |
||
270 | cb(); |
||
271 | }); |
||
272 | |||
273 | gulp.task('dist', function () { |
||
274 | gulp.src([paths.build.scripts + swiper.filename + '.js']) |
||
275 | .pipe(gulp.dest(paths.dist.scripts)) |
||
276 | .pipe(sourcemaps.init()) |
||
277 | .pipe(uglify()) |
||
278 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date })) |
||
279 | .pipe(rename(function(path) { |
||
280 | path.basename = swiper.filename + '.min'; |
||
281 | })) |
||
282 | .pipe(sourcemaps.write('./maps')) |
||
283 | .pipe(gulp.dest(paths.dist.scripts)); |
||
284 | |||
285 | gulp.src([paths.build.scripts + swiper.filename + '.jquery.js']) |
||
286 | .pipe(gulp.dest(paths.dist.scripts)) |
||
287 | .pipe(sourcemaps.init()) |
||
288 | .pipe(uglify()) |
||
289 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
290 | .pipe(rename(function(path) { |
||
291 | path.basename = swiper.filename + '.jquery.min'; |
||
292 | })) |
||
293 | .pipe(sourcemaps.write('./maps')) |
||
294 | .pipe(gulp.dest(paths.dist.scripts)); |
||
295 | |||
296 | gulp.src([paths.build.scripts + swiper.filename + '.jquery.umd.js']) |
||
297 | .pipe(gulp.dest(paths.dist.scripts)) |
||
298 | .pipe(sourcemaps.init()) |
||
299 | .pipe(uglify()) |
||
300 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date } )) |
||
301 | .pipe(rename(function(path) { |
||
302 | path.basename = swiper.filename + '.jquery.umd.min'; |
||
303 | })) |
||
304 | .pipe(sourcemaps.write('./maps')) |
||
305 | .pipe(gulp.dest(paths.dist.scripts)); |
||
306 | |||
307 | gulp.src(paths.build.styles + '*.css') |
||
308 | .pipe(gulp.dest(paths.dist.styles)) |
||
309 | .pipe(cleanCSS({ |
||
310 | advanced: false, |
||
311 | aggressiveMerging: false, |
||
312 | })) |
||
313 | .pipe(header(swiper.banner, { pkg : swiper.pkg, date: swiper.date })) |
||
314 | .pipe(rename(function(path) { |
||
315 | path.basename = swiper.filename + '.min'; |
||
316 | })) |
||
317 | .pipe(gulp.dest(paths.dist.styles)); |
||
318 | }); |
||
319 | |||
320 | /* ================================= |
||
321 | Custom Build |
||
322 | ================================= */ |
||
323 | gulp.task('custom', function () { |
||
324 | var modules = process.argv.slice(3); |
||
325 | modules = modules.toString(); |
||
326 | if (modules === '') { |
||
327 | modules = []; |
||
328 | } |
||
329 | else { |
||
330 | modules = modules.substring(1).replace(/ /g, '').replace(/,,/g, ','); |
||
331 | modules = modules.split(','); |
||
332 | } |
||
333 | var modulesJs = [], modulesLess = []; |
||
334 | var i, module; |
||
335 | modulesJs.push.apply(modulesJs, swiper.modules.core_intro.js); |
||
336 | modulesLess.push.apply(modulesLess, swiper.modules.core_intro.less); |
||
337 | |||
338 | for (i = 0; i < modules.length; i++) { |
||
339 | module = swiper.modules[modules[i]]; |
||
340 | if (!(module)) continue; |
||
341 | |||
342 | if (module.dependencies && module.dependencies.length > 0) { |
||
343 | modules.push.apply(modules, module.dependencies); |
||
344 | } |
||
345 | if (module.js.length > 0) { |
||
346 | modulesJs.push.apply(modulesJs, module.js); |
||
347 | } |
||
348 | if (module.less && module.less.length > 0) { |
||
349 | modulesLess.push.apply(modulesLess, module.less); |
||
350 | } |
||
351 | } |
||
352 | modulesJs.push.apply(modulesJs, swiper.modules.core_outro.js); |
||
353 | modulesLess.push.apply(modulesLess, swiper.modules.core_outro.less); |
||
354 | |||
355 | // Unique |
||
356 | var customJsList = []; |
||
357 | var customLessList = []; |
||
358 | for (i = 0; i < modulesJs.length; i++) { |
||
359 | if (customJsList.indexOf(modulesJs[i]) < 0) customJsList.push(modulesJs[i]); |
||
360 | } |
||
361 | for (i = 0; i < modulesLess.length; i++) { |
||
362 | if (customLessList.indexOf(modulesLess[i]) < 0) customLessList.push(modulesLess[i]); |
||
363 | } |
||
364 | |||
365 | // JS |
||
366 | gulp.src(customJsList) |
||
367 | .pipe(tap(function (file, t){ |
||
368 | addJSIndent (file, t); |
||
369 | })) |
||
370 | .pipe(concat(swiper.filename + '.custom.js')) |
||
371 | .pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') } )) |
||
372 | .pipe(jshint()) |
||
373 | .pipe(jshint.reporter(stylish)) |
||
374 | .pipe(gulp.dest(paths.custom.scripts)) |
||
375 | |||
376 | .pipe(uglify()) |
||
377 | .pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') })) |
||
378 | .pipe(rename(function(path) { |
||
379 | path.basename = path.basename + '.min'; |
||
380 | })) |
||
381 | .pipe(gulp.dest(paths.custom.scripts)); |
||
382 | |||
383 | // CSSes |
||
384 | gulp.src(customLessList) |
||
385 | .pipe(concat(swiper.filename + '.custom.less')) |
||
386 | .pipe(less({ |
||
387 | paths: [ path.join(__dirname, 'less', 'includes') ] |
||
388 | })) |
||
389 | .pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') } )) |
||
390 | .pipe(gulp.dest(paths.custom.styles)) |
||
391 | |||
392 | .pipe(cleanCSS({ |
||
393 | advanced: false, |
||
394 | aggressiveMerging: false |
||
395 | })) |
||
396 | .pipe(header(swiper.customBanner, { pkg : swiper.pkg, date: swiper.date, modulesList: modules.join(',') })) |
||
397 | .pipe(rename(function(path) { |
||
398 | path.basename = path.basename + '.min'; |
||
399 | })) |
||
400 | .pipe(gulp.dest(paths.custom.styles)); |
||
401 | }); |
||
402 | |||
403 | gulp.task('watch', function () { |
||
404 | gulp.watch(paths.source.scripts, [ 'scripts' ]); |
||
405 | gulp.watch(paths.source.styles + '*.less', [ 'styles' ]); |
||
406 | }); |
||
407 | |||
408 | gulp.task('connect', function () { |
||
409 | return connect.server({ |
||
410 | root: [ paths.root ], |
||
411 | livereload: true, |
||
412 | port:'3000' |
||
413 | }); |
||
414 | }); |
||
415 | |||
416 | gulp.task('open', function () { |
||
417 | return gulp.src(paths.playground.root + 'index.html').pipe(open({ uri: 'http://localhost:3000/' + paths.playground.root + 'index.html'})); |
||
418 | }); |
||
419 | |||
420 | gulp.task('server', [ 'watch', 'connect', 'open' ]); |
||
421 | |||
422 | gulp.task('default', [ 'server' ]); |
||
423 | })(); |