Skip to content
Permalink
Browse files

feat(option): add build option build[client|server] both default to true

  • Loading branch information
jyounce committed Sep 24, 2015
1 parent a4108d9 commit 8af0923e6a48e480854af698290dc7354fb7f461
Showing with 199 additions and 78 deletions.
  1. +1 −0 README.md
  2. +1 −0 config.coffee
  3. +43 −0 config/config-build.coffee
  4. +7 −1 config/config-options.coffee
  5. +6 −6 helpers/extra.coffee
  6. +1 −0 src/server/server.coffee
  7. +2 −0 tasks/browser/browser-sync.coffee
  8. +4 −2 tasks/browser/open-browser.coffee
  9. +5 −3 tasks/build/build-angular-modules.coffee
  10. +12 −10 tasks/build/build-files.coffee
  11. +2 −0 tasks/build/build-spa.coffee
  12. +2 −1 tasks/compile/coffee.coffee
  13. +2 −1 tasks/compile/es6.coffee
  14. +4 −1 tasks/compile/less.coffee
  15. +4 −1 tasks/compile/sass.coffee
  16. +4 −0 tasks/config/update-config.coffee
  17. +1 −0 tasks/copy/copy-bower_components.coffee
  18. +4 −1 tasks/copy/copy-css.coffee
  19. +5 −2 tasks/copy/copy-html.coffee
  20. +4 −1 tasks/copy/copy-images.coffee
  21. +2 −1 tasks/copy/copy-js.coffee
  22. +3 −1 tasks/copy/copy-libs.coffee
  23. +3 −1 tasks/copy/copy-server-config.coffee
  24. +3 −1 tasks/copy/copy-server-node_modules.coffee
  25. +7 −5 tasks/extra/compile-extra-coffee.coffee
  26. +7 −5 tasks/extra/compile-extra-es6.coffee
  27. +2 −1 tasks/extra/compile-extra-less.coffee
  28. +2 −1 tasks/extra/compile-extra-sass.coffee
  29. +2 −1 tasks/extra/copy-extra-files.coffee
  30. +1 −0 tasks/format/absolute-css-urls.coffee
  31. +1 −0 tasks/manage/bower.coffee
  32. +2 −0 tasks/minify/minify-client.coffee
  33. +5 −3 tasks/minify/minify-server.coffee
  34. +4 −1 tasks/minify/template-cache.coffee
  35. +5 −3 tasks/server/nodemon.coffee
  36. +2 −0 tasks/server/spawn-server.coffee
  37. +5 −3 tasks/test/clean-test-dist.coffee
  38. +2 −0 tasks/test/common-test.coffee
  39. +27 −21 tasks/watch/watch.coffee
@@ -99,6 +99,7 @@ gulp rapid-build:test:prod
# Example: options.ports.server = 5000
# Options is an object, you can set the following properties:
# -----------------------------------------------------------
# build[client|server] = (boolean) both default to true = atleast one is required to be true
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|scripts|styles|test|views].dir = (string) defaults to property name
@@ -13,6 +13,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-env") config
config = require("#{config.req.config}/config-rb") config, rbDir
config = require("#{config.req.config}/config-app") config, options
config = require("#{config.req.config}/config-build") config, options
config = require("#{config.req.config}/config-ports") config, options
config = require("#{config.req.config}/config-server") config
config = require("#{config.req.config}/config-file-names") config
@@ -0,0 +1,43 @@
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init build
# ==========
build = {}
build.client = if options.build.client is false then false else true
build.server = if options.build.server is false then false else true

# build check
# ===========
unless build.client or build.server
process.on 'exit', ->
msg = 'Atleast one build, client or server must be enabled.'
console.error msg.error
.exit 1

# methods
# =======
build.getLocs = ->
locs = []
locs.push 'client' if build.client
locs.push 'server' if build.server
locs

# add build to config
# ===================
config.build = build

# logs
# ====
# log.json build, 'build ='

# tests
# =====
test.log 'true', config.build, 'add build to config'

# return
# ======
config


@@ -6,6 +6,11 @@ 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

distAndSrcOptions = ->
['dist', 'src'].forEach (v1) ->
options[v1] = {} if not isType.object options[v1]
@@ -130,7 +135,8 @@ module.exports = (config, options) ->

# init
# ====
distAndSrcOptions() # must be first
buildOptions()
distAndSrcOptions() # must be 2nd
portOptions()
orderOptions()
angularOptions()
@@ -4,11 +4,11 @@ module.exports = (config) ->

