Skip to content
Permalink
Browse files

feat(cli option): add cli option --cache-list to display the build's …

…internal cache
  • Loading branch information
jyounce committed Aug 30, 2016
1 parent 8b2311d commit 164ddc4293e3c3e2a043aafc2c670b43341ee430
Showing with 50 additions and 2 deletions.
  1. +3 −2 bin/build.js
  2. +45 −0 src/cli/cache-list.coffee
  3. +2 −0 src/cli/get-cli-opts.coffee
@@ -40,9 +40,10 @@ config.build.generated.path = path.join(BUILD_PATH, 'generated');
************/
require(path.join(config.build.cli.path, 'add-colors'))();
if (config.build.cli.opts.quickStart.length) return require(path.join(config.build.cli.path, 'quick-start'))(config);
if (!!config.build.cli.opts.cacheClean) return require(path.join(config.build.cli.path, 'cache-clean'))(config);
var build = require(path.join(config.build.cli.path, 'get-build'))(config);
if (!!config.build.cli.opts.cacheClean) return require(path.join(config.build.cli.path, 'cache-clean'))(config);
if (!!config.build.cli.opts.cacheList) return require(path.join(config.build.cli.path, 'cache-list'))(config);

var build = require(path.join(config.build.cli.path, 'get-build'))(config);
/**
* Run Build - in the console type one of the following:
* build
@@ -0,0 +1,45 @@
# List the build's cache dirs in generated directory.
# ===================================================
module.exports = (config) ->
cacheList = config.build.cli.opts.cacheList
return unless cacheList

# requires
# ========
fs = require 'fs'
path = require 'path'

# helpers (gen = generated)
# =========================
addGenPathToDirs = (dirs, _path) -> # []
return [] if not dirs or not dirs.length
dirs = (path.join _path, dir for dir in dirs)

getCacheInfo = (_path) -> # {}
cache = dirs: [], paths: []
try
dirs = fs.readdirSync(_path).filter (file) ->
fs.statSync(path.join(_path, file)).isDirectory()
cache.dirs = dirs
cache.paths = addGenPathToDirs dirs, _path
catch e
cache

# vars
# ====
genPath = config.build.generated.path
cacheInfo = getCacheInfo genPath

# task
# ====
logCacheTask = (dirsOrPaths) -> # void
if not dirsOrPaths or not dirsOrPaths.length
msg = "#{config.build.pkg.name}'s cache is clean"
return console.log msg.attn

for val, i in dirsOrPaths
console.log "#{i+1}) #{val}".attn

# return
# ======
logCacheTask cacheInfo.dirs
@@ -29,12 +29,14 @@ module.exports = (config) ->
.version config.build.pkg.version
.option '-s, --skip-options [opts]', 'skip build option(s) ex: dev,prod', list, []
.option '--cache-clean [opt]', "cleans #{config.build.pkg.name}'s internal cache for an app, optionally provide * to clean internal cache for all apps"
.option '--cache-list', "list #{config.build.pkg.name}'s internal cache for all apps"
.option '--quick-start [location]', 'creates a simple application structure with a couple files. optional location: client or server. defaults to both'
.parse process.argv

# return
# ======
opts =
cacheClean: getCacheClean program.cacheClean # bool | '*'
cacheList: program.cacheList # options n/a
quickStart: getQuickStart program.quickStart # []
skipOpts: program.skipOptions # []

0 comments on commit 164ddc4

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