rm ignored files
This commit is contained in:
parent
52786613dc
commit
9d2121df6a
7 changed files with 74 additions and 78 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -7,4 +7,5 @@ js/node_modules
|
|||
go.work
|
||||
go.work.sum
|
||||
.idea
|
||||
!framework/assets/dist
|
||||
!framework/assets/dist
|
||||
/**/__htmgo
|
||||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HasFileFromRoot(file string) bool {
|
||||
|
|
@ -73,3 +74,65 @@ func CopyFile(src, dst string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteAllExcept(path string, keepDir string) error {
|
||||
// Get the info of the path
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
// We only care about directories
|
||||
return nil
|
||||
}
|
||||
|
||||
// If path is the keepDir, do nothing
|
||||
if path == keepDir {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if keepDir is under path (path is an ancestor of keepDir)
|
||||
relToKeepDir, err := filepath.Rel(path, keepDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(relToKeepDir, "..") {
|
||||
// keepDir is under path; recurse into subdirectories
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
entryPath := filepath.Join(path, entry.Name())
|
||||
err := DeleteAllExcept(entryPath, keepDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check if path is under keepDir (path is a descendant of keepDir)
|
||||
relFromKeepDir, err := filepath.Rel(keepDir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(relFromKeepDir, "..") {
|
||||
// path is under keepDir; do nothing
|
||||
return nil
|
||||
} else {
|
||||
// path is neither keepDir nor related; delete it
|
||||
slog.Debug("Deleting directory:", slog.String("path", path))
|
||||
err = os.RemoveAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Skip further traversal since the directory is deleted
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package downloadtemplate
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/maddalax/htmgo/cli/htmgo/internal/dirutil"
|
||||
"github.com/maddalax/htmgo/cli/htmgo/tasks/process"
|
||||
"github.com/maddalax/htmgo/cli/htmgo/tasks/run"
|
||||
"github.com/maddalax/htmgo/cli/htmgo/tasks/util"
|
||||
|
|
@ -13,31 +14,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func deleteAllExceptTemplate(outPath string, excludeDir string) {
|
||||
// List all files and directories in the root folder
|
||||
files, err := os.ReadDir(outPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading directory: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Iterate through each item in the root folder
|
||||
for _, file := range files {
|
||||
// Skip the excluded directory
|
||||
if file.Name() == excludeDir {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get full path
|
||||
fullPath := filepath.Join(outPath, file.Name())
|
||||
|
||||
err := os.RemoveAll(fullPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error removing %s: %v\n", fullPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DownloadTemplate(outPath string) {
|
||||
cwd, _ := os.Getwd()
|
||||
|
||||
|
|
@ -69,13 +45,16 @@ func DownloadTemplate(outPath string) {
|
|||
return
|
||||
}
|
||||
|
||||
deleteAllExceptTemplate(outPath, templatePath)
|
||||
dirutil.DeleteAllExcept(outPath, templatePath)
|
||||
|
||||
newDir := filepath.Join(cwd, outPath)
|
||||
|
||||
dirutil.CopyDir(templatePath, newDir, func(path string, exists bool) bool {
|
||||
return true
|
||||
})
|
||||
|
||||
commands := [][]string{
|
||||
{"cp", "-vaR", fmt.Sprintf("%s/.", templateName), "."},
|
||||
{"rm", "-rf", templateName},
|
||||
{"rm", "-rf", templatePath},
|
||||
{"go", "get", "github.com/maddalax/htmgo/framework"},
|
||||
{"go", "get", "github.com/maddalax/htmgo/framework-ui"},
|
||||
{"git", "init"},
|
||||
|
|
|
|||
2
templates/starter/.gitignore
vendored
2
templates/starter/.gitignore
vendored
|
|
@ -2,3 +2,5 @@
|
|||
tmp
|
||||
node_modules
|
||||
.idea
|
||||
__htmgo
|
||||
dist
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
package __htmgo
|
||||
|
||||
import "github.com/labstack/echo/v4"
|
||||
import "github.com/maddalax/htmgo/framework/h"
|
||||
import "starter-template/pages"
|
||||
|
||||
func RegisterPages(f *echo.Echo) {
|
||||
f.GET("/", func(ctx echo.Context) error {
|
||||
cc := ctx.(*h.RequestContext)
|
||||
return h.HtmlView(ctx, pages.IndexPage(cc))
|
||||
})
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
package __htmgo
|
||||
|
||||
import "github.com/maddalax/htmgo/framework/h"
|
||||
import "github.com/labstack/echo/v4"
|
||||
import "starter-template/partials"
|
||||
|
||||
func GetPartialFromContext(ctx echo.Context) *h.Partial {
|
||||
path := ctx.Request().URL.Path
|
||||
if path == "CounterPartial" || path == "/starter-template/partials.CounterPartial" {
|
||||
cc := ctx.(*h.RequestContext)
|
||||
return partials.CounterPartial(cc)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func RegisterPartials(f *echo.Echo) {
|
||||
f.Any("starter-template/partials*", func(ctx echo.Context) error {
|
||||
partial := GetPartialFromContext(ctx)
|
||||
if partial == nil {
|
||||
return ctx.NoContent(404)
|
||||
}
|
||||
return h.PartialView(ctx, partial)
|
||||
})
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
package __htmgo
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func Register(e *echo.Echo) {
|
||||
RegisterPartials(e)
|
||||
RegisterPages(e)
|
||||
}
|
||||
Loading…
Reference in a new issue