diff --git a/_example/sesamy.yaml b/_example/sesamy.yaml index 958bb45..28201ce 100644 --- a/_example/sesamy.yaml +++ b/_example/sesamy.yaml @@ -16,8 +16,15 @@ google: credentials_file: ./tmp/google_service_account_creds.json -events: +typescript: packages: - path: "github.com/foomo/sesamy-cli/_example/server" output_path: "./_example/client/types.d.ts" indent: "\t" + +tagmanager: + packages: + - path: "github.com/foomo/sesamy-cli/_example/server" + output_path: "./_example/client/types.d.ts" + exclude_files: + - item.go diff --git a/cmd/tagmanagerweb.go b/cmd/tagmanagerweb.go index ce54300..b442ba0 100644 --- a/cmd/tagmanagerweb.go +++ b/cmd/tagmanagerweb.go @@ -21,7 +21,7 @@ var tagmanagerWebCmd = &cobra.Command{ clientCredentialsOption = option.WithCredentialsJSON([]byte(cfg.Google.CredentialsJSON)) } - eventParameters, err := internal.GetEventParameters(cfg) + eventParameters, err := internal.GetEventParameters(cfg.Tagmanager) if err != nil { return err } diff --git a/cmd/typescript.go b/cmd/typescript.go index 34b8766..0a1a2b8 100644 --- a/cmd/typescript.go +++ b/cmd/typescript.go @@ -12,9 +12,9 @@ var typescriptCmd = &cobra.Command{ PersistentPreRunE: preRunReadConfig, RunE: func(cmd *cobra.Command, args []string) error { gen := tygo.New(&tygo.Config{ - Packages: cfg.Events.Packages, + Packages: cfg.Typescript.Packages, }) - for k, v := range cfg.Events.TypeMappings { + for k, v := range cfg.Typescript.TypeMappings { gen.SetTypeMapping(k, v) } diff --git a/internal/events.go b/internal/events.go index dd0d562..ac3362a 100644 --- a/internal/events.go +++ b/internal/events.go @@ -13,12 +13,12 @@ import ( "golang.org/x/tools/go/packages" ) -func GetEventParameters(cfg *config.Config) (map[string][]string, error) { +func GetEventParameters(source config.Source) (map[string][]string, error) { ret := map[string][]string{} pkgs, err := packages.Load(&packages.Config{ Mode: packages.NeedSyntax | packages.NeedFiles, - }, cfg.Events.PackageNames()...) + }, source.PackageNames()...) if err != nil { return nil, err } @@ -32,7 +32,7 @@ func GetEventParameters(cfg *config.Config) (map[string][]string, error) { return nil, fmt.Errorf("no input go files for package index %d", i) } - conf := cfg.Events.PackageConfig(pkg.ID) + conf := source.PackageConfig(pkg.ID) for i, file := range pkg.Syntax { if conf.IsFileIgnored(pkg.GoFiles[i]) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 0cfdd88..c0a2976 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -7,7 +7,9 @@ import ( type Config struct { Google Google `yaml:"google"` // https://github.com/gzuidhof/tygo - Events Events `yaml:"events"` + Typescript Source `yaml:"typescript"` + // https://github.com/gzuidhof/tygo + Tagmanager Source `yaml:"tagmanager"` } type Google struct { @@ -27,12 +29,12 @@ type GTM struct { Server Container `yaml:"server"` } -type Events struct { +type Source struct { Packages []*tygo.PackageConfig `yaml:"packages"` TypeMappings map[string]string `yaml:"type_mappings"` } -func (e Events) PackageNames() []string { +func (e Source) PackageNames() []string { ret := make([]string, len(e.Packages)) for i, value := range e.Packages { ret[i] = value.Path @@ -40,7 +42,7 @@ func (e Events) PackageNames() []string { return ret } -func (e Events) PackageConfig(path string) *tygo.PackageConfig { +func (e Source) PackageConfig(path string) *tygo.PackageConfig { for _, value := range e.Packages { if value.Path == path { return value