feat: split config

This commit is contained in:
Kevin Franklin Kim 2024-03-08 23:31:23 +01:00
parent 604aadb998
commit ea8cd02961
No known key found for this signature in database
5 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)
}

View File

@ -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]) {

View File

@ -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