Skip to content
Permalink
Browse files

fix(spa options): replace spa.src.file and dir with filePath and chan…

…ge spa.dist.file to fileName
  • Loading branch information
jyounce committed Jul 22, 2015
1 parent 24d8c9e commit 40cfee2d78dcc4a47ee0bef3a93b9bc05eaa4fdb
Showing with 35 additions and 57 deletions.
  1. +2 −3 README.md
  2. +7 −8 config/config-options.coffee
  3. +25 −30 config/config-spa.coffee
  4. +0 −15 tasks/build/build-spa.coffee
  5. +1 −1 tasks/watch/watch.coffee
@@ -126,9 +126,8 @@ gulp rapid-build:test:prod
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false = prefix template urls with a '/'
# spa.title = (string) defaults to package.json name or 'Application' = html title tag value
# spa.description = (string) defaults to package.json description = html meta description tag value
# 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.src.filePath = (string) 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.dist.fileName = (string) defaults to file name of spa.src.filePath or 'spa.html' = provide if you want the dist spa file to be named differently, example: 'index.html'
# spa.placeholders = (array of strings) = set to retain spa file placeholders, optional values are: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# minify.css.styles = (boolean) defaults to true = for prod build, minify the css
# minify.css.splitMinFile = (boolean) defaults to true = for prod build, task for ie9 and below, split styles.min.css into multiple files if selector count > 4,095
@@ -53,14 +53,13 @@ module.exports = (config, options) ->

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.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 = {} if not isType.object options.spa.dist
options.spa.dist.file = null if not isType.string options.spa.dist.file
options.spa.placeholders = null if not isType.array options.spa.placeholders
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

minifyOptions = ->
options.minify = {} if not isType.object options.minify
@@ -1,58 +1,53 @@
module.exports = (config, options) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()
pkg = require "#{config.req.app}/package.json"
path = require 'path'
log = require "#{config.req.helpers}/log"
pkg = require "#{config.req.app}/package.json"
pathHelp = require "#{config.req.helpers}/path"
test = require("#{config.req.helpers}/test")()

# helpers
# =======
getSrcDir = (_custom, dir) ->
getSrcFilePath = (_isCustom, _path) ->
rbDir = config.src.rb.client.dir
appDir = config.src.app.client.dir
return rbDir if not _custom
return appDir if not dir
# to keep windows happy
dir = dir.split path.sep
for own k, v of dir
continue if not v
appDir = path.join appDir, v
appDir
return path.join rbDir, 'spa.html' if not _isCustom
_path = pathHelp.format _path
_path = "/#{_path}" if _path[0] isnt '/'
_path = path.join appDir, _path
_path

# defaults
# ========
custom = !!options.spa.src.file
srcFile = options.spa.src.file or 'spa.html'
distFile = options.spa.dist.file or srcFile
srcDir = getSrcDir custom, options.spa.src.dir
if custom
distDir = options.spa.src.dir or ''
customDistDir = path.join(
config.dist.app.client.dir
distDir
)
customDistPath = path.join customDistDir, srcFile
customSrcPath = options.spa.src.filePath
isCustom = !!customSrcPath
srcFilePath = getSrcFilePath isCustom, customSrcPath
srcFile = path.basename srcFilePath
srcDir = path.dirname srcFilePath
distFile = options.spa.dist.fileName or srcFile
distFilePath = path.join config.dist.app.client.dir, distFile

# init spa
# ========
spa = {}
spa.custom = custom
spa.custom = isCustom

# placeholders
# ============
spa.title = options.spa.title or pkg.name or 'Application'
spa.description = options.spa.description or pkg.description or null

# dist
# ====
spa.dist =
file: distFile
path: path.join config.dist.app.client.dir, distFile
custom:
dir: customDistDir or null
path: customDistPath or null
path: distFilePath

# src
# ===
spa.src =
file: srcFile
path: path.join srcDir, srcFile
dir: srcDir
path: srcFilePath

# placeholders
# ============
@@ -43,20 +43,6 @@ module.exports = (gulp, config) ->
defer.resolve()
defer.promise

delCustomSpaTask = ->
return promiseHelp.get() unless config.spa.custom
defer = q.defer()
src = config.spa.dist.custom.path
del src, force:true, (e) ->
emptyDirs = dirHelper.get.emptyDirs(
config.dist.app.client.dir
[], 'reverse'
)
return defer.resolve() unless emptyDirs.length
del emptyDirs, force:true, (e) ->
defer.resolve()
defer.promise

# helpers
# =======
getFilesJson = (jsonEnvFile) ->
@@ -88,7 +74,6 @@ module.exports = (gulp, config) ->
config.spa.dist.file
data
)
# -> delCustomSpaTask()
]
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise
@@ -134,7 +134,7 @@ module.exports = (gulp, config, browserSync) ->
# ============================================
spaWatch = ->
if config.spa.custom
return createWatch config.spa.src.path, 'build spa', lang:config.spa.dist.file
return createWatch config.spa.src.path, 'build spa', lang: config.spa.dist.file
promiseHelp.get()

# register task

0 comments on commit 40cfee2

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