Skip to content
Permalink
Browse files

feat(config): add ability to change angular version via config

  • Loading branch information
jyounce committed Jun 9, 2015
1 parent 24f761d commit 2f6e2690d7dfc041030399b9a65e972059dd2ee7
@@ -46,26 +46,29 @@ gulp rapid-build:prod
##### Config Documentation - (better documentation coming soon)
```coffeescript
# CONFIG API (optional): config is an object
# 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 of strings) = file paths
# angular.modules = (array of strings) = additional angular modules to load, already loaded are ['ngAnimate', 'ngResource', 'ngRoute', 'ngSanitize']
# angular.moduleName = (string) defaults to 'app' = application module name, value for ng-app
# angular.templateCache.dev.enable = (boolean) defaults to false = use template cache when running default and dev task
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false = prefix template urls with a '/'
# spaFile.title = (string) defaults to package.json name or 'Application'
# 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.libs.dir = (string) defaults to 'libs' = bower components directory
# 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.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array of strings) = file paths
# angular.modules = (array of strings) = additional angular modules to load, already loaded are ['ngResource', 'ngRoute', 'ngSanitize']
# angular.moduleName = (string) defaults to 'app' = application module name, value for ng-app
# angular.version = (string) defaults to '1.x' = semver version required
# angular.templateCache.dev.enable = (boolean) defaults to false = use template cache when running default and dev task
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false = prefix template urls with a '/'
# spaFile.title = (string) defaults to package.json name or 'Application'
# spaFile.description = (string) defaults to package.json description
# ===================================================================================================================================================================
```


This file was deleted.

@@ -4,7 +4,7 @@ module.exports = (config, options) ->

# default modules
# ===============
modules = ['ngAnimate', 'ngResource', 'ngRoute', 'ngSanitize']
modules = ['ngResource', 'ngRoute', 'ngSanitize']

# init angular
# ============
@@ -17,7 +17,7 @@ module.exports = (config, options) ->

# version
# =======
angular.version = options.angular.version or null
angular.version = options.angular.version or '1.x'

# module name
# ===========
@@ -30,6 +30,14 @@ module.exports = (config, options) ->
angular.templateCache.dev.enable = options.angular.templateCache.dev.enable or false
angular.templateCache.useAbsolutePaths = options.angular.templateCache.useAbsolutePaths or false

# bower dependencies
# ==================
angular.bowerDeps =
'angular': angular.version
'angular-resource': angular.version
'angular-route': angular.version
'angular-sanitize': angular.version

# add angular to config
# =====================
config.angular = angular
@@ -9,7 +9,7 @@ module.exports = (config, options) ->
src: 'src'
client: 'client'
images: 'images'
libs: 'libs' # things like bower_components
libs: 'libs' # bower_components
server: 'server'
scripts: 'scripts'
styles: 'styles'
@@ -127,17 +127,6 @@ module.exports = (config, options) ->
file: file.spa
path: getSrcSpa()

# relative paths (old sauce)
# ==========================
addAppRelative = (loc, loc2, type) ->
a = options[loc].dir or dir[loc]
b = options[loc][loc2].dir or dir[loc2]
c = options[loc][loc2][type].dir or dir[type]
path.join a, b, c

# config.src.rb.client.libs.relative = path.join dir.src, dir.client, dir.libs
# config.src.app.client.libs.relative = addAppRelative 'src', 'client', 'libs'

