|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //go:build mage
-
- package main
-
- import (
- "errors"
- "fmt"
- "os"
- "path/filepath"
-
- "gitlink.org.cn/cloudream/common/magefiles"
-
- //mage:import
- _ "gitlink.org.cn/cloudream/common/magefiles/targets"
-
- cp "github.com/otiai10/copy"
- )
-
- const (
- BuildDir = "./build"
- )
-
- func All() error {
- if err := Bin(); err != nil {
- return err
- }
-
- if err := Scripts(); err != nil {
- return err
- }
-
- if err := Confs(); err != nil {
- return err
- }
-
- return nil
- }
-
- func Bin() error {
- if err := Hub(); err != nil {
- return err
- }
- if err := Client(); err != nil {
- return err
- }
- if err := Coordinator(); err != nil {
- return err
- }
-
- return nil
- }
-
- func Scripts() error {
- scriptsDir := "./common/assets/scripts"
-
- info, err := os.Stat(scriptsDir)
- if errors.Is(err, os.ErrNotExist) {
- fmt.Printf("no scripts.\n")
- return nil
- }
-
- if !info.IsDir() {
- return fmt.Errorf("scripts is not a directory")
- }
-
- fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "scripts"))
- if err != nil {
- return err
- }
-
- fmt.Printf("copying scripts to %s\n", fullDirPath)
-
- return cp.Copy(scriptsDir, fullDirPath)
- }
-
- func Confs() error {
- confDir := "./common/assets/confs"
-
- info, err := os.Stat(confDir)
- if errors.Is(err, os.ErrNotExist) {
- fmt.Printf("no confs.\n")
- return nil
- }
-
- if !info.IsDir() {
- return fmt.Errorf("confs is not a directory")
- }
-
- fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "confs"))
- if err != nil {
- return err
- }
-
- fmt.Printf("copying confs to %s\n", fullDirPath)
-
- return cp.Copy(confDir, fullDirPath)
- }
-
- func Hub() error {
- return magefiles.Build(magefiles.BuildArgs{
- OutputName: "hub",
- OutputDir: "hub",
- AssetsDir: "assets",
- EntryFile: "hub/main.go",
- })
- }
-
- func Client() error {
- return magefiles.Build(magefiles.BuildArgs{
- OutputName: "client",
- OutputDir: "client",
- AssetsDir: "assets",
- EntryFile: "client/main.go",
- })
- }
-
- func Coordinator() error {
- return magefiles.Build(magefiles.BuildArgs{
- OutputName: "coordinator",
- OutputDir: "coordinator",
- AssetsDir: "assets",
- EntryFile: "coordinator/main.go",
- })
- }
|