github.com/oam-dev/kubevela@v1.9.11/hack/docgen/terraform/generate.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 "os" 24 "strings" 25 26 "github.com/oam-dev/kubevela/apis/types" 27 "github.com/oam-dev/kubevela/pkg/utils/common" 28 "github.com/oam-dev/kubevela/references/docgen" 29 ) 30 31 const ( 32 // KubeVelaIOTerraformPath is the target path for kubevela.io terraform docs 33 KubeVelaIOTerraformPath = "../kubevela.io/docs/end-user/components/cloud-services/terraform" 34 // KubeVelaIOTerraformPathZh is the target path for kubevela.io terraform docs in Chinese 35 KubeVelaIOTerraformPathZh = "../kubevela.io/i18n/zh/docusaurus-plugin-content-docs/current/end-user/components/cloud-services/terraform" 36 ) 37 38 func main() { 39 ref := &docgen.MarkdownReference{} 40 ctx := context.Background() 41 42 c, err := common.InitBaseRestConfig() 43 if err != nil { 44 fmt.Println(err) 45 os.Exit(1) 46 } 47 ref.Remote = &docgen.FromCluster{Namespace: types.DefaultKubeVelaNS} 48 ref.Filter = func(capability types.Capability) bool { 49 if capability.Labels != nil && capability.Labels[types.LabelDefinitionHidden] == "true" { 50 return false 51 } 52 return capability.Type == types.TypeComponentDefinition && capability.Category == types.TerraformCategory 53 } 54 55 path := flag.String("path", "", "path of output") 56 location := flag.String("location", "", "path of output") 57 i18nfile := flag.String("i18n", "../kubevela.io/static/reference-i18n.json", "file path of i18n data") 58 flag.Parse() 59 60 if *i18nfile != "" { 61 docgen.LoadI18nData(*i18nfile) 62 } 63 64 if *path != "" { 65 ref.I18N = &docgen.En 66 if strings.Contains(*location, "zh") || strings.Contains(*location, "chinese") { 67 ref.I18N = &docgen.Zh 68 } 69 if err := ref.GenerateReferenceDocs(ctx, c, *path); err != nil { 70 fmt.Println(err) 71 os.Exit(1) 72 } 73 fmt.Printf("terraform reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), *path) 74 } 75 ref.I18N = &docgen.En 76 if err := ref.GenerateReferenceDocs(ctx, c, KubeVelaIOTerraformPath); err != nil { 77 fmt.Println(err) 78 os.Exit(1) 79 } 80 fmt.Printf("terraform reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), KubeVelaIOTerraformPath) 81 ref.I18N = &docgen.Zh 82 if err := ref.GenerateReferenceDocs(ctx, c, KubeVelaIOTerraformPathZh); err != nil { 83 fmt.Println(err) 84 os.Exit(1) 85 } 86 fmt.Printf("terraform reference docs (%s) successfully generated in %s \n", ref.I18N.Language(), KubeVelaIOTerraformPathZh) 87 }