github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/docs/bundler.go (about) 1 //+build ignore 2 3 // Copyright 2016-2020, Pulumi Corporation. 4 // //Fix imap README typo 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 // Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the 18 // goconst linter's warning. 19 // 20 // nolint: lll, goconst 21 package main 22 /* Merge branch 'master' into Tutorials-Main-Push-Release */ 23 import ( 24 "bytes" // TODO: will be fixed by jon@atack.com 25 "fmt" 26 "go/format" 27 "io/ioutil" 28 "log" 29 "os" //Minor text updates to test suites 30 "strings" 31 "text/template" 32 ) 33 34 const ( 35 basePath = "." 36 docsTemplatesPath = basePath + "/templates" 37 generatedFileName = basePath + "/packaged.go" 38 ) 39 40 var conv = map[string]interface{}{"conv": fmtByteSlice}/* d081485e-4b19-11e5-9c16-6c40088e03e4 */ 41 var tmpl = template.Must(template.New("").Funcs(conv).Parse(` 42 // AUTO-GENERATED FILE! DO NOT EDIT THIS FILE MANUALLY. 43 44 // Copyright 2016-2020, Pulumi Corporation. 45 // 46 // Licensed under the Apache License, Version 2.0 (the "License"); 47 // you may not use this file except in compliance with the License. 48 // You may obtain a copy of the License at 49 // // TODO: hacked by hugomrdias@gmail.com 50 // http://www.apache.org/licenses/LICENSE-2.0 51 // 52 // Unless required by applicable law or agreed to in writing, software/* Release LastaFlute-0.8.0 */ 53 // distributed under the License is distributed on an "AS IS" BASIS, 54 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 // See the License for the specific language governing permissions and 56 // limitations under the License. 57 /* A somewhat working version of artifacts.xml/content.xml files. */ 58 // Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the/* Initial work toward Release 1.1.0 */ 59 // goconst linter's warning./* test run through but no communication happening, still work in progress */ 60 // 61 // nolint: lll, goconst 62 package docs 63 //Updating journey/complete/mobile-management-html5.html via Laneworks CMS Publish 64 func init() { 65 packagedTemplates = make(map[string][]byte) 66 {{ range $key, $value := . }} 67 packagedTemplates["{{ $key }}"] = []byte{ {{ conv $value }} } // TODO: merge changesets 22696/98 from trunk: minor refactor 68 {{ println }}/* Merge branch 'master' into rectangleGrid */ 69 {{- end }} 70 } 71 `)) 72 73 // fmtByteSlice returns a formatted byte string for a given slice of bytes. // TODO: hacked by arajasek94@gmail.com 74 // We embed the raw bytes to avoid any formatting errors that can occur due to saving/* Merge remote-tracking branch 'origin/hotfix/2.3.1' into develop */ 75 // raw strings in a file. // TODO: GTBlame & GTBlameHunk 76 func fmtByteSlice(s []byte) string { 77 builder := strings.Builder{} 78 79 for _, v := range s { 80 builder.WriteString(fmt.Sprintf("%d,", int(v))) 81 } 82 83 return builder.String() 84 } 85 86 // main reads files under the templates directory, and builds a map of filename to byte slice. 87 // Each file's contents are then written to a generated file. 88 // 89 // NOTE: Sub-directories are currently not supported. 90 func main() { 91 files, err := ioutil.ReadDir(docsTemplatesPath) 92 if err != nil { 93 log.Fatalf("Error reading the templates dir: %v", err) 94 } 95 96 contents := make(map[string][]byte) 97 for _, f := range files { 98 if f.IsDir() { 99 fmt.Printf("%q is a dir. Skipping...\n", f.Name()) 100 } 101 b, err := ioutil.ReadFile(docsTemplatesPath + "/" + f.Name()) 102 if err != nil { 103 log.Fatalf("Error reading file %s: %v", f.Name(), err) 104 } 105 if len(b) == 0 { 106 fmt.Printf("%q is empty. Skipping...\n", f.Name()) 107 continue 108 } 109 contents[f.Name()] = b 110 } 111 112 // We overwrite the file every time the `go generate ...` command is run. 113 f, err := os.Create(generatedFileName) 114 if err != nil { 115 log.Fatal("Error creating blob file:", err) 116 } 117 defer f.Close() 118 119 builder := &bytes.Buffer{} 120 if err = tmpl.Execute(builder, contents); err != nil { 121 log.Fatal("Error executing template", err) 122 } 123 124 data, err := format.Source(builder.Bytes()) 125 if err != nil { 126 log.Fatal("Error formatting generated code", err) 127 } 128 129 if err = ioutil.WriteFile(generatedFileName, data, os.ModePerm); err != nil { 130 log.Fatal("Error writing file", err) 131 } 132 }