Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 73437ceade | |||
| 571bf57002 | |||
| 8d6e6f3c4b |
29
build.sh
Executable file
29
build.sh
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Define the list of target platforms
|
||||||
|
PLATFORMS=("darwin-amd64" "linux-386" "linux-amd64" "windows-386" "windows-amd64")
|
||||||
|
|
||||||
|
# Create the dist directory if it doesnt exist
|
||||||
|
mkdir -p dist
|
||||||
|
|
||||||
|
for PLATFORM in "${PLATFORMS[@]}"; do
|
||||||
|
# Extract the GOOS and GOARCH values from the platform string
|
||||||
|
GOOS=${PLATFORM%%-*}
|
||||||
|
GOARCH=${PLATFORM##*-}
|
||||||
|
echo "Building for $GOOS/$GOARCH..."
|
||||||
|
|
||||||
|
# Set the GOOS and GOARCH environment variables
|
||||||
|
export GOOS
|
||||||
|
export GOARCH
|
||||||
|
|
||||||
|
# Determine the binary extension based on the target OS
|
||||||
|
BIN_EXT=""
|
||||||
|
if [[ "$GOOS" == "windows" ]]; then
|
||||||
|
BIN_EXT=".exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build the executable
|
||||||
|
go build -o "dist/JSONUIHELPER-$GOOS-$GOARCH$BIN_EXT"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Build completed."
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"watchDir": "/path/to/path",
|
"watchDir": "/root/dev/test1/rpHive2",
|
||||||
"zipDir": "/path/to/path",
|
"zipDir": "/root/dev/test1/resource_packs/",
|
||||||
"jsonFile": "manifest.json",
|
"jsonFile": "manifest.json",
|
||||||
"zipFileName": "name_pack.zip",
|
"zipFileName": "andromeda.zip",
|
||||||
"zip": "true"
|
"zip": true
|
||||||
}
|
}
|
||||||
26
main.go
26
main.go
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"encoding/json"
|
"encodiang/json"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"io"
|
"io"
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config struct to hold configuration values from config.json
|
||||||
type Config struct {
|
type Config struct {
|
||||||
WatchDir string `json:"watchDir"`
|
WatchDir string `json:"watchDir"`
|
||||||
ZipDir string `json:"zipDir"`
|
ZipDir string `json:"zipDir"`
|
||||||
@@ -26,12 +27,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Load configuration from config.json
|
||||||
loadConfig()
|
loadConfig()
|
||||||
|
|
||||||
|
// Check if watch directory and zip directory are the same
|
||||||
if config.WatchDir == config.ZipDir {
|
if config.WatchDir == config.ZipDir {
|
||||||
log.Fatal("Watch directory and zip directory cannot be the same.")
|
log.Fatal("Watch directory and zip directory cannot be the same.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new file system watcher
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -46,25 +50,22 @@ func main() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Check if the event is a write or create event
|
||||||
if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create {
|
if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create {
|
||||||
info, err := os.Stat(event.Name)
|
info, err := os.Stat(event.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error:", err)
|
log.Println("Error:", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Check if the modification time is after the last modified time
|
||||||
if info.ModTime().After(lastModifiedTime) {
|
if info.ModTime().After(lastModifiedTime) {
|
||||||
log.Println("Modified file:", event.Name)
|
log.Println("Modified file:", event.Name)
|
||||||
updateJSONFile()
|
updateJSONFile()
|
||||||
|
// Zip or copy folder contents based on the config
|
||||||
if config.Zip {
|
if config.Zip {
|
||||||
err := zipFolderContents(config.WatchDir, filepath.Join(config.ZipDir, config.ZipFileName))
|
zipFolderContents(config.WatchDir, filepath.Join(config.ZipDir, config.ZipFileName))
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
err := copyFolderContents(config.WatchDir, config.ZipDir)
|
copyFolderContents(config.WatchDir, config.ZipDir)
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,11 +78,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Add the watch directory to the watcher
|
||||||
err = watcher.Add(config.WatchDir)
|
err = watcher.Add(config.WatchDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Walk through the watch directory and add all subdirectories to the watcher
|
||||||
err = filepath.Walk(config.WatchDir, func(path string, info os.FileInfo, err error) error {
|
err = filepath.Walk(config.WatchDir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -98,6 +101,7 @@ func main() {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load configuration from config.json
|
||||||
func loadConfig() {
|
func loadConfig() {
|
||||||
file, err := os.Open("config.json")
|
file, err := os.Open("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -112,6 +116,7 @@ func loadConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the JSON file with new UUIDs
|
||||||
func updateJSONFile() {
|
func updateJSONFile() {
|
||||||
filePath := filepath.Join(config.WatchDir, config.JsonFile)
|
filePath := filepath.Join(config.WatchDir, config.JsonFile)
|
||||||
file, err := os.ReadFile(filePath)
|
file, err := os.ReadFile(filePath)
|
||||||
@@ -141,6 +146,7 @@ func updateJSONFile() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate new UUIDs for the header and modules
|
||||||
jsonConfig.Header.UUID = uuid.New().String()
|
jsonConfig.Header.UUID = uuid.New().String()
|
||||||
for i := range jsonConfig.Modules {
|
for i := range jsonConfig.Modules {
|
||||||
jsonConfig.Modules[i].UUID = uuid.New().String()
|
jsonConfig.Modules[i].UUID = uuid.New().String()
|
||||||
@@ -159,6 +165,7 @@ func updateJSONFile() {
|
|||||||
lastModifiedTime = time.Now()
|
lastModifiedTime = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zip the contents of the source directory and save it to the target file
|
||||||
func zipFolderContents(source, target string) error {
|
func zipFolderContents(source, target string) error {
|
||||||
zipfile, err := os.Create(target)
|
zipfile, err := os.Create(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -216,6 +223,7 @@ func zipFolderContents(source, target string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the contents of the source directory to the target directory
|
||||||
func copyFolderContents(source, target string) error {
|
func copyFolderContents(source, target string) error {
|
||||||
return filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
|
return filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user