github.com/devstream-io/devstream@v0.13.3/internal/pkg/scaffold/scaffold.go (about) 1 package scaffold 2 3 func Scaffold(tree string) error { 4 return nil 5 } 6 7 // parseTreeToList parses the directory tree represented by a string and 8 // returns a list of directories and files. 9 // for example input:" 10 // testdir/ 11 // ├── dir1/ 12 // │ ├── file1.go 13 // │ └── dir2/ 14 // │ ├── file1.go 15 // │ └── file2.go 16 // └── FILE3.md 17 // " 18 // output: 19 // 20 // []string{ 21 // "testdir/", 22 // "testdir/dir1/", 23 // "testdir/dir1/file1.go", 24 // "testdir/dir1/dir2/", 25 // "testdir/dir1/dir2/file1.go", 26 // "testdir/dir1/dir2/file2.go", 27 // } 28 //func parseTreeToList(tree string) ([]string, error) { 29 // tree = strings.ReplaceAll(tree, "\r\n", "\n") 30 // tree = strings.ReplaceAll(tree, "\r", "\n") 31 // tree = strings.ReplaceAll(tree, "\t", "") 32 // tree = strings.ReplaceAll(tree, "\n\n", "\n") 33 // tree = strings.ReplaceAll(tree, "─", "-") 34 // tree = strings.ReplaceAll(tree, "│", "|") 35 // 36 // lines := strings.Split(tree, "\n") 37 // var result []string 38 // 39 // for _, line := range lines { 40 // line = strings.TrimSpace(line) 41 // 42 // if len(line) == 0 { 43 // continue 44 // } 45 // 46 // level := 0 47 // for ; strings.HasPrefix(line, " "); level++ { 48 // line = line[2:] 49 // } 50 // 51 // prefix := strings.Repeat(" ", level) 52 // 53 // if strings.HasSuffix(line, "/") { 54 // result = append(result, prefix+line) 55 // } else { 56 // result = append(result, prefix+line) 57 // } 58 // 59 // } 60 // 61 // return result, nil 62 //} 63 // 64 //func ParseTree(tree string) ([]string, error) { 65 // var result []string 66 // 67 // lines := strings.Split(tree, "\n") 68 // for _, line := range lines { 69 // if strings.TrimSpace(line) == "" { 70 // continue 71 // } 72 // 73 // parts := strings.Split(line, " ") 74 // level := strings.Count(parts[0], "│") + strings.Count(parts[0], "└") + strings.Count(parts[0], "├") 75 // name := strings.TrimSpace(parts[len(parts)-1]) 76 // 77 // // Construct the full path by combining the names of all parent directories 78 // path := "" 79 // for i := 1; i < level; i++ { 80 // if len(result) < i { 81 // return nil, fmt.Errorf("parent directory not found: %s", line) 82 // } 83 // path += result[i-1] + "/" 84 // } 85 // path += name 86 // 87 // result = append(result, path) 88 // } 89 // 90 // return result, nil 91 //}