Skip to content
Permalink
Browse files

feat(options): add options spa.exclude.scripts and styles, exclude fr…

…om spa.html file and min files
  • Loading branch information
jyounce committed Jun 30, 2015
1 parent 395cd37 commit 5273bb602445ee3cb8256feb76f600e4025db58e
@@ -125,6 +125,8 @@ gulp rapid-build:prod
# spa.src.dir = (string) defaults to null = set if you are using your own spa file and that file is located in a directory in your client src directory
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html' = provide if you want the dist spa file to be named differently, example: 'index.html'
# spa.placeholders = (array of strings) = set to retain spa file placeholders, optional values are: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# spa.exclude.scripts = (array of strings) = file paths: exclude files from automatically being generated in the spa.html and scripts.min.js file
# spa.exclude.styles = (array of strings) = file paths: exclude files from automatically being generated in the spa.html and styles.min.css file
# minify.css.styles = (boolean) defaults to true = for prod build, minify the css
# minify.html.views = (boolean) defaults to true = for prod build, minify the html
# minify.html.templateCache = (boolean) defaults to true = for prod build, use the template cache
@@ -30,12 +30,14 @@
# spa.src.dir = (string) defaults to null
# spa.dist.file = (string) defaults to spa.src.file or 'spa.html'
# spa.placeholders = (array of strings) = optionals: ['scripts', 'styles', 'description', 'moduleName', 'title'] or ['all']
# spa.exclude.scripts = (array of strings) = file paths: exclude files from automatically being generated in the spa.html and scripts.min.js file
# spa.exclude.styles = (array of strings) = file paths: exclude files from automatically being generated in the spa.html and styles.min.css file
# minify.css.styles = (boolean) defaults to true
# minify.html.views = (boolean) defaults to true
# minify.html.templateCache = (boolean) defaults to true
# minify.js.scripts = (boolean) defaults to true
# minify.js.mangle = (boolean) defaults to true
# =====================================================================================================================================================
# =========================================================================================================================================================================
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
@@ -93,11 +95,14 @@ module.exports = (config, options) ->
options.spa.title = null if not isType.string options.spa.title
options.spa.description = null if not isType.string options.spa.description
options.spa.src = {} if not isType.object options.spa.src
options.spa.dist = {} if not isType.object options.spa.dist
options.spa.placeholders = null if not isType.array options.spa.placeholders
options.spa.src.dir = null if not isType.string options.spa.src.dir
options.spa.src.file = null if not isType.string options.spa.src.file
options.spa.dist = {} if not isType.object options.spa.dist
options.spa.dist.file = null if not isType.string options.spa.dist.file
options.spa.placeholders = null if not isType.array options.spa.placeholders
options.spa.exclude = {} if not isType.object options.spa.exclude
options.spa.exclude.scripts = null if not isType.array options.spa.exclude.scripts
options.spa.exclude.styles = null if not isType.array options.spa.exclude.styles

minifyOptions = ->
options.minify = {} if not isType.object options.minify
@@ -48,6 +48,26 @@ module.exports = (config, options) ->
# ============
spa.placeholders = options.spa.placeholders or []

# exclude
# =======
spa.exclude =
rb:
scripts: []
styles: []
app:
scripts: options.spa.exclude.scripts or []
styles: options.spa.exclude.styles or []

formatExcludes = ->
for own k1, v1 of spa.exclude
for own k2, v2 of v1
continue if not v2.length
v2.forEach (v3, i) ->
v2[i] = path.join config.dist[k1].client.dir, v3
v2[i] = "!#{v2[i]}"

formatExcludes()

# add spa to config
# =================
config.spa = spa
@@ -0,0 +1,71 @@
module.exports = (config) ->
fs = require 'fs'
path = require 'path'
log = require "#{config.req.helpers}/log"

# helpers
# =======
getDirsRecursively = (_path, _dirs=[]) ->
try
filenames = fs.readdirSync _path
catch e
console.log e.message.error
return _dirs
return _dirs if not filenames.length
for filePath in filenames
newPath = path.join _path, filePath
continue if not fs.statSync(newPath).isDirectory()
_dirs.push newPath
getDirsRecursively newPath, _dirs
_dirs

filter = (dirs, filterPaths) ->
_dirs = []
for _path in dirs
flag = false
for fPath in filterPaths
if _path.indexOf(fPath) isnt -1 then flag = true; break
_dirs.push _path if not flag
_dirs

# API
# ===
filter:
dirs: filter

get:
dirs: (initPath, filterPaths=[], reverse) ->
dirs = getDirsRecursively initPath
dirs = filter dirs, filterPaths if filterPaths.length
dirs.reverse() if reverse is 'reverse'
# log.json dirs
dirs

emptyDirs: (initPath, filterPaths=[], reverse) ->
dirs = @dirs initPath, filterPaths, reverse
return dirs if not dirs.length
_dirs = []
fileDirs = {}

for _path in dirs
filenames = fs.readdirSync _path
for filePath, i in filenames
newPath = path.join _path, filePath
continue if not fs.statSync(newPath).isFile()
fileDirs[_path] = i + 1 # total files

return dirs if not Object.keys(fileDirs).length

for _path in dirs
flag = false
for own k, v of fileDirs
if k.indexOf(_path) isnt -1 then flag = true; break
_dirs.push _path if not flag

_dirs






@@ -22,16 +22,28 @@ module.exports = (gulp, config) ->

# globs
# =====
getExcludes = (appOrRb, type, glob) ->
return glob if not config.spa.exclude[appOrRb][type].length
glob = glob.concat config.spa.exclude[appOrRb][type]
glob

