Skip to content
Permalink
Browse files

feat(bower): start of app support for bower

  • Loading branch information
jyounce committed Jun 1, 2015
1 parent b7f757f commit 74825ef8d5f21744675b2902bdd407b992f24f9a
Showing with 137 additions and 67 deletions.
  1. +1 −0 config.coffee
  2. +42 −0 config/config-bower.coffee
  3. +0 −8 config/config-json.coffee
  4. +60 −50 helpers/bower.coffee
  5. +18 −2 tasks/copy/copy-libs.coffee
  6. +16 −7 tasks/manage/bower.coffee
@@ -30,6 +30,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-order") config, options
config = require("#{config.req.config}/config-globs") config
config = require("#{config.req.config}/config-json") config
config = require("#{config.req.config}/config-bower") config, options

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

# defaults
# ========
defaults =
file: 'bower.json'

# init json
# =========
bower = {}
bower.rb = {}
bower.app = {}

# add info
# ========
addInfo = ->
['app', 'rb'].forEach (v) ->
bower[v].file = defaults.file
bower[v].dir = config[v].dir
bower[v].path = path.join bower[v].dir, bower[v].file
addInfo()

# add bower to config
# ===================
config.bower = bower

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

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

# return
# ======
config


@@ -6,17 +6,9 @@ module.exports = (config) ->
# init json
# =========
json = {}
json.bower = {}
json.config = {}
json.files = {}

# json bower
# ==========
json.bower = {}
json.bower.file = 'bower.json'
json.bower.dir = config.rb.dir
json.bower.path = path.join json.bower.dir, json.bower.file

# json config
# ===========
json.config = {}
@@ -1,17 +1,19 @@
# API
# bowerHelper.has.installed.pkg 'angular'
# bowerHelper.get.json.from.rb()
# bowerHelper.get.json.from.pkg 'angular'
# bowerHelper.get.pkgs.from.rb()
# bowerHelper.get.pkgs.to.install()
# bowerHelper.get.pkgs.to.install true
# bowerHelper.get.installed.pkgs()
# bowerHelper.get.installed.pkg 'angular'
# bowerHelper.get.missing.pkgs()
# bowerHelper.has.installed.pkg 'angular', appOrRb
# bowerHelper.get.json.from.appOrRb appOrRb
# bowerHelper.get.json.from.pkg 'angular', appOrRb
# bowerHelper.get.pkgs.from.appOrRb appOrRb
# bowerHelper.get.pkgs.to.install appOrRb
# bowerHelper.get.pkgs.to.install appOrRb, true
# bowerHelper.get.installed.pkgs appOrRb
# bowerHelper.get.installed.pkg 'angular', appOrRb
# bowerHelper.get.missing.pkgs appOrRb
# bowerHelper.get.src.pkgs appOrRb
# =======================================
module.exports = (config) ->
fs = require 'fs'
path = require 'path'
log = require "#{config.req.helpers}/log"

# helpers
# =======
@@ -22,9 +24,9 @@ module.exports = (config) ->
catch e
false

getPath: (pkgName, file) ->
getPath: (pkgName, file, loc='rb') ->
path.join(
config.src.rb.client.libs.dir
config.src[loc].client.libs.dir
pkgName
file
)
@@ -39,20 +41,20 @@ module.exports = (config) ->
base = path.basename file, ext
"#{base}.min#{ext}"

getDevFileInfo: (pkgName, file) ->
getDevFileInfo: (pkgName, file, loc='rb') ->
file = @getDevFile file
_path = @getPath pkgName, file
_path = @getPath pkgName, file, loc
{ file, path: _path }

getProdFileInfo: (pkgName, fileInfo) ->
getProdFileInfo: (pkgName, fileInfo, loc='rb') ->
file = @getProdFile fileInfo.file
_path = @getPath pkgName, file
_path = @getPath pkgName, file, loc
return fileInfo if not @isFile _path
{ file, path: _path }

getPkg: (pkg) ->
devFileInfo = @getDevFileInfo pkg.name, pkg.main
prodFileInfo = @getProdFileInfo pkg.name, devFileInfo
getPkg: (pkg, loc='rb') ->
devFileInfo = @getDevFileInfo pkg.name, pkg.main, loc
prodFileInfo = @getProdFileInfo pkg.name, devFileInfo, loc
name: pkg.name
version: pkg.version
dev: devFileInfo
@@ -62,9 +64,9 @@ module.exports = (config) ->
fs.writeFileSync file, version
true

forceInstall: -> # technique for users to get bower updates
version = me.get.json.from.rb().version
file = path.join config.src.rb.client.libs.dir, '.bower'
forceInstall: (loc='rb') -> # technique for users to get bower updates
version = me.get.json.from.appOrRb(loc).version
file = path.join config.src[loc].client.libs.dir, '.bower'
if not @isFile file
@writeVersionFile file, version
else
@@ -74,83 +76,91 @@ module.exports = (config) ->

me =
has:
bower: (loc='rb') ->
helper.isFile config.bower[loc].path

