mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 13:40:38 +03:00
modules: Improve "hugo mod clean"
* Only clean project modules * Optional glob pattern of module paths to clean Closes #6907
This commit is contained in:
parent
0b96aba022
commit
dce210ab56
3 changed files with 62 additions and 22 deletions
|
@ -26,6 +26,9 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
|
@ -339,6 +342,38 @@ func (c *Client) Verify(clean bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Clean(pattern string) error {
|
||||
mods, err := c.listGoMods()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var g glob.Glob
|
||||
|
||||
if pattern != "" {
|
||||
var err error
|
||||
g, err = hglob.GetGlob(pattern)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, m := range mods {
|
||||
if m.Replace != nil || m.Main {
|
||||
continue
|
||||
}
|
||||
|
||||
if g != nil && !g.Match(m.Path) {
|
||||
continue
|
||||
}
|
||||
_, err = hugofs.MakeReadableAndRemoveAllModulePkgDir(c.fs, m.Dir)
|
||||
if err == nil {
|
||||
c.logger.FEEDBACK.Printf("hugo: cleaned module cache for %q", m.Path)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) runVerify() error {
|
||||
return c.runGo(context.Background(), ioutil.Discard, "mod", "verify")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue