Skip to content
Permalink
Browse files

perf(tasks): lazy load build tasks

  • Loading branch information
jyounce committed Oct 7, 2015
1 parent 96f9b9c commit 18c9e578fef7062edcf58b7d4be4e63146353e23
Showing with 1,524 additions and 1,344 deletions.
  1. +1 −1 config/config-angular.coffee
  2. +5 −5 config/config-exclude.coffee
  3. +10 −10 config/config-globs.coffee
  4. +1 −1 config/config-internal.coffee
  5. +3 −3 config/config-order.coffee
  6. +1 −1 config/config-spa.coffee
  7. +1 −1 gulpfile.coffee
  8. +3 −3 helpers/Less.coffee
  9. +3 −3 helpers/Sass.coffee
  10. +13 −13 helpers/bower.coffee
  11. +8 −8 helpers/dir.coffee
  12. +4 −1 helpers/isType.coffee
  13. +3 −3 helpers/path.coffee
  14. +1 −1 helpers/promise.coffee
  15. +38 −11 helpers/tasks.coffee
  16. +1 −1 init/rapid.coffee
  17. +84 −73 init/tasks.coffee
  18. +1 −1 package.json
  19. +3 −3 plugins/gulp-absolute-css-urls.coffee
  20. +2 −2 src/server/http-proxy.coffee
  21. +61 −29 tasks/browser/browser-sync.coffee
  22. +12 −10 tasks/browser/open-browser.coffee
  23. +23 −24 tasks/build/build-angular-modules.coffee
  24. +23 −24 tasks/build/build-bower-json.coffee
  25. +9 −11 tasks/build/build-config.coffee
  26. +22 −26 tasks/build/build-files.coffee
  27. +30 −30 tasks/build/build-prod-files-blueprint.coffee
  28. +27 −27 tasks/build/build-prod-files.coffee
  29. +24 −25 tasks/build/build-spa.coffee
  30. +13 −12 tasks/clean/clean-config.coffee
  31. +20 −16 tasks/clean/clean-dist.coffee
  32. +13 −11 tasks/clean/clean-files.coffee
  33. +20 −20 tasks/clean/cleanup-client.coffee
  34. +35 −30 tasks/common/common-client.coffee
  35. +24 −19 tasks/common/common-server.coffee
  36. +22 −17 tasks/common/common-test-client.coffee
  37. +15 −10 tasks/common/common-test-server.coffee
  38. +18 −13 tasks/common/common.coffee
  39. +14 −20 tasks/compile/coffee.coffee
  40. +14 −20 tasks/compile/es6.coffee
  41. +23 −23 tasks/compile/less.coffee
  42. +21 −23 tasks/compile/sass.coffee
  43. +13 −5 tasks/config/set-env-config.coffee
  44. +15 −13 tasks/config/update-angular-mocks-config.coffee
  45. +16 −14 tasks/copy/copy-bower_components.coffee
  46. +20 −22 tasks/copy/copy-css.coffee
  47. +14 −16 tasks/copy/copy-html.coffee
  48. +14 −16 tasks/copy/copy-images.coffee
  49. +14 −20 tasks/copy/copy-js.coffee
  50. +22 −20 tasks/copy/copy-libs.coffee
  51. +17 −16 tasks/copy/copy-server-config.coffee
  52. +19 −17 tasks/copy/copy-server-node_modules.coffee
  53. +15 −11 tasks/copy/copy-views.coffee
  54. +9 −7 tasks/extra/compile-extra-coffee.coffee
  55. +9 −7 tasks/extra/compile-extra-es6.coffee
  56. +9 −10 tasks/extra/compile-extra-less.coffee
  57. +9 −10 tasks/extra/compile-extra-sass.coffee
  58. +9 −10 tasks/extra/copy-extra-files.coffee
  59. +31 −28 tasks/format/absolute-css-urls.coffee
  60. +14 −16 tasks/manage/bower.coffee
  61. +25 −23 tasks/minify/cache-bust.coffee
  62. +16 −16 tasks/minify/concat-scripts-and-styles.coffee
  63. +18 −12 tasks/minify/css-file-split.coffee
  64. +32 −30 tasks/minify/inline-css-imports.coffee
  65. +28 −23 tasks/minify/minify-client.coffee
  66. +15 −13 tasks/minify/minify-css.coffee
  67. +16 −14 tasks/minify/minify-html.coffee
  68. +19 −11 tasks/minify/minify-images.coffee
  69. +14 −12 tasks/minify/minify-js.coffee
  70. +19 −16 tasks/minify/minify-server.coffee
  71. +17 −11 tasks/minify/minify-spa.coffee
  72. +14 −12 tasks/minify/template-cache.coffee
  73. +16 −15 tasks/server/find-open-port.coffee
  74. +21 −14 tasks/server/nodemon.coffee
  75. +13 −9 tasks/server/spawn-server.coffee
  76. +15 −15 tasks/server/start-server.coffee
  77. +14 −9 tasks/server/stop-server.coffee
  78. +22 −21 tasks/test/client/build-client-test-files.coffee
  79. +15 −12 tasks/test/client/build-inject-angular-mocks.coffee
  80. +15 −14 tasks/test/client/clean-client-test-dist.coffee
  81. +14 −12 tasks/test/client/clean-rb-client-test-src.coffee
  82. +13 −11 tasks/test/client/copy-angular-mocks.coffee
  83. +29 −28 tasks/test/client/copy-client-tests.coffee
  84. +12 −13 tasks/test/client/run-client-tests.coffee
  85. +14 −12 tasks/test/server/clean-server-test-dist.coffee
  86. +30 −29 tasks/test/server/copy-server-tests.coffee
  87. +15 −17 tasks/test/server/run-server-tests.coffee
  88. +14 −9 tasks/watch/watch-build-spa.coffee
  89. +81 −68 tasks/watch/watch.coffee
