Skip to content

Commit

Permalink
Merge pull request #18 from djrasmusp/feature/command-files-list
Browse files Browse the repository at this point in the history
Feature/command files list
  • Loading branch information
djrasmusp authored Jan 31, 2025
2 parents c78b337 + 5b01520 commit 69b60a1
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 31 deletions.
169 changes: 166 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Committy",
"name": "committy",
"version": "1.0.0",
"main": "src/index.js",
"type": "module",
Expand All @@ -17,6 +17,7 @@
"@inquirer/prompts": "^7.2.4",
"commander": "^13.1.0",
"consola": "^3.4.0",
"inquirer-select-pro": "^1.0.0-alpha.9",
"simple-git": "^3.27.0"
}
}
10 changes: 2 additions & 8 deletions src/commands/createBranch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {input, select} from '@inquirer/prompts';
import {COMMIT_TYPES} from '../utils/constants.js'
import {newBranch} from "../utils/gitUtils.js";
import {kebabCase} from "../utils/utils.js";
import {consola} from "consola";
import {errorHandling, kebabCase} from "../utils/utils.js";

export async function createBranch() {
try {
Expand Down Expand Up @@ -31,11 +30,6 @@ export async function createBranch() {

await newBranch(name)
} catch (error) {
if (error instanceof Error && error.name === 'ExitPromptError') {
console.log('👋 until next time!');
return
}

consola.error(error);
errorHandling(error)
}
}
28 changes: 18 additions & 10 deletions src/commands/createCommit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import {editor, input, select} from '@inquirer/prompts';
import {COMMIT_TYPES, ENVIROMENTS} from '../utils/constants.js'
import {appendFiles, commitMessage, getDefaults} from "../utils/gitUtils.js";
import {consola} from "consola";
import {select as multiselect} from 'inquirer-select-pro';
import {appendFiles, commitMessage, getDefaults, listOfFiles} from "../utils/gitUtils.js";
import {errorHandling} from "../utils/utils.js";

export async function createCommit() {
export async function createCommit(allFilesSelected) {
try {
const {scope, id} = await getDefaults()
let selectedFiles = ['.']

appendFiles()
if (!allFilesSelected) {
const files = await listOfFiles()

selectedFiles = await multiselect({
multiple: true,
message: 'Select files',
options: files,
validate: (options) => options.length > 0
})
}

const answers = {
scope: await select({
Expand Down Expand Up @@ -50,6 +61,8 @@ export async function createCommit() {
})
}

await appendFiles(selectedFiles)

let message = `${answers.scope}(${answers.id}): ${answers.title}`

if (answers.message) {
Expand All @@ -67,11 +80,6 @@ ENV: ${answers.environment}`
await commitMessage(message)

} catch (error) {
if (error instanceof Error && error.name === 'ExitPromptError') {
console.log('👋 until next time!');
return
}

consola.error(error);
errorHandling(error)
}
}
27 changes: 27 additions & 0 deletions src/commands/restoreFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {gitRestoreFiles, listOfFiles} from "../utils/gitUtils.js";
import {select as multiselect} from 'inquirer-select-pro';
import {errorHandling} from "../utils/utils.js";


export async function restoreFiles(allFilesSelected) {
try {

let selectedFiles = ['.']

if (!allFilesSelected) {
const files = await listOfFiles()

selectedFiles = await multiselect({
multiple: true,
message: 'Select files',
options: files,
validate: (options) => options.length > 0
})
}


await gitRestoreFiles(selectedFiles)
} catch (error) {
errorHandling(error)
}
}
Loading

0 comments on commit 69b60a1

Please sign in to comment.