Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.0 #288

Merged
merged 13 commits into from
Jul 5, 2024
Merged

1.3.0 #288

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ Now, you can re-run `regolith run`.

Check `com.mojang`, and open the new `texture_list.json` file in `RP/textures/texture_list.json`. Every time you run regolith, this file will be re-created, based on your current textures. No need to manually edit it ever again!

{: .notice--warning}
:::: warning
`Warning:` If your resource pack already contains `texture_list.json`, you should delete it. You don't need to manually worry about it anymore - Regolith will handle it!
::::

{: .notice--warning}
:::: warning
`Warning:` If your project doesn't have any textures, than `texture_list.json` will simply create a blank file `[]`. Consider adding some textures to see the filter at work!
::::

## Whats Next

Expand Down
12 changes: 10 additions & 2 deletions docs/docs/guide/installing-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ Regolith is intended to be used with git version control, and by default the `.r

You may use the command `regolith install-all`, which will check `config.json`, and install every filter in the `filterDefinitions`.

{: .notice--warning}
:::: warning
This is only intended to be used with existing projects. To install new filters, use `regolith install`.
::::

## Filter Versioning

Filters in Regolith are optionally versioned with a [semantic version](https://semver.org/). As filters get updated, new versions will be released, and you can optionally update.

{: .notice--warning}
:::: warning
If you don't specify a version, the `install` command will pick a sensible default. First, it will search for the latest release. If that doesn't exist (such as a filter that has no versions), it will select the latest commit in the repository. In both cases, the installed version will be `pinned`.
::::

### Installing a Specific Version

Expand Down Expand Up @@ -102,6 +104,12 @@ regolith install name_ninja --update

Alternatively, you can modify the `version` field in `config.json` and run `regolith install-all`. Regolith install-all is useful for working in a team, when other team members may have to update or add filters to the project.

If you want to update all filters in your project, you can use the `--update` flag with the `install-all` command.

```
regolith install-all --update
```

### Updating resolvers

When using short names for filters, Regolith uses a resolver file from a remote repository to determine the URL of the filter.
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func main() {
&force, "force", "f", false, "Force the operation, overriding potential safeguards.")
subcommands = append(subcommands, cmdInit)

profiles := []string{"default"}
profiles := []string{}
// regolith install
var update, resolverRefresh, filterRefresh bool
cmdInstall := &cobra.Command{
Expand All @@ -233,7 +233,10 @@ func main() {
cmd.Help()
return
}
err = regolith.Install(filters, force || update, resolverRefresh, filterRefresh, cmd.Flags().Lookup("profile").Changed, profiles, burrito.PrintStackTrace)
if cmd.Flags().Lookup("profile").Changed && len(profiles) == 0 {
profiles = append(profiles, "default")
}
err = regolith.Install(filters, force || update, resolverRefresh, filterRefresh, profiles, burrito.PrintStackTrace)
},
}
cmdInstall.Flags().BoolVarP(
Expand All @@ -254,11 +257,13 @@ func main() {
Short: "Installs all nonexistent or outdated filters defined in filterDefinitions list",
Long: regolithInstallAllDesc,
Run: func(cmd *cobra.Command, _ []string) {
err = regolith.InstallAll(force, burrito.PrintStackTrace, filterRefresh)
err = regolith.InstallAll(force, update, burrito.PrintStackTrace, filterRefresh)
},
}
cmdInstallAll.Flags().BoolVarP(
&force, "force", "f", false, "Force the operation, overriding potential safeguards.")
cmdInstallAll.Flags().BoolVarP(
&update, "update", "u", false, "Updates the remote filters to the latest stable version available.")
cmdInstallAll.Flags().BoolVar(
&filterRefresh, "force-filter-refresh", false, "Force filter cache refresh.")
subcommands = append(subcommands, cmdInstallAll)
Expand Down
51 changes: 30 additions & 21 deletions regolith/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,7 @@ func (c *RunContext) StartWatchingSourceFiles() error {
if c.interruptionChannel != nil {
return burrito.WrappedError("Files are already being watched.")
}
rpWatcher, err := NewDirWatcher(c.Config.ResourceFolder)
if err != nil {
return burrito.WrapError(err, "Could not create resource pack watcher.")
}
bpWatcher, err := NewDirWatcher(c.Config.BehaviorFolder)
if err != nil {
return burrito.WrapError(err, "Could not create behavior pack watcher.")
}
dataWatcher, err := NewDirWatcher(c.Config.DataPath)
if err != nil {
return burrito.WrapError(err, "Could not create data watcher.")
}

c.interruptionChannel = make(chan string)
yieldChanges := func(
watcher *DirWatcher, sourceName string,
Expand All @@ -81,16 +70,36 @@ func (c *RunContext) StartWatchingSourceFiles() error {
}
}
}
go yieldChanges(rpWatcher, "rp")
go yieldChanges(bpWatcher, "bp")
go yieldChanges(dataWatcher, "data")
return nil
}

// AwaitInterruption locks the goroutine with the interruption channel until
// the Config is interrupted and returns the interruption message.
func (c *RunContext) AwaitInterruption() string {
return <-c.interruptionChannel
addWatcher := func(watchedPath, watcherString string) error {
watcher, err := NewDirWatcher(watchedPath)
if err != nil {
return burrito.PassError(err)
}
go yieldChanges(watcher, watcherString)
return nil
}

var err error
if c.Config.ResourceFolder != "" {
err = addWatcher(c.Config.ResourceFolder, "rp")
if err != nil {
return burrito.WrapError(err, "Could not create resource pack watcher.")
}
}
if c.Config.BehaviorFolder != "" {
err = addWatcher(c.Config.BehaviorFolder, "bp")
if err != nil {
return burrito.WrapError(err, "Could not create behavior pack watcher.")
}
}
if c.Config.DataPath != "" {
err = addWatcher(c.Config.DataPath, "data")
if err != nil {
return burrito.WrapError(err, "Could not create data watcher.")
}
}
return nil
}

// IsInterrupted returns true if there is a message on the interruptionChannel
Expand Down
10 changes: 6 additions & 4 deletions regolith/filter_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ func FilterDefinitionFromTheInternet(
if version == "" { // "" locks the version to the latest
version, err = GetRemoteFilterDownloadRef(url, name, version)
if err != nil {
return nil, burrito.WrappedErrorf(
getRemoteFilterDownloadRefError, url, name, version)
return nil, burrito.WrapErrorf(
err, getRemoteFilterDownloadRefError, url, name, version)
}
version = trimFilterPrefix(version, name)
}
Expand Down Expand Up @@ -547,10 +547,10 @@ func (f *RemoteFilterDefinition) InstalledVersion(dotRegolithPath string) (strin
return versionStr, nil
}

func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath string, isInstall, refreshFilters bool) error {
func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath, dataPath string, refreshFilters bool) error {
installedVersion, err := f.InstalledVersion(dotRegolithPath)
installedVersion = trimFilterPrefix(installedVersion, f.Id)
if err != nil && (!isInstall || force) {
if err != nil && force {
Logger.Warnf("Unable to get installed version of filter %q.", f.Id)
}
MeasureStart("Get remote filter download ref")
Expand All @@ -569,6 +569,8 @@ func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath string, isIn
if err != nil {
return burrito.PassError(err)
}
// Copy the data of the remote filter to the data path
f.CopyFilterData(dataPath, dotRegolithPath)
err = f.InstallDependencies(f, dotRegolithPath)
if err != nil {
return burrito.PassError(err)
Expand Down
56 changes: 50 additions & 6 deletions regolith/install_add.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package regolith

import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -28,8 +29,8 @@ type parsedInstallFilterArg struct {
// and copies their data to the data path. If the filter is already installed,
// it returns an error unless the force flag is set.
func installFilters(
filterDefinitions map[string]FilterInstaller, force bool,
dataPath, dotRegolithPath string, isInstall, refreshFilters bool,
filtersToInstall map[string]FilterInstaller, force bool,
dataPath, dotRegolithPath string, refreshFilters bool,
) error {
joinedPath := filepath.Join(dotRegolithPath, "cache/filters")
err := os.MkdirAll(joinedPath, 0755)
Expand All @@ -43,16 +44,14 @@ func installFilters(
}

// Download all the remote filters
for name, filterDefinition := range filterDefinitions {
for name, filterDefinition := range filtersToInstall {
Logger.Infof("Downloading %q filter...", name)
if remoteFilter, ok := filterDefinition.(*RemoteFilterDefinition); ok {
// Download the remote filter, and its dependencies
err := remoteFilter.Update(force, dotRegolithPath, isInstall, refreshFilters)
err := remoteFilter.Update(force, dotRegolithPath, dataPath, refreshFilters)
if err != nil {
return burrito.WrapErrorf(err, remoteFilterDownloadError, name)
}
// Copy the data of the remote filter to the data path
remoteFilter.CopyFilterData(dataPath, dotRegolithPath)
} else {
// Non-remote filters must always update their dependencies.
// TODO - add option to track if the filter already installed
Expand All @@ -70,6 +69,51 @@ func installFilters(
return nil
}

// addFiltersToConfig modifies the config by adding the specified filters
// to the list of the filters in the project. If the profiles list is not
// empty, it also adds the filters to the specified profiles. After modifying
// the config, it saves it to the standard config file location.
func addFiltersToConfig(
config map[string]interface{},
filterInstallers map[string]FilterInstaller,
profiles []string,
) error {
filterDefinitions, err := filterDefinitionsFromConfigMap(config)
if err != nil {
return burrito.WrapError(
err,
"Failed to get the list of filter definitions from config file.")
}
// Add the filters to the config
for name, downloadedFilter := range filterInstallers {
// Add the filter to config file
filterDefinitions[name] = downloadedFilter
// Add the filter to the profile
for _, profile := range profiles {
profileMap, err := FindByJSONPath[map[string]interface{}](config, "regolith/profiles/"+EscapePathPart(profile))
if err != nil {
return burrito.WrapErrorf(
err, "Profile %s does not exist or is invalid.", profile)
}
if profileMap["filters"] == nil {
profileMap["filters"] = make([]interface{}, 0)
}
// Add the filter to the profile
profileMap["filters"] = append(
profileMap["filters"].([]interface{}), map[string]interface{}{
"filter": name,
})
}
}
// Save the config file
jsonBytes, _ := json.MarshalIndent(config, "", "\t")
err = os.WriteFile(ConfigFilePath, jsonBytes, 0644)
if err != nil {
return burrito.WrapErrorf(err, fileWriteError, ConfigFilePath)
}
return nil
}

// parseInstallFilterArgs parses a list of arguments of the
// "regolith install" command and returns a list of download tasks.
func parseInstallFilterArgs(
Expand Down
Loading
Loading