Skip to content

Commit

Permalink
feat(cli option): add cli option --cache-list to display the build's …
Browse files Browse the repository at this point in the history
…internal cache
  • Loading branch information
jyounce committed Aug 30, 2016
1 parent 8b2311d commit 164ddc4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin/build.js
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions src/cli/cache-list.coffee
@@ -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
2 changes: 2 additions & 0 deletions src/cli/get-cli-opts.coffee
Expand Up @@ -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.