Skip to content

Commit

Permalink
feat(cli): List files to be published
Browse files Browse the repository at this point in the history
  • Loading branch information
James Womack committed May 13, 2016
1 parent 86ba947 commit c509791
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

'use strict'; // force block-scoping

const
Undertaker = require('undertaker'),
colors = require('chalk'),
Expand All @@ -8,7 +10,8 @@ const
values = require('object-values'),
vinylFS = require('vinyl-fs'),
writeChangelog = require('./lib/changelog'),
Deploy = require('./lib/deploy')
Deploy = require('./lib/deploy'),
ls = require('./lib/ls')

// Module-level CLI globals
var
Expand Down Expand Up @@ -57,6 +60,10 @@ taskManager.task(CHANGELOG_WRITE, function (done) {
}
})

taskManager.task('ls', function () {
return ls()
})

taskManager.task(CHANGELOG_COMMIT, function () {
if (isDryRun) {
return true
Expand Down Expand Up @@ -110,6 +117,11 @@ if (!module.parent) {
describe: 'The SemVer version type such as "patch"',
type: 'string'
})
.option('ls', {
alias: 'l',
describe: 'Prints the files and directories that will and won\'t be published',
type: 'boolean'
})
.option('repoType', {
alias: 'r',
describe: 'The remote repository type such as "stash"',
Expand All @@ -133,6 +145,10 @@ if (!module.parent) {
})

if (unleash.type) {
if (unleash.ls) {
ls()
}

var taskName = bumperize(unleash.type)
versionType = unleash.type
repoType = unleash.repoType
Expand All @@ -145,6 +161,9 @@ if (!module.parent) {

const task = taskManager.task(taskName)
task()
} else if (unleash.ls) {
const task = taskManager.task('ls')
task()
} else {
throw new Error('Need a task homie')
}
Expand Down
36 changes: 36 additions & 0 deletions lib/ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function ls (onEnd) {
const FN = require('fstream-npm')
const color = require('chalk')
const glob = require('glob')
const exclude = require('lodash.difference')

const included = [ ]

const all = glob.sync('**/**', { ignore : [ 'node_modules/**/**' ], nodir : true })

FN({ path: process.cwd() })
.on('child', function (e) {
included.push(e._path.replace(e.root.path + '/', ''))
})
.on('end', function () {
const excluded = exclude(all, included)

console.info(color.magenta('\n\nWILL BE PUBLISHED\n'))
console.info(color.green(included.join('\n')))
console.info(color.magenta('\n\nWON\'T BE PUBLISHED\n'))
console.info(color.red(excluded.join('\n')))

if (typeof onEnd === 'function') {
onEnd({
included : included,
excluded : excluded
})
}
})
}

module.exports = ls

if (!module.parent) {
ls()
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
"dependencies": {
"chalk": "1.1.1",
"fancy-log": "1.1.0",
"fstream-npm": "1.0.7",
"glob": "7.0.3",
"gulp-babel": "5.3.0",
"gulp-bump": "1.0.0",
"gulp-filter": "3.0.1",
"gulp-git": "1.6.0",
"gulp-sourcemaps": "1.6.0",
"gulp-tag-version": "1.3.0",
"gulp-util": "3.0.7",
"lodash.difference": "4.3.0",
"lodash.merge": "3.3.2",
"lodash.partial": "3.1.1",
"lodash.template": "3.6.2",
Expand Down
Binary file added screens/ls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ describe('The Unleash task manager', () => {
it('Has a task function (well it inherits from Undertaker)', () => {
Assert.func(unleashTaskManager.task)
})

it('Has an ls task', () => {
Assert.func(unleashTaskManager.task('ls'))
})
})

0 comments on commit c509791

Please sign in to comment.