Skip to content
Permalink
Browse files

feat(add build): create and expose build rapid-build:test:prod for te…

…sting prod builds
  • Loading branch information
jyounce committed Jul 18, 2015
1 parent c4cec72 commit f54d1142da24f583034ff4133a92e01ee9e4cd2e
@@ -20,6 +20,8 @@ files/prod-files.json
files/prod-files-blueprint.json
files/test-files.json
src/client/scripts/app.coffee
src/client/test/angular-mocks.js
src/client/test/inject-angular-mocks.coffee

# test
# ====
@@ -60,8 +60,8 @@ var rapid = require('rapid-build')(options) // init rapid, pass in options here
/**
* After initializing rapid, execute it to kick off the build.
* 1 optional param (the build mode), values are: nothing, 'dev', 'test' or 'prod'.
* Rapid has 4 build modes: default, dev, test and prod (see build modes).
* 1 optional param (the build mode), values are: nothing, 'dev', 'prod' or 'test'.
* Rapid has 4 build modes: default, dev, prod and test (see build modes).
*/
rapid().then(function() {
console.log('whatever you want') // probably won't need to do anything
@@ -76,7 +76,7 @@ rapid().then(function() {
* In your gulpfile.js init rapid-build and
* pass in gulp (pass in options too if you need customization).
* 4 build tasks become available after initializing rapid (see build modes).
* Build tasks are: 'rapid-build', 'rapid-build:dev', 'rapid-build:test' and 'rapid-build:prod'
* Build tasks are: 'rapid-build', 'rapid-build:dev', 'rapid-build:prod' and 'rapid-build:test'
* *********************************************************************************************/
var gulp = require('gulp')
var options = {}
@@ -85,12 +85,13 @@ require('rapid-build')(gulp, options)
// execute rapid via a gulp task dependency
gulp.task('default', ['rapid-build'])
// or from the terminal type one of the 5:
// or from the terminal type one of the 6:
gulp rapid-build
gulp rapid-build:dev
gulp rapid-build:test
gulp rapid-build:prod
gulp rapid-build:prod:server
gulp rapid-build:test
gulp rapid-build:test:prod
```

## Options API
@@ -173,11 +174,6 @@ gulp rapid-build:prod:server
4. open the browser
5. fireup the file watchers (on saving a file, the browser will refresh)

#### Test Build:
1. run common tasks (see above)
2. copy test scripts to dist/client/
3. run tests in [PhantomJS](http://phantomjs.org/)

#### Prod Build:
1. run common tasks (see above)
2. minify the application files
@@ -192,6 +188,11 @@ gulp rapid-build:prod:server
6. cache bust the files (client)
7. minify server js files

#### Test Build:
1. run common tasks (see above)
2. copy test scripts to dist/client/
3. run tests in [PhantomJS](http://phantomjs.org/)

## Develop Rapidly!
![Shake and Bake!](docs/shake-and-bake.jpg "Shake n' Bake!")

@@ -17,9 +17,10 @@ module.exports = (config, options) ->
httpBackendDir = options.angular.httpBackend.dir or 'mocks'
httpBackendDir = path.join config.src.app.client.scripts.dir, httpBackendDir
angular.httpBackend = {}
angular.httpBackend.dev = options.angular.httpBackend.dev or false
angular.httpBackend.prod = options.angular.httpBackend.prod or false
angular.httpBackend.dir = httpBackendDir
angular.httpBackend.dev = options.angular.httpBackend.dev or false
angular.httpBackend.prod = options.angular.httpBackend.prod or false
angular.httpBackend.enabled = false # see updateHttpBackendStatus()
angular.httpBackend.dir = httpBackendDir

# modules
# =======
@@ -55,12 +56,18 @@ module.exports = (config, options) ->
angular.modules.splice 0, 1

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

angular.updateHttpBackendStatus = ->
if config.env.is.test and angular.httpBackend.dev
httpBackendEnabled = true
else if config.env.is.prod and angular.httpBackend.prod
httpBackendEnabled = true
config.angular.httpBackend.enabled = !!httpBackendEnabled

# add angular to config
# =====================
config.angular = angular
@@ -33,7 +33,7 @@ module.exports = (config) ->
env.is =
default: true
defaultOrDev: true
dev: false
dev: false
prod: false
test: false

@@ -139,7 +139,6 @@ module.exports = (config) ->
removeAppAngularMocksDir()

glob.removeRbAngularMocks = ->
return if config.env.is.test
if config.env.is.prod
removeRbAngularMocks() if not config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
@@ -65,7 +65,6 @@ module.exports = (config, options) ->
order.rb.scripts.first.splice 1, 1

order.removeRbAngularMocks = ->
return if config.env.is.test
if config.env.is.prod
removeRbAngularMocks() if not config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
@@ -15,9 +15,10 @@ module.exports = (config, rbDir) ->
rb.tasks = {}
rb.tasks.default = 'rapid-build'
rb.tasks.dev = "#{rb.tasks.default}:dev"
rb.tasks.test = "#{rb.tasks.default}:test"
rb.tasks.prod = "#{rb.tasks.default}:prod"
rb.tasks['prod:server'] = "#{rb.tasks.default}:prod:server"
rb.tasks.test = "#{rb.tasks.default}:test"
rb.tasks['test:prod'] = "#{rb.tasks.default}:test:prod"

# prefixes
# ========
@@ -9,7 +9,7 @@
# bowerHelper.get.installed.pkgs appOrRb
# bowerHelper.get.installed.pkg 'angular', appOrRb
# bowerHelper.get.missing.pkgs appOrRb
# bowerHelper.get.src appOrRb
# bowerHelper.get.src appOrRb, opts
# ================================================
module.exports = (config) ->
fs = require 'fs'
@@ -154,7 +154,6 @@ module.exports = (config) ->

removeRbAngularMocks: (loc, paths) ->
return if loc isnt 'rb'
return if config.env.is.test
if config.env.is.prod
@_removeRbAngularMocks paths if not config.angular.httpBackend.prod
else if not config.angular.httpBackend.dev
@@ -245,13 +244,16 @@ module.exports = (config) ->
pkgs.push "#{pkg}##{version}" if missing
pkgs

src: (loc='rb', env) ->
src: (loc='rb', opts={}) ->
return if not me.has.bower loc
env = env or config.env.name
env = opts.env or config.env.name
env = 'dev' if ['dev','prod'].indexOf(env) is -1
absPaths = []
relPaths = {}
pkgs = me.get.installed.pkgs loc
if opts.pkg
pkgs = [ me.get.installed.pkg opts.pkg, loc ]
else
pkgs = me.get.installed.pkgs loc
# log.json pkgs
pkgs.forEach (pkg) ->
pkg[env].forEach (file) ->
@@ -260,13 +262,10 @@ module.exports = (config) ->
relPaths[file.path] = path.join name, file.file
absPaths.push file.path
paths =
paths:
absolute: absPaths # []
relative: relPaths # {}
helper.removeRbAngularMocks loc, paths.paths # conditionally
# log.json paths
paths

absolute: absPaths # []
relative: relPaths # {}
helper.removeRbAngularMocks loc, paths unless opts.test
{ paths }



@@ -26,16 +26,6 @@ module.exports = (gulp, config) ->
cb
) -> defer.resolve()

# TEST: rapid-build:test
# ======================
gulp.task config.rb.tasks.test, ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}copy-tests"
"#{config.rb.prefix.task}build-test-files"
"#{config.rb.prefix.task}run-tests"
cb
) -> defer.resolve()

# PROD: rapid-build:prod
# ======================
gulp.task config.rb.tasks.prod, ["#{config.rb.prefix.task}common"], (cb) ->
@@ -46,9 +36,12 @@ module.exports = (gulp, config) ->
]
cb
) ->
prodServer = config.rb.tasks['prod:server']
calledFromProdServer = gulp.seq.indexOf(prodServer) isnt -1
defer.resolve() unless calledFromProdServer
prodServer = config.rb.tasks['prod:server']
testProd = config.rb.tasks['test:prod']
calledFromApi = gulp.seq.indexOf(prodServer) isnt -1
calledFromApi = gulp.seq.indexOf(testProd) isnt -1 unless calledFromApi
# console.log "call from api: #{calledFromApi}".cyan
defer.resolve() unless calledFromApi

# PROD SERVER: rapid-build:prod:server
# ====================================
@@ -59,8 +52,29 @@ module.exports = (gulp, config) ->
cb
) -> defer.resolve()

# TEST: rapid-build:test
# ======================
gulp.task config.rb.tasks.test, ["#{config.rb.prefix.task}common"], (cb) ->
return defer.resolve() if config.exclude.angular.files
gulpSequence(
"#{config.rb.prefix.task}common-test"
cb
) -> defer.resolve()

# TEST PROD: rapid-build:test:prod
# ================================
gulp.task config.rb.tasks['test:prod'], [config.rb.tasks.prod], (cb) ->
return defer.resolve() if config.exclude.angular.files
gulpSequence(
"#{config.rb.prefix.task}common-test"
"#{config.rb.prefix.task}clean-test-dist"
cb
) -> defer.resolve()

# return
# ======
defer.promise




@@ -16,7 +16,6 @@ module.exports = (gulp, config) ->
require("#{config.req.tasks}/build/build-files") gulp, config # build-files
require("#{config.req.tasks}/build/build-prod-files") gulp, config # build-prod-files
require("#{config.req.tasks}/build/build-prod-files-blueprint") gulp, config # build-prod-files-blueprint
require("#{config.req.tasks}/build/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/build/build-spa") gulp, config # build-spa

# clean
@@ -77,6 +76,12 @@ module.exports = (gulp, config) ->

# test
# ====
require("#{config.req.tasks}/test/build-inject-angular-mocks") gulp, config # build-inject-angular-mocks
require("#{config.req.tasks}/test/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/test/clean-rb-test-src") gulp, config # clean-rb-test-src
require("#{config.req.tasks}/test/clean-test-dist") gulp, config # clean-test-dist
require("#{config.req.tasks}/test/common-test") gulp, config # common-test
require("#{config.req.tasks}/test/copy-angular-mocks") gulp, config # copy-angular-mocks
require("#{config.req.tasks}/test/copy-tests") gulp, config # copy-tests
require("#{config.req.tasks}/test/run-tests") gulp, config # run-tests

No changes.
@@ -12,15 +12,16 @@ module.exports = (gulp, config) ->

# angular
# =======
config.angular.removeRbMocksModule() # conditionally
config.angular.removeRbMocksModule()
config.angular.updateHttpBackendStatus()

# order
# =====
config.order.removeRbAngularMocks() # conditionally
config.order.removeRbAngularMocks()

# globs
# =====
config.glob.removeRbAngularMocks() # conditionally
config.glob.removeRbAngularMocks()

# return
# ======
@@ -51,14 +51,17 @@ module.exports = (gulp, config) ->
defer.promise

runCacheBustTask = -> # synchronously
defer = q.defer()
bust = new Bust bustOpts
srcFiles = config.glob.dist.app.client.cacheBust.files
srcRefs = config.glob.dist.app.client.cacheBust.references
dest = config.dist.app.client.dir
defer = q.defer()
bust = new Bust bustOpts
srcFiles = config.glob.dist.app.client.cacheBust.files
srcRefs = config.glob.dist.app.client.cacheBust.references
dest = config.dist.app.client.dir
prodFilesSrc = path.join config.templates.files.dest.dir, 'prod-files.json'
prodFilesDest = config.templates.files.dest.dir
tasks = [
-> runStampFiles srcFiles, dest, bust
-> runStampRefs srcRefs, dest, bust
-> runStampRefs prodFilesSrc, prodFilesDest, bust
-> runDelUnstampedPaths()
]
tasks.reduce(q.when, q()).done -> defer.resolve()
@@ -0,0 +1,38 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
rename = require 'gulp-rename'
template = require 'gulp-template'
promiseHelp = require "#{config.req.helpers}/promise"

# helpers
# =======
getData = ->
data = moduleName: config.angular.moduleName

# tasks
# =====
buildTask = (src, dest, file, data={}) ->
defer = q.defer()
gulp.src src
.pipe rename file
.pipe template data
.pipe gulp.dest dest
.on 'end', ->
# console.log 'inject-angular-mocks.coffee built'.yellow
defer.resolve()
defer.promise

runTask = ->
data = getData()
src = path.join config.templates.dir, 'inject-angular-mocks.tpl'
dest = config.src.rb.client.test.dir
file = 'inject-angular-mocks.coffee'
buildTask src, dest, file, data

# register task
# =============
gulp.task "#{config.rb.prefix.task}build-inject-angular-mocks", ->
return promiseHelp.get() if config.angular.httpBackend.enabled
runTask()

0 comments on commit f54d114

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