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 3, 2024
2 parents 7147480 + 1a7b93a commit dcd0fab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 7 additions & 5 deletions internal/utils/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"
"os"
"strings"

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

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

Expand All @@ -19,15 +21,15 @@ func modifyNpmIgnore(filesToAdd interface{}) {
}()

WriteMessage(WriteMessageProps{
Type: "info",
Type: enums.MessageTypeInfo,
Message: "Writing in the file \".npmignore\"...",
})

dir, err := os.Getwd()

if err != nil {
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("GetWorkingDirectory"),
})

Expand All @@ -53,7 +55,7 @@ func modifyNpmIgnore(filesToAdd interface{}) {
filesToWrite = strings.Join(v, "\n")
default:
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForFilesToAdd"),
})

Expand Down Expand Up @@ -90,7 +92,7 @@ func modifyNpmIgnore(filesToAdd interface{}) {
trimmedIgnoredFilesArray = append(trimmedIgnoredFilesArray, v...)
default:
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForFilesToAdd"),
})

Expand Down
10 changes: 6 additions & 4 deletions internal/utils/package-json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package utils

import (
"os"

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

type addScriptProps struct {
Expand Down Expand Up @@ -31,7 +33,7 @@ func addScript(props addScriptProps) {
defer func() {
if r := recover(); r != nil {
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("AddScript"),
})

Expand All @@ -40,7 +42,7 @@ func addScript(props addScriptProps) {
}()

WriteMessage(WriteMessageProps{
Type: "info",
Type: enums.MessageTypeInfo,
Message: "Modifying package.json...",
})

Expand All @@ -61,7 +63,7 @@ func addScript(props addScriptProps) {
scriptsSection[v.Key] = v.Value
default:
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("InvalidTypeForScriptsToAdd"),
})
os.Exit(1)
Expand All @@ -70,7 +72,7 @@ func addScript(props addScriptProps) {
jsonMarshalIndentAndWriteFile(packageJsonObj, packageJsonPath)

WriteMessage(WriteMessageProps{
Type: "success",
Type: enums.MessageTypeSuccess,
Message: "Package.json modified successfully",
})
}
12 changes: 7 additions & 5 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"os"
"strings"

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

func exists(filePath string) bool {
Expand All @@ -17,7 +19,7 @@ func createEmptyFile(fileName string) {

if err != nil {
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("CreateEmptyFile"),
})

Expand All @@ -33,7 +35,7 @@ func readFile(filename string) []byte {
errorMessage := GetErrorMessage("ReadFile")

WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: strings.Replace(errorMessage, "{fileName}", filename, -1),
})

Expand All @@ -50,7 +52,7 @@ func writeFile(filename string, newData []byte) {
errorMessage := GetErrorMessage("WriteFile")

WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: strings.Replace(errorMessage, "{fileName}", filename, -1),
})
}
Expand All @@ -61,7 +63,7 @@ func jsonMarshalIndent(packageJsonObj map[string]interface{}) []byte {

if err != nil {
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("JsonMarshal"),
})

Expand All @@ -78,7 +80,7 @@ func jsonUnmarshal(data []byte) map[string]interface{} {

if err != nil {
WriteMessage(WriteMessageProps{
Type: "error",
Type: enums.MessageTypeError,
Message: GetErrorMessage("JsonUnmarshal"),
})

Expand Down

0 comments on commit dcd0fab

Please sign in to comment.