Socket
Socket
Sign inDemoInstall

git-wiz

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-wiz - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

utils/program.js

19

bin/index.js
#! /usr/bin/env node
// @ts-check
const { showFilesChooser } = require('../utils/cli');
const { gitStatus, gitAdd } = require('../utils/git');
const {init} = require('../utils/program');
(async () => {
try {
const status = await gitStatus();
if (!status.length) {
console.log('\x1b[33m', 'There are no changes here. Get back to work 🤓')
return;
}
const choices = status.map((file) => file.path);
const files = await showFilesChooser(choices);
await gitAdd(files);
} catch (err) {
console.log('\x1b[31m', 'Oops, something went wrong', err);
}
})();
init();
{
"name": "git-wiz",
"version": "1.0.2",
"version": "1.1.0",
"author": {

@@ -13,2 +13,3 @@ "email": "moshfeu.dev@gmail.com",

"dependencies": {
"commander": "^6.1.0",
"inquirer": "^7.3.3"

@@ -23,5 +24,5 @@ },

},
"homepage": "https://github.com/spread-the-code/git-wiz",
"homepage": "https://github.com/spread-the-code/git-wiz#readme",
"license": "MIT",
"description": "Make git commands interactive"
}

@@ -0,5 +1,10 @@

<img src="https://moshef9.wixsite.com/shield/_functions/view/git-wiz" />
<img src="https://img.shields.io/npm/v/git-wiz" />
# Git Wiz 🧙‍♂️
This is a tool for running some of git commands in interactive mode.
Git Wiz 🧙‍♂️ is a tool for running some of git commands in interactive mode.
![screen record of the terminal with the tool](https://user-images.githubusercontent.com/3723951/92808490-75941500-f3c4-11ea-9ab0-e08072e9b178.gif)
## Getting Started

@@ -26,2 +31,2 @@

- `add`
- `checkout` (TBD)
- `reset`

@@ -1,2 +0,1 @@

// @ts-check
const inquirer = require('inquirer');

@@ -3,0 +2,0 @@ /**

//@ts-check
const { execCommand } = require('../utils/exec');
/**
* @typedef {{
* status: 'tracked' | 'staged' | 'untracked'
* path: string
* }} File
* @returns {Promise<Array<File>>}
*/
async function gitStatus() {
const status = await execCommand('git status --porcelain=v2 -uall');
/**
* @type Array<File>
*/
const initialFiles = [];
const files = status

@@ -10,20 +21,27 @@ .split(/\n/g)

.reduce((prev, line) => {
let status;
const [index, ...params] = line.split(/ +/g);
const path = params[params.length - 1];
if (index === '1') {
const [stagedIndication, changedIndication] = params[0].split('');
if (stagedIndication !== '.') {
prev.push({
status: 'staged',
path
});
}
if (changedIndication !== '.') {
status = 'tracked';
prev.push({
status: 'tracked',
path
});
}
} else if (index === '?') {
status = 'untracked';
}
if (status) {
prev.push({
status,
path: params[params.length - 1]
})
status: 'untracked',
path
});
}
return prev;
}, []);
}, initialFiles);

@@ -34,11 +52,27 @@ return files;

/**
* @param {string} command
* @param {Array<string>} files
*/
async function runCommand(command, files) {
const gitCommand = `git ${command} ${files.join(' ')}`;
await execCommand(gitCommand);
console.log('\x1b[0m', `"${gitCommand}"`, '\x1b[32m', 'did great 🤟');
}
/**
* @param {Array<string>} files
*/
async function gitAdd(files) {
const command = `git add ${files.join(' ')}`;
await execCommand(command);
console.log('\x1b[0m', `"${command}"`, '\x1b[32m', 'did great 🤟');
await runCommand('add', files);
}
/**
* @param {Array<string>} files
*/
async function gitReset(files) {
await runCommand('reset HEAD -- ', files);
}
exports.gitAdd = gitAdd;
exports.gitReset = gitReset;
exports.gitStatus = gitStatus;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc