DigitalStorageTweak/magefile.go

54 lines
1.4 KiB
Go

//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const (
zipName = "DigitalStorageTweaks.zip"
filesToCopy = "./ContentLib ./DigitalStorageTweaks.uplugin"
targetDirs = "Windows WindowsServer LinuxServer"
)
// Default target to run when none is specified
var Default = Package
// Package creates the distribution zip file
func Package() error {
mg.Deps(Clean)
fmt.Println("Creating target directories...")
for _, dir := range []string{"Windows", "WindowsServer", "LinuxServer"} {
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create directory %s: %v", dir, err)
}
fmt.Printf("Copying files to %s...\n", dir)
if err := sh.Run("cp", "-r", "./ContentLib", "./DigitalStorageTweaks.uplugin", dir+"/"); err != nil {
return fmt.Errorf("failed to copy files to %s: %v", dir, err)
}
}
fmt.Println("Creating zip archive...")
return sh.Run("7z", "a", "-r", zipName, "Windows/", "LinuxServer/", "WindowsServer/")
}
// Clean removes generated directories and zip file
func Clean() error {
fmt.Println("Cleaning up...")
toRemove := []string{"Windows", "WindowsServer", "LinuxServer", zipName}
for _, path := range toRemove {
if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("failed to remove %s: %v", path, err)
}
}
return nil
}