Skip to content

Commit

Permalink
fix: list all files on commit base
Browse files Browse the repository at this point in the history
  • Loading branch information
costaluu committed Sep 14, 2024
1 parent 5bd0c9b commit 30830fe
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 142 deletions.
5 changes: 2 additions & 3 deletions src/bubbletea/components/fileiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/costaluu/flag/constants"
"github.com/costaluu/flag/logger"
"github.com/costaluu/flag/types"
)
Expand Down Expand Up @@ -57,7 +56,7 @@ func (m IteratorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Everything's been installed. We're done!
m.done = true
return m, tea.Sequence(
tea.Printf("%s %s", constants.CheckMark.Render(), path.Path), // print the last success message
tea.Printf(" %s", path.Path), // print the last success message
tea.Quit, // exit the program
)
}
Expand All @@ -66,7 +65,7 @@ func (m IteratorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.index++

return m, tea.Batch(
tea.Printf("%s %s", constants.CheckMark.Render(), path.Path), // print success message above our program
tea.Printf(" %s", path.Path), // print success message above our program
m.runner(m.paths[m.index]), // process the next path
)
case spinner.TickMsg:
Expand Down
49 changes: 24 additions & 25 deletions src/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func ListBlocksFromPath(path string) []types.BlockFeature {

var features []types.BlockFeature = []types.BlockFeature{}

normalizedPath := utils.HashFilePath(path)
hashedPath := utils.HashFilePath(path)

err := filepath.WalkDir(filepath.Join(rootDir, ".features", "blocks", normalizedPath), func(path string, d os.DirEntry, err error) error {
err := filepath.WalkDir(filepath.Join(rootDir, ".features", "blocks", hashedPath), func(path string, d os.DirEntry, err error) error {
if err != nil {
logger.Fatal[error](err)
}
Expand Down Expand Up @@ -302,27 +302,26 @@ func AllBlocksDetails() {

func UnSyncAllBlocksFromPath(path string) {
var rootDir string = git.GetRepositoryRoot()
var normalizedPath = utils.HashFilePath(path)
var hashedPath = utils.HashFilePath(path)

features := ListBlocksFromPath(path)

for _, feature := range features {
// fmt.Println(feature.Id)
feature.Synced = false

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", feature.Id)), feature)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", feature.Id)), feature)
}
}

func RemoveAllUnsyncedBlocksFromPath(path string) {
var rootDir string = git.GetRepositoryRoot()
var normalizedPath = utils.HashFilePath(path)
var hashedPath = utils.HashFilePath(path)

features := ListBlocksFromPath(path)

for _, feature := range features {
if feature.Synced == false {
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", feature.Id)))
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", feature.Id)))
}
}
}
Expand Down Expand Up @@ -382,8 +381,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
} else if state == constants.STATE_OFF {
var foundBlockById *types.Match = nil

Expand All @@ -410,8 +409,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
} else {
continue
}
Expand Down Expand Up @@ -443,8 +442,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
} else if state == constants.STATE_OFF {
continue
} else {
Expand Down Expand Up @@ -474,8 +473,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
}
} else {
if state == constants.STATE_ON {
Expand Down Expand Up @@ -507,8 +506,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
} else {
var foundBlockById *types.Match = nil

Expand Down Expand Up @@ -536,8 +535,8 @@ func ToggleBlockFeature(featureName string, state string) {

ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)

normalizedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
hashedPath := utils.HashFilePath(path)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", tempBlock.Id)), tempBlock)
}
}
}
Expand Down Expand Up @@ -572,7 +571,7 @@ func PromoteBlockFeature(featureName string) {

for path, blockList := range blocksSet {
featuresMatch := ExtractMatchDataFromFile(filepath.Join(rootDir, path))
normalizedPath := utils.HashFilePath(path)
hashedPath := utils.HashFilePath(path)

for _, block := range blockList {
if block.State == constants.STATE_DEV || block.State == constants.STATE_ON {
Expand Down Expand Up @@ -613,13 +612,13 @@ func PromoteBlockFeature(featureName string) {
ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)
}

filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", block.Id)))
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", block.Id)))
}

blocks := ListBlocksFromPath(path)

if len(blocks) == 0 {
filesystem.FileDeleteFolder(filepath.Join(rootDir, ".features", "blocks", normalizedPath))
filesystem.FileDeleteFolder(filepath.Join(rootDir, ".features", "blocks", hashedPath))
}
}

Expand Down Expand Up @@ -652,7 +651,7 @@ func DemoteBlockFeature(featureName string) {

for path, blockList := range blocksSet {
featuresMatch := ExtractMatchDataFromFile(filepath.Join(rootDir, path))
normalizedPath := utils.HashFilePath(path)
hashedPath := utils.HashFilePath(path)

for _, block := range blockList {
if block.State == constants.STATE_DEV || block.State == constants.STATE_OFF {
Expand Down Expand Up @@ -693,13 +692,13 @@ func DemoteBlockFeature(featureName string) {
ReplaceStringInFile(filepath.Join(rootDir, path), oldString, newString)
}

filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", normalizedPath, fmt.Sprintf("%s.block", block.Id)))
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "blocks", hashedPath, fmt.Sprintf("%s.block", block.Id)))
}

blocks := ListBlocksFromPath(path)

if len(blocks) == 0 {
filesystem.FileDeleteFolder(filepath.Join(rootDir, ".features", "blocks", normalizedPath))
filesystem.FileDeleteFolder(filepath.Join(rootDir, ".features", "blocks", hashedPath))
}
}

Expand Down
Loading

0 comments on commit 30830fe

Please sign in to comment.