Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulCatalinas committed Dec 4, 2024
2 parents dcd0fab + 130a633 commit faffcb4
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 77 deletions.
42 changes: 1 addition & 41 deletions internal/constants/errors.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
package constants

var ERROR_MESSAGES = map[string]string{
"NotFound": "The {fileName} file wasn't found in the current directory.",

"Default": "Something went wrong, please try again later, if the error persists please report it on " + ISSUES + ".",

"Dependencies": "An error occurred while installing dependencies, please try again later, if the error persists please report it on " + ISSUES + ".",

"Husky": "An error has occurred during the Husky configuration process, please try again later, if the error persists please report it on " + ISSUES + ".",

"CommitLintConfig": "An error has occurred during the commitlint configuration process, please try again later, if the error persists please report it on " + ISSUES + ".",

"AddCommitLint": "An error occurred while asking if you wanna add commitlint, please try again later, if the error persists please report it on " + ISSUES + ".",

"PackageManagerSelection": "An error occurred while selecting the package manager, please try again later, if the error persists, please report it on " + ISSUES + ".",

"CreateEmptyFile": "An error occurred while creating the empty file. Please try again later, if the error persists please report it on " + ISSUES + ".",

"CreateFolder": "An error occurred while creating the folder: {folderName}, please try again later, if the error persists, please report it on " + ISSUES + ".",

"ReadFile": "An error has occurred while reading the {fileName} file, please try again later, if the error persists, please report it on " + ISSUES + ".",

"WriteFile": "An error has occurred while writing to the {fileName} file, please try again later, if the error persists, please report it on " + ISSUES + ".",

"ConfigFilesCreate": "An error occurred while creating configuration files. Please try again later, if the error persists please report it on " + ISSUES + ".",

"ShouldPublishToNpm": "An error occurred while confirming npm publication. Please try again later, if the error persists, please report it on" + ISSUES + ".",

"NpmIgnoreWrite": "An error occurred while writing to the '.npmignore' file. Please try again later, if the error persists please report it on " + ISSUES + ".",

"GitHubRepoOpen": "An error occurred while opening the GitHub repository in a new browser tab. Please try again later, if the error persists please report it on" + ISSUES + ".",

"JsonUnmarshal": "Replace this with an error message that's descriptive and easily understandable by any developer.",

"JsonMarshal": "Replace this with an error message that's descriptive and easily understandable by any developer.",

"GetWorkingDirectory": "Replace this with an error message that's descriptive and easily understandable by any developer.",

"InvalidTypeForFilesToAdd": "Replace this with an error message that's descriptive and easily understandable by any developer.",

"CheckingFolderOrFile": "Replace this with an error message that's descriptive and easily understandable by any developer.",
}
const BASE_ERROR_MESSAGE = "Please try again later, if the error persists please report it on " + ISSUES + "."
38 changes: 38 additions & 0 deletions internal/enums/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package enums

type FileError string
type ConfigError string
type ProcessError string
type UserInputError string

const (
NotFoundError FileError = "NotFound"
ReadFileError FileError = "ReadFile"
WriteFileError FileError = "WriteFile"
CreateEmptyFileError FileError = "CreateEmptyFile"
CreateFolderError FileError = "CreateFolder"
NpmIgnoreWriteError FileError = "NpmIgnoreWrite"
AddScriptError FileError = "AddScript"
)

const (
HuskyError ConfigError = "Husky"
CommitLintConfigError ConfigError = "CommitLintConfig"
ConfigFilesCreateError ConfigError = "ConfigFilesCreate"
)

const (
JsonUnmarshalError ProcessError = "JsonUnmarshal"
JsonMarshalError ProcessError = "JsonMarshal"
GetWorkingDirectoryError ProcessError = "GetWorkingDirectory"
InvalidTypeForFilesToAddError ProcessError = "InvalidTypeForFilesToAdd"
CheckingFolderOrFileError ProcessError = "CheckingFolderOrFile"
DependenciesError ProcessError = "Dependencies"
GitHubRepoOpenError ProcessError = "GitHubRepoOpen"
)

const (
AddCommitLintError UserInputError = "AddCommitLint"
PackageManagerSelectionError UserInputError = "PackageManagerSelection"
ShouldPublishToNpmError UserInputError = "ShouldPublishToNpm"
)
9 changes: 9 additions & 0 deletions internal/error_messages/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package error_messages

import "github.com/RaulCatalinas/HuskyBC/internal/enums"

