-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
184 additions
and
154 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# 1.0.1 (09/02/2018) | ||
|
||
- cleans up code | ||
- adds key to help menu | ||
|
||
# 1.0.0 (12/18/2017) | ||
|
||
- removes commander | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
- [ ] remove sync operations | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const child_process = require('child_process'); | ||
const { promisify } = require('util'); | ||
const path = require('path') | ||
const { getContents, getDirectories } = require('./utils') | ||
|
||
const exec = promisify(child_process.exec); | ||
const readdir = promisify(fs.readdir); | ||
const stat = promisify(fs.stat); | ||
|
||
async function getContents(directory) { | ||
try { | ||
const git = await stat(path.resolve(directory, '.git')); | ||
if (git.isDirectory()) { | ||
const { stdout } = await exec('git status --porcelain --branch', { | ||
cwd: path.resolve(directory) | ||
}); | ||
return stdout; | ||
} | ||
} catch (ex) { | ||
return; | ||
} | ||
} | ||
|
||
async function getDirectories(directory) { | ||
try { | ||
let found = []; | ||
const files = await readdir(directory); | ||
for(var i = 0; i < files.length; i++) { | ||
const dir = await stat(path.resolve(directory, files[i])); | ||
if(dir.isDirectory()) { | ||
found.push(path.resolve(directory, files[i])); | ||
} | ||
} | ||
return found; | ||
} catch(ex) { | ||
return []; | ||
} | ||
} | ||
|
||
async function search(directory, depth) { | ||
let found = [[directory]]; | ||
let output = {}; | ||
async function search (directory, depth) { | ||
const found = [[directory]] | ||
const output = {} | ||
|
||
for (var i = 0; i <= depth; i++) { | ||
for (var s = 0; s <= found[i].length - 1; s++) { | ||
if (i < depth) { | ||
found.push(await getDirectories(found[i][s])); | ||
found.push(await getDirectories(found[i][s])) | ||
} | ||
} | ||
} | ||
|
||
let all = [].concat.apply([], found); | ||
for(var p = 0; p < all.length; p++) { | ||
const dir = all[p]; | ||
const contents = await getContents(path.resolve(directory, dir)); | ||
const all = [].concat.apply([], found) | ||
|
||
for (const dir of all) { | ||
const contents = await getContents(path.resolve(directory, dir)) | ||
|
||
if (contents) { | ||
output[path.resolve(directory, dir)] = contents; | ||
output[path.resolve(directory, dir)] = contents | ||
} | ||
} | ||
|
||
return output; | ||
return output | ||
} | ||
|
||
module.exports = { | ||
search, | ||
getDirectories, | ||
getContents | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const childProcess = require('child_process') | ||
const { promisify } = require('util') | ||
const debug = require('debug') | ||
|
||
const exec = promisify(childProcess.exec) | ||
const readdir = promisify(fs.readdir) | ||
const stat = promisify(fs.stat) | ||
|
||
async function getContents (directory) { | ||
try { | ||
const git = await stat(path.resolve(directory, '.git')) | ||
|
||
if (git.isDirectory()) { | ||
const { stdout } = await exec('git status --porcelain --branch', { | ||
cwd: path.resolve(directory) | ||
}) | ||
return stdout | ||
} | ||
} catch (ex) { | ||
debug('failed to get git output', ex) | ||
} | ||
} | ||
|
||
async function getDirectories (directory) { | ||
const found = [] | ||
|
||
try { | ||
const files = await readdir(directory) | ||
|
||
for (const file of files) { | ||
const dir = await stat(path.resolve(directory, file)) | ||
if (dir.isDirectory()) { | ||
found.push(path.resolve(directory, file)) | ||
} | ||
} | ||
} catch (ex) { | ||
debug('failed to parse directory', ex) | ||
} | ||
|
||
return found | ||
} | ||
|
||
function colorize (line) { | ||
// 'M' -> 'modified' | ||
// 'A ' -> 'added' | ||
// 'D' -> 'deleted' | ||
// 'R' -> 'renamed' | ||
// 'C' -> 'copied' | ||
// '??' -> 'untracked' | ||
|
||
switch (line.substring(0, 2).trim()) { | ||
case 'M': | ||
return chalk.red(line) | ||
case 'A': | ||
return chalk.green(line) | ||
case 'C': | ||
return chalk.yellow(line) | ||
case 'R': | ||
return chalk.magenta(line) | ||
case 'D': | ||
return chalk.bgRed.white(line) | ||
case '??': | ||
return chalk.gray(line) | ||
default: | ||
return chalk.white(line) | ||
} | ||
} | ||
|
||
module.exports = { | ||
colorize, | ||
getContents, | ||
getDirectories | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.