installed:
pkg: (pkg) ->
pkg: (pkg, loc='rb') ->
try
fs.lstatSync(
path.join(
config.src.rb.client.libs.dir
config.src[loc].client.libs.dir
pkg
config.json.bower.file
config.bower[loc].file
)
).isFile()
catch e
false
get:
json:
from:
rb: ->
require config.json.bower.path
pkg: (pkg) ->
return if not me.has.installed.pkg pkg
appOrRb: (loc='rb') ->
require config.bower[loc].path

pkg: (pkg, loc='rb') ->
return if not me.has.installed.pkg pkg, loc
# console.log pkg, loc
require(
path.join(
config.src.rb.client.libs.dir
config.src[loc].client.libs.dir
pkg
config.json.bower.file
config.bower[loc].file
)
)

pkgs:
from:
rb: ->
me.get.json.from.rb().dependencies
appOrRb: (loc='rb') ->
me.get.json.from.appOrRb(loc).dependencies
to:
install: (force = false) ->
force = helper.forceInstall() if not force
install: (loc='rb', force=false) ->
return if not me.has.bower loc
force = helper.forceInstall loc if not force
pkgs = []
pkgsObj = me.get.pkgs.from.rb()
pkgsObj = me.get.pkgs.from.appOrRb loc
if force
for own pkg, version of pkgsObj
pkgs.push "#{pkg}##{version}"
else
missing = me.get.missing.pkgs()
missing = me.get.missing.pkgs loc
for own pkg, version of pkgsObj
_pkg = "#{pkg}##{version}"
continue if missing.indexOf(_pkg) is -1
pkgs.push _pkg
pkgs

installed:
pkg: (pkg) ->
pkg = me.get.json.from.pkg pkg
pkg: (pkg, loc='rb') ->
pkg = me.get.json.from.pkg pkg, loc
return if not pkg
helper.getPkg pkg
pkgs: ->
# log.json pkg
helper.getPkg pkg, loc

pkgs: (loc='rb') ->
pkgs = []
pkgsObj = me.get.pkgs.from.rb()
pkgsObj = me.get.pkgs.from.appOrRb loc
for own pkg, version of pkgsObj
_pkg = @pkg pkg
_pkg = @pkg pkg, loc
pkgs.push _pkg if _pkg
pkgs

missing:
pkgs: ->
pkgs = []
rbPkgs = me.get.pkgs.from.rb()
iPkgs = me.get.installed.pkgs()
for own pkg, version of rbPkgs
pkgs: (loc='rb') ->
pkgs = []
jPkgs = me.get.pkgs.from.appOrRb loc
iPkgs = me.get.installed.pkgs loc
for own pkg, version of jPkgs
missing = true
iPkgs.forEach (v) ->
missing = false if v.name is pkg
pkgs.push "#{pkg}##{version}" if missing
pkgs

src: (env) ->
src: (loc='rb', env) ->
return if not me.has.bower loc
env = env or config.env.name
env = 'dev' if ['dev','prod'].indexOf(env) is -1
paths = []
pkgs = me.get.installed.pkgs()
pkgs = me.get.installed.pkgs loc
pkgs.forEach (pkg) ->
paths.push pkg[env].path
paths
@@ -11,6 +11,9 @@ module.exports = (gulp, config) ->

runTask = (src, dest) ->
defer = q.defer()
return if not src or not src.length
defer.resolve()
defer.promise
gulp.src src
.pipe removeMin()
.pipe gulp.dest dest
@@ -19,10 +22,23 @@ module.exports = (gulp, config) ->
defer.resolve()
defer.promise

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

# register task
# =============
gulp.task "#{config.rb.prefix.task}copy-libs", ->
bowerLibs = bowerHelper.get.src()
runTask bowerLibs, config.dist.rb.client.libs.dir
runTasks()


@@ -1,22 +1,20 @@
module.exports = (gulp, config) ->
q = require 'q'
fs = require 'fs'
path = require 'path'
bower = require 'bower'
bowerHelper = require("#{config.req.helpers}/bower") config
bowerPkgs = bowerHelper.get.pkgs.to.install()

gulp.task "#{config.rb.prefix.task}bower", ->
defer = q.defer()
runTask = (appOrRb) ->
defer = q.defer()
bowerPkgs = bowerHelper.get.pkgs.to.install appOrRb

return if not bowerPkgs.length
return if not bowerPkgs or not bowerPkgs.length
defer.resolve()
defer.promise

bower.commands.install bowerPkgs, force: true,
directory: ''
forceLatest: true
cwd: config.src.rb.client.libs.dir
cwd: config.src[appOrRb].client.libs.dir
.on 'log', (result) ->
console.log "bower: #{result.id.cyan} #{result.message.cyan}"
.on 'error', (e) ->
@@ -26,3 +24,14 @@ module.exports = (gulp, config) ->
defer.resolve()

defer.promise

runTasks = ->
defer = q.defer()
q.all([
runTask 'rb'
runTask 'app'
]).done -> defer.resolve()
defer.promise

gulp.task "#{config.rb.prefix.task}bower", ->
runTasks()

0 comments on commit 74825ef

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