generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(mage): add action to generate readme
- Loading branch information
Showing
4 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//go:build mage | ||
// +build mage | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type ReadmeParams struct { | ||
Docs string | ||
Name string | ||
ContractName string | ||
SchemaName string | ||
Ref string | ||
} | ||
|
||
func generateReadme(contract string) error { | ||
fmt.Printf(" 📄 Generating %s readme\n", contract) | ||
|
||
readme, err := os.ReadFile(filepath.Join(CONTRACTS_TMP_DIR, "docs", fmt.Sprintf("%s.md", contract))) | ||
name := strings.TrimPrefix(contract, "axone-") | ||
schemaName := fmt.Sprintf("%s-schema", name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
params := ReadmeParams{ | ||
Docs: string(readme), | ||
Name: name, | ||
ContractName: contract, | ||
SchemaName: schemaName, | ||
Ref: tag(), | ||
} | ||
|
||
return ts(params) | ||
} | ||
|
||
func ts(params ReadmeParams) error { | ||
fmt.Println(" ➡️ Typescript readme") | ||
tmpl, err := template.ParseFiles(filepath.Join("ts", "README.md.template")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
readmeFile, err := os.Create(filepath.Join("ts", params.SchemaName, "README.md")) | ||
if err != nil { | ||
return err | ||
} | ||
defer readmeFile.Close() | ||
|
||
return tmpl.Execute(readmeFile, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters