Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
package-lock.json
yarn.lock
bin
5 changes: 0 additions & 5 deletions bin/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions jsconfig.json

This file was deleted.

26 changes: 18 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
{
"name": "git-wiz",
"version": "1.1.1",
"version": "1.1.2",
"author": {
"email": "moshfeu.dev@gmail.com",
"name": "Mosh Feu",
"url": "https://github.com/moshfeu"
},
"scripts": {
"build": "webpack"
},
"bin": {
"git-wiz": "bin/index.js"
},
"dependencies": {
"commander": "^6.1.0",
"inquirer": "^7.3.3"
},
"files": [
"bin/index.js",
"utils"
"bin/index.js"
],
"repository": {
"url": "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"
"description": "Make git commands interactive",
"dependencies": {
"commander": "^6.1.0",
"inquirer": "^7.3.3",
"ts-loader": "^8.0.3",
"typescript": "^4.0.2"
},
"devDependencies": {
"@types/inquirer": "^7.3.1",
"json-loader": "^0.5.7",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { init } from './utils/program';

init();
22 changes: 22 additions & 0 deletions src/utils/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import inquirer from 'inquirer';

export async function showFilesChooser(choices: Array<string>) {
const answer = await inquirer.prompt<{
files: Array<string>
}>([
{
type: 'checkbox',
name: 'files',
message: 'What to add?',
choices,
validate: (answer: string) => {
if (answer.length < 1) {
return 'Are you tricking me 🤨? Please choose files to add';
}
return true;
},
},
]);

return answer.files;
}
14 changes: 4 additions & 10 deletions utils/exec.js → src/utils/exec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//@ts-check
const cp = require('child_process');
/**
* @param {string} command
* @returns {Promise<string>}
*/
function execCommand(command) {
import {exec} from 'child_process';

export function execCommand(command: string): Promise<string> {
return new Promise((resolve, reject) =>
cp.exec(
exec(
command,
{
cwd: process.cwd(),
Expand All @@ -22,5 +18,3 @@ function execCommand(command) {
)
);
}

exports.execCommand = execCommand;
59 changes: 19 additions & 40 deletions utils/git.js → src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//@ts-check
const { execCommand } = require('../utils/exec');
import { execCommand } from './exec';

/**
* @typedef {{
* status: 'tracked' | 'staged' | 'untracked'
* path: string
* }} File
* @returns {Promise<Array<File>>}
*/
async function gitStatus() {
type File = {
status: 'tracked' | 'staged' | 'untracked';
path: string;
};

async function runCommand(command: string, files: Array<string>) {
const gitCommand = `git ${command} ${files.join(' ')}`;
await execCommand(gitCommand);
console.log('\x1b[0m', `"${gitCommand}"`, '\x1b[32m', 'did great 🤟');
}

export async function gitStatus(): Promise<Array<File>> {
const status = await execCommand('git status --porcelain=v2 -uall');
/**
* @type Array<File>
*/
const initialFiles = [];
const files = status
.split(/\n/g)
.filter((line) => line)
Expand All @@ -26,51 +25,31 @@ async function gitStatus() {
if (stagedIndication !== '.') {
prev.push({
status: 'staged',
path
path,
});
}
if (changedIndication !== '.') {
prev.push({
status: 'tracked',
path
path,
});
}
} else if (index === '?') {
prev.push({
status: 'untracked',
path
path,
});
}
return prev;
}, initialFiles);
}, []);

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) {
export async function gitAdd(files: Array<string>) {
await runCommand('add', files);
}

/**
* @param {Array<string>} files
*/
async function gitReset(files) {
export async function gitReset(files: Array<string>) {
await runCommand('reset HEAD -- ', files);
}

exports.gitAdd = gitAdd;
exports.gitReset = gitReset;
exports.gitStatus = gitStatus;
10 changes: 4 additions & 6 deletions utils/program.js → src/utils/program.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { program } = require('commander');
const { add, reset } = require('./wiz');
const { version } = require('../package.json');
import { program } from 'commander';
import { add, reset } from './wiz';
import { version } from '../../package.json';

function init() {
export function init() {
try {
program.version(version);

Expand All @@ -21,5 +21,3 @@ function init() {
console.log(error);
}
}

exports.init = init;
11 changes: 4 additions & 7 deletions utils/wiz.js → src/utils/wiz.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { showFilesChooser } = require('./cli');
const { gitStatus, gitAdd, gitReset } = require('./git');
import { showFilesChooser } from './cli';
import { gitStatus, gitAdd, gitReset } from './git';

async function add() {
export async function add() {
try {
const status = (await gitStatus()).filter(
(file) => file.status !== 'staged'
Expand All @@ -18,7 +18,7 @@ async function add() {
}
}

async function reset() {
export async function reset() {
try {
const status = (await gitStatus()).filter(
(file) => file.status === 'staged'
Expand All @@ -37,6 +37,3 @@ async function reset() {
console.log('\x1b[31m', 'Oops, something went wrong', err);
}
}

exports.add = add;
exports.reset = reset;
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"jsx": "react",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"types": [
"commander"
]
}
}
27 changes: 0 additions & 27 deletions utils/cli.js

This file was deleted.

26 changes: 26 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
entry: './src/index.ts',
target: 'node',
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.ts', '.js' ],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'bin'),
},
plugins: [
new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }),
]
};