Skip to content
Permalink
Browse files

feat(libs): add support for client 3rd party libs and move bower comp…

…s to bower_components
  • Loading branch information
jyounce committed Jun 11, 2015
1 parent 837fb08 commit 41d671f441b1d7cbc7d7e1a99bd4f7ccc71f0480
@@ -1,7 +1,6 @@
.DS_Store
temp/
bower_components/
src/client/libs/
src/client/scripts/app.coffee
dist/
public/
@@ -49,14 +49,16 @@ gulp rapid-build:prod
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|scripts|styles|views].dir = (string) defaults to property name
# dist.client.libs.dir = (string) defaults to 'libs' = bower components directory
# dist.client.bower.dir = (string) defaults to 'bower_components'
# dist.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# dist.client.spa.file = (string) defaults to 'spa.html'
# dist.server.dir = (string) defaults to 'server'
# dist.server.file = (string) defaults to 'routes.js'
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|scripts|styles|views].dir = (string) defaults to property name
# src.client.libs.dir = (string) defaults to 'libs' = bower components directory
# src.client.bower.dir = (string) defaults to 'bower_components'
# src.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# src.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
@@ -9,7 +9,8 @@ module.exports = (config, options) ->
src: 'src'
client: 'client'
images: 'images'
libs: 'libs' # bower_components
bower: 'bower_components'
libs: 'libs'
server: 'server'
scripts: 'scripts'
styles: 'styles'
@@ -28,6 +29,7 @@ module.exports = (config, options) ->
o.dir = options[loc].dir
if isApp
o.clientDir = options[loc].client.dir
o.clientBower = options[loc].client.bower.dir
o.clientImages = options[loc].client.images.dir
o.clientLibs = options[loc].client.libs.dir
o.clientScripts = options[loc].client.scripts.dir
@@ -38,6 +40,8 @@ module.exports = (config, options) ->
dir: o.dir or dir[loc]
client:
dir: o.clientDir or dir.client
bower:
dir: o.clientBower or dir.bower
images:
dir: o.clientImages or dir.images
libs:
@@ -30,19 +30,21 @@ module.exports = (config) ->
if v2 isnt 'server'
glob[loc][v1][v2].all = "#{config[loc][v1][v2].dir}/**"

addGlob = (loc, type, langs, includeLibs) ->
addGlob = (loc, type, langs, includeBower, includeLibs) ->
for own k1, v1 of glob[loc]
for own k2, v2 of v1
continue if k2 is 'server' and type isnt 'scripts'
continue if k2 is 'server' and includeLibs
continue if k2 is 'server' and (includeBower or includeLibs)
v2[type] = {} if not isType.object v2[type]
langs.forEach (v3) ->
typeDir = pathHelp.format config[loc][k1][k2][type].dir
if includeLibs
libsDir = pathHelp.format config[loc][k1][k2]['libs'].dir
if includeBower or includeLibs
bowerDir = pathHelp.format config[loc][k1][k2]['bower'].dir
libsDir = pathHelp.format config[loc][k1][k2]['libs'].dir
v2[type][v3] = [
path.join libsDir, lang[v3]
path.join typeDir, lang[v3]
path.join bowerDir, lang[v3]
path.join libsDir, lang[v3]
path.join typeDir, lang[v3]
]
else
v2[type][v3] = path.join typeDir, lang[v3]
@@ -55,6 +57,7 @@ module.exports = (config) ->
# src
# ===
addGlob 'src', 'images', ['all']
addGlob 'src', 'libs', ['all']
addGlob 'src', 'scripts', ['js']
addGlob 'src', 'scripts', ['coffee']
addGlob 'src', 'scripts', ['es6']
@@ -65,12 +68,13 @@ module.exports = (config) ->

