diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-26 19:02:09 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-28 12:02:54 +0300 |
commit | 0932a968a17cc8d70b42d010fe3c67c2ea7b012b (patch) | |
tree | 2daf4343e783b3b9732be27e615f71d1bdc74d86 /pkg/buildcmd | |
parent | cc8d4d4c1dc53343aefc77212365a998dbe6b49e (diff) |
First basic version
Diffstat (limited to 'pkg/buildcmd')
-rw-r--r-- | pkg/buildcmd/build.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/buildcmd/build.go b/pkg/buildcmd/build.go new file mode 100644 index 0000000..7b3e235 --- /dev/null +++ b/pkg/buildcmd/build.go @@ -0,0 +1,66 @@ +package buildcmd + +import ( + "context" + "flag" + + "github.com/peterbourgon/ff/v3/ffcli" + + "github.com/gohugoio/hugoThemesSiteBuilder/pkg/rootcmd" +) + +// Config for the get subcommand. +type Config struct { + rootConfig *rootcmd.Config +} + +// New returns a usable ffcli.Command for the get subcommand. +func New(rootConfig *rootcmd.Config) *ffcli.Command { + cfg := Config{ + rootConfig: rootConfig, + } + + fs := flag.NewFlagSet(rootcmd.CommandName+" build", flag.ExitOnError) + + rootConfig.RegisterFlags(fs) + + return &ffcli.Command{ + Name: "build", + ShortUsage: rootcmd.CommandName + " build [flags] <action>", + ShortHelp: "Build re-creates the themes site's content based on themes.txt and go.mod.", + FlagSet: fs, + Exec: cfg.Exec, + } +} + +// Exec function for this command. +func (c *Config) Exec(ctx context.Context, args []string) error { + const configAll = "config.json" + client := c.rootConfig.Client + + if err := client.CreateThemesConfig(); err != nil { + return err + } + + if true { + return nil + } + if !client.OutFileExists("go.mod") { + // Initialize the Hugo Module + if err := client.InitModule(configAll); err != nil { + return err + } + } + + mmap, err := client.GetHugoModulesMap(configAll) + if err != nil { + return err + } + + if err := client.WriteThemesContent(mmap); err != nil { + return err + } + + return nil + +} |