var CONFIG_ERROR_MESSAGES = map[enums.ConfigError]string{
enums.HuskyError: generateErrorMessage("configuring Husky"),
enums.CommitLintConfigError: generateErrorMessage("configuring commitlint"),
enums.ConfigFilesCreateError: generateErrorMessage("creating configuration files"),
}
13 changes: 13 additions & 0 deletions internal/error_messages/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package error_messages

import "github.com/RaulCatalinas/HuskyBC/internal/enums"

var FILE_ERROR_MESSAGES = map[enums.FileError]string{
enums.NotFoundError: "The {fileName} file wasn't found in the current directory.",
enums.ReadFileError: generateErrorMessage("reading the {fileName} file"),
enums.WriteFileError: generateErrorMessage("writing to the {fileName} file"),
enums.CreateEmptyFileError: generateErrorMessage("creating the empty file"),
enums.CreateFolderError: generateErrorMessage("creating the folder"),
enums.NpmIgnoreWriteError: generateErrorMessage("writing to the '.npmignore' file"),
enums.AddScriptError: generateErrorMessage("trying to add a script to the package.json file."),
}
7 changes: 7 additions & 0 deletions internal/error_messages/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package error_messages

import (
"github.com/RaulCatalinas/HuskyBC/internal/constants"
)

const DEFAULT_ERROR_MESSAGE = "Something went wrong. " + constants.BASE_ERROR_MESSAGE
19 changes: 19 additions & 0 deletions internal/error_messages/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package error_messages

import "github.com/RaulCatalinas/HuskyBC/internal/enums"

var PROCESS_ERROR_MESSAGES = map[enums.ProcessError]string{
enums.JsonUnmarshalError: "Replace this with an error message that's descriptive and easily understandable by any developer.",

enums.JsonMarshalError: "Replace this with an error message that's descriptive and easily understandable by any developer.",

enums.GetWorkingDirectoryError: "Replace this with an error message that's descriptive and easily understandable by any developer.",

enums.InvalidTypeForFilesToAddError: "Replace this with an error message that's descriptive and easily understandable by any developer.",

enums.CheckingFolderOrFileError: "Replace this with an error message that's descriptive and easily understandable by any developer.",

enums.DependenciesError: generateErrorMessage("installing dependencies"),

enums.GitHubRepoOpenError: generateErrorMessage("opening the GitHub repository in a new browser tab"),
}
11 changes: 11 additions & 0 deletions internal/error_messages/user-input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package error_messages

import "github.com/RaulCatalinas/HuskyBC/internal/enums"

var USER_INPUT_ERROR_MESSAGES = map[enums.UserInputError]string{
enums.AddCommitLintError: generateErrorMessage("asking if you want to add commitlint"),

enums.PackageManagerSelectionError: generateErrorMessage("selecting the package manager"),

enums.ShouldPublishToNpmError: generateErrorMessage("confirming npm publication"),
}
7 changes: 7 additions & 0 deletions internal/error_messages/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package error_messages

import "github.com/RaulCatalinas/HuskyBC/internal/constants"

