diff --git a/bin/build.js b/bin/build.js index 817f109..b664b24 100755 --- a/bin/build.js +++ b/bin/build.js @@ -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 diff --git a/src/cli/cache-list.coffee b/src/cli/cache-list.coffee new file mode 100644 index 0000000..ba04494 --- /dev/null +++ b/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 diff --git a/src/cli/get-cli-opts.coffee b/src/cli/get-cli-opts.coffee index c77c2d8..d499b6a 100644 --- a/src/cli/get-cli-opts.coffee +++ b/src/cli/get-cli-opts.coffee @@ -29,6 +29,7 @@ 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 @@ -36,5 +37,6 @@ module.exports = (config) -> # ====== opts = cacheClean: getCacheClean program.cacheClean # bool | '*' + cacheList: program.cacheList # options n/a quickStart: getQuickStart program.quickStart # [] skipOpts: program.skipOptions # []