Skip to content

Commit

Permalink
Refactor of Go code
Browse files Browse the repository at this point in the history
  • Loading branch information
connerdouglass committed Nov 11, 2021
1 parent 441a9d3 commit b97626e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 46 deletions.
10 changes: 3 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
project_name: customrealms-cli
# release:
# github:
# owner: customrealms
# name: cli
builds:
- id: customrealms-cli-darwin-amd64
ldflags:
- -s -w -X github.com/customrealms/cli/pkg/version.Version={{.Version}}
binary: crx
main: ./main.go
main: ./cmd/crx/main.go
env:
- CGO_ENABLED=0
goos:
Expand All @@ -18,7 +14,7 @@ builds:
- id: customrealms-cli-linux-amd64
ldflags:
- -s -w -X github.com/customrealms/cli/pkg/version.Version={{.Version}}
main: ./main.go
main: ./cmd/crx/main.go
binary: crx
env:
- CGO_ENABLED=0
Expand All @@ -29,7 +25,7 @@ builds:
- id: customrealms-cli-windows-amd64
ldflags:
- -s -w -X github.com/customrealms/cli/pkg/version.Version={{.Version}}
main: ./main.go
main: ./cmd/crx/main.go
binary: crx
env:
- CGO_ENABLED=0
Expand Down
43 changes: 43 additions & 0 deletions cmd/crx/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"os"
"strings"

"github.com/customrealms/cli/lib"
)

const TEMPLATE_JAR = "/Users/conner/Projects/customrealms/bukkit-runtime/target/bukkit-runtime-jar-with-dependencies.jar"
const output = "/Users/conner/Desktop/mcserver/plugins/bukkit-runtime-jar-with-dependencies.jar"

func main() {

// Open the output file for the final JAR
file, err := os.Create(output)
if err != nil {
panic(err)
}
defer file.Close()

// Create a reader for the plugin source code
pluginCode := strings.NewReader("setInterval(() => console.log('YOOOOOO'), 3000)")

// Define the plugin.yml details for the plugin
pluginYml := lib.PluginYml{
Name: "MyPlugin",
ApiVersion: "1.17",
Version: "0.0.1",
Main: "io.customrealms.MainPlugin",
}

// Produce the final JAR file
if err := lib.CreateFinalJar(
file,
TEMPLATE_JAR,
pluginCode,
&pluginYml,
); err != nil {
panic(err)
}

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/customrealms/crbuild
module github.com/customrealms/cli

go 1.17
38 changes: 1 addition & 37 deletions main.go → lib/jarbuilder.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
package main
package lib

import (
"archive/zip"
"io"
"os"
"strings"
)

const TEMPLATE_JAR = "/Users/conner/Projects/customrealms/bukkit-runtime/target/bukkit-runtime-jar-with-dependencies.jar"
const output = "/Users/conner/Desktop/mcserver/plugins/bukkit-runtime-jar-with-dependencies.jar"

func main() {

// Open the output file for the final JAR
file, err := os.Create(output)
if err != nil {
panic(err)
}
defer file.Close()

// Create a reader for the plugin source code
pluginCode := strings.NewReader("setInterval(() => console.log('YOOOOOO'), 3000)")

// Define the plugin.yml details for the plugin
pluginYml := PluginYml{
Name: "MyPlugin",
ApiVersion: "1.17",
Version: "0.0.1",
Main: "io.customrealms.MainPlugin",
}

// Produce the final JAR file
if err := CreateFinalJar(
file,
TEMPLATE_JAR,
pluginCode,
&pluginYml,
); err != nil {
panic(err)
}

}

func CreateFinalJar(
writer io.Writer,
templateJar string,
Expand Down
2 changes: 1 addition & 1 deletion plugin_yml.go → lib/pluginyml.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package lib

import (
"fmt"
Expand Down

0 comments on commit b97626e

Please sign in to comment.