Skip to content
Permalink
Browse files

feat(option): add build option extra.compile

  • Loading branch information
jyounce committed Sep 20, 2015
1 parent c19c4e7 commit 9cdfa16c4baecedb94dbdd0166d36d9a0584357b
@@ -150,6 +150,8 @@ gulp rapid-build:test:prod
# 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
# extra.compile.client[coffee|es6|less] = (array of strings) = file paths: additional files to compile to dist/client that the build didn't compile
# extra.compile.server.less = (array of strings) = file paths: additional files to compile to dist/server that the build didn't compile
# =============================================================================================================================================================================================================================
```

@@ -8,30 +8,31 @@ module.exports = (rbDir, options) ->

# get config in order
# ===================
config = require("#{rbDir}/config/config-req") config, rbDir
options = require("#{config.req.config}/config-options") config, 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-ports") config, options
config = require("#{config.req.config}/config-server") config
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-minify") config, options
config = require("#{config.req.config}/config-dist-and-src") config, 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
config = require("#{config.req.config}/config-node_modules") config, options
config = require("#{config.req.config}/config-order") config, options
config = require("#{config.req.config}/config-globs") config
config = require("#{config.req.config}/config-bower") config, options
config = require("#{config.req.config}/config-test") config, options
config = require("#{config.req.config}/config-internal") config
config = require("#{rbDir}/config/config-req") config, rbDir
options = require("#{config.req.config}/config-options") config, 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-ports") config, options
config = require("#{config.req.config}/config-server") config
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-minify") config, options
config = require("#{config.req.config}/config-dist-and-src") config, 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-extra-compile") 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
config = require("#{config.req.config}/config-node_modules") config, options
config = require("#{config.req.config}/config-order") config, options
config = require("#{config.req.config}/config-globs") config
config = require("#{config.req.config}/config-bower") config, options
config = require("#{config.req.config}/config-test") config, options
config = require("#{config.req.config}/config-internal") config

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

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

# format compile paths
# ====================
formatCompilePaths = (appOrRb) ->
for loc in ['client','server']
for lang in ['coffee','es6','less']
files = compile[appOrRb][loc][lang]
continue unless files
continue unless files.length
for file, i in files
files[i] = path.join config.src[appOrRb][loc].dir, files[i]

formatCompilePaths 'rb'
formatCompilePaths 'app'

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

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

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

# return
# ======
config
@@ -107,13 +107,25 @@ 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
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

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.server.less = null if not isType.array options.extra.compile.server.less

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
extraCopy()
extraCompile()

# init
# ====
distAndSrcOptions() # must be first
@@ -0,0 +1,46 @@
module.exports = (config) ->
q = require 'q'
promiseHelp = require "#{config.req.helpers}/promise"

# private
# =======
getTasks = (tasksCb, srcBase, srcTask) ->
args = []
tasks = []
for appOrRb in ['rb','app']
for loc in ['client','server']
src = srcBase[appOrRb][loc]
src = src[srcTask] if srcTask
_args = {
src
dest: config.dist[appOrRb][loc].dir
base: config.src[appOrRb][loc].dir
appOrRb, loc
}
continue unless _args.src
continue unless _args.src.length
args.push _args
return tasks unless args.length
for v, i in args
do (v) ->
tasks[i] = -> tasksCb v.src, v.dest, v.base, v.appOrRb, v.loc
tasks

# public
# ======
run:
tasks:
async: (tasksCb, task, subTask) ->
defer = q.defer()
tasks = getTasks tasksCb, config.extra[task], subTask
return promiseHelp.get defer unless tasks.length
promises = tasks.map (_task) -> _task()
q.all(promises).done -> defer.resolve()
defer.promise

sync: (tasksCb, task, subTask) ->
defer = q.defer()
tasks = getTasks tasksCb, config.extra[task], subTask
return promiseHelp.get defer unless tasks.length
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise
@@ -43,7 +43,6 @@ 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
@@ -52,6 +51,13 @@ module.exports = (gulp, config) ->
require("#{config.req.tasks}/copy/copy-server-node_modules") gulp, config # copy-server-node_modules
require("#{config.req.tasks}/copy/copy-views") gulp, config # copy-views

# extra
# =====
require("#{config.req.tasks}/extra/compile-extra-coffee") gulp, config # compile-extra-coffee
require("#{config.req.tasks}/extra/compile-extra-es6") gulp, config # compile-extra-es6
require("#{config.req.tasks}/extra/compile-extra-less") gulp, config # compile-extra-less
require("#{config.req.tasks}/extra/copy-extra-files") gulp, config # copy-extra-files

# format
# ======
require("#{config.req.tasks}/format/absolute-css-urls") gulp, config # absolute-css-urls
@@ -23,6 +23,9 @@ 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}compile-extra-coffee"
"#{config.rb.prefix.task}compile-extra-es6"
"#{config.rb.prefix.task}compile-extra-less"
"#{config.rb.prefix.task}copy-extra-files"
]
"#{config.rb.prefix.task}absolute-css-urls"

This file was deleted.

@@ -0,0 +1,24 @@
module.exports = (gulp, config) ->
q = require 'q'
coffee = require 'gulp-coffee'
plumber = require 'gulp-plumber'
extraHelp = require("#{config.req.helpers}/extra") config

runTask = (src, dest, base, appOrRb, loc) ->
defer = q.defer()
gulp.src src, { base }
.pipe plumber()
.pipe coffee bare: true
.pipe gulp.dest dest
.on 'end', ->
console.log "compiled extra coffee to #{appOrRb} #{loc}".yellow
defer.resolve()
defer.promise

runTasks = ->
extraHelp.run.tasks.async runTask, 'compile', 'coffee'

# register task
# =============
gulp.task "#{config.rb.prefix.task}compile-extra-coffee", ->
runTasks()
@@ -0,0 +1,24 @@
module.exports = (gulp, config) ->
q = require 'q'
babel = require 'gulp-babel'
plumber = require 'gulp-plumber'
extraHelp = require("#{config.req.helpers}/extra") config

runTask = (src, dest, base, appOrRb, loc) ->
defer = q.defer()
gulp.src src, { base }
.pipe plumber()
.pipe babel()
.pipe gulp.dest dest
.on 'end', ->
console.log "compiled extra es6 to #{appOrRb} #{loc}".yellow
defer.resolve()
defer.promise

runTasks = ->
extraHelp.run.tasks.async runTask, 'compile', 'es6'

# register task
# =============
gulp.task "#{config.rb.prefix.task}compile-extra-es6", ->
runTasks()
@@ -0,0 +1,24 @@
module.exports = (gulp, config) ->
q = require 'q'
less = require 'gulp-less'
plumber = require 'gulp-plumber'
extraHelp = require("#{config.req.helpers}/extra") config

runTask = (src, dest, base, appOrRb, loc) ->
defer = q.defer()
gulp.src src, { base }
.pipe plumber()
.pipe less()
.pipe gulp.dest dest
.on 'end', ->
console.log "compiled extra less to #{appOrRb} #{loc}".yellow
defer.resolve()
defer.promise

runTasks = ->
extraHelp.run.tasks.async runTask, 'compile', 'less'

# register task
# =============
gulp.task "#{config.rb.prefix.task}compile-extra-less", ->
runTasks()
@@ -0,0 +1,20 @@
module.exports = (gulp, config) ->
q = require 'q'
extraHelp = require("#{config.req.helpers}/extra") config

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

runTasks = ->
extraHelp.run.tasks.async runTask, 'copy'

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

0 comments on commit 9cdfa16

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