| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  | // enable debug for gulp
 | 
					
						
							|  |  |  | process.env.DEBUG = process.env.DEBUG || 'freecc:*'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-01 15:04:13 -07:00
										 |  |  | require('babel-core/register'); | 
					
						
							| 
									
										
										
										
											2015-07-03 17:40:12 -07:00
										 |  |  | var Rx = require('rx'), | 
					
						
							|  |  |  |   gulp = require('gulp'), | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   path = require('path'), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // utils
 | 
					
						
							| 
									
										
										
										
											2015-07-25 08:51:41 -07:00
										 |  |  |   plumber = require('gulp-plumber'), | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   notify = require('gulp-notify'), | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |   gutil = require('gulp-util'), | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |   reduce = require('gulp-reduce-file'), | 
					
						
							|  |  |  |   sortKeys = require('sort-keys'), | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   debug = require('debug')('freecc:gulp'), | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   // react app
 | 
					
						
							|  |  |  |   webpack = require('gulp-webpack'), | 
					
						
							|  |  |  |   webpackConfig = require('./webpack.config.js'), | 
					
						
							|  |  |  |   webpackConfigNode = require('./webpack.config.node.js'), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   // server process
 | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   nodemon = require('gulp-nodemon'), | 
					
						
							|  |  |  |   sync = require('browser-sync'), | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // css
 | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   less = require('gulp-less'), | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   // rev
 | 
					
						
							|  |  |  |   rev = require('gulp-rev'), | 
					
						
							|  |  |  |   revReplace = require('gulp-rev-replace'), | 
					
						
							| 
									
										
										
										
											2015-09-10 19:01:12 -07:00
										 |  |  |   revDel = require('rev-del'), | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   // lint
 | 
					
						
							| 
									
										
										
										
											2015-08-24 16:19:34 -07:00
										 |  |  |   jsonlint = require('gulp-jsonlint'), | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   eslint = require('gulp-eslint'); | 
					
						
							| 
									
										
										
										
											2014-10-13 14:14:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 11:46:34 -07:00
										 |  |  | Rx.config.longStackSupport = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  | var __DEV__ = process.env.NODE_ENV !== 'production'; | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | var reloadDelay = 1000; | 
					
						
							|  |  |  | var reload = sync.reload; | 
					
						
							| 
									
										
										
										
											2014-12-22 13:38:48 -08:00
										 |  |  | var paths = { | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   server: './server/server.js', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   serverIgnore: [ | 
					
						
							|  |  |  |     'gulpfile.js', | 
					
						
							|  |  |  |     'public/', | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     '!public/js/bundle*', | 
					
						
							| 
									
										
										
										
											2015-07-04 16:02:31 -07:00
										 |  |  |     'node_modules/', | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     'client/', | 
					
						
							| 
									
										
										
										
											2015-09-14 17:31:24 -07:00
										 |  |  |     'seed', | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |     'server/manifests/*.json', | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     'server/rev-manifest.json' | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   ], | 
					
						
							| 
									
										
										
										
											2015-07-16 16:01:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   publicJs: './public/js', | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   css: 'public/css', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   loopback: { | 
					
						
							|  |  |  |     client: './client/loopbackClient', | 
					
						
							|  |  |  |     root: path.join(__dirname, 'client/'), | 
					
						
							|  |  |  |     clientName: 'lbApp' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   client: { | 
					
						
							|  |  |  |     src: './client', | 
					
						
							|  |  |  |     dest: 'public/js' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   js: [ | 
					
						
							|  |  |  |     'client/main.js', | 
					
						
							|  |  |  |     'client/iFrameScripts.js', | 
					
						
							|  |  |  |     'client/plugin.js' | 
					
						
							|  |  |  |   ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   dependents: [ | 
					
						
							| 
									
										
										
										
											2015-09-10 19:01:12 -07:00
										 |  |  |     'client/commonFramework.js' | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   less: './client/less/main.less', | 
					
						
							| 
									
										
										
										
											2015-10-16 13:28:53 -07:00
										 |  |  |   lessFiles: './client/less/*.less', | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |   manifest: 'server/manifests/', | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   node: { | 
					
						
							|  |  |  |     src: './client', | 
					
						
							| 
									
										
										
										
											2015-07-01 15:04:13 -07:00
										 |  |  |     dest: 'common/app' | 
					
						
							| 
									
										
										
										
											2015-06-29 09:50:25 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   syncWatch: [ | 
					
						
							|  |  |  |     'public/**/*.*' | 
					
						
							| 
									
										
										
										
											2015-08-24 16:19:34 -07:00
										 |  |  |   ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   challenges: [ | 
					
						
							|  |  |  |     'seed/challenges/*.json', | 
					
						
							|  |  |  |     'seed/under-construction/*.json' | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |   ] | 
					
						
							| 
									
										
										
										
											2014-12-23 08:48:28 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-25 09:02:56 -07:00
										 |  |  | var webpackOptions = { | 
					
						
							|  |  |  |   devtool: 'inline-source-map' | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-25 08:51:41 -07:00
										 |  |  | function errorHandler() { | 
					
						
							|  |  |  |   var args = Array.prototype.slice.call(arguments); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Send error to notification center with gulp-notify
 | 
					
						
							|  |  |  |   notify.onError({ | 
					
						
							|  |  |  |     title: 'Compile Error', | 
					
						
							|  |  |  |     message: '<%= error %>' | 
					
						
							|  |  |  |   }).apply(this, args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Keep gulp from hanging on this task
 | 
					
						
							|  |  |  |   this.emit('end'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  | function delRev(dest, manifestName) { | 
					
						
							|  |  |  |   // in production do not delete old revisions
 | 
					
						
							|  |  |  |   if (!__DEV__) { | 
					
						
							|  |  |  |     return gutil.noop(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return revDel({ | 
					
						
							|  |  |  |     oldManifest: path.join(paths.manifest, manifestName), | 
					
						
							|  |  |  |     dest: dest | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 13:38:48 -08:00
										 |  |  | gulp.task('serve', function(cb) { | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   var called = false; | 
					
						
							|  |  |  |   nodemon({ | 
					
						
							|  |  |  |     script: paths.server, | 
					
						
							| 
									
										
										
										
											2015-09-08 16:53:57 -07:00
										 |  |  |     ext: '.jsx .js .json', | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     ignore: paths.serverIgnore, | 
					
						
							| 
									
										
										
										
											2015-08-01 12:26:57 -07:00
										 |  |  |     exec: path.join(__dirname, 'node_modules/.bin/babel-node'), | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     env: { | 
					
						
							|  |  |  |       'NODE_ENV': 'development', | 
					
						
							|  |  |  |       'DEBUG': process.env.DEBUG || 'freecc:*' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |     .on('start', function() { | 
					
						
							|  |  |  |       if (!called) { | 
					
						
							|  |  |  |         called = true; | 
					
						
							|  |  |  |         setTimeout(function() { | 
					
						
							|  |  |  |           cb(); | 
					
						
							|  |  |  |         }, reloadDelay); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-12-22 13:38:48 -08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     .on('restart', function(files) { | 
					
						
							|  |  |  |       if (files) { | 
					
						
							|  |  |  |         debug('Files that changes: ', files); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       setTimeout(function() { | 
					
						
							|  |  |  |         debug('Restarting browsers'); | 
					
						
							|  |  |  |         reload(); | 
					
						
							|  |  |  |       }, reloadDelay); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2014-12-22 13:38:48 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  | var syncDepenedents = [ | 
					
						
							|  |  |  |   'serve', | 
					
						
							|  |  |  |   'js', | 
					
						
							|  |  |  |   'less', | 
					
						
							|  |  |  |   'dependents', | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |   'pack-watch', | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |   'build-manifest' | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('sync', syncDepenedents, function() { | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |   sync.init(null, { | 
					
						
							|  |  |  |     proxy: 'http://localhost:3000', | 
					
						
							|  |  |  |     logLeval: 'debug', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  |     files: paths.syncWatch, | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     port: 3001, | 
					
						
							|  |  |  |     open: false, | 
					
						
							|  |  |  |     reloadDelay: reloadDelay | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2014-12-22 13:38:48 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2014-10-13 14:14:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 16:19:34 -07:00
										 |  |  | gulp.task('lint-js', function() { | 
					
						
							| 
									
										
										
										
											2015-04-15 18:20:20 -04:00
										 |  |  |   return gulp.src(['public/js/lib/**/*']) | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     .pipe(eslint()) | 
					
						
							|  |  |  |     .pipe(eslint.format()); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 16:19:34 -07:00
										 |  |  | gulp.task('lint-json', function() { | 
					
						
							|  |  |  |   return gulp.src(paths.challenges) | 
					
						
							|  |  |  |     .pipe(jsonlint()) | 
					
						
							|  |  |  |     .pipe(jsonlint.reporter()); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('test-challenges', ['lint-json']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  | gulp.task('pack-client', function() { | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |   var manifestName = 'react-manifest.json'; | 
					
						
							|  |  |  |   var dest = webpackConfig.output.path; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |   return gulp.src(webpackConfig.entry) | 
					
						
							|  |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							|  |  |  |     .pipe(webpack(Object.assign( | 
					
						
							|  |  |  |       {}, | 
					
						
							|  |  |  |       webpackConfig, | 
					
						
							|  |  |  |       webpackOptions | 
					
						
							|  |  |  |     ))) | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     .pipe(rev()) | 
					
						
							|  |  |  |     // copy files to public
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							|  |  |  |     // create manifest
 | 
					
						
							|  |  |  |     .pipe(rev.manifest(manifestName)) | 
					
						
							|  |  |  |     // delete old rev
 | 
					
						
							|  |  |  |     .pipe(delRev( | 
					
						
							|  |  |  |       dest, | 
					
						
							|  |  |  |       manifestName | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     .pipe(gulp.dest(paths.manifest)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  | var defaultStatsOptions = { | 
					
						
							|  |  |  |   colors: gutil.colors.supportsColor, | 
					
						
							|  |  |  |   hash: false, | 
					
						
							|  |  |  |   timings: false, | 
					
						
							|  |  |  |   chunks: false, | 
					
						
							|  |  |  |   chunkModules: false, | 
					
						
							|  |  |  |   modules: false, | 
					
						
							|  |  |  |   children: true, | 
					
						
							|  |  |  |   version: true, | 
					
						
							|  |  |  |   cached: false, | 
					
						
							|  |  |  |   cachedAssets: false, | 
					
						
							|  |  |  |   reasons: false, | 
					
						
							|  |  |  |   source: false, | 
					
						
							|  |  |  |   errorDetails: false | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('pack-watch', function(cb) { | 
					
						
							|  |  |  |   var called = false; | 
					
						
							|  |  |  |   gulp.src(webpackConfig.entry) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							|  |  |  |     .pipe(webpack(Object.assign( | 
					
						
							|  |  |  |       {}, | 
					
						
							|  |  |  |       webpackConfig, | 
					
						
							|  |  |  |       webpackOptions, | 
					
						
							|  |  |  |       { watch: true } | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |     ), null, function(notUsed, stats) { | 
					
						
							|  |  |  |       if (stats) { | 
					
						
							|  |  |  |         gutil.log(stats.toString(defaultStatsOptions)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!called) { | 
					
						
							|  |  |  |         debug('webpack watch completed'); | 
					
						
							|  |  |  |         called = true; | 
					
						
							|  |  |  |         cb(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     })) | 
					
						
							|  |  |  |     .pipe(gulp.dest(webpackConfig.output.path)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 09:53:40 -07:00
										 |  |  | gulp.task('pack-watch-manifest', function() { | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |   var manifestName = 'react-manifest.json'; | 
					
						
							|  |  |  |   var dest = webpackConfig.output.path; | 
					
						
							|  |  |  |   return gulp.src(dest + '/bundle.js') | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     .pipe(rev()) | 
					
						
							|  |  |  |     // copy files to public
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     // create manifest
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(rev.manifest(manifestName)) | 
					
						
							|  |  |  |     .pipe(delRev( | 
					
						
							|  |  |  |       dest, | 
					
						
							|  |  |  |       manifestName | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     .pipe(gulp.dest(paths.manifest)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('pack-node', function() { | 
					
						
							|  |  |  |   return gulp.src(webpackConfigNode.entry) | 
					
						
							|  |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							|  |  |  |     .pipe(webpack(webpackConfigNode)) | 
					
						
							|  |  |  |     .pipe(gulp.dest(webpackConfigNode.output.path)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('pack', ['pack-client', 'pack-node']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('less', function() { | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |   var manifestName = 'css-manifest.json'; | 
					
						
							|  |  |  |   var dest = paths.css; | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   return gulp.src(paths.less) | 
					
						
							| 
									
										
										
										
											2015-07-25 15:08:44 -07:00
										 |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // copile
 | 
					
						
							| 
									
										
										
										
											2015-06-12 23:31:42 -04:00
										 |  |  |     .pipe(less({ | 
					
						
							|  |  |  |       paths: [ path.join(__dirname, 'less', 'includes') ] | 
					
						
							|  |  |  |     })) | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // add revision
 | 
					
						
							|  |  |  |     .pipe(rev()) | 
					
						
							|  |  |  |     // copy files to public
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // create and merge manifest
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(rev.manifest(manifestName)) | 
					
						
							|  |  |  |     .pipe(delRev( | 
					
						
							|  |  |  |       dest, | 
					
						
							|  |  |  |       manifestName | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     .pipe(gulp.dest(paths.manifest)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('js', function() { | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |   var manifestName = 'js-manifest.json'; | 
					
						
							|  |  |  |   var dest = paths.publicJs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   return gulp.src(paths.js) | 
					
						
							|  |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // create registry file
 | 
					
						
							|  |  |  |     .pipe(rev()) | 
					
						
							|  |  |  |     // copy revisioned assets to dest
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // create manifest file
 | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(rev.manifest(manifestName)) | 
					
						
							|  |  |  |     .pipe(delRev( | 
					
						
							|  |  |  |       dest, | 
					
						
							|  |  |  |       manifestName | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     // copy manifest file to dest
 | 
					
						
							|  |  |  |     .pipe(gulp.dest(paths.manifest)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // commonFramework depend on iFrameScripts
 | 
					
						
							|  |  |  | // sandbox depends on plugin
 | 
					
						
							|  |  |  | gulp.task('dependents', ['js'], function() { | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |   var manifestName = 'dependents-manifest.json'; | 
					
						
							|  |  |  |   var dest = paths.publicJs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   var manifest = gulp.src( | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |     path.join(__dirname, paths.manifest, 'js-manifest.json') | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return gulp.src(paths.dependents) | 
					
						
							|  |  |  |     .pipe(plumber({ errorHandler: errorHandler })) | 
					
						
							|  |  |  |     .pipe(revReplace({ manifest: manifest })) | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     .pipe(rev()) | 
					
						
							| 
									
										
										
										
											2015-09-10 19:34:40 -07:00
										 |  |  |     .pipe(gulp.dest(dest)) | 
					
						
							|  |  |  |     .pipe(rev.manifest(manifestName)) | 
					
						
							|  |  |  |     .pipe(delRev( | 
					
						
							|  |  |  |       dest, | 
					
						
							|  |  |  |       manifestName | 
					
						
							|  |  |  |     )) | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |     .pipe(gulp.dest(paths.manifest)); | 
					
						
							| 
									
										
										
										
											2015-04-15 18:20:20 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  | function collector(file, memo) { | 
					
						
							|  |  |  |   return Object.assign({}, JSON.parse(file.contents), memo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function done(manifest) { | 
					
						
							|  |  |  |   return sortKeys(manifest); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function buildManifest() { | 
					
						
							|  |  |  |   return gulp.src(paths.manifest + '*.json') | 
					
						
							|  |  |  |     .pipe(reduce('rev-manifest.json', collector, done, {})) | 
					
						
							|  |  |  |     .pipe(gulp.dest('server/')); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var buildDependents = ['less', 'js', 'dependents']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('build-manifest', buildDependents, function() { | 
					
						
							|  |  |  |   return buildManifest(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('build-manifest-watch', function() { | 
					
						
							|  |  |  |   return buildManifest(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2015-06-16 14:53:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  | gulp.task('build', [ | 
					
						
							|  |  |  |   'less', | 
					
						
							|  |  |  |   'js', | 
					
						
							|  |  |  |   'dependents', | 
					
						
							|  |  |  |   'pack-client', | 
					
						
							|  |  |  |   'build-manifest' | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var watchDependents = [ | 
					
						
							|  |  |  |   'less', | 
					
						
							|  |  |  |   'js', | 
					
						
							|  |  |  |   'dependents', | 
					
						
							|  |  |  |   'serve', | 
					
						
							|  |  |  |   'sync', | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |   'build-manifest', | 
					
						
							|  |  |  |   'pack-watch', | 
					
						
							|  |  |  |   'pack-watch-manifest' | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gulp.task('watch', watchDependents, function() { | 
					
						
							| 
									
										
										
										
											2015-10-16 13:28:53 -07:00
										 |  |  |   gulp.watch(paths.lessFiles, ['less']); | 
					
						
							| 
									
										
										
										
											2015-08-26 23:20:56 -07:00
										 |  |  |   gulp.watch(paths.js, ['js']); | 
					
						
							| 
									
										
										
										
											2015-08-24 16:19:34 -07:00
										 |  |  |   gulp.watch(paths.challenges, ['test-challenges']); | 
					
						
							| 
									
										
										
										
											2015-08-28 15:54:40 -07:00
										 |  |  |   gulp.watch(paths.js, ['js', 'dependents']); | 
					
						
							|  |  |  |   gulp.watch(paths.dependents, ['dependents']); | 
					
						
							|  |  |  |   gulp.watch(paths.manifest + '/*.json', ['build-manifest-watch']); | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  |   gulp.watch(webpackConfig.output.path + '/bundle.js', ['pack-watch-manifest']); | 
					
						
							| 
									
										
										
										
											2015-06-16 12:32:12 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 09:20:55 -07:00
										 |  |  | gulp.task('default', [ | 
					
						
							|  |  |  |   'less', | 
					
						
							|  |  |  |   'serve', | 
					
						
							|  |  |  |   'pack-watch', | 
					
						
							|  |  |  |   'pack-watch-manifest', | 
					
						
							|  |  |  |   'watch', | 
					
						
							|  |  |  |   'sync' | 
					
						
							|  |  |  | ]); | 
					
						
							| 
									
										
										
										
											2015-06-26 16:27:10 -07:00
										 |  |  | 
 |