Skip to content
Permalink
Browse files

feat(option): add build option extra.copy[client|server]

  • Loading branch information
jyounce committed Sep 1, 2015
1 parent 9a8a00e commit 757f32823f270eec4146817dcee4d69f8090897d
@@ -148,6 +148,7 @@ gulp rapid-build:test:prod
# test.browsers = (array of browser names) = phantomjs will run by default, optional browser names are ['chrome', 'firefox', 'ie', 'safari']
# server.node_modules = (array of module names) = node_modules you would like to copy to the server dist, example: ['q']
# httpProxy = (array of objects) = object format: { context: array or string, options: object } for details see: https://www.npmjs.com/package/http-proxy-middleware
# extra.copy[client|server] = (array of strings) = file paths: additional files to copy to dist/client and or dist/server that the build didn't copy
# =============================================================================================================================================================================================================================
```

@@ -21,6 +21,8 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-angular") config, options
config = require("#{config.req.config}/config-spa") config, options
config = require("#{config.req.config}/config-exclude") config, options
config = require("#{config.req.config}/config-extra") config
config = require("#{config.req.config}/config-extra-copy") config, options
config = require("#{config.req.config}/config-templates") config
config = require("#{config.req.config}/config-temp") config
config = require("#{config.req.config}/config-http-proxy") config, options
@@ -0,0 +1,44 @@
module.exports = (config, options) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init extra.copy
# copy additional files to
# dist that the build didn't copy
# ===============================
copy =
rb:
client: []
server: []
app:
client: options.extra.copy.client or []
server: options.extra.copy.server or []

# format copy paths
# =================
formatCopyPaths = (appOrRb) ->
for loc in ['client','server']
files = copy[appOrRb][loc]
continue unless files.length
for file, i in files
files[i] = path.join config.src[appOrRb][loc].dir, files[i]

formatCopyPaths 'rb'
formatCopyPaths 'app'

# add copy to config.extra
# ========================
config.extra.copy = copy

# logs
# ====
# log.json extra.copy, 'extra.copy ='

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

# return
# ======
config
@@ -0,0 +1,22 @@
module.exports = (config, options) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init extra object
# contains useful tasks that
# the build doesn't do by default
# ===============================
extra = {}

# add extra to config
# ===================
config.extra = extra

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

# return
# ======
config
@@ -106,6 +106,13 @@ module.exports = (config, options) ->
proxyOptions = ->
options.httpProxy = null if not isType.array options.httpProxy

extraOptions = ->
options.extra = {} if not isType.object options.extra
# copy additional files to dist that the build didn't copy
options.extra.copy = {} if not isType.object options.extra.copy
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

# init
# ====
distAndSrcOptions() # must be first
@@ -119,6 +126,7 @@ module.exports = (config, options) ->
serverDistOptions()
serverOptions()
proxyOptions()
extraOptions()

# logs
# ====
@@ -43,6 +43,7 @@ module.exports = (gulp, config) ->
# ====
require("#{config.req.tasks}/copy/copy-bower_components") gulp, config # copy-bower_components
require("#{config.req.tasks}/copy/copy-css") gulp, config # copy-css
require("#{config.req.tasks}/copy/copy-extra-files") gulp, config # copy-extra-files
require("#{config.req.tasks}/copy/copy-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
require("#{config.req.tasks}/copy/copy-js") gulp, config # copy-js
@@ -23,6 +23,7 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}less"
"#{config.rb.prefix.task}copy-server-config"
"#{config.rb.prefix.task}copy-server-node_modules"
"#{config.rb.prefix.task}copy-extra-files"
]
"#{config.rb.prefix.task}build-files"
cb
@@ -0,0 +1,46 @@
module.exports = (gulp, config) ->
q = require 'q'

runTask = (src, dest, base, appOrRb) ->
defer = q.defer()
gulp.src src, { base, buffer: false }
.pipe gulp.dest dest
.on 'end', ->
# console.log "copied #{appOrRb} extra files".yellow
defer.resolve()
defer.promise

runTasks = ->
defer = q.defer()
q.all([
runTask(
config.extra.copy.rb.client
config.dist.rb.client.dir
config.src.rb.client.dir
'rb'
)
runTask(
config.extra.copy.rb.server
config.dist.rb.server.dir
config.src.rb.server.dir
'rb'
)
runTask(
config.extra.copy.app.client
config.dist.app.client.dir
config.src.app.client.dir
'app'
)
runTask(
config.extra.copy.app.server
config.dist.app.server.dir
config.src.app.server.dir
'app'
)
]).done -> defer.resolve()
defer.promise

# register task
# =============
gulp.task "#{config.rb.prefix.task}copy-extra-files", ->
runTasks()

0 comments on commit 757f328

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