@@ -47,7 +47,7 @@ var base64 = require('gulp-base64');
4747var minimist = require ( 'minimist' ) ;
4848var open = require ( 'gulp-open' ) ;
4949
50- const C = {
50+ var C = {
5151 SRC :'src/' ,
5252 BUILD : 'build/' ,
5353 BUILD_DOCS : 'build_docs/' ,
@@ -58,18 +58,18 @@ const C = {
5858 MODULE_HTML : 'mm-*.html' ,
5959 SHARED : 'shared/' ,
6060 BOWER : 'bower_components/' ,
61+ SASS_INCLUDE : [ 'bower_components/bourbon/app/assets/stylesheets/' , 'src/shared/sass/' ] ,
6162 LIVE_PORT : 8000 ,
6263 DOCS_PORT : 8001
6364} ;
6465
6566
6667
6768var PATCH_LIST = [
68- 'bower_components /moment/min/moment.min.js'
69+ j ( C . BOWER , ' /moment/min/moment.min.js')
6970] ;
7071
7172var IS_DEBUG = ! ! gutil . env . debug ;
72- console . log ( IS_DEBUG ) ;
7373
7474function dbg ( t ) {
7575 return gif ( IS_DEBUG , debug ( { title :t } ) ) ;
@@ -78,10 +78,10 @@ function dbg(t) {
7878/** BUILD **/
7979
8080gulp . task ( 'patch-lib' , function ( ) {
81- gulp . src ( C . PATCH_LIST , { base : j ( __dirname , 'bower_components' ) } )
81+ gulp . src ( C . PATCH_LIST , { base : j ( __dirname , C . BOWER ) } )
8282 . pipe ( dbg ( 'patch-lib' ) )
8383 . pipe ( wrap ( "(function(define, require) { {{{contents}}} })();" , { } , { engine :"hogan" } ) . on ( 'error' , console . error ) )
84- . pipe ( gulp . dest ( j ( __dirname , 'bower_components' ) ) ) ;
84+ . pipe ( gulp . dest ( j ( __dirname , C . BOWER ) ) ) ;
8585} ) ;
8686
8787gulp . task ( 'clean' , function ( ) {
@@ -103,7 +103,7 @@ gulp.task('sass', function() {
103103 var wrapper = fs . readFileSync ( j ( C . TEMPLATES , "style_module_template.html" ) , 'utf8' ) ;
104104 return gulp . src ( j ( C . SRC , C . MODULE_MASK , '*.scss' ) )
105105 . pipe ( cache ( 'scss' ) )
106- . pipe ( sass ( { includePaths : [ './bower_components/bourbon/app/assets/stylesheets/' , './src/shared/sass/' ] } ) . on ( 'error' , sass . logError ) )
106+ . pipe ( sass ( { includePaths : C . SASS_INCLUDE } ) . on ( 'error' , sass . logError ) )
107107 . pipe ( postcss ( [ autoprefixer ( { browsers : [ 'last 2 versions' ] } ) ] ) )
108108 . pipe ( dbg ( 'sass' ) )
109109 . pipe ( gulp . dest ( C . BUILD ) )
@@ -117,8 +117,8 @@ gulp.task('sass', function() {
117117} ) ;
118118
119119gulp . task ( 'font' , function ( ) {
120- return gulp . src ( C . SRC + 'shared /fonts/fonts.scss')
121- . pipe ( sass ( { includePaths : [ './bower_components/bourbon/app/assets/stylesheets/' , './src/shared/sass/' ] } ) . on ( 'error' , sass . logError ) )
120+ return gulp . src ( j ( C . SRC , C . SHARED , ' /fonts/fonts.scss') )
121+ . pipe ( sass ( { includePaths : C . SASS_INCLUDE } ) . on ( 'error' , sass . logError ) )
122122 . pipe ( dbg ( 'font' ) )
123123 . pipe ( gulp . dest ( C . BUILD + 'shared/fonts/' ) )
124124 . pipe ( wrap ( "<style>{{{contents}}}</style>" , { } , { engine :"hogan" } ) . on ( 'error' , console . log ) )
@@ -159,9 +159,9 @@ function vulcanizeSingle(opts, baseList, basePath) {
159159}
160160
161161gulp . task ( 'vulcanize' , function ( ) {
162- var moduleGlob = j ( C . BUILD , 'mm-*/mm-*.html' ) ;
162+ var moduleGlob = j ( C . BUILD , C . MODULE_MASK , C . MODULE_HTML ) ;
163163 var excludes = glob . sync ( moduleGlob ) ;
164- excludes . push ( 'bower_components /polymer/polymer.html') ;
164+ excludes . push ( j ( C . BOWER , ' /polymer/polymer.html') ) ;
165165
166166 var modules = gulp . src ( moduleGlob )
167167 . pipe ( cache ( 'v-modules' ) )
@@ -193,10 +193,10 @@ gulp.task('build', function(cb) {
193193} ) ;
194194
195195gulp . task ( 'build:prod' , [ 'patch-lib' , 'build' ] , function ( ) {
196- var excludes = glob . sync ( j ( C . BUILD , 'mm-*/mm-*.html' ) ) ;
196+ var excludes = glob . sync ( j ( C . BUILD , C . MODULE_MASK , C . MODULE_HTML ) ) ;
197197 excludes . push ( 'bower_components/polymer/polymer.html' ) ;
198198
199- var modules = gulp . src ( j ( C . BUILD , 'mm-*/mm-*.html' ) )
199+ var modules = gulp . src ( j ( C . BUILD , C . MODULE_MASK , C . MODULE_HTML ) )
200200 . pipe ( vulcanizeSingle ( {
201201 inlineScripts : true ,
202202 inlineCss : true ,
@@ -241,28 +241,28 @@ gulp.task('clean:docs', function() {
241241} ) ;
242242
243243gulp . task ( 'copy:docs' , function ( ) {
244- var assets = gulp . src ( 'docs /images/**', { base :'./docs' } ) ;
244+ var assets = gulp . src ( j ( C . DOCS , ' /images/**') , { base :C . DOCS } ) ;
245245 var cname = gulp . src ( 'CNAME' ) ;
246246 var license = gulp . src ( 'LICENSE.txt' ) ;
247247
248248 var merged_static = merge ( assets , cname , license )
249249 . pipe ( gulp . dest ( C . BUILD_DOCS ) ) ;
250250
251- var bower_components = gulp . src ( [ 'bower_components /webcomponentsjs/**/*', 'bower_components /polymer/**/*'] , { base :'bower_components' } )
251+ var bower_components = gulp . src ( [ j ( C . BOWER , ' /webcomponentsjs/**/*') , j ( C . BOWER , ' /polymer/**/*') ] , { base :C . BOWER } )
252252 . pipe ( dbg ( 'copy-bower' ) )
253- . pipe ( gulp . dest ( C . BUILD_DOCS + '/bower_components/' ) ) ;
253+ . pipe ( gulp . dest ( j ( C . BUILD_DOCS , C . BOWER ) ) ) ;
254254
255255 var lib = gulp . src ( j ( C . BUILD , '**' ) )
256256 . pipe ( dbg ( 'copy-lib' ) )
257- . pipe ( gulp . dest ( j ( C . BUILD_DOCS , '/bower_components /strand/dist') ) ) ;
257+ . pipe ( gulp . dest ( j ( C . BUILD_DOCS , C . BOWER , ' /strand/dist') ) ) ;
258258
259259 return merge ( bower_components , merged_static , lib ) ;
260260} ) ;
261261
262262gulp . task ( 'sass:docs' , function ( ) {
263- return gulp . src ( 'docs /**/*.scss')
263+ return gulp . src ( j ( C . DOCS , ' /**/*.scss') )
264264 . pipe ( dbg ( 'sass-docs' ) )
265- . pipe ( sass ( { includePaths : [ './bower_components/bourbon/app/assets/stylesheets/' , './src/shared/sass/' ] } ) . on ( 'error' , sass . logError ) )
265+ . pipe ( sass ( { includePaths : C . SASS_INCLUDE } ) . on ( 'error' , sass . logError ) )
266266 . pipe ( postcss ( [ autoprefixer ( { browsers : [ 'last 2 versions' ] } ) ] ) )
267267 . pipe ( gulp . dest ( C . BUILD_DOCS ) ) ;
268268} ) ;
@@ -326,7 +326,7 @@ gulp.task('docs:templates', function() {
326326 function injectModuleData ( pkg , moduleMap , articleList , articleMap ) {
327327 return through . obj ( function ( file , enc , cb ) {
328328 var moduleDoc = JSON . parse ( file . contents ) ;
329- var examplePath = path . join ( C . SRC , moduleDoc . name , 'example.html' ) ;
329+ var examplePath = j ( C . SRC , moduleDoc . name , 'example.html' ) ;
330330 var example ;
331331 try {
332332 example = fs . readFileSync ( examplePath ) . toString ( 'utf8' ) ;
@@ -358,7 +358,7 @@ gulp.task('docs:templates', function() {
358358 articleList : articles ,
359359 articleMap : articleMap
360360 } ;
361- var templatePath = path . join ( __dirname , 'docs /article_template.html') ;
361+ var templatePath = j ( __dirname , C . DOCS , ' /article_template.html') ;
362362 var templateString = fs . readFileSync ( templatePath ) . toString ( 'utf8' ) ;
363363 var template = hogan . compile ( templateString ) ;
364364 var doc = template . render ( articleDoc , partialMap ) ;
@@ -371,25 +371,25 @@ gulp.task('docs:templates', function() {
371371 var pkg = getPkgInfo ( ) ;
372372
373373 // Create moduleList from directory listing
374- var modules = glob . sync ( "mm-* /doc.json", { cwd :C . SRC } ) ;
374+ var modules = glob . sync ( j ( C . MODULE_MASK , " /doc.json") , { cwd :C . SRC } ) ;
375375 var moduleList = modules . map ( function ( name ) { return name . replace ( '/doc.json' , '' ) ; } ) ;
376376 var moduleMap = moduleList . map ( function ( name ) { return { name : name } ; } ) ;
377377
378378 // Create behaviorsMap
379- var behaviors = glob . sync ( j ( C . SRC , 'shared /behaviors/*.json') ) ;
379+ var behaviors = glob . sync ( j ( C . SRC , C . SHARED , ' /behaviors/*.json') ) ;
380380 var behaviorsMap = { } ;
381381 behaviors . forEach ( function ( behavior ) {
382- var behaviorKey = behavior . replace ( j ( C . SRC , 'shared /behaviors/') , '' )
382+ var behaviorKey = behavior . replace ( j ( C . SRC , C . SHARED , ' /behaviors/') , '' )
383383 . replace ( '.json' , '' )
384384 . toLowerCase ( ) ;
385385 behaviorsMap [ behaviorKey ] = JSON . parse ( fs . readFileSync ( behavior ) ) ;
386386 } ) ;
387387
388388 // Create articleList and articleMap
389- var articles = glob . sync ( "*.md" , { cwd :"./docs/ articles/"} ) ;
390- var articleMap = JSON . parse ( fs . readFileSync ( './docs/ articles/manifest.json') ) ;
389+ var articles = glob . sync ( "*.md" , { cwd :j ( C . DOCS , "/ articles/") } ) ;
390+ var articleMap = JSON . parse ( fs . readFileSync ( j ( C . DOCS , '/ articles/manifest.json') ) ) ;
391391 var articleList = articles . map ( function ( article ) {
392- var file = fs . readFileSync ( './docs/ articles/'+ article ) . toString ( 'utf8' ) ,
392+ var file = fs . readFileSync ( j ( C . DOCS , '/ articles/', article ) , 'utf8' ) ,
393393 name = file . split ( "\n" ) [ 0 ] . replace ( "#" , "" ) ,
394394 key = path . basename ( article , '.md' ) ,
395395 link = "article_" + key + ".html" ;
@@ -414,15 +414,15 @@ gulp.task('docs:templates', function() {
414414 } ) ;
415415
416416 // Compile partials
417- var partials = glob . sync ( "*.html" , { cwd :"./docs/" , ignore : '(*_template).html' } ) ;
417+ var partials = glob . sync ( "*.html" , { cwd :C . DOCS , ignore : '(*_template).html' } ) ;
418418 var partialMap = { } ;
419419 partials . forEach ( function ( part ) {
420420 var name = part . replace ( '.html' , '' ) ;
421- var partialString = fs . readFileSync ( './docs/' + part ) . toString ( 'utf8' ) ;
421+ var partialString = fs . readFileSync ( j ( C . DOCS , part ) , 'utf8' ) ;
422422 partialMap [ name ] = hogan . compile ( partialString ) ;
423423 } ) ;
424424
425- var indexStream = gulp . src ( './docs/ index.html')
425+ var indexStream = gulp . src ( j ( C . DOCS , '/ index.html') )
426426 . pipe ( cache ( 'docs_dex' ) )
427427 . pipe ( through . obj ( function ( file , enc , cb ) {
428428 // TODO: Put this in a closure
@@ -435,15 +435,15 @@ gulp.task('docs:templates', function() {
435435 } ) )
436436 . pipe ( gulp . dest ( C . BUILD_DOCS ) ) ;
437437
438- var moduleStream = gulp . src ( j ( C . SRC , 'mm-* /doc.json') )
438+ var moduleStream = gulp . src ( j ( C . SRC , C . MODULE_MASK , ' /doc.json') )
439439 . pipe ( cache ( 'docs_module' ) )
440440 . pipe ( injectBehaviorDocs ( behaviorsMap ) )
441441 . pipe ( injectModuleData ( pkg , moduleMap , articleList , articleMap ) )
442442 . pipe ( dbg ( 'docs-modules' ) )
443443 . pipe ( through . obj ( function ( file , enc , cb ) {
444444 var moduleDoc = JSON . parse ( file . contents ) ;
445- var templatePath = path . join ( __dirname , 'docs /component_template.html') ;
446- var templateString = fs . readFileSync ( templatePath ) . toString ( 'utf8' ) ;
445+ var templatePath = j ( __dirname , C . DOCS , ' /component_template.html') ;
446+ var templateString = fs . readFileSync ( templatePath , 'utf8' ) ;
447447 var template = hogan . compile ( templateString ) ;
448448 var doc = template . render ( moduleDoc , partialMap ) ;
449449 file . contents = new Buffer ( doc , enc ) ;
@@ -458,7 +458,7 @@ gulp.task('docs:templates', function() {
458458 . pipe ( gulp . dest ( C . BUILD_DOCS ) )
459459 . on ( 'error' , console . log ) ;
460460
461- var articleStream = gulp . src ( './docs/ articles/*.md')
461+ var articleStream = gulp . src ( j ( C . DOCS , '/ articles/*.md') )
462462 . pipe ( cache ( 'docs_article' ) )
463463 . pipe ( marked ( ) . on ( 'error' , console . log ) )
464464 . pipe ( injectArticleData ( pkg , moduleMap , articleList , articleMap ) )
@@ -481,24 +481,25 @@ gulp.task('gh-pages', function() {
481481/** LIVE **/
482482
483483gulp . task ( 'watch' , function ( ) {
484- gulp . watch ( j ( C . SRC , 'mm-*/*.scss' ) , [ 'sass' ] ) ;
485- gulp . watch ( j ( C . SRC , 'mm-*/*.html' ) , [ 'copy' , 'vulcanize' ] ) ;
484+ gulp . watch ( j ( C . SRC , C . MODULE_MASK , '/*.scss' ) , [ 'sass' ] ) ;
485+ gulp . watch ( j ( C . SRC , C . MODULE_MASK , C . MODULE_HTML ) , [ 'copy' , 'vulcanize' ] ) ;
486+ gulp . watch ( j ( C . SRC , C . SHARED , '**' ) , [ 'copy' ] ) ;
486487} ) ;
487488
488489gulp . task ( 'index' , function ( ) {
489- var modules = glob . sync ( "mm-* /index.html", { cwd :C . SRC } ) ;
490+ var modules = glob . sync ( j ( C . MODULE_MASK , " /index.html") , { cwd :C . SRC } ) ;
490491 var moduleList = modules . map ( function ( name ) { return name . replace ( '/index.html' , '' ) ; } ) ;
491492 var moduleMap = { modules : moduleList } ;
492- var templatePath = path . join ( __dirname , 'gulp/templates /index_template.html') ;
493- var templateString = fs . readFileSync ( templatePath ) . toString ( 'utf8' ) ;
493+ var templatePath = j ( __dirname , C . TEMPLATES , ' /index_template.html') ;
494+ var templateString = fs . readFileSync ( templatePath , 'utf8' ) ;
494495 var template = hogan . compile ( templateString ) ;
495496 var index = template . render ( moduleMap ) ;
496497 fs . writeFileSync ( j ( C . BUILD , 'index.html' ) , index ) ;
497498} ) ;
498499
499500gulp . task ( 'server' , function ( ) {
500501 var server = connect ( )
501- . use ( '/bower_components' , serveStatic ( './bower_components' ) )
502+ . use ( '/bower_components' , serveStatic ( C . BOWER ) )
502503 . use ( serveStatic ( C . BUILD ) )
503504 . listen ( C . LIVE_PORT ) ;
504505
@@ -511,7 +512,7 @@ gulp.task('server', function() {
511512gulp . task ( 'live' , [ 'index' , 'watch' , 'server' ] ) ;
512513
513514gulp . task ( 'watch:docs' , function ( ) {
514- gulp . watch ( [ 'docs /**/*.md', C . SRC + '**/doc.json' ] , [ 'docs:templates' ] ) ;
515+ gulp . watch ( [ j ( C . DOCS , ' /**/*.md') , C . SRC + '**/doc.json' ] , [ 'docs:templates' ] ) ;
515516} ) ;
516517
517518gulp . task ( 'server:docs' , function ( ) {
0 commit comments