# dist
# ====
addGlob 'dist', 'bower', ['all']
addGlob 'dist', 'images', ['all']
addGlob 'dist', 'libs', ['all']
addGlob 'dist', 'scripts', ['all']
addGlob 'dist', 'scripts', ['js'], true
addGlob 'dist', 'scripts', ['js' ], true, true
addGlob 'dist', 'styles', ['all']
addGlob 'dist', 'styles', ['css'], true
addGlob 'dist', 'styles', ['css'], true, true
addGlob 'dist', 'views', ['all']
addGlob 'dist', 'views', ['html']

@@ -1,25 +1,29 @@
# API - Prep Options
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# dist.client.spa.file = (string) defaults to 'spa.html'
# dist.server.dir = (string) defaults to 'server'
# dist.server.file = (string) defaults to 'routes.js'
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# src.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array) expects file paths
# angular.modules = (array) additional angular modules
# angular.version = (string) defaults to '1.x'
# angular.moduleName = (string) application module name
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# spaFile.title = (string) defaults to package.json name
# spaFile.description = (string) defaults to package.json description
# ==================================================================================================
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|scripts|styles|views].dir = (string) defaults to property name
# dist.client.bower.dir = (string) defaults to 'bower_components'
# dist.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# dist.client.spa.file = (string) defaults to 'spa.html'
# dist.server.dir = (string) defaults to 'server'
# dist.server.file = (string) defaults to 'routes.js'
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|scripts|styles|views].dir = (string) defaults to property name
# src.client.bower.dir = (string) defaults to 'bower_components'
# src.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# src.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array) expects file paths
# angular.modules = (array) additional angular modules
# angular.version = (string) defaults to '1.x'
# angular.moduleName = (string) application module name
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# spaFile.title = (string) defaults to package.json name
# spaFile.description = (string) defaults to package.json description
# ===============================================================================================================================
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
@@ -36,7 +40,7 @@ module.exports = (config, options) ->
options[v1][v2].dir = null if not isType.string options[v1][v2].dir
return if v2 is 'server'
# types dir
['images', 'libs', 'scripts', 'styles', 'views'].forEach (v3) ->
['bower', 'images', 'libs', 'scripts', 'styles', 'views'].forEach (v3) ->
options[v1][v2][v3] = {} if not isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null if not isType.string options[v1][v2][v3].dir
# spa dist file
@@ -14,6 +14,7 @@ module.exports = (config, options) ->
# defaults
# ========
rb =
bower: config.dist.rb.client.bower.dirName
libs: config.dist.rb.client.libs.dirName
scripts: getDirName 'rb', 'scripts'
styles: getDirName 'rb', 'styles'
@@ -35,10 +36,10 @@ module.exports = (config, options) ->
# rb order
# ========
order.rb.scripts.first = [
"#{rb.libs}/angular"
"#{rb.libs}/angular-resource"
"#{rb.libs}/angular-route"
"#{rb.libs}/angular-sanitize"
"#{rb.bower}/angular"
"#{rb.bower}/angular-resource"
"#{rb.bower}/angular-route"
"#{rb.bower}/angular-sanitize"
"#{rb.scripts}/app"
]

@@ -25,7 +25,7 @@ module.exports = (config) ->
helper =
getPath: (pkgName, file, loc='rb') ->
path.join(
config.src[loc].client.libs.dir
config.src[loc].client.bower.dir
pkgName
file
)
@@ -119,7 +119,7 @@ module.exports = (config) ->
forceInstall: (loc='rb') -> # technique for users to get bower updates
force = false
bowerJson = me.get.json.from.appOrRb(loc)
dir = config.src[loc].client.libs.dir
dir = config.src[loc].client.bower.dir
_path = path.join dir, '.bower'

if not fileHelp.exists _path
@@ -132,7 +132,7 @@ module.exports = (config) ->
force = true
if force
del.sync dir, force:true
console.log "#{loc} libs directory cleaned".yellow
console.log "#{loc} bower_components directory cleaned".yellow

