Skip to content

Commit

Permalink
feat(options): change option spa.exclude value to be an array of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jyounce committed Jun 17, 2015
1 parent 99564c2 commit 171426f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ gulp rapid-build:prod
# spa.src.file = (string) defaults to 'spa.html' = set if you want to use your own spa file and not the build system's (file must be located in your client src directory)
# spa.src.dir = (string) defaults to null = set if you are using your own spa file and that file is located in a directory in your client src directory
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html' = provide if you want the dist spa file to be named differently, example: 'index.html'
# spa.exclude.styles = (boolean) defaults to false = set to true to exclude styles from the spa file
# spa.exclude.scripts = (boolean) defaults to false = set to true to exclude scripts from the spa file
# ==============================================================================================================================================================================================================
# spa.exclude = (array of strings) = set to retain spa file placeholders, optional values are: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# ==========================================================================================================================================================================================================
```

## Build Modes
Expand Down
15 changes: 3 additions & 12 deletions config/config-options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
# spa.src.file = (string) defaults to 'spa.html'
# spa.src.dir = (string) defaults to null
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html'
# spa.exclude.styles = (boolean) defaults to false
# spa.exclude.scripts = (boolean) defaults to false
# spa.exclude.title = (boolean) defaults to false
# spa.exclude.moduleName = (boolean) defaults to false
# spa.exclude.description = (boolean) defaults to false
# ===============================================================================================================================
# spa.exclude = (array of strings) = optionals: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# =====================================================================================================================================================
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
Expand Down Expand Up @@ -87,15 +83,10 @@ module.exports = (config, options) ->
options.spa.description = null if not isType.string options.spa.description
options.spa.src = {} if not isType.object options.spa.src
options.spa.dist = {} if not isType.object options.spa.dist
options.spa.exclude = {} if not isType.object options.spa.exclude
options.spa.exclude = null if not isType.array options.spa.exclude
options.spa.src.dir = null if not isType.string options.spa.src.dir
options.spa.src.file = null if not isType.string options.spa.src.file
options.spa.dist.file = null if not isType.string options.spa.dist.file
options.spa.exclude.styles = null if not isType.boolean options.spa.exclude.styles
options.spa.exclude.scripts = null if not isType.boolean options.spa.exclude.scripts
options.spa.exclude.title = null if not isType.boolean options.spa.exclude.title
options.spa.exclude.moduleName = null if not isType.boolean options.spa.exclude.moduleName
options.spa.exclude.description = null if not isType.boolean options.spa.exclude.description

distAndSrcOptions()
serverOptions()
Expand Down
7 changes: 1 addition & 6 deletions config/config-spa.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ module.exports = (config, options) ->

# exclude
# =======
spa.exclude =
styles: options.spa.exclude.styles or false
scripts: options.spa.exclude.scripts or false
title: options.spa.exclude.title or false
moduleName: options.spa.exclude.moduleName or false
description: options.spa.exclude.description or false
spa.exclude = options.spa.exclude or []

# add spa to config
# =================
Expand Down
19 changes: 12 additions & 7 deletions tasks/build/build-spa.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ module.exports = (gulp, config) ->
# helpers
# =======
runReplace = (type) ->
newKey = "<%= #{type} %>"
key = "<!--#include #{type}-->"
exclude = config.spa.exclude[type]
gulpif not exclude, replace key, newKey
newKey = "<%= #{type} %>"
key = "<!--#include #{type}-->"
exclude = config.spa.exclude
replacePH = true # PH = placeholder
if exclude.indexOf('all') isnt -1
replacePH = false
else if exclude.indexOf(type) isnt -1
replacePH = false
gulpif replacePH, replace key, newKey

# task
# ====
runTask = (src, dest, file, data={}) ->
defer = q.defer()
gulp.src src
.pipe rename file
.pipe runReplace 'styles'
.pipe runReplace 'scripts'
.pipe runReplace 'description'
.pipe runReplace 'moduleName'
.pipe runReplace 'scripts'
.pipe runReplace 'styles'
.pipe runReplace 'title'
.pipe runReplace 'description'
.pipe template data
.pipe gulp.dest dest
.on 'end', ->
Expand Down

0 comments on commit 171426f

Please sign in to comment.