Skip to content
Permalink
Browse files

feat(option): add build option exclude.spa, defaults to false

  • Loading branch information
jyounce committed Sep 25, 2015
1 parent f27d57c commit 0f0df60c15b879ce704c4bc82bb1ae59ba3bd286
@@ -141,6 +141,7 @@ gulp rapid-build:test:prod
# minify.js.mangle = (boolean) defaults to true = for prod build, mangle the names in the js
# minify.spa.file = (boolean) defaults to true = for prod build, minify the spa.html file
# minify.cacheBust = (boolean) defaults to true = for prod build, ensures the user always receives the latest files, adds an md5 checksum to the client files before their extension
# exclude.spa = (boolean) defaults to false = set to true to exclude spa.html from client dist
# exclude.angular.files = (boolean) defaults to false = set to true to exclude the angular files that come with rapid-build from dist (lib and modules)
# exclude.angular.modules = (boolean) defaults to false = set to true to exclude injecting the angular modules that come with rapid-build ['ngResource', 'ngRoute', 'ngSanitize']
# exclude.from.cacheBust = (array of strings) = file paths: exclude files from the cache bust
@@ -21,6 +21,7 @@ module.exports = (config, options) ->
# init exclude
# ============
exclude =
spa: !!options.exclude.spa
angular:
files: get.opt.deep2 'angular', 'files', false
rb:
@@ -7,135 +7,136 @@ module.exports = (config, options) ->
# format options helpers
# ======================
buildOptions = ->
options.build = {} if not isType.object options.build
options.build.client = null if not isType.boolean options.build.client
options.build.server = null if not isType.boolean options.build.server
options.build = {} unless isType.object options.build
options.build.client = null unless isType.boolean options.build.client
options.build.server = null unless isType.boolean options.build.server

distAndSrcOptions = ->
['dist', 'src'].forEach (v1) ->
options[v1] = {} if not isType.object options[v1]
options[v1].dir = null if not isType.string options[v1].dir
options[v1] = {} unless isType.object options[v1]
options[v1].dir = null unless isType.string options[v1].dir
['client', 'server'].forEach (v2) ->
# dir
options[v1][v2] = {} if not isType.object options[v1][v2]
options[v1][v2].dir = null if not isType.string options[v1][v2].dir
options[v1][v2] = {} unless isType.object options[v1][v2]
options[v1][v2].dir = null unless isType.string options[v1][v2].dir
return if v2 is 'server'
# types dir
['bower', 'images', 'libs', 'scripts', 'styles', 'test', 'views'].forEach (v3) ->
options[v1][v2][v3] = {} if not isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null if not isType.string options[v1][v2][v3].dir
options[v1][v2][v3] = {} unless isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null unless isType.string options[v1][v2][v3].dir

portOptions = -> # server ports
options.ports = {} if not isType.object options.ports
options.ports.server = null if not isType.number options.ports.server
options.ports.reload = null if not isType.number options.ports.reload
options.ports.reloadUI = null if not isType.number options.ports.reloadUI
options.ports.test = null if not isType.number options.ports.test
options.ports = {} unless isType.object options.ports
options.ports.server = null unless isType.number options.ports.server
options.ports.reload = null unless isType.number options.ports.reload
options.ports.reloadUI = null unless isType.number options.ports.reloadUI
options.ports.test = null unless isType.number options.ports.test

orderOptions = ->
options.order = {} if not isType.object options.order
options.order.scripts = {} if not isType.object options.order.scripts
options.order.styles = {} if not isType.object options.order.styles
options.order.scripts.first = null if not isType.array options.order.scripts.first
options.order.scripts.last = null if not isType.array options.order.scripts.last
options.order.styles.first = null if not isType.array options.order.styles.first
options.order.styles.last = null if not isType.array options.order.styles.last
options.order = {} unless isType.object options.order
options.order.scripts = {} unless isType.object options.order.scripts
options.order.styles = {} unless isType.object options.order.styles
options.order.scripts.first = null unless isType.array options.order.scripts.first
options.order.scripts.last = null unless isType.array options.order.scripts.last
options.order.styles.first = null unless isType.array options.order.styles.first
options.order.styles.last = null unless isType.array options.order.styles.last