@@ -63,7 +63,7 @@ module.exports = (config, options) ->

angular.removeRbMocksModule = ->
if config.env.is.prod
removeRbMocksModule() if not angular.httpBackend.prod
removeRbMocksModule() unless angular.httpBackend.prod
else if not angular.httpBackend.dev
removeRbMocksModule()

@@ -101,18 +101,18 @@ module.exports = (config, options) ->

getExcludeFromDist = (appOrRb, loc) -> # prepend src path to values then prepend '!'
paths = exclude[appOrRb].from.dist[loc]
return [] if not paths.length
return [] unless paths.length
types = getExcludeFromDirTypes appOrRb, loc
srcPath = config.src[appOrRb][loc].dir
paths = (path.join srcPath, _path for _path in paths)
eTypes = {}
for _path in paths
type = getExcludeFromDistType types, appOrRb, loc, _path
continue if not type
eTypes[type.type] = {} if not eTypes[type.type]
eTypes[type.type][type.lang] = [] if not eTypes[type.type][type.lang]
continue unless type
eTypes[type.type] = {} unless eTypes[type.type]
eTypes[type.type][type.lang] = [] unless eTypes[type.type][type.lang]
eTypes[type.type][type.lang].push type.path
return [] if not Object.keys(eTypes).length
return [] unless Object.keys(eTypes).length
eTypes

exclude.rb.from.dist.client = getExcludeFromDist 'rb', 'client'
@@ -60,7 +60,7 @@ module.exports = (config) ->
for own k2, v2 of v1
continue if k2 is 'server' and ['scripts','test'].indexOf(type) is -1
continue if k2 is 'server' and (includeBower or includeLibs)
v2[type] = {} if not isType.object v2[type]
v2[type] = {} unless isType.object v2[type]
for v3 in langs
continue if k2 is 'server' and type is 'test' and v3 is 'css'
typeDir = pathHelp.format config[loc][k1][k2][type].dir
@@ -160,7 +160,7 @@ module.exports = (config) ->

glob.removeRbAngularMocks = ->
if config.env.is.prod
removeRbAngularMocks() if not config.angular.httpBackend.prod
removeRbAngularMocks() unless config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
removeRbAngularMocks()

@@ -173,12 +173,12 @@ module.exports = (config) ->
v1[i] += ".#{ext}"

addFirst = (appOrRb, type, array, ext) ->
return if not array.length
return unless array.length
array.slice().reverse().forEach (v) ->
glob.dist[appOrRb].client[type][ext].unshift v

addLast = (appOrRb, type, array, ext) ->
return if not array.length
return unless array.length
array.forEach (v) ->
glob.dist[appOrRb].client[type][ext].push "!#{v}", v

@@ -187,7 +187,7 @@ module.exports = (config) ->
for own k2, v2 of v1
tot = config.order[k1][k2].first.length +
config.order[k1][k2].last.length
continue if not tot
continue unless tot
ext = 'js' if k2 is 'scripts'
ext = 'css' if k2 is 'styles'
addDistDir k1, v2, ext
@@ -201,16 +201,16 @@ module.exports = (config) ->
addExcludeFromDist = (loc) ->
for appOrRb in ['app','rb']
excludes = config.exclude[appOrRb].from.dist[loc]
continue if not Object.keys(excludes).length
continue unless Object.keys(excludes).length
for own k1, v1 of glob.src[appOrRb][loc]
continue if k1 is 'all'
for own k2, v2 of v1
continue if not v2.length
continue if not excludes[k1]
continue unless v2.length
continue unless excludes[k1]
ePaths = excludes[k1]['all']
ePaths = if ePaths then ePaths else excludes[k1][k2]
continue if not ePaths
continue if not ePaths.length
continue unless ePaths
continue unless ePaths.length
glob.src[appOrRb][loc][k1][k2] = v2.concat ePaths

