diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-04 18:24:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-16 18:01:29 +0200 |
commit | 241b21b0fd34d91fccb2ce69874110dceae6f926 (patch) | |
tree | d4e0118eac7e9c42f065815447a70805f8d6ad3e /modules/collect.go | |
parent | 6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff) |
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.
Also,
* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.
Closes #10896
Closes #10620
Diffstat (limited to 'modules/collect.go')
-rw-r--r-- | modules/collect.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/modules/collect.go b/modules/collect.go index fcde1d379..c69e7e7ee 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -52,20 +52,6 @@ func IsNotExist(err error) bool { return errors.Is(err, os.ErrNotExist) } -// CreateProjectModule creates modules from the given config. -// This is used in tests only. -func CreateProjectModule(cfg config.Provider) (Module, error) { - workingDir := cfg.GetString("workingDir") - var modConfig Config - - mod := createProjectModule(nil, workingDir, modConfig) - if err := ApplyProjectConfigDefaults(cfg, mod); err != nil { - return nil, err - } - - return mod, nil -} - func (h *Client) Collect() (ModulesConfig, error) { mc, coll := h.collect(true) if coll.err != nil { @@ -90,6 +76,9 @@ func (h *Client) Collect() (ModulesConfig, error) { } func (h *Client) collect(tidy bool) (ModulesConfig, *collector) { + if h == nil { + panic("nil client") + } c := &collector{ Client: h, } @@ -133,6 +122,16 @@ type ModulesConfig struct { GoWorkspaceFilename string } +func (m ModulesConfig) HasConfigFile() bool { + for _, mod := range m.ActiveModules { + if len(mod.ConfigFilenames()) > 0 { + return true + } + + } + return false +} + func (m *ModulesConfig) setActiveMods(logger loggers.Logger) error { var activeMods Modules for _, mod := range m.AllModules { @@ -230,6 +229,7 @@ func (c *collector) getVendoredDir(path string) (vendoredModule, bool) { } func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool) (*moduleAdapter, error) { + var ( mod *goModule moduleDir string @@ -299,7 +299,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool return nil, nil } if found, _ := afero.Exists(c.fs, moduleDir); !found { - c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found; either add it as a Hugo Module or store it in %q.`, modulePath, c.ccfg.ThemesDir)) + c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found in % q; either add it as a Hugo Module or store it in %q.`, modulePath, moduleDir, c.ccfg.ThemesDir)) return nil, nil } } @@ -347,7 +347,7 @@ func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error { moduleConfig := owner.Config() if owner.projectMod { if err := c.applyMounts(Import{}, owner); err != nil { - return err + return fmt.Errorf("failed to apply mounts for project module: %w", err) } } @@ -618,7 +618,7 @@ func (c *collector) mountCommonJSConfig(owner *moduleAdapter, mounts []Mount) ([ // Mount the common JS config files. fis, err := afero.ReadDir(c.fs, owner.Dir()) if err != nil { - return mounts, err + return mounts, fmt.Errorf("failed to read dir %q: %q", owner.Dir(), err) } for _, fi := range fis { |