Skip to content

Commit

Permalink
misc: nth refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed May 16, 2024
1 parent bb1e32d commit 3b5456e
Show file tree
Hide file tree
Showing 339 changed files with 6,303 additions and 6,296 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Versions
MANALA_GO_VERSION=1.22.2
MANALA_GO_VERSION=1.22.3
MANALA_GORELEASER_VERSION=1.25.1
MANALA_GOLANGCI_LINT_VERSION=1.57.2
MANALA_GOLANGCI_LINT_VERSION=1.58.1
MANALA_RICHGO_VERSION=0.3.12
MANALA_MKDOCS_VERSION=9.0.6
MANALA_VHS_VERSION=0.6.0
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# See: https://github.com/golangci/golangci-lint-action/pull/704
cache: false
- name: Lint - GolangCI
uses: golangci/golangci-lint-action@v5
uses: golangci/golangci-lint-action@v6
with:
version: v${{ env.MANALA_GOLANGCI_LINT_VERSION }}
# See: https://github.com/golangci/golangci-lint-action/issues/297
Expand Down
124 changes: 8 additions & 116 deletions app/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,16 @@ package api

import (
"log/slog"
"manala/app"
"manala/app/config"
"manala/app/project"
"manala/app/recipe"
"manala/app/repository"
"manala/internal/cache"
"manala/internal/syncer"
"manala/internal/ui"
"manala/internal/watcher"
)

// New creates an api
func New(conf *config.Config, log *slog.Logger, out ui.Output, opts ...Option) *Api {
// Api
func New(log *slog.Logger, cache *cache.Cache, opts ...Option) *Api {
api := &Api{
config: conf,
log: log,
out: out,
exclusionPaths: []string{
// Git
".git", ".github",
// NodeJS
"node_modules",
// Composer
"vendor",
// IntelliJ
".idea",
// Manala
".manala",
},
log: log,
cache: cache,
}

// Cache
cache := cache.New(
api.config.CacheDir,
cache.WithUserDir("manala"),
)

// Syncer
api.syncer = syncer.New(api.log)

// Watcher manager
api.watcherManager = watcher.NewManager(api.log)

// Repository manager
api.repositoryManager = repository.NewUrlProcessorManager(
api.log,
repository.NewCacheManager(
api.log,
repository.NewGetterManager(
api.log,
cache,
),
),
)
api.repositoryManager.AddUrl(
api.config.Repository,
-10,
)

// Recipe manager
api.recipeManager = recipe.NewNameProcessorManager(
api.log,
recipe.NewDirManager(
api.log,
recipe.WithExclusionPaths(api.exclusionPaths),
),
)

// Project manager
api.projectManager = project.NewManager(
api.log,
api.repositoryManager,
api.recipeManager,
)

// Options
for _, opt := range opts {
opt(api)
Expand All @@ -87,57 +21,15 @@ func New(conf *config.Config, log *slog.Logger, out ui.Output, opts ...Option) *
}

type Api struct {
config *config.Config
log *slog.Logger
out ui.Output
syncer *syncer.Syncer
watcherManager *watcher.Manager
repositoryManager *repository.UrlProcessorManager
recipeManager *recipe.NameProcessorManager
projectManager app.ProjectManager
exclusionPaths []string
log *slog.Logger
cache *cache.Cache
defaultRepositoryUrl string
}

type Option func(api *Api)

func WithRepositoryUrl(url string) Option {
return func(api *Api) {
priority := 10

// Log
api.log.Debug("repository option",
"url", url,
"priority", priority,
)

api.repositoryManager.AddUrl(url, priority)
}
}

func WithRepositoryRef(ref string) Option {
return func(api *Api) {
priority := 20

// Log
api.log.Debug("repository option",
"ref", ref,
"priority", priority,
)

api.repositoryManager.AddUrlQuery("ref", ref, priority)
}
}

func WithRecipeName(name string) Option {
func WithDefaultRepositoryUrl(url string) Option {
return func(api *Api) {
priority := 10

// Log
api.log.Debug("recipe option",
"name", name,
"priority", priority,
)

api.recipeManager.AddName(name, priority)
api.defaultRepositoryUrl = url
}
}
14 changes: 0 additions & 14 deletions app/api/api_test.go

This file was deleted.

Loading

0 comments on commit 3b5456e

Please sign in to comment.