# private
# =======
getTasks = (tasksCb, srcBase, srcTask) ->
getTasks = (tasksCb, srcBase, srcTask, locs) ->
args = []
tasks = []
for appOrRb in ['rb','app']
for loc in ['client','server']
for loc in locs
src = srcBase[appOrRb][loc]
src = src[srcTask] if srcTask
_args = {
@@ -30,17 +30,17 @@ module.exports = (config) ->
# ======
run:
tasks:
async: (tasksCb, task, subTask) ->
async: (tasksCb, task, subTask, locs) ->
defer = q.defer()
tasks = getTasks tasksCb, config.extra[task], subTask
tasks = getTasks tasksCb, config.extra[task], subTask, locs
return promiseHelp.get defer unless tasks.length
promises = tasks.map (_task) -> _task()
q.all(promises).done -> defer.resolve()
defer.promise

sync: (tasksCb, task, subTask) ->
sync: (tasksCb, task, subTask, locs) ->
defer = q.defer()
tasks = getTasks tasksCb, config.extra[task], subTask
tasks = getTasks tasksCb, config.extra[task], subTask, locs
return promiseHelp.get defer unless tasks.length
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise
@@ -20,6 +20,7 @@ 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
res.sendFile spa, root: clientDirPath

# options to pass
@@ -1,6 +1,7 @@
module.exports = (gulp, config) ->
q = require 'q'
browserSync = require 'browser-sync'
promiseHelp = require "#{config.req.helpers}/promise"
bs = browserSync.create()

# helpers
@@ -24,6 +25,7 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}browser-sync", ->
return promiseHelp.get() unless config.build.server
defer = q.defer()
bsConfig = getBsConfig()
bs.init bsConfig, ->
@@ -1,6 +1,7 @@
module.exports = (gulp, config) ->
q = require 'q'
open = require 'open'
q = require 'q'
open = require 'open'
promiseHelp = require "#{config.req.helpers}/promise"

runTask = (port) ->
defer = q.defer()
@@ -9,4 +10,5 @@ module.exports = (gulp, config) ->
defer.promise

gulp.task "#{config.rb.prefix.task}open-browser", ->
return promiseHelp.get() unless config.build.server
runTask config.ports.server
@@ -1,7 +1,8 @@
module.exports = (gulp, config) ->
q = require 'q'
rename = require 'gulp-rename'
template = require 'gulp-template'
q = require 'q'
rename = require 'gulp-rename'
template = require 'gulp-template'
promiseHelp = require "#{config.req.helpers}/promise"

# task
# ====
@@ -26,6 +27,7 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}build-angular-modules", ->
return promiseHelp.get() unless config.build.client
data = getData()
runTask(
config.templates.angularModules.src.path
@@ -4,16 +4,17 @@
# scripts: []
# ===================
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
gs = require 'glob-stream'
rename = require 'gulp-rename'
template = require 'gulp-template'
pathHelp = require "#{config.req.helpers}/path"
log = require "#{config.req.helpers}/log"
format = require("#{config.req.helpers}/format")()
data = client: styles:[], scripts:[]
globs = null
q = require 'q'
path = require 'path'
gs = require 'glob-stream'
rename = require 'gulp-rename'
template = require 'gulp-template'
pathHelp = require "#{config.req.helpers}/path"
log = require "#{config.req.helpers}/log"
promiseHelp = require "#{config.req.helpers}/promise"
format = require("#{config.req.helpers}/format")()
data = client: styles:[], scripts:[]
globs = null

# task
# ====
@@ -135,6 +136,7 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}build-files", taskDeps, ->
return promiseHelp.get() unless config.build.client
runTask()


@@ -79,8 +79,10 @@ module.exports = (gulp, config) ->
# register tasks
# ==============
gulp.task "#{config.rb.prefix.task}build-spa", ->
return promiseHelp.get() unless config.build.client
runTask getData 'files.json'

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

@@ -20,10 +20,11 @@ module.exports = (gulp, config, watchFile={}) ->
runTask watchFile.path, watchFile.rbDistDir

runMulti = ->
locs = config.build.getLocs()
tasks.run.async(
config, runTask,
'scripts', 'coffee',
['client', 'server']
locs
)

# register task
@@ -20,10 +20,11 @@ module.exports = (gulp, config, watchFile={}) ->
runTask watchFile.path, watchFile.rbDistDir

runMulti = ->
locs = config.build.getLocs()
tasks.run.async(
config, runTask,
'scripts', 'es6',
['client', 'server']
locs
)

