From 2b6bb711b6ef93b7f731d9ba3005d3cbd77698e9 Mon Sep 17 00:00:00 2001 From: Gabriel Csapo Date: Sat, 9 Sep 2017 01:53:49 -0400 Subject: [PATCH] 0.3.0 - code cleanup - drops support for node@4 - updates license in package.json - updates chalk@2.0.1 -> chalk@2.1.0 --- .eslintignore | 1 + .travis.yml | 1 - CHANGELOG.md | 7 +++++++ README.md | 4 +--- TODO.md | 1 + bin/index.js | 2 +- lib/search.js | 16 +++++++--------- package.json | 11 ++++++----- test/index.js | 40 +++++++++++++++++++++++++++------------- 9 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 TODO.md diff --git a/.eslintignore b/.eslintignore index 3c3629e..ba2a97b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ node_modules +coverage diff --git a/.travis.yml b/.travis.yml index b9ece2e..39cc132 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ script: - npm run coverage - cat coverage/lcov.info | node-coverage-cli --url https://node-coverage-server.herokuapp.com node_js: - - "4" - "6" - "8" os: diff --git a/CHANGELOG.md b/CHANGELOG.md index f09b067..6064611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.3.0 (09/09/2017) + +- code cleanup +- drops support for node@4 +- updates license in package.json +- updates `chalk@2.0.1` -> `chalk@2.1.0` + # 0.2.0 (07/13/2017) - updates readme to include the ability to run as a custom git command diff --git a/README.md b/README.md index d021ffe..e07b0de 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # git-unstaged -[![Greenkeeper badge](https://badges.greenkeeper.io/gabrielcsapo/git-unstaged.svg)](https://greenkeeper.io/) - -> Get all unstaged git repos in a folder +> 🎭 Get all unstaged git repos in a folder [![Npm Version](https://img.shields.io/npm/v/git-unstaged.svg)](https://www.npmjs.com/package/git-unstaged) [![Build Status](https://travis-ci.org/gabrielcsapo/git-unstaged.svg?branch=master)](https://travis-ci.org/gabrielcsapo/git-unstaged) diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..c808d47 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +- [ ] remove sync operations diff --git a/bin/index.js b/bin/index.js index 40c7f2c..593ee22 100755 --- a/bin/index.js +++ b/bin/index.js @@ -2,7 +2,7 @@ const chalk = require('chalk'); const program = require('commander'); -const search = require('../lib/search').search; +const { search } = require('../lib/search'); const log = console.log; // eslint-disable-line program diff --git a/lib/search.js b/lib/search.js index 7ccd7cc..89f9f4d 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,17 +1,17 @@ const path = require('path'); const fs = require('fs'); -const exec = require('child_process').execSync; +const { execSync } = require('child_process'); function getContents(directory) { try { const git = fs.statSync(path.resolve(directory, '.git')); if(git.isDirectory()) { - return exec(' git status --porcelain --branch', { + return execSync('git status --porcelain --branch', { cwd: path.resolve(directory) }).toString('utf8'); } } catch(ex) { - // noop + return; } } @@ -22,9 +22,8 @@ function getDirectories(directory) { } function search(directory, depth, callback) { - const output = {}; - - const found = [[directory]]; + let found = [[directory]]; + let output = {}; for(var i = 0; i <= depth; i++) { found[i].forEach((dir) => { @@ -34,9 +33,7 @@ function search(directory, depth, callback) { }); } - const directories = [].concat.apply([], found); - - directories.forEach((dir) => { + [].concat.apply([], found).forEach((dir) => { const contents = getContents(path.resolve(directory, dir)); if(contents) { output[path.resolve(directory, dir)] = contents; @@ -47,5 +44,6 @@ function search(directory, depth, callback) { module.exports = { search, + getDirectories, getContents }; diff --git a/package.json b/package.json index e2b7fae..5f413e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "git-unstaged", "version": "0.2.0", - "description": "Get all unstaged git repos in a folder", + "description": "🎭 Get all unstaged git repos in a folder", "author": "Gabriel J. Csapo ", "license": "MIT", "bugs": { @@ -15,6 +15,7 @@ "keywords": [ "git" ], + "license": "MIT", "main": "index.js", "bin": { "git-unstaged": "./bin/index.js" @@ -25,12 +26,12 @@ "coverage": "tap test/*.js --coverage --coverage-report=lcov" }, "dependencies": { - "chalk": "^2.0.1", + "chalk": "^2.1.0", "commander": "^2.11.0" }, "devDependencies": { - "eslint": "^4.1.1", - "tap": "^10.7.0", - "tape": "^4.7.0" + "eslint": "^4.6.1", + "tap": "^10.7.2", + "tape": "^4.8.0" } } diff --git a/test/index.js b/test/index.js index b975594..f7610f6 100644 --- a/test/index.js +++ b/test/index.js @@ -2,31 +2,45 @@ const test = require('tape'); const path = require('path'); const exec = require('child_process').exec; -const search = require('../lib/search').search; +const { search, getDirectories, getContents } = require('../lib/search'); + +const fixturesDirectory = path.resolve(__dirname, 'fixtures'); test('git-unstaged', (t) => { - const fixturesDirectory = path.resolve(__dirname, 'fixtures'); + t.plan(3); - t.test('create random git repos with content in them', (t) => { + t.test('runs search in new directory', (t) => { exec('mkdir test1 && cd test1 && git init && cat "hello world" > t.txt', { cwd: fixturesDirectory }); - t.end(); + setTimeout(() => { + search(fixturesDirectory, 1, (c) => { + t.equal(c[path.resolve(fixturesDirectory, 'test1')], "## Initial commit on master\n?? t.txt\n"); + exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => { + t.end(); + }); + }); + }, 1000); }); - t.test('runs git-unstaged in test directory', (t) => { + t.test('runs getContents in new directory', (t) => { + exec('mkdir test1 && cd test1 && git init && cat "hello world" > t.txt', { + cwd: fixturesDirectory + }); setTimeout(() => { - search(fixturesDirectory, 1, (c) => { - t.equal(c[path.resolve(fixturesDirectory, 'test1')], "## Initial commit on master\n?? t.txt\n"); - t.end(); - }); + const contents = getContents(path.resolve(fixturesDirectory, 'test1')); + t.equal(contents, '## Initial commit on master\n?? t.txt\n') + exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => { + t.end(); + }); }, 1000); }); - t.test('removes fixtures directory', (t) => { - exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => { - t.end(); - }); + t.test('return fixtures directory', (t) => { + const directories = getDirectories(__dirname); + t.equal(directories.length, 1); + t.equal(directories[0].substring(directories[0].lastIndexOf('/') + 1, directories[0].length), 'fixtures'); + t.end(); }); });