Skip to content

Commit

Permalink
feat(angular): add template cache options dev.enable and useAbsoluteP…
Browse files Browse the repository at this point in the history
…aths to config
  • Loading branch information
jyounce committed Jun 5, 2015
1 parent c31dae6 commit dc48e5b
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 139 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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
# ======================================================================================
```

Expand Down
3 changes: 2 additions & 1 deletion config/config-angular.coffee
Expand Up @@ -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
Expand Down
27 changes: 12 additions & 15 deletions config/config-file-names.coffee
Expand Up @@ -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
# ======================
Expand Down
5 changes: 3 additions & 2 deletions config/config-options.coffee
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 6 additions & 11 deletions config/config-temp.coffee
Expand Up @@ -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
# =========
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion init/tasks.coffee
Expand Up @@ -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
# ======
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tasks/clean/cleanup-client.coffee
Expand Up @@ -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}/**/*"
Expand Down
2 changes: 1 addition & 1 deletion tasks/common.coffee
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions tasks/copy/copy-views.coffee
@@ -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

19 changes: 1 addition & 18 deletions tasks/minify/concat-all-files.coffee
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion tasks/minify/minify-client.coffee
Expand Up @@ -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"
]
Expand Down
79 changes: 0 additions & 79 deletions tasks/minify/minify-html.coffee

This file was deleted.

11 changes: 7 additions & 4 deletions tasks/minify/minify-images.coffee
@@ -1,5 +1,6 @@
module.exports = (gulp, config) ->
q = require 'q'
q = require 'q'
path = require 'path'

moveTask = (src, dest) ->
defer = q.defer()
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions tasks/minify/template-cache.coffee
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit dc48e5b

Please sign in to comment.