Skip to content

Commit

Permalink
feat(create/templaterepository): use template-base, run stencil (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard authored Apr 13, 2022
1 parent aca92d9 commit 4b14ca9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
27 changes: 21 additions & 6 deletions cmd/stencil/create_templaterepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
package main

import (
"errors"
"fmt"
"os"
"os/exec"
"path"

"github.com/getoutreach/stencil/pkg/configuration"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
)
Expand All @@ -22,7 +24,7 @@ func NewCreateTemplateRepositoryCommand() *cli.Command {
Description: "Creates a templaterepository with the provided name in the current directory",
ArgsUsage: "create templaterepository <name>",
Action: func(c *cli.Context) error {
var manifestFileName = "manifest.yaml"
var manifestFileName = "service.yaml"

// ensure we have a name
if c.NArg() != 1 {
Expand Down Expand Up @@ -50,8 +52,11 @@ func NewCreateTemplateRepositoryCommand() *cli.Command {
}
}

tm := &configuration.TemplateRepositoryManifest{
Name: c.Args().Get(0),
tm := &configuration.ServiceManifest{
Name: path.Base(c.Args().Get(0)),
Modules: []*configuration.TemplateRepository{{
Name: "github.com/getoutreach/stencil-template-base",
}},
}

if _, err := os.Stat(manifestFileName); err == nil {
Expand All @@ -65,9 +70,19 @@ func NewCreateTemplateRepositoryCommand() *cli.Command {
defer f.Close()

enc := yaml.NewEncoder(f)
defer enc.Close()
if err := enc.Encode(tm); err != nil {
return err
}
if err := enc.Close(); err != nil {
return err
}

return enc.Encode(tm)
//nolint:gosec // Why: intentional
cmd := exec.CommandContext(c.Context, os.Args[0])
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return errors.Wrap(cmd.Run(), "failed ot run stancil")
},
}
}
10 changes: 5 additions & 5 deletions pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ type TemplateRepository struct {

// Deprecated: Use name instead
// URL is a full URL for a given module
URL string `yaml:"url"`
URL string `yaml:"url,omitempty"`

// Version is a semantic version or branch of the template repository
// that should be downloaded if not set then the latest version is used.
// Note: Setting this equates to pinning the versions, this is not recommended.
Version string `yaml:"version"`
Version string `yaml:"version,omitempty"`
}

// TemplateRepositoryManifest is a manifest of a template repository
Expand All @@ -110,14 +110,14 @@ type TemplateRepositoryManifest struct {
Modules []*TemplateRepository `yaml:"modules"`

// Type is the type of repository this is
Type TemplateRepositoryType `yaml:"type"`
Type TemplateRepositoryType `yaml:"type,omitempty"`

// PostRunCommand is a command to be ran after rendering and post-processors
// have been ran on the project
PostRunCommand []*PostRunCommandSpec `yaml:"postRunCommand"`
PostRunCommand []*PostRunCommandSpec `yaml:"postRunCommand,omitempty"`

// Arguments are a declaration of arguments to the template generator
Arguments map[string]Argument
Arguments map[string]Argument `yaml:"arguments,omitempty"`
}

// PostRunCommandSpec is the spec of a command to be ran and its
Expand Down

0 comments on commit 4b14ca9

Please sign in to comment.