angularOptions = ->
options.angular = {} if not isType.object options.angular
options.angular.modules = null if not isType.array options.angular.modules
options.angular.version = null if not isType.string options.angular.version
options.angular.moduleName = null if not isType.string options.angular.moduleName
options.angular.ngFormify = null if not isType.boolean options.angular.ngFormify
options.angular.httpBackend = {} if not isType.object options.angular.httpBackend
options.angular.httpBackend.dev = null if not isType.boolean options.angular.httpBackend.dev
options.angular.httpBackend.prod = null if not isType.boolean options.angular.httpBackend.prod
options.angular.httpBackend.dir = null if not isType.string options.angular.httpBackend.dir
options.angular.templateCache = {} if not isType.object options.angular.templateCache
options.angular.templateCache.dev = null if not isType.boolean options.angular.templateCache.dev
options.angular.templateCache.urlPrefix = null if not isType.string options.angular.templateCache.urlPrefix
options.angular.templateCache.useAbsolutePaths = null if not isType.boolean options.angular.templateCache.useAbsolutePaths
options.angular = {} unless isType.object options.angular
options.angular.modules = null unless isType.array options.angular.modules
options.angular.version = null unless isType.string options.angular.version
options.angular.moduleName = null unless isType.string options.angular.moduleName
options.angular.ngFormify = null unless isType.boolean options.angular.ngFormify
options.angular.httpBackend = {} unless isType.object options.angular.httpBackend
options.angular.httpBackend.dev = null unless isType.boolean options.angular.httpBackend.dev
options.angular.httpBackend.prod = null unless isType.boolean options.angular.httpBackend.prod
options.angular.httpBackend.dir = null unless isType.string options.angular.httpBackend.dir
options.angular.templateCache = {} unless isType.object options.angular.templateCache
options.angular.templateCache.dev = null unless isType.boolean options.angular.templateCache.dev
options.angular.templateCache.urlPrefix = null unless isType.string options.angular.templateCache.urlPrefix
options.angular.templateCache.useAbsolutePaths = null unless isType.boolean options.angular.templateCache.useAbsolutePaths

spaOptions = ->
options.spa = {} if not isType.object options.spa
options.spa.title = null if not isType.string options.spa.title
options.spa.description = null if not isType.string options.spa.description
options.spa.src = {} if not isType.object options.spa.src
options.spa.src.filePath = null if not isType.string options.spa.src.filePath
options.spa.dist = {} if not isType.object options.spa.dist
options.spa.dist.fileName = null if not isType.string options.spa.dist.fileName
options.spa.placeholders = null if not isType.array options.spa.placeholders
options.spa = {} unless isType.object options.spa
options.spa.title = null unless isType.string options.spa.title
options.spa.description = null unless isType.string options.spa.description
options.spa.src = {} unless isType.object options.spa.src
options.spa.src.filePath = null unless isType.string options.spa.src.filePath
options.spa.dist = {} unless isType.object options.spa.dist
options.spa.dist.fileName = null unless isType.string options.spa.dist.fileName
options.spa.placeholders = null unless isType.array options.spa.placeholders

