Skip to content

Commit

Permalink
feat: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Oct 8, 2020
1 parent de14633 commit 9dc5a66
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
## Change log

**0.2.0**
**1.4.0**

- Support command `rename`

**1.3.0**

- Nothing, I'm not sure why it was a major 🤨

**1.2.0**

- Support commands `stash` and `diff` (also added webpack + typescript)

**0.1.0**
**1.1.0**

- Support commands `add` and `reset`
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ git-wiz
- `reset`
- `stash`
- `diff`
- `rename` (`mv`)

## Development

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git-wiz",
"version": "1.3.0",
"version": "1.4.0",
"author": {
"email": "moshfeu.dev@gmail.com",
"name": "Mosh Feu",
Expand Down Expand Up @@ -31,15 +31,15 @@
],
"dependencies": {
"commander": "^6.1.0",
"inquirer": "^7.3.3",
"ts-loader": "^8.0.3",
"typescript": "^4.0.2"
"inquirer": "^7.3.3"
},
"devDependencies": {
"@types/inquirer": "^7.3.1",
"json-loader": "^0.5.7",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-node-externals": "^2.5.2"
"webpack-node-externals": "^2.5.2",
"ts-loader": "^8.0.3",
"typescript": "^4.0.2"
}
}
11 changes: 10 additions & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execCommand } from './exec';
import { basename } from 'path';

type File = {
status: 'tracked' | 'staged' | 'untracked';
Expand Down Expand Up @@ -72,9 +73,17 @@ export async function gitReset(files: Array<string>) {
export async function gitStash(files: Array<string>, message?: string) {
await gitAdd(files);
// sorry for the 'replace', the space conflicts with: https://github.com/spread-the-code/git-wiz/blob/134f7cb9053cc20edcb0b969848d39d836b0ce31/src/utils/exec.ts#L6
await runCommand(`stash push${message ? ` -m ${message.replace(/ /g, '-')}` : ''}`, files);
await runCommand(
`stash push${message ? ` -m ${message.replace(/ /g, '-')}` : ''}`,
files
);
}

export function gitDiff(files: Array<string>, flags: Array<string>) {
return runCommand('diff', files, flags, true);
}

export function gitMv(path: string, newName: string) {
const newPath = path.replace(basename(path), newName);
return runCommand('mv', [], [path, newPath]);
}
9 changes: 8 additions & 1 deletion src/utils/program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { program } from 'commander';
import { add, diff, reset, stash } from './wiz';
import { add, diff, rename, reset, stash } from './wiz';
import { version } from '../../package.json';

export function init() {
Expand Down Expand Up @@ -29,6 +29,13 @@ export function init() {
)
.action(diff);

program
.command('rename <path> <newName>')
.description(
'do "git mv" (for renaming) with style 🔖'
)
.action(rename);

program.parse(process.argv);
} catch (error) {
console.log(error);
Expand Down
6 changes: 5 additions & 1 deletion src/utils/wiz.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'commander';
import { showFilesChooser, showFilesChooserAnd } from './cli';
import { gitStatus, gitAdd, gitReset, gitStash, gitDiff } from './git';
import { gitStatus, gitAdd, gitReset, gitStash, gitDiff, gitMv } from './git';

export const add = withErrorHandler(async () => {
const status = (await gitStatus()).filter((file) => file.status !== 'staged');
Expand Down Expand Up @@ -67,6 +67,10 @@ export const diff = withErrorHandler(async (comObj: Command) => {
await gitDiff(files, comObj.args);
});

export const rename = withErrorHandler(async ({args: [path, newName]}: Command) => {
await gitMv(path, newName);
});

function withErrorHandler(fn: Function) {
return (...args: Array<unknown>): Promise<void> => {
try {
Expand Down

0 comments on commit 9dc5a66

Please sign in to comment.