Skip to content
Permalink
Browse files

feat(angular): add template cache options dev.enable and useAbsoluteP…

…aths to config
  • Loading branch information
jyounce committed Jun 5, 2015
1 parent c31dae6 commit dc48e5b29b21a59a21d23b4a3f9da4fd2b8a1e43
@@ -59,6 +59,8 @@ gulp rapid-build:prod
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array of strings) file paths
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# ======================================================================================
```

@@ -21,7 +21,8 @@ module.exports = (config, options) ->
# template cache
# ==============
angular.templateCache = {}
angular.templateCache.devEnable = options.angular.templateCache.devEnable or false
angular.templateCache.dev = {}
angular.templateCache.dev.enable = options.angular.templateCache.dev.enable or false
angular.templateCache.useAbsolutePaths = options.angular.templateCache.useAbsolutePaths or false

# add angular to config
@@ -2,21 +2,18 @@ module.exports = (config) ->
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init fileName
# =============
fileName = {}
fileName.scripts = {}
fileName.styles = {}
fileName.views = {}

# names
# =====
fileName.scripts.all = 'all.js'
fileName.styles.all = 'all.css'
fileName.views.main = 'views.js'
fileName.scripts.min = 'scripts.min.js'
fileName.styles.min = 'styles.min.js'
fileName.views.min = 'views.min.js'
# init fileName (used in config-temp.coffee)
# ==========================================
fileName =
scripts:
all: 'all.js'
min: 'scripts.min.js'
styles:
all: 'all.css'
min: 'styles.min.css'
views:
main: 'views.js'
min: 'views.min.js'

# add fileName to config
# ======================
@@ -15,7 +15,7 @@
# angular.modules = (array) additional angular modules
# angular.version = (string) defaults to '1.4.x'
# angular.moduleName = (string) application module name
# angular.templateCache.devEnable = (boolean) defaults to false
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# ========================================================================================
module.exports = (config, options) ->
@@ -65,8 +65,9 @@ module.exports = (config, options) ->
options.angular.version = null if not isType.string options.angular.version
options.angular.moduleName = null if not isType.string options.angular.moduleName
options.angular.templateCache = {} if not isType.object options.angular.templateCache
options.angular.templateCache.devEnable = null if not isType.boolean options.angular.templateCache.devEnable
options.angular.templateCache.useAbsolutePaths = null if not isType.boolean options.angular.templateCache.useAbsolutePaths
options.angular.templateCache.dev = {} if not isType.object options.angular.templateCache.dev
options.angular.templateCache.dev.enable = null if not isType.boolean options.angular.templateCache.dev.enable

formatOptions()
formatServerOptions()
@@ -5,16 +5,9 @@ module.exports = (config) ->

# constants
# =========
tDir = '.temp'
types =
styles:
all: 'all.css'
min: 'styles.min.css'
scripts:
all: 'all.js'
min: 'scripts.min.js'
views:
min: 'views.min.js'
tDir = '.temp'
types = ['scripts', 'styles']
files = ['all', 'min']

# init temp
# =========
@@ -25,12 +18,14 @@ module.exports = (config) ->
# add types
# =========
addTypes = ->
for own k1, v1 of types
for own k1, v1 of config.fileName
continue if types.indexOf(k1) is -1
temp.client[k1] = {}
temp.client[k1].dir =
path.join temp.client.dir,
config.dist.app.client[k1].dirName
for own k2, v2 of v1
continue if files.indexOf(k2) is -1
temp.client[k1][k2] = {}
temp.client[k1][k2].file = v2
temp.client[k1][k2].path =
@@ -41,6 +41,7 @@ module.exports = (gulp, config) ->
require("#{config.req.tasks}/copy/copy-libs") gulp, config # copy-libs
require("#{config.req.tasks}/copy/copy-server-config") gulp, config # copy-server-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

# manage
# ======
@@ -52,7 +53,6 @@ module.exports = (gulp, config) ->
require("#{config.req.tasks}/minify/concat-app-files") gulp, config # concat-app-files
require("#{config.req.tasks}/minify/minify-client") gulp, config # minify-client
require("#{config.req.tasks}/minify/minify-css") gulp, config # minify-css
require("#{config.req.tasks}/minify/minify-html") gulp, config # minify-html
require("#{config.req.tasks}/minify/minify-images") gulp, config # minify-images
require("#{config.req.tasks}/minify/minify-js") gulp, config # minify-js
require("#{config.req.tasks}/minify/minify-server") gulp, config # minify-server
@@ -24,14 +24,12 @@ module.exports = (gulp, config) ->
-> delTask [
config.temp.client.styles.all.path
config.temp.client.scripts.all.path
config.temp.client.views.dir
]
-> delTask [
config.glob.dist.rb.client.all
config.glob.dist.app.client.libs.all
config.glob.dist.app.client.scripts.all
config.glob.dist.app.client.styles.all
config.glob.dist.app.client.views.all
]
-> moveTask(
"#{config.temp.client.dir}/**/*"
@@ -11,7 +11,7 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}build-config"
[
"#{config.rb.prefix.task}copy-css"
"#{config.rb.prefix.task}copy-html"
"#{config.rb.prefix.task}copy-views"
"#{config.rb.prefix.task}copy-images"
"#{config.rb.prefix.task}copy-js"
"#{config.rb.prefix.task}copy-libs"
@@ -0,0 +1,15 @@
module.exports = (gulp, config) ->
gulpSequence = require('gulp-sequence').use gulp

# register task
# =============
gulp.task "#{config.rb.prefix.task}copy-views", (cb) ->
if config.env.name is 'prod'
task = 'template-cache'
else if config.angular.templateCache.dev.enable
task = 'template-cache'
else
task = 'copy-html'

gulpSequence "#{config.rb.prefix.task}#{task}", cb

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

concatViews = (src, dest, file, viewsFile) ->
defer = q.defer()
gulp.src src
.pipe concat file
.pipe gulp.dest dest
.on 'end', ->
console.log "added #{viewsFile} to #{file}".yellow
defer.resolve()
defer.promise

runTasks = (loc, exclude) ->
defer = q.defer()
client = require(config.json.files.path).client
@@ -48,14 +38,7 @@ module.exports = (gulp, config) ->
loc.scripts.min.file
'script'
)
]).done ->
# angular templatecache views
concatViews(
[loc.scripts.min.path, loc.views.min.path]
loc.scripts.dir
loc.scripts.min.file
loc.views.min.file
).done -> defer.resolve()
]).done -> defer.resolve()
defer.promise

# register task
@@ -8,7 +8,6 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}concat-app-files"
[
"#{config.rb.prefix.task}minify-css"
"#{config.rb.prefix.task}minify-html"
"#{config.rb.prefix.task}minify-images"
"#{config.rb.prefix.task}minify-js"
]

This file was deleted.

@@ -1,5 +1,6 @@
module.exports = (gulp, config) ->
q = require 'q'
q = require 'q'
path = require 'path'

moveTask = (src, dest) ->
defer = q.defer()
@@ -13,9 +14,11 @@ module.exports = (gulp, config) ->
# register task
# =============
gulp.task "#{config.rb.prefix.task}minify-images", ->
rbImgDest = config.temp.client.dir + '/' +
config.rb.prefix.distDir + '/' +
config.dist.rb.client.images.dirName
rbImgDest = path.join(
config.temp.client.dir
config.rb.prefix.distDir
config.dist.rb.client.images.dirName
)
moveTask(
"#{config.glob.dist.rb.client.images.all}/*"
rbImgDest
@@ -3,7 +3,6 @@ module.exports = (gulp, config) ->
path = require 'path'
es = require 'event-stream'
gulpif = require 'gulp-if'
minifyJs = require 'gulp-uglify'
minifyHtml = require 'gulp-minify-html'
templateCache = require 'gulp-angular-templatecache'

@@ -47,7 +46,6 @@ module.exports = (gulp, config) ->
.pipe addToDistPath()
.pipe gulpif isProd, minifyHtml()
.pipe templateCache file, opts
.pipe gulpif isProd, minifyJs()
.pipe gulp.dest dest
.on 'end', ->
console.log "created #{file}".yellow
@@ -59,9 +57,8 @@ module.exports = (gulp, config) ->
gulp.task "#{config.rb.prefix.task}template-cache", ->
isProd = config.env.name is 'prod'
file = if isProd then 'min' else 'main'
dest = if isProd then config.temp else config.dist.rb
file = config.fileName.views[file]
dest = dest.client.scripts.dir
dest = config.dist.rb.client.scripts.dir
src = [ glob.views.rb, glob.views.app ]
runTask src, dest, file, isProd

0 comments on commit dc48e5b

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