Skip to content

Commit

Permalink
fix: checkworkspace now recreates the .feature folder
Browse files Browse the repository at this point in the history
  • Loading branch information
costaluu committed Sep 27, 2024
1 parent 78d654d commit b1ca6d8
Showing 1 changed file with 57 additions and 42 deletions.
99 changes: 57 additions & 42 deletions src/core/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,45 @@ import (
"github.com/costaluu/flag/types"
)

var delimeters types.Delimeters = map[string]types.Delimeter{
".xqy": {
Start: "(:~ ",
End: " ~:)",
},
".xml": {
Start: "<!-- ",
End: " -->",
},
".html": {
Start: "<!-- ",
End: " -->",
},
".cc": {
Start: "// ",
End: " //",
},
".cpp": {
Start: "// ",
End: " //",
},
".go": {
Start: "// ",
End: " //",
},
".py": {
Start: "# ",
End: " #",
},
"default": {
Start: "// ",
End: " //",
},
}

func CheckWorkspaceFolder() bool {
repoRoot := git.GetRepositoryRoot()
rootDir := git.GetRepositoryRoot()

featuresPath := filepath.Join(repoRoot, ".features")
featuresPath := filepath.Join(rootDir, ".features")

// Check if the .features directory exists
if _, err := os.Stat(featuresPath); os.IsNotExist(err) {
Expand All @@ -22,11 +57,27 @@ func CheckWorkspaceFolder() bool {
logger.Fatal[error](err)
}

versionsExists := filesystem.FileFolderExists(filepath.Join(repoRoot, ".features", "versions"))
blocksExists := filesystem.FileFolderExists(filepath.Join(repoRoot, ".features", "blocks"))
delimetersExists := filesystem.FileExists(filepath.Join(repoRoot, ".features", "delimeters"))
versionsExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "versions"))
blocksExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "blocks"))
delimetersExists := filesystem.FileExists(filepath.Join(rootDir, ".features", "delimeters"))

if !versionsExists && !blocksExists && !delimetersExists {
return false
}

if !versionsExists {
filesystem.FileCreateFolder(filepath.Join(rootDir, ".features", "versions"))
}

return versionsExists && blocksExists && delimetersExists
if !blocksExists {
filesystem.FileCreateFolder(filepath.Join(rootDir, ".features", "blocks"))
}

if !delimetersExists {
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "delimeters"), delimeters)
}

return true
}

func CreateNewWorkspace() {
Expand All @@ -37,42 +88,6 @@ func CreateNewWorkspace() {
filesystem.FileCreateFolder(filepath.Join(rootDir, ".features"))
filesystem.FileCreateFolder(filepath.Join(rootDir, ".features", "blocks"))
filesystem.FileCreateFolder(filepath.Join(rootDir, ".features", "versions"))

var delimeters types.Delimeters = map[string]types.Delimeter{
".xqy": {
Start: "(:~ ",
End: " ~:)",
},
".xml": {
Start: "<!-- ",
End: " -->",
},
".html": {
Start: "<!-- ",
End: " -->",
},
".cc": {
Start: "// ",
End: " //",
},
".cpp": {
Start: "// ",
End: " //",
},
".go": {
Start: "// ",
End: " //",
},
".py": {
Start: "# ",
End: " #",
},
"default": {
Start: "// ",
End: " //",
},
}

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "delimeters"), delimeters)

logger.Success[string]("folder .features created")
Expand Down

0 comments on commit b1ca6d8

Please sign in to comment.