mirror of
https://github.com/foomo/sesamy-cli.git
synced 2025-10-16 12:35:36 +00:00
feat: split config
This commit is contained in:
parent
604aadb998
commit
ea8cd02961
@ -16,8 +16,15 @@ google:
|
|||||||
|
|
||||||
credentials_file: ./tmp/google_service_account_creds.json
|
credentials_file: ./tmp/google_service_account_creds.json
|
||||||
|
|
||||||
events:
|
typescript:
|
||||||
packages:
|
packages:
|
||||||
- path: "github.com/foomo/sesamy-cli/_example/server"
|
- path: "github.com/foomo/sesamy-cli/_example/server"
|
||||||
output_path: "./_example/client/types.d.ts"
|
output_path: "./_example/client/types.d.ts"
|
||||||
indent: "\t"
|
indent: "\t"
|
||||||
|
|
||||||
|
tagmanager:
|
||||||
|
packages:
|
||||||
|
- path: "github.com/foomo/sesamy-cli/_example/server"
|
||||||
|
output_path: "./_example/client/types.d.ts"
|
||||||
|
exclude_files:
|
||||||
|
- item.go
|
||||||
|
|||||||
@ -21,7 +21,7 @@ var tagmanagerWebCmd = &cobra.Command{
|
|||||||
clientCredentialsOption = option.WithCredentialsJSON([]byte(cfg.Google.CredentialsJSON))
|
clientCredentialsOption = option.WithCredentialsJSON([]byte(cfg.Google.CredentialsJSON))
|
||||||
}
|
}
|
||||||
|
|
||||||
eventParameters, err := internal.GetEventParameters(cfg)
|
eventParameters, err := internal.GetEventParameters(cfg.Tagmanager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,9 @@ var typescriptCmd = &cobra.Command{
|
|||||||
PersistentPreRunE: preRunReadConfig,
|
PersistentPreRunE: preRunReadConfig,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
gen := tygo.New(&tygo.Config{
|
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)
|
gen.SetTypeMapping(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,12 +13,12 @@ import (
|
|||||||
"golang.org/x/tools/go/packages"
|
"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{}
|
ret := map[string][]string{}
|
||||||
|
|
||||||
pkgs, err := packages.Load(&packages.Config{
|
pkgs, err := packages.Load(&packages.Config{
|
||||||
Mode: packages.NeedSyntax | packages.NeedFiles,
|
Mode: packages.NeedSyntax | packages.NeedFiles,
|
||||||
}, cfg.Events.PackageNames()...)
|
}, source.PackageNames()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
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 {
|
for i, file := range pkg.Syntax {
|
||||||
if conf.IsFileIgnored(pkg.GoFiles[i]) {
|
if conf.IsFileIgnored(pkg.GoFiles[i]) {
|
||||||
|
|||||||
@ -7,7 +7,9 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Google Google `yaml:"google"`
|
Google Google `yaml:"google"`
|
||||||
// https://github.com/gzuidhof/tygo
|
// 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 {
|
type Google struct {
|
||||||
@ -27,12 +29,12 @@ type GTM struct {
|
|||||||
Server Container `yaml:"server"`
|
Server Container `yaml:"server"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Events struct {
|
type Source struct {
|
||||||
Packages []*tygo.PackageConfig `yaml:"packages"`
|
Packages []*tygo.PackageConfig `yaml:"packages"`
|
||||||
TypeMappings map[string]string `yaml:"type_mappings"`
|
TypeMappings map[string]string `yaml:"type_mappings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Events) PackageNames() []string {
|
func (e Source) PackageNames() []string {
|
||||||
ret := make([]string, len(e.Packages))
|
ret := make([]string, len(e.Packages))
|
||||||
for i, value := range e.Packages {
|
for i, value := range e.Packages {
|
||||||
ret[i] = value.Path
|
ret[i] = value.Path
|
||||||
@ -40,7 +42,7 @@ func (e Events) PackageNames() []string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Events) PackageConfig(path string) *tygo.PackageConfig {
|
func (e Source) PackageConfig(path string) *tygo.PackageConfig {
|
||||||
for _, value := range e.Packages {
|
for _, value := range e.Packages {
|
||||||
if value.Path == path {
|
if value.Path == path {
|
||||||
return value
|
return value
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user