getGlob = (type, lang) ->
glob = pathHelp.format config.dist.app.client[type].dir
glob += "/**/*#{lang}"
glob = [
pathHelp.format config.dist.rb.client[type].dir
pathHelp.format config.dist.app.client[type].dir
]
for g, i in glob
glob[i] += "/**/*.#{lang}"
glob = getExcludes 'rb', type, glob
glob = getExcludes 'app', type, glob
glob

# helpers
# =======
processFiles = (files) ->
locDir = pathHelp.format(config.app.dir) + '/'
appDir = pathHelp.format(config.app.dir) + '/'
files.forEach (v, i) ->
files[i] = pathHelp.format(files[i]).replace locDir, ''
files[i] = pathHelp.format(files[i]).replace appDir, ''
files

addData = (type, files) ->
@@ -1,12 +1,19 @@
# BUILD CLIENT FILES
# client:
# styles: []
# scripts: []
# ===================
module.exports = (gulp, config) ->
q = require 'q'
path = require 'path'
gs = require 'glob-stream'
rename = require 'gulp-rename'
template = require 'gulp-template'
pathHelp = require "#{config.req.helpers}/path"
log = require "#{config.req.helpers}/log"
format = require("#{config.req.helpers}/format")()
data = client: styles:[], scripts:[]
globs = null

# task
# ====
@@ -30,23 +37,32 @@ module.exports = (gulp, config) ->

# globs
# =====
getGlob = (loc, type, lang) ->
config.glob.dist[loc].client[type][lang]
getExcludes = (appOrRb, type, glob) ->
return glob if not config.spa.exclude[appOrRb][type].length
glob = glob.concat config.spa.exclude[appOrRb][type]
# log.json glob, "#{appOrRb} #{type}"
glob

globs =
css:
rb: getGlob 'rb', 'styles', 'css'
app: getGlob 'app', 'styles', 'css'
js:
rb: getGlob 'rb', 'scripts', 'js'
app: getGlob 'app', 'scripts', 'js'
getGlob = (appOrRb, type, lang) ->
glob = config.glob.dist[appOrRb].client[type][lang]
glob = getExcludes appOrRb, type, glob
glob

setGlobs = ->
globs =
css:
rb: getGlob 'rb', 'styles', 'css'
app: getGlob 'app', 'styles', 'css'
js:
rb: getGlob 'rb', 'scripts', 'js'
app: getGlob 'app', 'scripts', 'js'

# helpers
# =======
processFiles = (files) ->
locDir = pathHelp.format(config.app.dir) + '/'
appDir = pathHelp.format(config.app.dir) + '/'
files.forEach (v, i) ->
files[i] = pathHelp.format(files[i]).replace locDir, ''
files[i] = pathHelp.format(files[i]).replace appDir, ''
files

addData = (type, files) ->
@@ -65,18 +81,19 @@ module.exports = (gulp, config) ->
defer.promise

getAllFiles = (type, lang) -> # sync
tasks = []
defer = q.defer()
locs = Object.keys globs[lang]
tasks = []
defer = q.defer()
appAndRb = Object.keys globs[lang]

locs.forEach (loc) ->
appAndRb.forEach (appOrRb) ->
tasks.push ->
getFiles type, globs[lang][loc]
getFiles type, globs[lang][appOrRb]

tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

buildData = -> # async
setGlobs()
q.all [
getAllFiles 'styles', 'css'
getAllFiles 'scripts', 'js'
@@ -1,14 +1,69 @@
module.exports = (gulp, config) ->
q = require 'q'
del = require 'del'
q = require 'q'
del = require 'del'
path = require 'path'
log = require "#{config.req.helpers}/log"
dirHelper = require("#{config.req.helpers}/dir") config

# globs
# =====
globs =
del:
temp:
dir: config.temp.client.dir
paths: [
config.temp.client.scripts.glob
config.temp.client.styles.glob
"!#{config.temp.client.scripts.min.path}"
"!#{config.temp.client.styles.min.path}"
]
dist:
paths: [
"#{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}/*.*"
]
# helpers
# =======
getExcludes = ->
[].concat(
config.spa.exclude.rb.scripts
config.spa.exclude.rb.styles
config.spa.exclude.app.scripts
config.spa.exclude.app.styles
)

getDirDelSrc = ->
src = globs.del.dist.paths
excludes = getExcludes()
src = src.concat excludes
src

# tasks
# =====
delTask = (src) ->
defer = q.defer()
del src, force:true, (e) ->
del src, force:true, ->
# console.log 'cleanup complete'.yellow
defer.resolve()
defer.promise

delTaskDirs = (src) ->
defer = q.defer()
appDir = path.join config.app.dir, '/'
del src, force:true, ->
emptyDirs = dirHelper.get.emptyDirs(
config.dist.app.client.dir
[ config.temp.client.dir ]
'reverse'
)
del emptyDirs, force:true, ->
console.log 'client dist cleanup complete'.yellow
defer.resolve()
defer.promise

moveTask = (src, dest) ->
defer = q.defer()
gulp.src src
@@ -21,24 +76,10 @@ module.exports = (gulp, config) ->
runTasks = -> # synchronously
defer = q.defer()
tasks = [
-> delTask [
config.temp.client.scripts.glob
config.temp.client.styles.glob
"!#{config.temp.client.scripts.min.path}"
"!#{config.temp.client.styles.min.path}"
]
-> 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
]
-> moveTask(
config.temp.client.glob
config.dist.app.client.dir
)
-> delTask config.temp.client.dir
-> delTask globs.del.temp.paths
-> delTaskDirs getDirDelSrc()
-> moveTask config.temp.client.glob, config.dist.app.client.dir
-> delTask globs.del.temp.dir
]
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

0 comments on commit 5273bb6

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