2021-12-02 04:00:33 +00:00
|
|
|
//go:build tools
|
|
|
|
// +build tools
|
|
|
|
|
2022-06-08 20:56:32 +00:00
|
|
|
package main
|
2021-12-02 04:00:33 +00:00
|
|
|
|
2022-06-08 20:56:32 +00:00
|
|
|
import (
|
2022-10-14 16:11:16 +00:00
|
|
|
"os"
|
2023-12-28 02:32:56 +00:00
|
|
|
"os/user"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2022-10-14 16:11:16 +00:00
|
|
|
|
2022-06-08 20:56:32 +00:00
|
|
|
"github.com/spf13/cobra/doc"
|
2022-10-14 16:11:16 +00:00
|
|
|
|
|
|
|
"github.com/satisfactorymodding/ficsit-cli/cmd"
|
2023-12-28 02:32:56 +00:00
|
|
|
|
|
|
|
_ "github.com/Khan/genqlient/generate"
|
2022-06-08 20:56:32 +00:00
|
|
|
)
|
2021-12-02 04:00:33 +00:00
|
|
|
|
|
|
|
//go:generate go run github.com/Khan/genqlient
|
2022-10-14 16:11:16 +00:00
|
|
|
//go:generate go run -tags tools tools.go
|
2022-06-08 20:56:32 +00:00
|
|
|
|
|
|
|
func main() {
|
2023-12-28 02:32:56 +00:00
|
|
|
var err error
|
2022-06-08 20:56:32 +00:00
|
|
|
_ = os.RemoveAll("./docs/")
|
|
|
|
|
2023-12-28 02:32:56 +00:00
|
|
|
if err = os.Mkdir("./docs/", 0o777); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = doc.GenMarkdownTree(cmd.RootCmd, "./docs/")
|
|
|
|
if err != nil {
|
2022-06-08 20:56:32 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-12-28 02:32:56 +00:00
|
|
|
// replace user dir information with generic username
|
|
|
|
baseCacheDir, err := os.UserCacheDir()
|
2022-06-08 20:56:32 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-12-28 02:32:56 +00:00
|
|
|
|
|
|
|
var baseLocalDir string
|
|
|
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
|
|
|
baseLocalDir = os.Getenv("APPDATA")
|
|
|
|
case "linux":
|
|
|
|
baseLocalDir = filepath.Join(os.Getenv("HOME"), ".local", "share")
|
2024-08-14 00:36:41 +00:00
|
|
|
case "darwin":
|
|
|
|
baseLocalDir = filepath.Join(os.Getenv("HOME"), "Library", "Application Support")
|
2023-12-28 02:32:56 +00:00
|
|
|
default:
|
|
|
|
panic("unsupported platform: " + runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
docFiles, err := os.ReadDir("./docs/")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range docFiles {
|
|
|
|
fPath := "./docs/" + f.Name()
|
|
|
|
oldContents, err := os.ReadFile(fPath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
newContents := strings.ReplaceAll(
|
|
|
|
string(oldContents),
|
|
|
|
baseCacheDir,
|
|
|
|
strings.ReplaceAll(baseCacheDir, user.Username, "{{Username}}"),
|
|
|
|
)
|
|
|
|
|
|
|
|
newContents = strings.ReplaceAll(
|
|
|
|
newContents,
|
|
|
|
baseLocalDir,
|
|
|
|
strings.ReplaceAll(baseLocalDir, user.Username, "{{Username}}"),
|
|
|
|
)
|
|
|
|
|
|
|
|
os.WriteFile(fPath, []byte(newContents), 0o777)
|
|
|
|
}
|
2022-06-08 20:56:32 +00:00
|
|
|
}
|