mkdirp.sync dir
fileHelp.write.json _path, bowerJson if force
@@ -146,7 +146,7 @@ module.exports = (config) ->
installed:
pkg: (pkg, loc='rb') ->
_path = path.join(
config.src[loc].client.libs.dir
config.src[loc].client.bower.dir
pkg
config.bower[loc].file
)
@@ -162,7 +162,7 @@ module.exports = (config) ->
# console.log pkg, loc
require(
path.join(
config.src[loc].client.libs.dir
config.src[loc].client.bower.dir
pkg
config.bower[loc].file
)
@@ -36,6 +36,7 @@ module.exports = (gulp, config) ->

# copy
# ====
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-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
@@ -27,6 +27,7 @@ module.exports = (gulp, config) ->
]
-> delTask [
config.glob.dist.rb.client.all
config.glob.dist.app.client.bower.all
config.glob.dist.app.client.libs.all
config.glob.dist.app.client.scripts.all
config.glob.dist.app.client.styles.all
@@ -11,11 +11,12 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}build-config"
"#{config.rb.prefix.task}build-angular-modules"
[
"#{config.rb.prefix.task}copy-bower_components"
"#{config.rb.prefix.task}copy-css"
"#{config.rb.prefix.task}copy-views"
"#{config.rb.prefix.task}copy-images"
"#{config.rb.prefix.task}copy-js"
"#{config.rb.prefix.task}copy-libs"
"#{config.rb.prefix.task}copy-views"
"#{config.rb.prefix.task}coffee"
"#{config.rb.prefix.task}es6"
"#{config.rb.prefix.task}less"
@@ -0,0 +1,55 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
es = require 'event-stream'
bowerHelper = require("#{config.req.helpers}/bower") config

removeMin = -> # for prod env, to avoid additional work elsewhere
transform = (file, cb) ->
file.path = file.path.replace '.min', ''
cb null, file
es.map transform

addDistBasePath = (relPaths) ->
transform = (file, cb) ->
relPath = relPaths[file.path]
name = path.basename relPath
dir = path.dirname relPath
file.path = path.join file.base, dir, name
cb null, file
es.map transform

runTask = (src, dest) ->
defer = q.defer()
return if not src or not src.paths.absolute.length
defer.resolve()
defer.promise
gulp.src src.paths.absolute
.pipe addDistBasePath src.paths.relative
.pipe removeMin()
.pipe gulp.dest dest
.on 'end', ->
# console.log dest
defer.resolve()
defer.promise

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

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


@@ -1,55 +1,32 @@
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
es = require 'event-stream'
bowerHelper = require("#{config.req.helpers}/bower") config
q = require 'q'

removeMin = -> # for prod env, to avoid additional work elsewhere
transform = (file, cb) ->
file.path = file.path.replace '.min', ''
cb null, file
es.map transform

addDistBasePath = (relPaths) ->
transform = (file, cb) ->
relPath = relPaths[file.path]
name = path.basename relPath
dir = path.dirname relPath
file.path = path.join file.base, dir, name
cb null, file
es.map transform

runTask = (src, dest) ->
runTask = (src, dest, appOrRb) ->
defer = q.defer()
return if not src or not src.paths.absolute.length
defer.resolve()
defer.promise
gulp.src src.paths.absolute
.pipe addDistBasePath src.paths.relative
.pipe removeMin()
gulp.src src
.pipe gulp.dest dest
.on 'end', ->
# console.log dest
# console.log "copied #{appOrRb} libs".yellow
defer.resolve()
defer.promise

runTasks = ->
defer = q.defer()
q.all([
runTask(
bowerHelper.get.src 'rb'
config.glob.src.rb.client.libs.all
config.dist.rb.client.libs.dir
'rb'
)
runTask(
bowerHelper.get.src 'app'
config.glob.src.app.client.libs.all
config.dist.app.client.libs.dir
'app'
)
]).done -> defer.resolve()
defer.promise

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


runTasks()

0 comments on commit 41d671f

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