Skip to content
Permalink
Browse files

feat(build option dist.pack): disabled by default, enable to pack/cre…

…ate a zip, tar or tgz file from the dist directory once the build completes
  • Loading branch information
jyounce committed Feb 9, 2017
1 parent ada6fbe commit 729ef3d11370d1c08f3f3c7ccdde00abfddae14c
@@ -75,6 +75,7 @@
"gulp-coffee": "2.3.3",
"gulp-concat": "2.6.1",
"gulp-cssnano": "2.1.2",
"gulp-gzip": "1.4.0",
"gulp-htmlmin": "3.0.0",
"gulp-if": "2.0.2",
"gulp-jsonminify": "1.0.0",
@@ -85,11 +86,13 @@
"gulp-replace": "0.5.4",
"gulp-sass": "3.1.0",
"gulp-sequence": "0.4.6",
"gulp-tar": "1.9.0",
"gulp-template": "4.0.0",
"gulp-typescript": "2.13.6",
"gulp-uglify": "2.0.1",
"gulp-util": "3.0.8",
"gulp-watch": "4.3.11",
"gulp-zip": "4.0.0",
"jasmine": "2.5.1",
"jasmine-core": "2.5.2",
"jasmine-expect": "3.5.0",
@@ -1,6 +1,8 @@
module.exports = (config, options) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
path = require 'path'
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
pathHelp = require "#{config.req.helpers}/path"

# defaults
# ========
@@ -202,6 +204,74 @@ module.exports = (config, options) ->
config.dist.client.paths = {}
config.dist.client.paths.absolute = if options.dist.client.paths.absolute is null then true else !!options.dist.client.paths.absolute

# pack dist helpers
# =================
pack =
format:
opts: { 'tar', 'tgz', 'zip' }
get:
base: (includeBase) ->
return '.' if includeBase # pack dist folder and contents
config.dist.dir # pack dist contents

format: (format='zip') ->
format = format.toLowerCase()
format = pack.format.opts[format]
return pack.format.opts.zip unless format
format

fileName: (format, fileName='dist') -> # return ex: dist.zip
formatExt = ".#{format}"
fileName = path.basename fileName, formatExt
"#{fileName}.#{format}"

filePath: (fileName) -> # place file in project root
path.join config.app.dir, fileName


glob: (glob='**') -> # glob: string | string[]
glob = if isType.stringArray glob
then @globPatterns glob
else @globPattern glob
# console.log 'GLOB:'.info, glob
glob

globPattern: (glob) -> # glob pattern: string
negate = '!'
glob = glob.trim()
return glob unless glob.length
isNegated = glob[0] is negate
glob = glob.slice 1 if isNegated
glob = path.join config.dist.dir, glob # prepend dist directory name
glob = pathHelp.format glob # glob needs forward back slashes
glob = "#{negate}#{glob}" if isNegated # prepend !
glob

globPatterns: (glob) -> # string[pattern]
return glob unless glob.length
for v, i in glob
glob[i] = @globPattern v
glob

isFormatMap: (fileName) -> # return: {} of is format flags
map = {}
for own key, val of pack.format.opts
map[key] = fileName.indexOf(".#{val}") != -1
map.gzip = map.tgz # extra info
map

# pack dist (in order)
# ====================
config.dist.pack = {}
config.dist.pack.enabled = if options.dist.pack.enable is null then false else options.dist.pack.enable
config.dist.pack.format = pack.get.format options.dist.pack.format
config.dist.pack.fileName = pack.get.fileName config.dist.pack.format, options.dist.pack.fileName
config.dist.pack.filePath = pack.get.filePath config.dist.pack.fileName
config.dist.pack.glob = pack.get.glob options.dist.pack.glob
config.dist.pack.includeBase = if options.dist.pack.includeBase is null then false else options.dist.pack.includeBase
config.dist.pack.base = pack.get.base config.dist.pack.includeBase
config.dist.pack.is = pack.get.isFormatMap config.dist.pack.fileName

# logs
# ====
# log.json config.dist, 'config.dist ='
@@ -29,6 +29,15 @@ module.exports = (config, options) ->
options.dist.client.paths = {} unless isType.object options.dist.client.paths
options.dist.client.paths.absolute = null unless isType.boolean options.dist.client.paths.absolute

# pack dist
# =========
options.dist.pack = {} unless isType.object options.dist.pack
options.dist.pack.enable = null unless isType.boolean options.dist.pack.enable
options.dist.pack.format = null unless isType.string options.dist.pack.format
options.dist.pack.fileName = null unless isType.string options.dist.pack.fileName
options.dist.pack.glob = null unless isType.string(options.dist.pack.glob) or isType.stringArray options.dist.pack.glob
options.dist.pack.includeBase = null unless isType.boolean options.dist.pack.includeBase

# return
# ======
options
@@ -28,5 +28,11 @@ module.exports =
string: (v) ->
typeof v is 'string'

stringArray: (v) -> # v should be an array of strings
return false unless @array v
for val in v
return false unless @string val
true

undefined: (v) ->
v is undefined

0 comments on commit 729ef3d

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