# register task
@@ -5,6 +5,7 @@ module.exports = (gulp, config, watchFile={}) ->
gulpif = require 'gulp-if'
less = require 'gulp-less'
plumber = require 'gulp-plumber'
promiseHelp = require "#{config.req.helpers}/promise"
lessHelper = require("#{config.req.helpers}/Less") config, gulp
forWatchFile = !!watchFile.path
absCssUrls = require "#{config.req.tasks}/format/absolute-css-urls" if forWatchFile
@@ -94,7 +95,9 @@ module.exports = (gulp, config, watchFile={}) ->
# register task
# =============
return runSingle() if forWatchFile
gulp.task "#{config.rb.prefix.task}less", -> runMulti()
gulp.task "#{config.rb.prefix.task}less", ->
return promiseHelp.get() unless config.build.client
runMulti()



@@ -5,6 +5,7 @@ module.exports = (gulp, config, watchFile={}) ->
gulpif = require 'gulp-if'
sass = require 'gulp-sass'
plumber = require 'gulp-plumber'
promiseHelp = require "#{config.req.helpers}/promise"
tasks = require("#{config.req.helpers}/tasks")()
sassHelper = require("#{config.req.helpers}/Sass") config, gulp
forWatchFile = !!watchFile.path
@@ -99,7 +100,9 @@ module.exports = (gulp, config, watchFile={}) ->
# register task
# =============
return runSingle() if forWatchFile
gulp.task "#{config.rb.prefix.task}sass", -> runMulti()
gulp.task "#{config.rb.prefix.task}sass", ->
return promiseHelp.get() unless config.build.client
runMulti()



@@ -10,6 +10,10 @@ module.exports = (gulp, config) ->
# ===
config.env.set gulp # must be first

# build
# =====
return promiseHelp.get() unless config.build.client

# angular
# =======
config.angular.removeRbMocksModule()
@@ -60,6 +60,7 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}copy-bower_components", ->
return promiseHelp.get() unless config.build.client
runTasks()


@@ -1,5 +1,6 @@
module.exports = (gulp, config, watchFile={}) ->
q = require 'q'
promiseHelp = require "#{config.req.helpers}/promise"
tasks = require("#{config.req.helpers}/tasks")()
forWatchFile = !!watchFile.path
absCssUrls = require "#{config.req.tasks}/format/absolute-css-urls" if forWatchFile
@@ -32,4 +33,6 @@ module.exports = (gulp, config, watchFile={}) ->
# register task
# =============
return runSingle() if forWatchFile
gulp.task "#{config.rb.prefix.task}copy-css", -> runMulti()
gulp.task "#{config.rb.prefix.task}copy-css", ->
return promiseHelp.get() unless config.build.client
runMulti()
@@ -1,8 +1,9 @@
module.exports = (gulp, config, watchFile={}) ->
q = require 'q'
gulpif = require 'gulp-if'
tasks = require("#{config.req.helpers}/tasks")()
promiseHelp = require "#{config.req.helpers}/promise"
ngFormify = require "#{config.req.plugins}/gulp-ng-formify"
tasks = require("#{config.req.helpers}/tasks")()
runNgFormify = config.angular.ngFormify
forWatchFile = !!watchFile.path

@@ -29,4 +30,6 @@ module.exports = (gulp, config, watchFile={}) ->
# register task
# =============
return runSingle() if forWatchFile
gulp.task "#{config.rb.prefix.task}copy-html", -> runMulti()
gulp.task "#{config.rb.prefix.task}copy-html", ->
return promiseHelp.get() unless config.build.client
runMulti()
@@ -1,5 +1,6 @@
module.exports = (gulp, config, watchFile={}) ->
q = require 'q'
promiseHelp = require "#{config.req.helpers}/promise"
tasks = require("#{config.req.helpers}/tasks")()
forWatchFile = !!watchFile.path

@@ -25,4 +26,6 @@ module.exports = (gulp, config, watchFile={}) ->
# register task
# =============
return runSingle() if forWatchFile
gulp.task "#{config.rb.prefix.task}copy-images", -> runMulti()
gulp.task "#{config.rb.prefix.task}copy-images", ->
return promiseHelp.get() unless config.build.client
runMulti()
@@ -16,10 +16,11 @@ module.exports = (gulp, config, watchFile={}) ->
runTask watchFile.path, watchFile.rbDistDir

runMulti = ->
locs = config.build.getLocs()
tasks.run.async(
config, runTask,
'scripts', 'js',
['client', 'server']
locs
)

# register task
@@ -1,5 +1,6 @@
module.exports = (gulp, config) ->
q = require 'q'
q = require 'q'
promiseHelp = require "#{config.req.helpers}/promise"

runTask = (src, dest, appOrRb) ->
defer = q.defer()
@@ -29,4 +30,5 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}copy-libs", ->
return promiseHelp.get() unless config.build.client
runTasks()

0 comments on commit 8af0923

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