diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a967185..38f6b95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,9 +14,7 @@ jobs: run: | [[ -f bld ]] && rm -f bld go build -buildvcs=false -o bld ./builder - ./bld b - mkdir dist - mv *.zip *.tar.gz *.mrpack dist + ./bld version bundle-all - name: Upload Artifacts uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index 242c7ea..d6443a0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ server /bld .build /bld.exe +dist diff --git a/build.toml b/build.toml index be204de..18fa15a 100644 --- a/build.toml +++ b/build.toml @@ -9,7 +9,9 @@ pack_author = "HappyRedstone Modding" pack_version = "3.0.0" enabled = true common = "common" +versions = "versions" temp = ".build/temp" +output = "dist" [[multi_version.bootstrap_mods]] id = "reeses-sodium-options" diff --git a/builder/cmd/client/bundle/all.go b/builder/cmd/client/bundle/all.go index 16b0518..1252648 100644 --- a/builder/cmd/client/bundle/all.go +++ b/builder/cmd/client/bundle/all.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/client" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var AllCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return client.Bundle() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return client.Bundle("output", &pack) }, } diff --git a/builder/cmd/client/bundle/curseforge.go b/builder/cmd/client/bundle/curseforge.go index 95babd7..f4254b0 100644 --- a/builder/cmd/client/bundle/curseforge.go +++ b/builder/cmd/client/bundle/curseforge.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/client" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var CurseforgeCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return client.CurseForge() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return client.CurseForge("output", &pack) }, } diff --git a/builder/cmd/client/bundle/modrinth.go b/builder/cmd/client/bundle/modrinth.go index 91248da..ccb2d2f 100644 --- a/builder/cmd/client/bundle/modrinth.go +++ b/builder/cmd/client/bundle/modrinth.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/client" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var ModrinthCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return client.Modrinth() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return client.Modrinth("output", &pack) }, } diff --git a/builder/cmd/client/clean.go b/builder/cmd/client/clean.go index 0d2574d..90f9812 100644 --- a/builder/cmd/client/clean.go +++ b/builder/cmd/client/clean.go @@ -2,6 +2,7 @@ package client import ( internalClient "github.com/HappyRedstone/SodiumPlus/builder/internal/client" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -12,6 +13,12 @@ var CleanCommand = &cobra.Command{ Aliases: []string{"c"}, RunE: func(cmd *cobra.Command, args []string) error { - return internalClient.Clean() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return internalClient.Clean(&pack) }, } diff --git a/builder/cmd/server/bundle/all.go b/builder/cmd/server/bundle/all.go index fb781c8..e8f3357 100644 --- a/builder/cmd/server/bundle/all.go +++ b/builder/cmd/server/bundle/all.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/server" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var AllCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return server.Bundle() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return server.Bundle("output", &pack) }, } diff --git a/builder/cmd/server/bundle/tar.go b/builder/cmd/server/bundle/tar.go index 18885e5..7e0043c 100644 --- a/builder/cmd/server/bundle/tar.go +++ b/builder/cmd/server/bundle/tar.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/server" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var TarCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return server.Tar() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return server.Tar(&pack) }, } diff --git a/builder/cmd/server/bundle/zip.go b/builder/cmd/server/bundle/zip.go index 9f4f5f3..77fcd55 100644 --- a/builder/cmd/server/bundle/zip.go +++ b/builder/cmd/server/bundle/zip.go @@ -2,6 +2,7 @@ package bundle import ( "github.com/HappyRedstone/SodiumPlus/builder/internal/server" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var ZipCommand = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - return server.Zip() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return server.Zip(&pack) }, } diff --git a/builder/cmd/server/clean.go b/builder/cmd/server/clean.go index 0e3cf19..c5a064d 100644 --- a/builder/cmd/server/clean.go +++ b/builder/cmd/server/clean.go @@ -2,6 +2,7 @@ package server import ( internalServer "github.com/HappyRedstone/SodiumPlus/builder/internal/server" + "github.com/packwiz/packwiz/core" "github.com/spf13/cobra" ) @@ -12,6 +13,12 @@ var CleanCommand = &cobra.Command{ Aliases: []string{"c"}, RunE: func(cmd *cobra.Command, args []string) error { - return internalServer.Clean() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + return internalServer.Clean("output", &pack) }, } diff --git a/builder/cmd/version/bundle.go b/builder/cmd/version/bundle.go new file mode 100644 index 0000000..a01d735 --- /dev/null +++ b/builder/cmd/version/bundle.go @@ -0,0 +1,46 @@ +package version + +import ( + "os" + "path/filepath" + + "github.com/HappyRedstone/SodiumPlus/builder/internal/config" + "github.com/HappyRedstone/SodiumPlus/builder/internal/multiver" + "github.com/spf13/cobra" +) + +var BundleCommand = CreateBundleCommand() + +func CreateBundleCommand() *cobra.Command { + cmd := cobra.Command{ + Use: "bundle [minecraft version] [loader]", + Short: "Bundle a version of a multiversion pack.", + Long: `Bundle a version of a multiversion pack.`, + Aliases: []string{"b", "export"}, + Args: cobra.MinimumNArgs(2), + + RunE: func(cmd *cobra.Command, args []string) error { + root, err := os.Getwd() + + if err != nil { + return err + } + + cfg, err := config.GetConfig() + + if err != nil { + return err + } + + outDir, err := filepath.Abs(cfg.MultiVersion.OutDir) + + if err != nil { + return err + } + + return multiver.BundlePack(outDir, cfg, root, args[0], args[1]) + }, + } + + return &cmd +} diff --git a/builder/cmd/version/bundle_all.go b/builder/cmd/version/bundle_all.go new file mode 100644 index 0000000..21a7dc8 --- /dev/null +++ b/builder/cmd/version/bundle_all.go @@ -0,0 +1,71 @@ +package version + +import ( + "fmt" + "os" + "path" + "path/filepath" + + "github.com/HappyRedstone/SodiumPlus/builder/internal/config" + "github.com/HappyRedstone/SodiumPlus/builder/internal/multiver" + "github.com/spf13/cobra" +) + +var BundleAllCommand = CreateBundleAllCommand() + +func CreateBundleAllCommand() *cobra.Command { + cmd := cobra.Command{ + Use: "bundle-all", + Short: "Bundle all version of a multiversion pack.", + Long: `Bundle all version of a multiversion pack.`, + Aliases: []string{"B", "export-all"}, + + RunE: func(cmd *cobra.Command, args []string) error { + baseRoot, err := os.Getwd() + + if err != nil { + return err + } + + root, err := filepath.Abs(baseRoot) + + if err != nil { + return err + } + + cfg, err := config.GetConfig() + + if err != nil { + return err + } + + outDir, err := filepath.Abs(cfg.MultiVersion.OutDir) + + if err != nil { + return err + } + + items, err := multiver.FindVersions(path.Join(root, cfg.MultiVersion.VersionsDir)) + + if err != nil { + return err + } + + for ver, loaders := range items { + for _, loader := range loaders { + fmt.Printf("Bundling for %s %s...\n", loader, ver) + + err = multiver.BundlePack(outDir, cfg, root, ver, loader) + + if err != nil { + return err + } + } + } + + return nil + }, + } + + return &cmd +} diff --git a/builder/cmd/version/expand.go b/builder/cmd/version/expand.go deleted file mode 100644 index 54da67d..0000000 --- a/builder/cmd/version/expand.go +++ /dev/null @@ -1,57 +0,0 @@ -package version - -import ( - "fmt" - "slices" - "strings" - - "github.com/HappyRedstone/SodiumPlus/builder/internal/config" - "github.com/HappyRedstone/SodiumPlus/builder/internal/multiver" - "github.com/spf13/cobra" -) - -var ExpandCommand = CreateExpandCommand() - -var MappedLoaders = map[string]string{ - "fabric": "Fabric", - "forge": "Forge", - "neoforge": "NeoForge", - "quilt": "Quilt", - "liteloader": "LiteLoader", -} - -var LowerLoaders = []string{"fabric", "forge", "neoforge", "quilt", "liteloader"} - -func CreateExpandCommand() *cobra.Command { - cmd := cobra.Command{ - Use: "expand [minecraft version] [loader]", - Short: "Expand a pack stub into its full form.", - Long: `Expand a pack stub into its full form.`, - Aliases: []string{"x"}, - Args: cobra.MinimumNArgs(2), - - RunE: func(cmd *cobra.Command, args []string) error { - cfg, err := config.GetConfig() - - if err != nil { - return err - } - - if !slices.Contains(LowerLoaders, strings.ToLower(args[1])) { - return fmt.Errorf("invalid loader: %s", args[1]) - } - - stub, err := multiver.LoadPackStub(args[0], MappedLoaders[strings.ToLower(args[1])]) - - if err != nil { - return err - } - - _, err = stub.InitRealPack(*cfg) - - return err - }, - } - - return &cmd -} diff --git a/builder/cmd/version/init.go b/builder/cmd/version/init.go index 96a3a42..c4a69ab 100644 --- a/builder/cmd/version/init.go +++ b/builder/cmd/version/init.go @@ -23,7 +23,6 @@ var BasePath string var Force bool var UseLatest bool var InitCommand = CreateInitCommand() -var Loaders = []string{"Forge", "Fabric", "NeoForge", "Quilt", "LiteLoader"} func CreateInitCommand() *cobra.Command { cmd := cobra.Command{ @@ -78,7 +77,7 @@ func InitFor(versions []string, ver string, loader string) error { found_loader := false // Use custom logic so we can properly capitalize the loader name - for _, loader_id := range Loaders { + for _, loader_id := range multiver.Loaders { if strings.EqualFold(loader_id, loader) { found_loader = true loader = loader_id diff --git a/builder/cmd/version/migrate.go b/builder/cmd/version/migrate.go index 291e96d..61f4d8c 100644 --- a/builder/cmd/version/migrate.go +++ b/builder/cmd/version/migrate.go @@ -70,7 +70,9 @@ func CreateMigrateCommand() *cobra.Command { cfg.MultiVersion.PackVersion = pack.Version cfg.MultiVersion.BootstrapMods = data cfg.MultiVersion.CommonDir = "common" + cfg.MultiVersion.VersionsDir = "versions" cfg.MultiVersion.TempDir = ".build/temp" + cfg.MultiVersion.OutDir = "output" cfg.Write() diff --git a/builder/cmd/version/version.go b/builder/cmd/version/version.go index cfcb1b0..9b7b5c4 100644 --- a/builder/cmd/version/version.go +++ b/builder/cmd/version/version.go @@ -16,7 +16,8 @@ func CreateVersionCommand() *cobra.Command { cmd.AddCommand(InitCommand) cmd.AddCommand(MigrateCommand) - cmd.AddCommand(ExpandCommand) + cmd.AddCommand(BundleCommand) + cmd.AddCommand(BundleAllCommand) return &cmd } diff --git a/builder/internal/all/all.go b/builder/internal/all/all.go index e4341e3..7f6bb40 100644 --- a/builder/internal/all/all.go +++ b/builder/internal/all/all.go @@ -1,19 +1,46 @@ package all import ( + "os" + "github.com/HappyRedstone/SodiumPlus/builder/internal/client" "github.com/HappyRedstone/SodiumPlus/builder/internal/config" + "github.com/HappyRedstone/SodiumPlus/builder/internal/helpers" "github.com/HappyRedstone/SodiumPlus/builder/internal/server" + "github.com/packwiz/packwiz/core" + "github.com/spf13/viper" ) func Clean() error { - err := client.Clean() + pack, err := core.LoadPack() + + if err != nil { + return err + } + + err = client.Clean(&pack) + + if err != nil { + return err + } + + err = server.Clean("output", &pack) + + if err != nil { + return err + } + + return nil +} + +func CleanFor(outDir string, pack *core.Pack) error { + err := client.Clean(pack) if err != nil { return err } - err = server.Clean() + err = server.Clean(outDir, pack) if err != nil { return err @@ -23,7 +50,23 @@ func Clean() error { } func Bundle() error { - err := client.Bundle() + out_dir := "output" + + if helpers.Exists(out_dir) { + err := os.RemoveAll(out_dir) + + if err != nil { + return err + } + } + + pack, err := core.LoadPack() + + if err != nil { + return err + } + + err = client.Bundle("output", &pack) if err != nil { return err @@ -36,7 +79,27 @@ func Bundle() error { } if cfg.Server.Enabled { - err = server.Bundle() + err = server.Bundle("output", &pack) + + if err != nil { + return err + } + } + + return nil +} + +func BundleFor(outDir string, root string, cfg *config.Config, pack *core.Pack) error { + err := client.Bundle(outDir, pack) + + if err != nil { + return err + } + + if cfg.Server.Enabled { + viper.Set("server-folder", root+"/server") + + err = server.Bundle(outDir, pack) if err != nil { return err diff --git a/builder/internal/client/all.go b/builder/internal/client/all.go index dbc9b73..e1c7e13 100644 --- a/builder/internal/client/all.go +++ b/builder/internal/client/all.go @@ -1,13 +1,15 @@ package client -func Bundle() error { - err := CurseForge() +import "github.com/packwiz/packwiz/core" + +func Bundle(outDir string, pack *core.Pack) error { + err := CurseForge(outDir, pack) if err != nil { return err } - err = Modrinth() + err = Modrinth(outDir, pack) if err != nil { return err diff --git a/builder/internal/client/clean.go b/builder/internal/client/clean.go index c5821ba..2de67e5 100644 --- a/builder/internal/client/clean.go +++ b/builder/internal/client/clean.go @@ -5,23 +5,19 @@ import ( "os" "path/filepath" - "github.com/HappyRedstone/SodiumPlus/builder/internal/helpers" + "github.com/packwiz/packwiz/core" ) var ( namedGlobs = []string{ "%s v*+*.zip", "%s v*+*.mrpack", + "%s v*+*-*.zip", + "%s v*+*-*.mrpack", } ) -func Clean() error { - pack, _, err := helpers.GetPack() - - if err != nil { - return err - } - +func Clean(pack *core.Pack) error { for _, glob := range namedGlobs { matches, err := filepath.Glob(fmt.Sprintf(glob, pack.Name)) diff --git a/builder/internal/client/curseforge.go b/builder/internal/client/curseforge.go index 8c13041..68afc6d 100644 --- a/builder/internal/client/curseforge.go +++ b/builder/internal/client/curseforge.go @@ -20,7 +20,7 @@ var ( curseOutputFormat = "%s %s.zip" ) -func CurseForge() error { +func CurseForge(outDir string, pack *core.Pack) error { fmt.Println("Exporting CurseForge pack...") err := helpers.Refresh() @@ -34,14 +34,6 @@ func CurseForge() error { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond, spinner.WithFinalMSG("✓ Done!\n")) s.Start() - s.Suffix = " Loading pack..." - - pack, err := core.LoadPack() - - if err != nil { - return err - } - s.Suffix = " Loading index..." index, err := pack.LoadIndex() @@ -85,10 +77,19 @@ func CurseForge() error { s.Suffix = " Creating file..." - versionString := "v" + pack.Version + "+" + pack.Versions["minecraft"] + loader := pack.GetLoaders()[0] + versionString := "v" + pack.Version + "+" + loader + "-" + pack.Versions["minecraft"] fileName := fmt.Sprintf(curseOutputFormat, pack.Name, versionString) - expFile, err := os.Create(fileName) + if !helpers.Exists(outDir) { + err := os.MkdirAll(outDir, 0755) + + if err != nil { + return err + } + } + + expFile, err := os.Create(outDir + "/" + fileName) if err != nil { return err @@ -201,7 +202,7 @@ func CurseForge() error { s.Suffix = " Writing manifest..." - err = packinterop.WriteManifestFromPack(pack, cfFileRefs, exportData.ProjectID, manifestFile) + err = packinterop.WriteManifestFromPack(*pack, cfFileRefs, exportData.ProjectID, manifestFile) if err != nil { _ = exp.Close() diff --git a/builder/internal/client/modrinth.go b/builder/internal/client/modrinth.go index 33c3a59..9602322 100644 --- a/builder/internal/client/modrinth.go +++ b/builder/internal/client/modrinth.go @@ -70,7 +70,7 @@ func AddToZip(dl core.CompletedDownload, exp *zip.Writer, dir string, index *cor return true } -func Modrinth() error { +func Modrinth(outDir string, pack *core.Pack) error { fmt.Println("Exporting Modrinth pack...") err := helpers.Refresh() @@ -84,14 +84,6 @@ func Modrinth() error { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond, spinner.WithFinalMSG("✓ Done!\n")) s.Start() - s.Suffix = " Loading pack..." - - pack, err := core.LoadPack() - - if err != nil { - return err - } - s.Suffix = " Loading index..." index, err := pack.LoadIndex() @@ -108,12 +100,21 @@ func Modrinth() error { return err } - versionString := "v" + pack.Version + "+" + pack.Versions["minecraft"] + loader := pack.GetLoaders()[0] + versionString := "v" + pack.Version + "+" + loader + "-" + pack.Versions["minecraft"] fileName := fmt.Sprintf(modrinthOutputFormat, pack.Name, versionString) s.Suffix = " Creating file..." - expFile, err := os.Create(fileName) + if !helpers.Exists(outDir) { + err := os.MkdirAll(outDir, 0755) + + if err != nil { + return err + } + } + + expFile, err := os.Create(outDir + "/" + fileName) if err != nil { return err diff --git a/builder/internal/config/config.go b/builder/internal/config/config.go index af246fb..6441f8d 100644 --- a/builder/internal/config/config.go +++ b/builder/internal/config/config.go @@ -38,6 +38,8 @@ type Config struct { BootstrapMods []Mod `toml:"bootstrap_mods"` CommonDir string `toml:"common"` TempDir string `toml:"temp"` + VersionsDir string `toml:"versions"` + OutDir string `toml:"output"` } `toml:"multi_version"` } diff --git a/builder/internal/multiver/bundle.go b/builder/internal/multiver/bundle.go new file mode 100644 index 0000000..c8c80e9 --- /dev/null +++ b/builder/internal/multiver/bundle.go @@ -0,0 +1,37 @@ +package multiver + +import ( + "fmt" + "os" + "slices" + "strings" + + "github.com/HappyRedstone/SodiumPlus/builder/internal/all" + "github.com/HappyRedstone/SodiumPlus/builder/internal/config" +) + +func BundlePack(outDir string, cfg *config.Config, root string, version string, loader string) error { + if !slices.Contains(LowerLoaders, strings.ToLower(loader)) { + return fmt.Errorf("invalid loader: %s", loader) + } + + stub, err := LoadPackStub(version, MappedLoaders[strings.ToLower(loader)]) + + if err != nil { + return err + } + + pack, err := stub.InitRealPack(*cfg) + + if err != nil { + return err + } + + err = all.BundleFor(outDir, root, cfg, pack) + + if err != nil { + return err + } + + return os.Chdir(root) +} diff --git a/builder/internal/multiver/data.go b/builder/internal/multiver/data.go new file mode 100644 index 0000000..8ecc813 --- /dev/null +++ b/builder/internal/multiver/data.go @@ -0,0 +1,12 @@ +package multiver + +var Loaders = []string{"Forge", "Fabric", "NeoForge", "Quilt", "LiteLoader"} +var LowerLoaders = []string{"fabric", "forge", "neoforge", "quilt", "liteloader"} + +var MappedLoaders = map[string]string{ + "fabric": "Fabric", + "forge": "Forge", + "neoforge": "NeoForge", + "quilt": "Quilt", + "liteloader": "LiteLoader", +} diff --git a/builder/internal/multiver/expand.go b/builder/internal/multiver/expand.go index 50c12b8..2f9c37e 100644 --- a/builder/internal/multiver/expand.go +++ b/builder/internal/multiver/expand.go @@ -147,8 +147,8 @@ func (stub PackStub) InitRealPack(config config.Config) (*core.Pack, error) { }, Versions: map[string]string{ - "minecraft": stub.Minecraft, - stub.Loader: stub.LoaderVersion, + "minecraft": stub.Minecraft, + strings.ToLower(stub.Loader): stub.LoaderVersion, }, } diff --git a/builder/internal/multiver/list.go b/builder/internal/multiver/list.go new file mode 100644 index 0000000..b7512fd --- /dev/null +++ b/builder/internal/multiver/list.go @@ -0,0 +1,40 @@ +package multiver + +import ( + "os" + "slices" + "strings" +) + +func FindVersions(dir string) (map[string][]string, error) { + vers := map[string][]string{} + + dirs, err := os.ReadDir(dir) + + if err != nil { + return nil, err + } + + for _, item := range dirs { + if item.IsDir() { + items := []string{} + loaders, err := os.ReadDir(dir + "/" + item.Name()) + + if err != nil { + return nil, err + } + + for _, loader := range loaders { + if slices.Contains(LowerLoaders, strings.ToLower(loader.Name())) { + realLoader := MappedLoaders[strings.ToLower(loader.Name())] + + items = append(items, realLoader) + } + } + + vers[item.Name()] = items + } + } + + return vers, nil +} diff --git a/builder/internal/server/bundle.go b/builder/internal/server/bundle.go index c1d7ef8..cc0a94b 100644 --- a/builder/internal/server/bundle.go +++ b/builder/internal/server/bundle.go @@ -1,19 +1,21 @@ package server -func Bundle() error { - err := Tar() +import "github.com/packwiz/packwiz/core" + +func Bundle(outDir string, pack *core.Pack) error { + err := Tar(pack) if err != nil { return err } - err = Zip() + err = Zip(pack) if err != nil { return err } - err = Rename() + err = Rename(outDir, pack) if err != nil { return err @@ -22,14 +24,14 @@ func Bundle() error { return nil } -func CleanBundle() error { - err := Clean() +func CleanBundle(outDir string, pack *core.Pack) error { + err := Clean(outDir, pack) if err != nil { return err } - err = Bundle() + err = Bundle(outDir, pack) if err != nil { return err diff --git a/builder/internal/server/clean.go b/builder/internal/server/clean.go index 6973a7a..dd7ac46 100644 --- a/builder/internal/server/clean.go +++ b/builder/internal/server/clean.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/HappyRedstone/SodiumPlus/builder/internal/helpers" + "github.com/packwiz/packwiz/core" ) var ( @@ -17,11 +18,13 @@ var ( namedGlobs = []string{ "%s (Server) v*+*.zip", "%s (Server) v*+*.tar.gz", + "%s (Server) v*+*-*.zip", + "%s (Server) v*+*-*.tar.gz", } ) -func Clean() error { - err := CleanNamed() +func Clean(outDir string, pack *core.Pack) error { + err := CleanNamed(outDir, pack) if err != nil { return err @@ -42,15 +45,9 @@ func Clean() error { return nil } -func CleanNamed() error { - pack, _, err := helpers.GetPack() - - if err != nil { - return err - } - +func CleanNamed(outDir string, pack *core.Pack) error { for _, glob := range namedGlobs { - matches, err := filepath.Glob(fmt.Sprintf(glob, pack.Name)) + matches, err := filepath.Glob(outDir + "/" + fmt.Sprintf(glob, pack.Name)) if err != nil { return err diff --git a/builder/internal/server/rename.go b/builder/internal/server/rename.go index bb1836a..e6a00b0 100644 --- a/builder/internal/server/rename.go +++ b/builder/internal/server/rename.go @@ -16,20 +16,23 @@ var ( } ) -func Rename() error { +func Rename(outDir string, pack *core.Pack) error { helpers.Setup() - pack, err := core.LoadPack() - - if err != nil { - return err - } - version := pack.Version minecraft := pack.Versions["minecraft"] pack_name := pack.Name + loader := pack.GetLoaders()[0] + + version_str := "v" + version + "+" + loader + "-" + minecraft + + if !helpers.Exists(outDir) { + err := os.MkdirAll(outDir, 0755) - version_str := "v" + version + "+" + minecraft + if err != nil { + return err + } + } for input, output := range inputMap { output_str := fmt.Sprintf(output, pack_name, version_str) @@ -48,7 +51,7 @@ func Rename() error { continue } - err = os.Rename(input, output_str) + err = os.Rename(input, outDir+"/"+output_str) if err != nil { return err diff --git a/builder/internal/server/tar.go b/builder/internal/server/tar.go index 2f8bc42..db2ef72 100644 --- a/builder/internal/server/tar.go +++ b/builder/internal/server/tar.go @@ -12,11 +12,12 @@ import ( "github.com/briandowns/spinner" "github.com/magefile/mage/target" + "github.com/packwiz/packwiz/core" ) var tarOutput = "server.tar.gz" -func Tar() error { +func Tar(pack *core.Pack) error { tarInputGlob := []string{ GetServerFolder() + "/**/*", GetServerFolder() + "/**", diff --git a/builder/internal/server/zip.go b/builder/internal/server/zip.go index 08bcf04..d993168 100644 --- a/builder/internal/server/zip.go +++ b/builder/internal/server/zip.go @@ -10,11 +10,12 @@ import ( "github.com/briandowns/spinner" "github.com/magefile/mage/target" + "github.com/packwiz/packwiz/core" ) var zipOutput = "server.zip" -func Zip() error { +func Zip(pack *core.Pack) error { zipInputGlob := []string{ GetServerFolder() + "/**/*", GetServerFolder() + "/**",