mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Documentation Update (#318)
* Initial update * update * Fix linter issues * Add new documentation template and fix
This commit is contained in:
committed by
Adrian Gallagher
parent
4a41c5cff3
commit
897bcfd9a4
@@ -3,12 +3,13 @@ Thanks to the following contributors:
|
||||
thrasher- | https://github.com/thrasher-
|
||||
shazbert | https://github.com/shazbert
|
||||
gloriousCode | https://github.com/gloriousCode
|
||||
ermalguni | https://github.com/ermalguni
|
||||
xtda | https://github.com/xtda
|
||||
ermalguni | https://github.com/ermalguni
|
||||
vadimzhukck | https://github.com/vadimzhukck
|
||||
140am | https://github.com/140am
|
||||
marcofranssen | https://github.com/marcofranssen
|
||||
vadimzhukck | https://github.com/vadimzhukck
|
||||
cranktakular | https://github.com/cranktakular
|
||||
leilaes | https://github.com/leilaes
|
||||
crackcomm | https://github.com/crackcomm
|
||||
MadCozBadd | https://github.com/MadCozBadd
|
||||
andreygrehov | https://github.com/andreygrehov
|
||||
@@ -29,5 +30,4 @@ starit | https://github.com/starit
|
||||
Jimexist | https://github.com/Jimexist
|
||||
lookfirst | https://github.com/lookfirst
|
||||
zeldrinn | https://github.com/zeldrinn
|
||||
mattkanwisher | https://github.com/mattkanwisher
|
||||
|
||||
|
||||
17
README.md
17
README.md
@@ -129,16 +129,16 @@ Binaries will be published once the codebase reaches a stable condition.
|
||||
### A very special thank you to all who have contributed to this program:
|
||||
|
||||
|User|Github|Contribution Amount|
|
||||
|--|--|--|
|
||||
| thrasher- | https://github.com/thrasher- | 526 |
|
||||
| shazbert | https://github.com/shazbert | 166 |
|
||||
| gloriousCode | https://github.com/gloriousCode | 146 |
|
||||
|--|--|--|| thrasher- | https://github.com/thrasher- | 540 |
|
||||
| shazbert | https://github.com/shazbert | 173 |
|
||||
| gloriousCode | https://github.com/gloriousCode | 150 |
|
||||
| xtda | https://github.com/xtda | 17 |
|
||||
| ermalguni | https://github.com/ermalguni | 14 |
|
||||
| xtda | https://github.com/xtda | 11 |
|
||||
| vadimzhukck | https://github.com/vadimzhukck | 10 |
|
||||
| 140am | https://github.com/140am | 8 |
|
||||
| marcofranssen | https://github.com/marcofranssen | 8 |
|
||||
| vadimzhukck | https://github.com/vadimzhukck | 8 |
|
||||
| cranktakular | https://github.com/cranktakular | 5 |
|
||||
| leilaes | https://github.com/leilaes | 3 |
|
||||
| crackcomm | https://github.com/crackcomm | 3 |
|
||||
| MadCozBadd | https://github.com/MadCozBadd | 2 |
|
||||
| andreygrehov | https://github.com/andreygrehov | 2 |
|
||||
@@ -159,10 +159,5 @@ Binaries will be published once the codebase reaches a stable condition.
|
||||
| Jimexist | https://github.com/Jimexist | 1 |
|
||||
| lookfirst | https://github.com/lookfirst | 1 |
|
||||
| zeldrinn | https://github.com/zeldrinn | 1 |
|
||||
| mattkanwisher | https://github.com/mattkanwisher | 1 |
|
||||
| mKurrels | https://github.com/mKurrels | 1 |
|
||||
| m1kola | https://github.com/m1kola | 1 |
|
||||
| cavapoo2 | https://github.com/cavapoo2 | 1 |
|
||||
|
||||
|
||||
|
||||
|
||||
98
cmd/documentation/README.md
Normal file
98
cmd/documentation/README.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# GoCryptoTrader package Documentation
|
||||
|
||||
<img src="https://github.com/thrasher-/gocryptotrader/blob/master/web/src/assets/page-logo.png?raw=true" width="350px" height="350px" hspace="70">
|
||||
|
||||
|
||||
[](https://travis-ci.org/thrasher-/gocryptotrader)
|
||||
[](https://github.com/thrasher-/gocryptotrader/blob/master/LICENSE)
|
||||
[](https://godoc.org/github.com/thrasher-/gocryptotrader/cmd/documentation)
|
||||
[](http://codecov.io/github/thrasher-/gocryptotrader?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/thrasher-/gocryptotrader)
|
||||
|
||||
|
||||
This documentation package is part of the GoCryptoTrader codebase.
|
||||
|
||||
## This is still in active development
|
||||
|
||||
You can track ideas, planned features and what's in progresss on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader).
|
||||
|
||||
Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTQyYjIxNGVhMWU5MDZlOGYzMmE0NTJmM2MzYWY5NGMzMmM4MzUwNTBjZTEzNjIwODM5NDcxODQwZDljMGQyNGY)
|
||||
|
||||
## Current Features for documentation
|
||||
|
||||
#### This tool allows for the generation of new documentation through templating
|
||||
|
||||
From the `gocryptotrader/cmd/documentation/` folder, using the go command: **go run documentation.go** this will auto-generate and regenerate documentation across the **GoCryptoTrader** code base.
|
||||
>Using the -v command will, ie **go run documentation.go -v** put the tool into verbose mode allowing you to see what is happening with a little more depth.
|
||||
|
||||
Be aware, this tool will:
|
||||
- Works off a configuration JSON file located at ``gocryptotrader/cmd/documentation/`` for future use with multiple repositories.
|
||||
- Automatically find the directory and file tree for the GoCryptoTrader source code and alert you of undocumented file systems which **need** to be updated.
|
||||
- Automatically find the template folder tree.
|
||||
- Fetch an updated contributor list and rank on pull request commit amount
|
||||
- Sets up core folder docs for the root directory tree including **LICENSE** and **CONTRIBUTORS**
|
||||
|
||||
### config.json example
|
||||
|
||||
```json
|
||||
{
|
||||
"githubRepo": "https://api.github.com/repos/thrasher-/gocryptotrader", This is your current repo
|
||||
"exclusionList": { This allows for excluded directories and files
|
||||
"Files": null,
|
||||
"Directories": [
|
||||
"_templates",
|
||||
".git",
|
||||
"web"
|
||||
]
|
||||
},
|
||||
"rootReadmeActive": true, allows a root directory README.md
|
||||
"licenseFileActive": true, allows for a license file to be generated
|
||||
"contributorFileActive": true, fetches a new contributor list
|
||||
"referencePathToRepo": "../../"
|
||||
}
|
||||
```
|
||||
### Template example
|
||||
>place a new template **example_file.tmpl** located in the current gocryptotrader/cmd/documentation/ folder; when the documentation tool finishes it will give you the define template associated name e.g. ``Template not found for path ../../cmd/documentation create new template with \{\{define "cmd documentation" -\}\} TEMPLATE HERE \{\{end}}`` so you can replace the below example with ``\{\{define "cmd documentation" -}}``
|
||||
|
||||
```
|
||||
\{\{\define "example_definition_created_by_documentation_tool" -}}
|
||||
\{\{\template "header" .}}
|
||||
## Current Features for documentation
|
||||
|
||||
#### A concise blurb about the package or tool system
|
||||
|
||||
+ Coding examples
|
||||
import "github.com/thrasher-/gocryptotrader/something"
|
||||
testString := "aAaAa"
|
||||
upper := strings.ToUpper(testString)
|
||||
// upper == "AAAAA"
|
||||
|
||||
{\{\template "contributions"}}
|
||||
{\{\template "donations"}}
|
||||
{\{\end}}
|
||||
```
|
||||
|
||||
### ALL NEW UPDATES AND FILE SYSTEM ADDITIONS NEED A DOCUMENTATION UPDATE USING THIS TOOL OR PR MERGE REQUEST MAY BE POSTPONED.
|
||||
|
||||
|
||||
### Please click GoDocs chevron above to view current GoDoc information for this package
|
||||
|
||||
## Contribution
|
||||
|
||||
Please feel free to submit any pull requests or suggest any desired features to be added.
|
||||
|
||||
When submitting a PR, please abide by our coding guidelines:
|
||||
|
||||
+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
|
||||
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
|
||||
+ Code must adhere to our [coding style](https://github.com/thrasher-/gocryptotrader/blob/master/doc/coding_style.md).
|
||||
+ Pull requests need to be based on and opened against the `master` branch.
|
||||
|
||||
## Donations
|
||||
|
||||
<img src="https://github.com/thrasher-/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
|
||||
|
||||
***1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB***
|
||||
|
||||
63
cmd/documentation/cmd_templates/documentation.tmpl
Normal file
63
cmd/documentation/cmd_templates/documentation.tmpl
Normal file
@@ -0,0 +1,63 @@
|
||||
{{define "cmd documentation" -}}
|
||||
{{template "header" .}}
|
||||
## Current Features for {{.Name}}
|
||||
|
||||
#### This tool allows for the generation of new documentation through templating
|
||||
|
||||
From the `gocryptotrader/cmd/documentation/` folder, using the go command: **go run documentation.go** this will auto-generate and regenerate documentation across the **GoCryptoTrader** code base.
|
||||
>Using the -v command will, ie **go run documentation.go -v** put the tool into verbose mode allowing you to see what is happening with a little more depth.
|
||||
|
||||
Be aware, this tool will:
|
||||
- Works off a configuration JSON file located at ``gocryptotrader/cmd/documentation/`` for future use with multiple repositories.
|
||||
- Automatically find the directory and file tree for the GoCryptoTrader source code and alert you of undocumented file systems which **need** to be updated.
|
||||
- Automatically find the template folder tree.
|
||||
- Fetch an updated contributor list and rank on pull request commit amount
|
||||
- Sets up core folder docs for the root directory tree including **LICENSE** and **CONTRIBUTORS**
|
||||
|
||||
### config.json example
|
||||
|
||||
```json
|
||||
{
|
||||
"githubRepo": "https://api.github.com/repos/thrasher-/gocryptotrader", This is your current repo
|
||||
"exclusionList": { This allows for excluded directories and files
|
||||
"Files": null,
|
||||
"Directories": [
|
||||
"_templates",
|
||||
".git",
|
||||
"web"
|
||||
]
|
||||
},
|
||||
"rootReadmeActive": true, allows a root directory README.md
|
||||
"licenseFileActive": true, allows for a license file to be generated
|
||||
"contributorFileActive": true, fetches a new contributor list
|
||||
"referencePathToRepo": "../../"
|
||||
}
|
||||
```
|
||||
### Template example
|
||||
>place a new template **example_file.tmpl** located in the current gocryptotrader/cmd/documentation/ folder; when the documentation tool finishes it will give you the define template associated name e.g. ``Template not found for path ../../cmd/documentation create new template with \{\{define "cmd documentation" -\}\} TEMPLATE HERE \{\{end}}`` so you can replace the below example with ``\{\{define "cmd documentation" -}}``
|
||||
|
||||
```
|
||||
\{\{\define "example_definition_created_by_documentation_tool" -}}
|
||||
\{\{\template "header" .}}
|
||||
## Current Features for {{.Name}}
|
||||
|
||||
#### A concise blurb about the package or tool system
|
||||
|
||||
+ Coding examples
|
||||
import "github.com/thrasher-/gocryptotrader/something"
|
||||
testString := "aAaAa"
|
||||
upper := strings.ToUpper(testString)
|
||||
// upper == "AAAAA"
|
||||
|
||||
{\{\template "contributions"}}
|
||||
{\{\template "donations"}}
|
||||
{\{\end}}
|
||||
```
|
||||
|
||||
### ALL NEW UPDATES AND FILE SYSTEM ADDITIONS NEED A DOCUMENTATION UPDATE USING THIS TOOL OR PR MERGE REQUEST MAY BE POSTPONED.
|
||||
|
||||
|
||||
### Please click GoDocs chevron above to view current GoDoc information for this package
|
||||
{{template "contributions"}}
|
||||
{{template "donations"}}
|
||||
{{end}}
|
||||
@@ -1,390 +1,397 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/core"
|
||||
)
|
||||
|
||||
const (
|
||||
commonPath = "..%s..%scommon%s"
|
||||
communicationsPath = "..%s..%scommunications%s"
|
||||
communicationsBasePath = "..%s..%scommunications%sbase%s"
|
||||
communicationsSlackPath = "..%s..%scommunications%sslack%s"
|
||||
communicationsSmsglobalPath = "..%s..%scommunications%ssmsglobal%s"
|
||||
communicationsSMTPPath = "..%s..%scommunications%ssmtpservice%s"
|
||||
communicationsTelegramPath = "..%s..%scommunications%stelegram%s"
|
||||
configPath = "..%s..%sconfig%s"
|
||||
currencyPath = "..%s..%scurrency%s"
|
||||
currencyFXPath = "..%s..%scurrency%sforexprovider%s"
|
||||
currencyFXBasePath = "..%s..%scurrency%sforexprovider%sbase%s"
|
||||
currencyFXCurrencyConverterPath = "..%s..%scurrency%sforexprovider%scurrencyconverterapi%s"
|
||||
currencyFXCurrencylayerPath = "..%s..%scurrency%sforexprovider%scurrencylayer%s"
|
||||
currencyFXFixerPath = "..%s..%scurrency%sforexprovider%sfixer.io%s"
|
||||
currencyFXOpenExchangeRatesPath = "..%s..%scurrency%sforexprovider%sopenexchangerates%s"
|
||||
currencyPairPath = "..%s..%scurrency%spair%s"
|
||||
currencySymbolPath = "..%s..%scurrency%ssymbol%s"
|
||||
currencyTranslationPath = "..%s..%scurrency%stranslation%s"
|
||||
eventsPath = "..%s..%sevents%s"
|
||||
exchangesPath = "..%s..%sexchanges%s"
|
||||
exchangesNoncePath = "..%s..%sexchanges%snonce%s"
|
||||
exchangesOrderbookPath = "..%s..%sexchanges%sorderbook%s"
|
||||
exchangesStatsPath = "..%s..%sexchanges%sstats%s"
|
||||
exchangesTickerPath = "..%s..%sexchanges%sticker%s"
|
||||
exchangesOrdersPath = "..%s..%sexchanges%sorders%s"
|
||||
exchangesRequestPath = "..%s..%sexchanges%srequest%s"
|
||||
portfolioPath = "..%s..%sportfolio%s"
|
||||
testdataPath = "..%s..%stestdata%s"
|
||||
toolsPath = "..%s..%stools%s"
|
||||
webPath = "..%s..%sweb%s"
|
||||
rootPath = "..%s..%s"
|
||||
// DefaultRepo is the main example repository
|
||||
DefaultRepo = "https://api.github.com/repos/[REPO ADDRESS HERE]"
|
||||
|
||||
// exchange packages
|
||||
alphapoint = "..%s..%sexchanges%salphapoint%s"
|
||||
anx = "..%s..%sexchanges%sanx%s"
|
||||
binance = "..%s..%sexchanges%sbinance%s"
|
||||
bitfinex = "..%s..%sexchanges%sbitfinex%s"
|
||||
bitflyer = "..%s..%sexchanges%sbitflyer%s"
|
||||
bithumb = "..%s..%sexchanges%sbithumb%s"
|
||||
bitmex = "..%s..%sexchanges%sbitmex%s"
|
||||
bitstamp = "..%s..%sexchanges%sbitstamp%s"
|
||||
bittrex = "..%s..%sexchanges%sbittrex%s"
|
||||
btcmarkets = "..%s..%sexchanges%sbtcmarkets%s"
|
||||
coinbasepro = "..%s..%sexchanges%scoinbasepro%s"
|
||||
coinut = "..%s..%sexchanges%scoinut%s"
|
||||
exmo = "..%s..%sexchanges%sexmo%s"
|
||||
gateio = "..%s..%sexchanges%sgateio%s"
|
||||
gemini = "..%s..%sexchanges%sgemini%s"
|
||||
hitbtc = "..%s..%sexchanges%shitbtc%s"
|
||||
huobi = "..%s..%sexchanges%shuobi%s"
|
||||
huobihadax = "..%s..%sexchanges%shuobihadax%s"
|
||||
itbit = "..%s..%sexchanges%sitbit%s"
|
||||
kraken = "..%s..%sexchanges%skraken%s"
|
||||
lakebtc = "..%s..%sexchanges%slakebtc%s"
|
||||
localbitcoins = "..%s..%sexchanges%slocalbitcoins%s"
|
||||
okcoin = "..%s..%sexchanges%sokcoin%s"
|
||||
okex = "..%s..%sexchanges%sokex%s"
|
||||
poloniex = "..%s..%sexchanges%spoloniex%s"
|
||||
yobit = "..%s..%sexchanges%syobit%s"
|
||||
zb = "..%s..%sexchanges%szb%s"
|
||||
// GithubAPIEndpoint allows the program to query your repository
|
||||
// contributor list
|
||||
GithubAPIEndpoint = "/contributors"
|
||||
|
||||
contributorsList = "https://api.github.com/repos/thrasher-/gocryptotrader/contributors"
|
||||
// LicenseFile defines a license file
|
||||
LicenseFile = "LICENSE"
|
||||
|
||||
licenseName = "LICENSE"
|
||||
contributorName = "CONTRIBUTORS"
|
||||
// ContributorFile defines contributor file
|
||||
ContributorFile = "CONTRIBUTORS"
|
||||
)
|
||||
|
||||
var (
|
||||
verbose, replace bool
|
||||
codebasePaths map[string]string
|
||||
codebaseTemplatePath map[string]string
|
||||
codebaseReadme map[string]readme
|
||||
tmpl *template.Template
|
||||
path string
|
||||
contributors []contributor
|
||||
)
|
||||
|
||||
type readme struct {
|
||||
Name string
|
||||
Contributors []contributor
|
||||
NameURL string
|
||||
Year int
|
||||
CapitalName string
|
||||
}
|
||||
|
||||
type contributor struct {
|
||||
// Contributor defines an account associated with this code base by doing
|
||||
// contributions
|
||||
type Contributor struct {
|
||||
Login string `json:"login"`
|
||||
URL string `json:"html_url"`
|
||||
Contributions int `json:"contributions"`
|
||||
}
|
||||
|
||||
// Config defines the running config to deploy documentation across a github
|
||||
// repository including exclusion lists for files and directories
|
||||
type Config struct {
|
||||
GithubRepo string `json:"githubRepo"`
|
||||
Exclusions Exclusions `json:"exclusionList"`
|
||||
RootReadme bool `json:"rootReadmeActive"`
|
||||
LicenseFile bool `json:"licenseFileActive"`
|
||||
ContributorFile bool `json:"contributorFileActive"`
|
||||
ReferencePathToRepo string `json:"referencePathToRepo"`
|
||||
}
|
||||
|
||||
// Exclusions defines the exclusion list so documents are not generated
|
||||
type Exclusions struct {
|
||||
Files []string `json:"Files"`
|
||||
Directories []string `json:"Directories"`
|
||||
}
|
||||
|
||||
// DocumentationDetails defines parameters to update documentation
|
||||
type DocumentationDetails struct {
|
||||
Directories []string
|
||||
Tmpl *template.Template
|
||||
Contributors []Contributor
|
||||
Verbose bool
|
||||
Config *Config
|
||||
}
|
||||
|
||||
// Attributes defines specific documentation attributes when a template is
|
||||
// executed
|
||||
type Attributes struct {
|
||||
Name string
|
||||
Contributors []Contributor
|
||||
NameURL string
|
||||
Year int
|
||||
CapitalName string
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.BoolVar(&verbose, "v", false, "-v Verbose flag prints more information to the std output")
|
||||
flag.BoolVar(&replace, "r", false, "-r Replace flag generates and replaces all documentation across the code base")
|
||||
verbose := flag.Bool("v", false, "Verbose output")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
fmt.Println(`
|
||||
GoCryptoTrader: Exchange documentation tool
|
||||
fmt.Println(core.Banner)
|
||||
fmt.Println("This will update and regenerate documentation for the different packages in your repo.")
|
||||
fmt.Println()
|
||||
|
||||
This will update and regenerate documentation for the different packages
|
||||
in GoCryptoTrader.`)
|
||||
|
||||
codebasePaths = make(map[string]string)
|
||||
codebaseTemplatePath = make(map[string]string)
|
||||
codebaseReadme = make(map[string]readme)
|
||||
path = getOSPathSlash()
|
||||
|
||||
if err := getContributorList(); err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange documentation tool GET error ", err)
|
||||
if *verbose {
|
||||
fmt.Println("Fetching configuration...")
|
||||
}
|
||||
|
||||
fmt.Println("Contributor list fetched")
|
||||
|
||||
if err := addTemplates(); err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange documentation tool add template error ", err)
|
||||
config, err := GetConfiguration()
|
||||
if err != nil {
|
||||
log.Fatalf("Documentation Generation Tool - GetConfiguration error %s",
|
||||
err)
|
||||
}
|
||||
|
||||
fmt.Println("Templates parsed")
|
||||
|
||||
if err := updateReadme(); err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange documentation tool update readme error ", err)
|
||||
if *verbose {
|
||||
fmt.Println("Fetching project directory tree...")
|
||||
}
|
||||
|
||||
fmt.Println("\nTool finished")
|
||||
}
|
||||
|
||||
// getOSPathSlash returns the slash used by the operating systems
|
||||
// file system
|
||||
// TO-DO: Change all paths to not use this
|
||||
func getOSPathSlash() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "\\"
|
||||
dirList, err := GetProjectDirectoryTree(&config, *verbose)
|
||||
if err != nil {
|
||||
log.Fatalf("Documentation Generation Tool - GetProjectDirectoryTree error %s",
|
||||
err)
|
||||
}
|
||||
return "/"
|
||||
}
|
||||
|
||||
// updateReadme iterates through codebase paths to check for readme files and either adds
|
||||
// or replaces with new readme files.
|
||||
func updateReadme() error {
|
||||
addPaths()
|
||||
var contributors []Contributor
|
||||
if config.ContributorFile {
|
||||
if *verbose {
|
||||
fmt.Println("Fetching repository contributor list...")
|
||||
}
|
||||
contributors, err = GetContributorList(config.GithubRepo)
|
||||
if err != nil {
|
||||
log.Fatalf("Documentation Generation Tool - GetContributorList error %s",
|
||||
err)
|
||||
}
|
||||
|
||||
for packageName := range codebasePaths {
|
||||
addReadmeData(packageName)
|
||||
|
||||
if !checkReadme(packageName) {
|
||||
if verbose {
|
||||
fmt.Printf("* %s Readme file FOUND.\n", packageName)
|
||||
if *verbose {
|
||||
fmt.Println("Contributor List Fetched")
|
||||
for i := range contributors {
|
||||
fmt.Println(contributors[i].Login)
|
||||
}
|
||||
if replace {
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Contributor list file disabled skipping fetching details")
|
||||
}
|
||||
|
||||
if *verbose {
|
||||
fmt.Println("Fetching template files...")
|
||||
}
|
||||
|
||||
tmpl, err := GetTemplateFiles()
|
||||
if err != nil {
|
||||
log.Fatalf("Documentation Generation Tool - GetTemplateFiles error %s",
|
||||
err)
|
||||
}
|
||||
|
||||
if *verbose {
|
||||
fmt.Println("All core systems fetched, updating documentation...")
|
||||
}
|
||||
|
||||
err = UpdateDocumentation(DocumentationDetails{
|
||||
dirList,
|
||||
tmpl,
|
||||
contributors,
|
||||
*verbose,
|
||||
&config})
|
||||
if err != nil {
|
||||
log.Fatalf("Documentation Generation Tool - UpdateDocumentation error %s",
|
||||
err)
|
||||
}
|
||||
|
||||
fmt.Println("\nDocumentation Generation Tool - Finished")
|
||||
}
|
||||
|
||||
// GetConfiguration retrieves the documentation configuration
|
||||
func GetConfiguration() (Config, error) {
|
||||
var c Config
|
||||
file, err := os.OpenFile("config.json", os.O_RDWR, os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Println("Creating configuration file, please add github repository path and preferences")
|
||||
|
||||
file, err = os.Create("config.json")
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
||||
// Set default params for configuration
|
||||
c.GithubRepo = DefaultRepo
|
||||
c.ContributorFile = true
|
||||
c.LicenseFile = true
|
||||
c.RootReadme = true
|
||||
c.ReferencePathToRepo = "../../"
|
||||
c.Exclusions.Directories = []string{".github"}
|
||||
|
||||
data, mErr := json.MarshalIndent(c, "", " ")
|
||||
if mErr != nil {
|
||||
return c, mErr
|
||||
}
|
||||
|
||||
_, err = file.WriteAt(data, 0)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
config, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(config, &c)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
||||
if c.GithubRepo == "" || c.GithubRepo == DefaultRepo {
|
||||
return c, errors.New("repository not set in config.json file, please change")
|
||||
}
|
||||
|
||||
if c.ReferencePathToRepo == "" {
|
||||
return c, errors.New("reference path not set in the config.json file, please set")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// IsExcluded returns if the file path is included in the exclusion list
|
||||
func IsExcluded(path string, exclusion []string) bool {
|
||||
for _, data := range exclusion {
|
||||
if strings.Contains(path, data) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetProjectDirectoryTree uses filepath walk functions to get each individual
|
||||
// directory name and path to match templates with
|
||||
func GetProjectDirectoryTree(c *Config, verbose bool) ([]string, error) {
|
||||
var directoryData []string
|
||||
if c.RootReadme { // Projects root README.md
|
||||
directoryData = append(directoryData, c.ReferencePathToRepo)
|
||||
}
|
||||
|
||||
if c.LicenseFile { // Standard license file
|
||||
directoryData = append(directoryData, c.ReferencePathToRepo+LicenseFile)
|
||||
}
|
||||
|
||||
if c.ContributorFile { // Standard contributor file
|
||||
directoryData = append(directoryData, c.ReferencePathToRepo+ContributorFile)
|
||||
}
|
||||
|
||||
walkfn := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
// Bypass what is contained in config.json directory exclusion
|
||||
if IsExcluded(info.Name(), c.Exclusions.Directories) {
|
||||
if verbose {
|
||||
fmt.Println("file replacement")
|
||||
fmt.Println("Excluding Directory:", info.Name())
|
||||
}
|
||||
if err := replaceReadme(packageName); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
return filepath.SkipDir
|
||||
}
|
||||
continue
|
||||
}
|
||||
if verbose {
|
||||
fmt.Printf("* %s Readme file NOT FOUND.\n", packageName)
|
||||
}
|
||||
if replace {
|
||||
if verbose {
|
||||
log.Println("file creation")
|
||||
// Don't append parent directory
|
||||
if strings.EqualFold(info.Name(), "..") {
|
||||
return nil
|
||||
}
|
||||
if err := createReadme(packageName); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
directoryData = append(directoryData, path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
|
||||
return directoryData, filepath.Walk(c.ReferencePathToRepo, walkfn)
|
||||
}
|
||||
|
||||
// addPaths adds paths to different potential README.md files in the codebase
|
||||
func addPaths() {
|
||||
codebasePaths["common"] = fmt.Sprintf(commonPath, path, path, path)
|
||||
// GetTemplateFiles parses and returns all template files in the documentation
|
||||
// tree
|
||||
func GetTemplateFiles() (*template.Template, error) {
|
||||
tmpl := template.New("")
|
||||
|
||||
codebasePaths["communications comms"] = fmt.Sprintf(communicationsPath, path, path, path)
|
||||
codebasePaths["communications base"] = fmt.Sprintf(communicationsBasePath, path, path, path, path)
|
||||
codebasePaths["communications slack"] = fmt.Sprintf(communicationsSlackPath, path, path, path, path)
|
||||
codebasePaths["communications smsglobal"] = fmt.Sprintf(communicationsSmsglobalPath, path, path, path, path)
|
||||
codebasePaths["communications smtp"] = fmt.Sprintf(communicationsSMTPPath, path, path, path, path)
|
||||
codebasePaths["communications telegram"] = fmt.Sprintf(communicationsTelegramPath, path, path, path, path)
|
||||
walkfn := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
if path == "." || path == ".." {
|
||||
return nil
|
||||
}
|
||||
|
||||
codebasePaths["config"] = fmt.Sprintf(configPath, path, path, path)
|
||||
var parseError error
|
||||
tmpl, parseError = tmpl.ParseGlob(filepath.Join(path, "*.tmpl"))
|
||||
if parseError != nil {
|
||||
return parseError
|
||||
}
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
codebasePaths["currency"] = fmt.Sprintf(currencyPath, path, path, path)
|
||||
codebasePaths["currency forexprovider"] = fmt.Sprintf(currencyFXPath, path, path, path, path)
|
||||
codebasePaths["currency forexprovider base"] = fmt.Sprintf(currencyFXBasePath, path, path, path, path, path)
|
||||
codebasePaths["currency forexprovider currencyconverter"] = fmt.Sprintf(currencyFXCurrencyConverterPath, path, path, path, path, path)
|
||||
codebasePaths["currency forexprovider currencylayer"] = fmt.Sprintf(currencyFXCurrencylayerPath, path, path, path, path, path)
|
||||
codebasePaths["currency forexprovider fixer"] = fmt.Sprintf(currencyFXFixerPath, path, path, path, path, path)
|
||||
codebasePaths["currency forexprovider openexchangerates"] = fmt.Sprintf(currencyFXOpenExchangeRatesPath, path, path, path, path, path)
|
||||
codebasePaths["currency pair"] = fmt.Sprintf(currencyPairPath, path, path, path, path)
|
||||
codebasePaths["currency symbol"] = fmt.Sprintf(currencySymbolPath, path, path, path, path)
|
||||
codebasePaths["currency translation"] = fmt.Sprintf(currencyTranslationPath, path, path, path, path)
|
||||
|
||||
codebasePaths["events"] = fmt.Sprintf(eventsPath, path, path, path)
|
||||
|
||||
codebasePaths["portfolio"] = fmt.Sprintf(portfolioPath, path, path, path)
|
||||
codebasePaths["testdata"] = fmt.Sprintf(testdataPath, path, path, path)
|
||||
codebasePaths["tools"] = fmt.Sprintf(toolsPath, path, path, path)
|
||||
codebasePaths["web"] = fmt.Sprintf(webPath, path, path, path)
|
||||
codebasePaths["root"] = fmt.Sprintf(rootPath, path, path)
|
||||
|
||||
codebasePaths["exchanges"] = fmt.Sprintf(exchangesPath, path, path, path)
|
||||
codebasePaths["exchanges nonce"] = fmt.Sprintf(exchangesNoncePath, path, path, path, path)
|
||||
codebasePaths["exchanges orderbook"] = fmt.Sprintf(exchangesOrderbookPath, path, path, path, path)
|
||||
codebasePaths["exchanges stats"] = fmt.Sprintf(exchangesStatsPath, path, path, path, path)
|
||||
codebasePaths["exchanges ticker"] = fmt.Sprintf(exchangesTickerPath, path, path, path, path)
|
||||
codebasePaths["exchanges orders"] = fmt.Sprintf(exchangesOrdersPath, path, path, path, path)
|
||||
codebasePaths["exchanges request"] = fmt.Sprintf(exchangesRequestPath, path, path, path, path)
|
||||
|
||||
codebasePaths["exchanges alphapoint"] = fmt.Sprintf(alphapoint, path, path, path, path)
|
||||
codebasePaths["exchanges anx"] = fmt.Sprintf(anx, path, path, path, path)
|
||||
codebasePaths["exchanges binance"] = fmt.Sprintf(binance, path, path, path, path)
|
||||
codebasePaths["exchanges bitfinex"] = fmt.Sprintf(bitfinex, path, path, path, path)
|
||||
codebasePaths["exchanges bitflyer"] = fmt.Sprintf(bitflyer, path, path, path, path)
|
||||
codebasePaths["exchanges bithumb"] = fmt.Sprintf(bithumb, path, path, path, path)
|
||||
codebasePaths["exchanges bitmex"] = fmt.Sprintf(bitmex, path, path, path, path)
|
||||
codebasePaths["exchanges bitstamp"] = fmt.Sprintf(bitstamp, path, path, path, path)
|
||||
codebasePaths["exchanges bittrex"] = fmt.Sprintf(bittrex, path, path, path, path)
|
||||
codebasePaths["exchanges btcmarkets"] = fmt.Sprintf(btcmarkets, path, path, path, path)
|
||||
codebasePaths["exchanges coinut"] = fmt.Sprintf(coinut, path, path, path, path)
|
||||
codebasePaths["exchanges exmo"] = fmt.Sprintf(exmo, path, path, path, path)
|
||||
codebasePaths["exchanges coinbasepro"] = fmt.Sprintf(coinbasepro, path, path, path, path)
|
||||
codebasePaths["exchanges gateio"] = fmt.Sprintf(gateio, path, path, path, path)
|
||||
codebasePaths["exchanges gemini"] = fmt.Sprintf(gemini, path, path, path, path)
|
||||
codebasePaths["exchanges hitbtc"] = fmt.Sprintf(hitbtc, path, path, path, path)
|
||||
codebasePaths["exchanges huobi"] = fmt.Sprintf(huobi, path, path, path, path)
|
||||
codebasePaths["exchanges huobihadax"] = fmt.Sprintf(huobihadax, path, path, path, path)
|
||||
codebasePaths["exchanges itbit"] = fmt.Sprintf(itbit, path, path, path, path)
|
||||
codebasePaths["exchanges kraken"] = fmt.Sprintf(kraken, path, path, path, path)
|
||||
codebasePaths["exchanges lakebtc"] = fmt.Sprintf(lakebtc, path, path, path, path)
|
||||
codebasePaths["exchanges localbitcoins"] = fmt.Sprintf(localbitcoins, path, path, path, path)
|
||||
codebasePaths["exchanges okcoin"] = fmt.Sprintf(okcoin, path, path, path, path)
|
||||
codebasePaths["exchanges okex"] = fmt.Sprintf(okex, path, path, path, path)
|
||||
codebasePaths["exchanges poloniex"] = fmt.Sprintf(poloniex, path, path, path, path)
|
||||
codebasePaths["exchanges yobit"] = fmt.Sprintf(yobit, path, path, path, path)
|
||||
codebasePaths["exchanges zb"] = fmt.Sprintf(zb, path, path, path, path)
|
||||
|
||||
codebasePaths["CONTRIBUTORS"] = fmt.Sprintf(rootPath, path, path)
|
||||
codebasePaths["LICENSE"] = fmt.Sprintf(rootPath, path, path)
|
||||
return tmpl, filepath.Walk(".", walkfn)
|
||||
}
|
||||
|
||||
func addReadmeData(packageName string) {
|
||||
readmeInfo := readme{
|
||||
Name: getName(packageName, false),
|
||||
// GetContributorList fetches a list of contributors from the github api
|
||||
// endpoint
|
||||
func GetContributorList(repo string) ([]Contributor, error) {
|
||||
var resp []Contributor
|
||||
return resp, common.SendHTTPGetRequest(repo+GithubAPIEndpoint, true, false, &resp)
|
||||
}
|
||||
|
||||
// GetDocumentationAttributes returns specific attributes for a file template
|
||||
func GetDocumentationAttributes(packageName string, contributors []Contributor) Attributes {
|
||||
return Attributes{
|
||||
Name: GetPackageName(packageName, false),
|
||||
Contributors: contributors,
|
||||
NameURL: getslashFromName(packageName),
|
||||
NameURL: GetGoDocURL(packageName),
|
||||
Year: time.Now().Year(),
|
||||
CapitalName: getName(packageName, true),
|
||||
CapitalName: GetPackageName(packageName, true),
|
||||
}
|
||||
codebaseReadme[packageName] = readmeInfo
|
||||
}
|
||||
|
||||
func getName(name string, capital bool) string {
|
||||
// GetPackageName returns the package name after cleaning path as a string
|
||||
func GetPackageName(name string, capital bool) string {
|
||||
newStrings := strings.Split(name, " ")
|
||||
var i int
|
||||
if len(newStrings) > 1 {
|
||||
if capital {
|
||||
return getCapital(newStrings[1])
|
||||
}
|
||||
return newStrings[1]
|
||||
i = 1
|
||||
}
|
||||
if capital {
|
||||
return getCapital(name)
|
||||
return strings.Title(newStrings[i])
|
||||
}
|
||||
return newStrings[i]
|
||||
}
|
||||
|
||||
// GetGoDocURL returns a string for godoc package names
|
||||
func GetGoDocURL(name string) string {
|
||||
if strings.Contains(name, " ") {
|
||||
return strings.Join(strings.Split(name, " "), "/")
|
||||
}
|
||||
if name == "testdata" ||
|
||||
name == "tools" ||
|
||||
name == ContributorFile ||
|
||||
name == LicenseFile {
|
||||
return ""
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func getCapital(name string) string {
|
||||
capLetter := strings.ToUpper(string(name[0]))
|
||||
last := name[1:]
|
||||
// UpdateDocumentation generates or updates readme/documentation files across
|
||||
// the codebase
|
||||
func UpdateDocumentation(details DocumentationDetails) error {
|
||||
for _, path := range details.Directories {
|
||||
data := strings.Split(path, "/")
|
||||
var temp []string
|
||||
for _, d := range data {
|
||||
if d == ".." {
|
||||
continue
|
||||
}
|
||||
if d == "" {
|
||||
break
|
||||
}
|
||||
|
||||
return capLetter + last
|
||||
}
|
||||
temp = append(temp, d)
|
||||
}
|
||||
|
||||
// getslashFromName returns a string for godoc package names
|
||||
func getslashFromName(packageName string) string {
|
||||
if strings.Contains(packageName, " ") {
|
||||
s := strings.Split(packageName, " ")
|
||||
return strings.Join(s, "/")
|
||||
}
|
||||
if packageName == "testdata" || packageName == "tools" || packageName == contributorName || packageName == licenseName {
|
||||
return ""
|
||||
}
|
||||
return packageName
|
||||
}
|
||||
var name string
|
||||
if len(temp) == 0 {
|
||||
name = "root"
|
||||
} else {
|
||||
name = strings.Join(temp, " ")
|
||||
}
|
||||
|
||||
var globS = []string{
|
||||
fmt.Sprintf("common_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("communications_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("config_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("currency_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("events_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("exchanges_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("portfolio_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("root_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("sub_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("testdata_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("tools_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("web_templates%s*", getOSPathSlash()),
|
||||
}
|
||||
if IsExcluded(name, details.Config.Exclusions.Files) {
|
||||
if details.Verbose {
|
||||
fmt.Println("Excluding file:", name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// addTemplates adds all the template files
|
||||
func addTemplates() error {
|
||||
tmpl = template.New("")
|
||||
if details.Tmpl.Lookup(name) == nil {
|
||||
fmt.Printf("Template not found for path %s create new template with {{define \"%s\" -}} TEMPLATE HERE {{end}}\n",
|
||||
path,
|
||||
name)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, s := range globS {
|
||||
_, err := tmpl.ParseGlob(s)
|
||||
var mainPath string
|
||||
if name == LicenseFile || name == ContributorFile {
|
||||
mainPath = path
|
||||
} else {
|
||||
mainPath = filepath.Join(path, "README.md")
|
||||
}
|
||||
|
||||
err := os.Remove(mainPath)
|
||||
if err != nil && !strings.Contains(err.Error(), "no such file or directory") {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.Create(mainPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
attr := GetDocumentationAttributes(name, details.Contributors)
|
||||
|
||||
err = details.Tmpl.ExecuteTemplate(file, name, attr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkReadme checks to see if the file exists
|
||||
func checkReadme(packageName string) bool {
|
||||
if packageName == licenseName || packageName == contributorName {
|
||||
_, err := os.Stat(codebasePaths[packageName] + packageName)
|
||||
return os.IsNotExist(err)
|
||||
}
|
||||
_, err := os.Stat(codebasePaths[packageName] + "README.md")
|
||||
return os.IsNotExist(err)
|
||||
}
|
||||
|
||||
// replaceReadme replaces readme file
|
||||
func replaceReadme(packageName string) error {
|
||||
if packageName == licenseName || packageName == contributorName {
|
||||
if err := deleteFile(codebasePaths[packageName] + packageName); err != nil {
|
||||
return err
|
||||
}
|
||||
return createReadme(packageName)
|
||||
}
|
||||
if err := deleteFile(codebasePaths[packageName] + "README.md"); err != nil {
|
||||
return err
|
||||
}
|
||||
return createReadme(packageName)
|
||||
}
|
||||
|
||||
// createReadme creates new readme file and executes template
|
||||
func createReadme(packageName string) error {
|
||||
if packageName == licenseName || packageName == contributorName {
|
||||
file, err := os.Create(codebasePaths[packageName] + packageName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
if verbose {
|
||||
fmt.Println("File done")
|
||||
}
|
||||
return tmpl.ExecuteTemplate(file, packageName, codebaseReadme[packageName])
|
||||
}
|
||||
file, err := os.Create(codebasePaths[packageName] + "README.md")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
if verbose {
|
||||
fmt.Println("File done")
|
||||
}
|
||||
return tmpl.ExecuteTemplate(file, packageName, codebaseReadme[packageName])
|
||||
}
|
||||
|
||||
func deleteFile(path string) error {
|
||||
return os.Remove(path)
|
||||
}
|
||||
|
||||
func getContributorList() error {
|
||||
return common.SendHTTPGetRequest(contributorsList, true, false, &contributors)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{define "CONTRIBUTORS"}}
|
||||
Thanks to the following contributors:
|
||||
{{ range $contributor := .Contributors -}}
|
||||
{{range $contributor := .Contributors -}}
|
||||
{{$contributor.Login}} | {{$contributor.URL}}
|
||||
{{ end }}
|
||||
{{end}}
|
||||
{{end}}
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
|User|Github|Contribution Amount|
|
||||
|--|--|--|
|
||||
{{ range $contributor := .Contributors -}}
|
||||
{{- range $contributor := .Contributors -}}
|
||||
| {{$contributor.Login}} | {{$contributor.URL}} | {{$contributor.Contributions}} |
|
||||
{{ end }}
|
||||
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@@ -6,5 +6,5 @@ This folder contains a configuration test file for non-deployement test params.
|
||||
It also has the code coverage test files that allow us to monitor our entire
|
||||
codebase, click this link for more information [https://codecov.io/](https://codecov.io/).
|
||||
{{template "contributions"}}
|
||||
{{template "donations"}}
|
||||
{{template "donations" -}}
|
||||
{{end}}
|
||||
|
||||
@@ -63,38 +63,6 @@ err := s.Connect
|
||||
Once the bot has started you can interact with the bot using these commands
|
||||
via Slack:
|
||||
|
||||
main.go
|
||||
```go
|
||||
var b exchange.IBotExchange
|
||||
|
||||
for i := range bot.Exchanges {
|
||||
if bot.Exchanges[i].GetName() == "Bitfinex" {
|
||||
b = bot.Exchanges[i]
|
||||
}
|
||||
}
|
||||
|
||||
// Public calls - wrapper functions
|
||||
|
||||
// Fetches current ticker information
|
||||
tick, err := b.FetchTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := b.FetchOrderbook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
|
||||
// set and AuthenticatedAPISupport is set to true
|
||||
|
||||
// Fetches current account information
|
||||
accountInfo, err := b.GetAccountInfo()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
!status - Displays current working status of bot
|
||||
!help - Displays help text
|
||||
|
||||
Reference in New Issue
Block a user