addExcludeFromDist 'client'
@@ -35,7 +35,7 @@ module.exports = (config) ->
_imports = []
negated = if negated then '!' else ''
for own k1, v1 of imports
continue if not v1.length
continue unless v1.length
for v2 in v1
_imports.push "#{negated}#{v2}"
_imports
@@ -56,7 +56,7 @@ module.exports = (config, options) ->
# rb order
# ========
files = []
files = files.concat rb.files.angular if not config.exclude.angular.files
files = files.concat rb.files.angular unless config.exclude.angular.files
order.rb.scripts.first = files.concat rb.files.rb

# methods
@@ -66,7 +66,7 @@ module.exports = (config, options) ->

order.removeRbAngularMocks = ->
if config.env.is.prod
removeRbAngularMocks() if not config.angular.httpBackend.prod
removeRbAngularMocks() unless config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
removeRbAngularMocks()

@@ -76,7 +76,7 @@ module.exports = (config, options) ->
for own k1, v1 of order
for own k2, v2 of v1
for own k3, v3 of v2
continue if not v3.length
continue unless v3.length
v3.forEach (v4, i) ->
ext = path.extname v4
v3[i] = v3[i].replace ext, '' if ext isnt '.min'
@@ -10,7 +10,7 @@ module.exports = (config, options) ->
getSrcFilePath = (_isCustom, _path) ->
rbDir = config.src.rb.client.dir
appDir = config.src.app.client.dir
return path.join rbDir, 'spa.html' if not _isCustom
return path.join rbDir, 'spa.html' unless _isCustom
_path = pathHelp.format _path
_path = "/#{_path}" if _path[0] isnt '/'
_path = path.join appDir, _path
@@ -5,7 +5,7 @@ module.exports = (gulp, options={}) ->
# if gulp isn't supplied, load it from rapid-build's node_modules
# ===============================================================
rbDir = __dirname
gulp = require 'gulp' if not gulp
gulp = require 'gulp' unless gulp
bootstrap = require("#{rbDir}/bootstrap")()
config = require("#{rbDir}/config") rbDir, options
tasks = require("#{config.req.init}/tasks") gulp, config
@@ -12,7 +12,7 @@ module.exports = (config, gulp) ->
getImports = (files) ->
imports = {}
for own k1, v1 of files
continue if not v1.length
continue unless v1.length
v1.forEach (v2, i) ->
imports[v2] = i
Object.keys imports
@@ -53,7 +53,7 @@ module.exports = (config, gulp) ->
# ==============
addImport: (file) ->
paths = findImports file
return @ if not paths.length
return @ unless paths.length
@files[file.path] = paths
@

@@ -78,7 +78,7 @@ module.exports = (config, gulp) ->
getWatchSrc: (_path) ->
files = @getFiles()
imports = getImports files
return [ _path ] if not isImport imports, _path
return [ _path ] unless isImport imports, _path
# is import, what non import(s) has it?
src = []
for own k1, v1 of files
@@ -12,7 +12,7 @@ module.exports = (config, gulp) ->
getImports = (files) ->
imports = {}
for own k1, v1 of files
continue if not v1.length
continue unless v1.length
v1.forEach (v2, i) ->
imports[v2] = i
Object.keys imports
@@ -68,7 +68,7 @@ module.exports = (config, gulp) ->
# ==============
addImport: (file) ->
paths = findImports file
return @ if not paths.length
return @ unless paths.length
@files[file.path] = paths
@

@@ -93,7 +93,7 @@ module.exports = (config, gulp) ->
getWatchSrc: (_path) ->
files = @getFiles()
imports = getImports files
return [ _path ] if not isImport imports, _path
return [ _path ] unless isImport imports, _path
# is import, what non import(s) has it?
src = []
for own _file, fileImports of files
@@ -65,9 +65,9 @@ module.exports = (config) ->
_files

getPkgDeps: (deps) ->
return null if not deps
return null if not isType.object deps
return null if not Object.keys(deps).length
return null unless deps
return null unless isType.object deps
return null unless Object.keys(deps).length
deps

getPkg: (pkg, loc='rb') ->
@@ -82,19 +82,19 @@ module.exports = (config) ->
deps: pkgDeps

getSubPkgs: (pkgs) ->
return null if not pkgs.length
return null unless pkgs.length
# log.json pkgs
rbPkgs = if me.has.bower 'rb' then me.get.pkgs.from.appOrRb 'rb' else {}
appPkgs = if me.has.bower 'app' then me.get.pkgs.from.appOrRb 'app' else {}
allPkgs = Object.keys(rbPkgs).concat Object.keys appPkgs
return null if not allPkgs.length
return null unless allPkgs.length
subPkgs = {}
for own i, pkg of pkgs
continue if not pkg.deps
continue unless pkg.deps
for own name, version of pkg.deps
continue if allPkgs.indexOf(name) isnt -1
subPkgs[name] = version
return null if not Object.keys(subPkgs).length
return null unless Object.keys(subPkgs).length
# log.json subPkgs
subPkgs

@@ -155,7 +155,7 @@ module.exports = (config) ->
removeRbAngularMocks: (loc, paths) ->
return if loc isnt 'rb'
if config.env.is.prod
@_removeRbAngularMocks paths if not config.angular.httpBackend.prod
@_removeRbAngularMocks paths unless config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
@_removeRbAngularMocks paths

@@ -179,7 +179,7 @@ module.exports = (config) ->
require config.bower[loc].path

pkg: (pkg, loc='rb') ->
return if not me.has.installed.pkg pkg, loc
return unless me.has.installed.pkg pkg, loc
# console.log pkg, loc
require(
path.join(
@@ -196,8 +196,8 @@ module.exports = (config) ->
mainDeps
to:
install: (loc='rb', force=false) ->
return if not me.has.bower loc
force = helper.forceInstall loc if not force
return unless me.has.bower loc
force = helper.forceInstall loc unless force
pkgs = []
pkgsObj = me.get.pkgs.from.appOrRb loc
if force
@@ -214,7 +214,7 @@ module.exports = (config) ->
installed:
pkg: (pkg, loc='rb') ->
pkg = me.get.json.from.pkg pkg, loc
return if not pkg
return unless pkg
# log.json pkg
helper.getPkg pkg, loc

@@ -245,7 +245,7 @@ module.exports = (config) ->
pkgs

src: (loc='rb', opts={}) ->
return if not me.has.bower loc
return unless me.has.bower loc
env = opts.env
env = 'prod' if not env and config.env.is.prod
env = 'dev' if ['dev','prod'].indexOf(env) is -1
@@ -12,10 +12,10 @@ module.exports = (config, gulp) ->
catch e
console.log e.message.error
return _dirs
return _dirs if not filenames.length
return _dirs unless filenames.length
for filePath in filenames
newPath = path.join _path, filePath
continue if not fs.statSync(newPath).isDirectory()
continue unless fs.statSync(newPath).isDirectory()
_dirs.push newPath
getDirsRecursively newPath, _dirs
_dirs
@@ -26,7 +26,7 @@ module.exports = (config, gulp) ->
flag = false
for fPath in filterPaths
if _path.indexOf(fPath) isnt -1 then flag = true; break
_dirs.push _path if not flag
_dirs.push _path unless flag
_dirs

# API
@@ -44,27 +44,27 @@ module.exports = (config, gulp) ->

emptyDirs: (initPath, filterPaths=[], reverse) ->
dirs = @dirs initPath, filterPaths, reverse
return dirs if not dirs.length
return dirs unless dirs.length
_dirs = []
fileDirs = {}

for _path in dirs
filenames = fs.readdirSync _path
for filePath, i in filenames
newPath = path.join _path, filePath
continue if not fs.statSync(newPath).isFile()
continue unless fs.statSync(newPath).isFile()
fileDirs[_path] = i + 1 # total files

return dirs if not Object.keys(fileDirs).length
return dirs unless Object.keys(fileDirs).length

for _path in dirs
flag = false
for own k, v of fileDirs
if k.indexOf(_path) isnt -1 then flag = true; break
_dirs.push _path if not flag
_dirs.push _path unless flag

_dirs

# returns promise with hasFiles boolean value
hasFiles: (src) ->
defer = q.defer()
@@ -5,8 +5,11 @@ module.exports =
boolean: (v) ->
typeof v is 'boolean'

function: (v) ->
typeof v is 'function'

int: (v) ->
return false if not @number v
return false unless @number v
v % 1 is 0

null: (v) ->
@@ -6,7 +6,7 @@ module.exports =
path.indexOf(':\\') isnt -1

removeDrive: (path) ->
return path if not @isWinAbs path
return path unless @isWinAbs path
i = path.indexOf(':\\') + 1
path = path.substr i

@@ -15,7 +15,7 @@ module.exports =
path.replace regx, '/'

format: (path) ->
return path if not @isWin path
return path unless @isWin path
path = @removeDrive path
path = @swapBackslashes path
path
@@ -26,7 +26,7 @@ module.exports =
removeLocPartial: (locPaths, partial) ->
paths = {}
partial = @format partial
partial += '/' if not @hasTrailingSlash partial
partial += '/' unless @hasTrailingSlash partial
for own k, v of locPaths
paths[k] = []
v.forEach (path, i) ->
@@ -1,5 +1,5 @@
module.exports =
get: (defer) ->
defer = require('q').defer() if not defer
defer = require('q').defer() unless defer
defer.resolve()
defer.promise

0 comments on commit 18c9e57

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