# server
# ======
removeServerDir = ->
@@ -36,7 +36,6 @@ module.exports = (config, options) ->
# ========
order.rb.scripts.first = [
"#{rb.libs}/angular"
"#{rb.libs}/angular-animate"
"#{rb.libs}/angular-resource"
"#{rb.libs}/angular-route"
"#{rb.libs}/angular-sanitize"
@@ -9,12 +9,24 @@ module.exports = (config) ->
# ==============
templates = {}
templates.dir = path.join config.rb.dir, 'templates'

# angular modules
# ===============
templates.angularModules =
src:
path: path.join templates.dir, 'angular-modules.tpl'
dest:
file: 'app.coffee'
dir: path.join config.src.rb.client.scripts.dir
dir: config.src.rb.client.scripts.dir

# bower.json
# ==========
templates.bowerJson =
src:
path: path.join templates.dir, 'bower-json.tpl'
dest:
file: 'bower.json'
dir: config.rb.dir

# add templates to config
# =======================
@@ -13,20 +13,16 @@
module.exports = (config) ->
fs = require 'fs'
path = require 'path'
del = require 'del'
mkdirp = require 'mkdirp'
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
pathHelp = require "#{config.req.helpers}/path"
fileHelp = require("#{config.req.helpers}/file")()

# helpers
# =======
helper =
isFile: (_path) ->
try
fs.lstatSync(_path).isFile()
catch e
false

getPath: (pkgName, file, loc='rb') ->
path.join(
config.src[loc].client.libs.dir
@@ -61,7 +57,7 @@ module.exports = (config) ->
files.forEach (file) =>
_file = @getProdFile file.file
_path = @getPath pkgName, _file, loc
if not @isFile _path
if not fileHelp.exists _path
_files.push file
else
_files.push file: _file, path: _path
@@ -108,39 +104,53 @@ module.exports = (config) ->
pkgs.push _pkg if _pkg
pkgs

writeVersionFile: (file, version) ->
fs.writeFileSync file, version
true
depsHaveChanged: (bowerJson, storedJson) ->
changed = false
bDeps = bowerJson.dependencies
sDeps = storedJson.dependencies
bDepsTot = Object.keys(bDeps).length
sDepsTot = Object.keys(sDeps).length
return true if bDepsTot isnt sDepsTot
for own pkg, version of bDeps
if not sDeps[pkg] or sDeps[pkg] isnt version
changed = true; break
changed

forceInstall: (loc='rb') -> # technique for users to get bower updates
version = me.get.json.from.appOrRb(loc).version
dir = config.src[loc].client.libs.dir
mkdirp.sync dir
file = path.join dir, '.bower'
if not @isFile file
@writeVersionFile file, version
force = false
bowerJson = me.get.json.from.appOrRb(loc)
dir = config.src[loc].client.libs.dir
_path = path.join dir, '.bower'

if not fileHelp.exists _path
force = true
else
storedVersion = fs.readFileSync(file).toString()
return false if storedVersion is version
@writeVersionFile file, version
storedJson = fileHelp.read.json _path
if bowerJson.version isnt storedJson.version
force = true
else if @depsHaveChanged bowerJson, storedJson
force = true
if force
del.sync dir, force:true
console.log "#{loc} libs directory cleaned".yellow

mkdirp.sync dir
fileHelp.write.json _path, bowerJson if force
force

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

installed:
pkg: (pkg, loc='rb') ->
try
fs.lstatSync(
path.join(
_path = path.join(
config.src[loc].client.libs.dir
pkg
config.bower[loc].file
)
).isFile()
catch e
false
fileHelp.exists _path
get:
json:
from:
@@ -0,0 +1,24 @@
module.exports = ->
fs = require 'fs'

exists: (_path) ->
try
fs.lstatSync(_path).isFile()
catch e
false

read:
json: (_path) ->
data = fs.readFileSync(_path).toString()
JSON.parse data

write:
json: (_path, data, pretty=true) ->
if pretty
data = JSON.stringify data, null, '\t'
else
data = JSON.stringify data
fs.writeFileSync _path, data



@@ -11,6 +11,7 @@ module.exports = (gulp, config) ->
# build
# =====
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-bower-json") gulp, config # build-bower-json
require("#{config.req.tasks}/build/build-config") gulp, config # build-config
require("#{config.req.tasks}/build/build-files") gulp, config # build-files
require("#{config.req.tasks}/build/build-files-prod") gulp, config # build-files-prod
@@ -0,0 +1,37 @@
module.exports = (gulp, config) ->
q = require 'q'
rename = require 'gulp-rename'
template = require 'gulp-template'

# task
# ====
runTask = (src, dest, file, data={}) ->
defer = q.defer()
gulp.src src
.pipe rename file
.pipe template data
.pipe gulp.dest dest
.on 'end', ->
# console.log 'bower.json built'.yellow
defer.resolve()
defer.promise

# helpers
# =======
getData = ->
version = '0.0.0'
deps = config.angular.bowerDeps
total = Object.keys(deps).length
data = { version, deps, total }

# register task
# =============
gulp.task "#{config.rb.prefix.task}build-bower-json", ->
data = getData()
runTask(
config.templates.bowerJson.src.path
config.templates.bowerJson.dest.dir
config.templates.bowerJson.dest.file
data
)

@@ -35,5 +35,6 @@ module.exports = (gulp, config) ->

# register task
# =============
gulp.task "#{config.rb.prefix.task}bower", ->
gulp.task "#{config.rb.prefix.task}bower",
["#{config.rb.prefix.task}build-bower-json"], ->
runTasks()
@@ -0,0 +1,7 @@
{<% var cnt = 1; %>
"name": "rapid-build",
"version": "<%= version %>",
"dependencies": {<% _.forEach(deps, function(version, dep) { %>
"<%= dep %>": "<%= version %>"<% if (total != cnt++) { %>,<% }}); %>
}
}

0 comments on commit 2f6e269

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