minifyOptions = ->
options.minify = {} if not isType.object options.minify
options.minify.css = {} if not isType.object options.minify.css
options.minify.html = {} if not isType.object options.minify.html
options.minify.js = {} if not isType.object options.minify.js
options.minify.spa = {} if not isType.object options.minify.spa
options.minify.cacheBust = null if not isType.boolean options.minify.cacheBust
options.minify.css.styles = null if not isType.boolean options.minify.css.styles
options.minify.css.splitMinFile = null if not isType.boolean options.minify.css.splitMinFile
options.minify.html.views = null if not isType.boolean options.minify.html.views
options.minify.html.templateCache = null if not isType.boolean options.minify.html.templateCache
options.minify.js.scripts = null if not isType.boolean options.minify.js.scripts
options.minify.js.mangle = null if not isType.boolean options.minify.js.mangle
options.minify.spa.file = null if not isType.boolean options.minify.spa.file
options.minify = {} unless isType.object options.minify
options.minify.css = {} unless isType.object options.minify.css
options.minify.html = {} unless isType.object options.minify.html
options.minify.js = {} unless isType.object options.minify.js
options.minify.spa = {} unless isType.object options.minify.spa
options.minify.cacheBust = null unless isType.boolean options.minify.cacheBust
options.minify.css.styles = null unless isType.boolean options.minify.css.styles
options.minify.css.splitMinFile = null unless isType.boolean options.minify.css.splitMinFile
options.minify.html.views = null unless isType.boolean options.minify.html.views
options.minify.html.templateCache = null unless isType.boolean options.minify.html.templateCache
options.minify.js.scripts = null unless isType.boolean options.minify.js.scripts
options.minify.js.mangle = null unless isType.boolean options.minify.js.mangle
options.minify.spa.file = null unless isType.boolean options.minify.spa.file

excludeOptions = ->
options.exclude = {} if not isType.object options.exclude
options.exclude.angular = {} if not isType.object options.exclude.angular
options.exclude.from = {} if not isType.object options.exclude.from
options.exclude.angular.files = null if not isType.boolean options.exclude.angular.files
options.exclude.angular.modules = null if not isType.boolean options.exclude.angular.modules
options.exclude.from.cacheBust = null if not isType.array options.exclude.from.cacheBust
options.exclude.from.minFile = {} if not isType.object options.exclude.from.minFile
options.exclude.from.spaFile = {} if not isType.object options.exclude.from.spaFile
options.exclude.from.dist = {} if not isType.object options.exclude.from.dist
options.exclude.from.minFile.scripts = null if not isType.array options.exclude.from.minFile.scripts
options.exclude.from.minFile.styles = null if not isType.array options.exclude.from.minFile.styles
options.exclude.from.spaFile.scripts = null if not isType.array options.exclude.from.spaFile.scripts
options.exclude.from.spaFile.styles = null if not isType.array options.exclude.from.spaFile.styles
options.exclude.from.dist.client = null if not isType.array options.exclude.from.dist.client
options.exclude.from.dist.server = null if not isType.array options.exclude.from.dist.server
options.exclude = {} unless isType.object options.exclude
options.exclude.angular = {} unless isType.object options.exclude.angular
options.exclude.from = {} unless isType.object options.exclude.from
options.exclude.spa = null unless isType.boolean options.exclude.spa
options.exclude.angular.files = null unless isType.boolean options.exclude.angular.files
options.exclude.angular.modules = null unless isType.boolean options.exclude.angular.modules
options.exclude.from.cacheBust = null unless isType.array options.exclude.from.cacheBust
options.exclude.from.minFile = {} unless isType.object options.exclude.from.minFile
options.exclude.from.spaFile = {} unless isType.object options.exclude.from.spaFile
options.exclude.from.dist = {} unless isType.object options.exclude.from.dist
options.exclude.from.minFile.scripts = null unless isType.array options.exclude.from.minFile.scripts
options.exclude.from.minFile.styles = null unless isType.array options.exclude.from.minFile.styles
options.exclude.from.spaFile.scripts = null unless isType.array options.exclude.from.spaFile.scripts
options.exclude.from.spaFile.styles = null unless isType.array options.exclude.from.spaFile.styles
options.exclude.from.dist.client = null unless isType.array options.exclude.from.dist.client
options.exclude.from.dist.server = null unless isType.array options.exclude.from.dist.server

testOptions = ->
options.test = {} if not isType.object options.test
options.test.browsers = null if not isType.array options.test.browsers
options.test = {} unless isType.object options.test
options.test.browsers = null unless isType.array options.test.browsers

serverDistOptions = -> # app server dist entry file
options.dist.server.fileName = null if not isType.string options.dist.server.fileName
options.dist.server.fileName = null unless isType.string options.dist.server.fileName