func generateErrorMessage(action string) string {
return "An error occurred while " + action + ". " + constants.BASE_ERROR_MESSAGE
}
3 changes: 2 additions & 1 deletion internal/handlers/handlers_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/RaulCatalinas/HuskyBC/internal/constants"
"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
userinput "github.com/RaulCatalinas/HuskyBC/internal/user-input"
"github.com/RaulCatalinas/HuskyBC/internal/utils"
"github.com/toqueteos/webbrowser"
Expand All @@ -24,7 +25,7 @@ func HandlerOptionCollaborate() {
if err != nil {
utils.WriteMessage(utils.WriteMessageProps{
Type: enums.MessageTypeError,
Message: utils.GetErrorMessage("GitHubRepoOpen"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.GitHubRepoOpenError],
})

os.Exit(1)
Expand Down
3 changes: 2 additions & 1 deletion internal/user-input/add-commitlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
"github.com/RaulCatalinas/HuskyBC/internal/utils"
)

Expand All @@ -28,7 +29,7 @@ func AddCommitlint() bool {
if err != nil {
utils.WriteMessage(utils.WriteMessageProps{
Type: enums.MessageTypeError,
Message: utils.GetErrorMessage("AddCommitLint"),
Message: errorMessages.USER_INPUT_ERROR_MESSAGES[enums.AddCommitLintError],
})

os.Exit(1)
Expand Down
3 changes: 2 additions & 1 deletion internal/user-input/package-managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
"github.com/RaulCatalinas/HuskyBC/internal/utils"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -38,7 +39,7 @@ func GetPackageManager() enums.PackageManager {
if err != nil {
utils.WriteMessage(utils.WriteMessageProps{
Type: enums.MessageTypeError,
Message: utils.GetErrorMessage("PackageManagerSelection"),
Message: errorMessages.USER_INPUT_ERROR_MESSAGES[enums.PackageManagerSelectionError],
})

os.Exit(1)
Expand Down
3 changes: 2 additions & 1 deletion internal/user-input/publishToNpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
"github.com/RaulCatalinas/HuskyBC/internal/utils"
)

Expand All @@ -28,7 +29,7 @@ func ShouldPublishToNpm() bool {
if err != nil {
utils.WriteMessage(utils.WriteMessageProps{
Type: enums.MessageTypeError,
Message: utils.GetErrorMessage("ShouldPublishToNpm"),
Message: errorMessages.USER_INPUT_ERROR_MESSAGES[enums.ShouldPublishToNpmError],
})

os.Exit(1)
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/commitlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/RaulCatalinas/HuskyBC/internal/constants"
"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
)

type CommitlintProps struct {
Expand All @@ -19,7 +20,7 @@ func GenerateCommitlintConfig(commitlintProps CommitlintProps) {
if r := recover(); r != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("Commitlint"),
Message: errorMessages.CONFIG_ERROR_MESSAGES[enums.CommitLintConfigError],
})

os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions internal/utils/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/RaulCatalinas/HuskyBC/internal/constants"
"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
)

type InstallProps struct {
Expand All @@ -27,7 +28,7 @@ func InstallDependencies(props InstallProps) {
if r := recover(); r != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("Dependencies"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.DependenciesError],
})

os.Exit(1)
Expand Down Expand Up @@ -60,7 +61,7 @@ func InstallDependencies(props InstallProps) {
if err != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("Dependencies"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.DependenciesError],
})

os.Exit(1)
Expand Down
7 changes: 0 additions & 7 deletions internal/utils/errors.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/utils/husky-library.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GenerateHuskyConfig(props Props) {

createHuskyConfigFiles(props.PackageManagerToUse, props.UseCommitlint)

addNecessaryScriptsToPakageJson(
addNecessaryScriptsToPackageJson(
props.PackageJsonPath,
props.PackageManagerToUse,
props.ShouldPublishToNpm,
Expand Down Expand Up @@ -70,7 +70,7 @@ type packageJsonScript struct {
Value string
}

func addNecessaryScriptsToPakageJson(
func addNecessaryScriptsToPackageJson(
packageJsonPath string,
packageManagerToUse enums.PackageManager,
shouldPublishToNpm bool,
Expand Down
9 changes: 5 additions & 4 deletions internal/utils/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"strings"

"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
)

func modifyNpmIgnore(filesToAdd interface{}) {
defer func() {
if r := recover(); r != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("NpmIgnoreWrite"),
Message: errorMessages.FILE_ERROR_MESSAGES[enums.NpmIgnoreWriteError],
})

os.Exit(1)
Expand All @@ -30,7 +31,7 @@ func modifyNpmIgnore(filesToAdd interface{}) {
if err != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("GetWorkingDirectory"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.GetWorkingDirectoryError],
})

os.Exit(1)
Expand All @@ -56,7 +57,7 @@ func modifyNpmIgnore(filesToAdd interface{}) {
default:
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForFilesToAdd"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.InvalidTypeForFilesToAddError],
})

os.Exit(1)
Expand Down Expand Up @@ -93,7 +94,7 @@ func modifyNpmIgnore(filesToAdd interface{}) {
default:
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForFilesToAdd"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.InvalidTypeForFilesToAddError],
})

os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions internal/utils/package-json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/RaulCatalinas/HuskyBC/internal/enums"
errorMessages "github.com/RaulCatalinas/HuskyBC/internal/error_messages"
)

type addScriptProps struct {
Expand Down Expand Up @@ -34,7 +35,7 @@ func addScript(props addScriptProps) {
if r := recover(); r != nil {
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("AddScript"),
Message: errorMessages.FILE_ERROR_MESSAGES[enums.AddScriptError],
})

os.Exit(1)
Expand Down Expand Up @@ -64,7 +65,7 @@ func addScript(props addScriptProps) {
default:
WriteMessage(WriteMessageProps{
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForScriptsToAdd"),
Message: errorMessages.PROCESS_ERROR_MESSAGES[enums.InvalidTypeForFilesToAddError],
})
os.Exit(1)
}
Expand Down
Loading

0 comments on commit faffcb4

Please sign in to comment.