serverOptions = ->
options.server = {} if not isType.object options.server
options.server.node_modules = null if not isType.array options.server.node_modules
options.server = {} unless isType.object options.server
options.server.node_modules = null unless isType.array options.server.node_modules

proxyOptions = ->
options.httpProxy = null if not isType.array options.httpProxy
options.httpProxy = null unless isType.array options.httpProxy

extraCopy = ->
options.extra.copy.client = null if not isType.array options.extra.copy.client
options.extra.copy.server = null if not isType.array options.extra.copy.server
options.extra.copy.client = null unless isType.array options.extra.copy.client
options.extra.copy.server = null unless isType.array options.extra.copy.server

extraCompile = ->
options.extra.compile.client.coffee = null if not isType.array options.extra.compile.client.coffee
options.extra.compile.client.es6 = null if not isType.array options.extra.compile.client.es6
options.extra.compile.client.less = null if not isType.array options.extra.compile.client.less
options.extra.compile.client.sass = null if not isType.array options.extra.compile.client.sass
options.extra.compile.server.less = null if not isType.array options.extra.compile.server.less
options.extra.compile.server.sass = null if not isType.array options.extra.compile.server.sass
options.extra.compile.client.coffee = null unless isType.array options.extra.compile.client.coffee
options.extra.compile.client.es6 = null unless isType.array options.extra.compile.client.es6
options.extra.compile.client.less = null unless isType.array options.extra.compile.client.less
options.extra.compile.client.sass = null unless isType.array options.extra.compile.client.sass
options.extra.compile.server.less = null unless isType.array options.extra.compile.server.less
options.extra.compile.server.sass = null unless isType.array options.extra.compile.server.sass

extraOptions = ->
options.extra = {} if not isType.object options.extra
options.extra.copy = {} if not isType.object options.extra.copy
options.extra.compile = {} if not isType.object options.extra.compile
options.extra.compile.client = {} if not isType.object options.extra.compile.client
options.extra.compile.server = {} if not isType.object options.extra.compile.server
options.extra = {} unless isType.object options.extra
options.extra.copy = {} unless isType.object options.extra.copy
options.extra.compile = {} unless isType.object options.extra.compile
options.extra.compile.client = {} unless isType.object options.extra.compile.client
options.extra.compile.server = {} unless isType.object options.extra.compile.server
extraCopy()
extraCompile()

browserOptions = ->
options.browser = {} if not isType.object options.browser
options.browser.open = null if not isType.boolean options.browser.open
options.browser = {} unless isType.object options.browser
options.browser.open = null unless isType.boolean options.browser.open

# init
# ====
@@ -20,7 +20,9 @@ app.listen port, ->
console.log "#{config.server.msg.start} #{config.ports.server}"

app.get '/', (req, res) ->
return res.send 'Hello Server!' unless config.build.client
msg = 'Hello Server!'
return res.send msg unless config.build.client
return res.send msg if config.exclude.spa
res.sendFile spa, root: clientDirPath

# options to pass
@@ -80,9 +80,11 @@ module.exports = (gulp, config) ->
# ==============
gulp.task "#{config.rb.prefix.task}build-spa", ->
return promiseHelp.get() unless config.build.client
return promiseHelp.get() if config.exclude.spa
runTask getData 'files.json'

gulp.task "#{config.rb.prefix.task}build-spa:prod", ->
return promiseHelp.get() unless config.build.client
return promiseHelp.get() if config.exclude.spa
runTask getData 'prod-files.json'

@@ -19,6 +19,7 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}minify-spa", ->
return promiseHelp.get() if config.exclude.spa
return promiseHelp.get() if not config.minify.spa.file
runTask(
config.spa.dist.path
@@ -118,6 +118,7 @@ module.exports = (gulp, config, browserSync) ->
# ============================================
spaWatch = (spaFilePath) ->
return promiseHelp.get() unless config.spa.custom
return promiseHelp.get() if config.exclude.spa
createWatch spaFilePath, 'build spa', lang: config.spa.dist.file

# callbacks

0 comments on commit 0f0df60

Please sign in to comment.
You can’t perform that action at this time.