Skip to content

Commit ed8bb81

Browse files
authored
Merge pull request #288 from Bedrock-OSS/develop
2 parents b0d6f09 + 46d6238 commit ed8bb81

File tree

9 files changed

+221
-136
lines changed

9 files changed

+221
-136
lines changed

docs/docs/guide/getting-started.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ Now, you can re-run `regolith run`.
131131

132132
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!
133133

134-
{: .notice--warning}
134+
:::: warning
135135
`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!
136+
::::
136137

137-
{: .notice--warning}
138+
:::: warning
138139
`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!
140+
::::
139141

140142
## Whats Next
141143

docs/docs/guide/installing-filters.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ Regolith is intended to be used with git version control, and by default the `.r
6565

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

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

7172
## Filter Versioning
7273

7374
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.
7475

75-
{: .notice--warning}
76+
:::: warning
7677
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`.
78+
::::
7779

7880
### Installing a Specific Version
7981

@@ -102,6 +104,12 @@ regolith install name_ninja --update
102104

103105
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.
104106

107+
If you want to update all filters in your project, you can use the `--update` flag with the `install-all` command.
108+
109+
```
110+
regolith install-all --update
111+
```
112+
105113
### Updating resolvers
106114

107115
When using short names for filters, Regolith uses a resolver file from a remote repository to determine the URL of the filter.

main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func main() {
221221
&force, "force", "f", false, "Force the operation, overriding potential safeguards.")
222222
subcommands = append(subcommands, cmdInit)
223223

224-
profiles := []string{"default"}
224+
profiles := []string{}
225225
// regolith install
226226
var update, resolverRefresh, filterRefresh bool
227227
cmdInstall := &cobra.Command{
@@ -233,7 +233,10 @@ func main() {
233233
cmd.Help()
234234
return
235235
}
236-
err = regolith.Install(filters, force || update, resolverRefresh, filterRefresh, cmd.Flags().Lookup("profile").Changed, profiles, burrito.PrintStackTrace)
236+
if cmd.Flags().Lookup("profile").Changed && len(profiles) == 0 {
237+
profiles = append(profiles, "default")
238+
}
239+
err = regolith.Install(filters, force || update, resolverRefresh, filterRefresh, profiles, burrito.PrintStackTrace)
237240
},
238241
}
239242
cmdInstall.Flags().BoolVarP(
@@ -254,11 +257,13 @@ func main() {
254257
Short: "Installs all nonexistent or outdated filters defined in filterDefinitions list",
255258
Long: regolithInstallAllDesc,
256259
Run: func(cmd *cobra.Command, _ []string) {
257-
err = regolith.InstallAll(force, burrito.PrintStackTrace, filterRefresh)
260+
err = regolith.InstallAll(force, update, burrito.PrintStackTrace, filterRefresh)
258261
},
259262
}
260263
cmdInstallAll.Flags().BoolVarP(
261264
&force, "force", "f", false, "Force the operation, overriding potential safeguards.")
265+
cmdInstallAll.Flags().BoolVarP(
266+
&update, "update", "u", false, "Updates the remote filters to the latest stable version available.")
262267
cmdInstallAll.Flags().BoolVar(
263268
&filterRefresh, "force-filter-refresh", false, "Force filter cache refresh.")
264269
subcommands = append(subcommands, cmdInstallAll)

regolith/filter.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,7 @@ func (c *RunContext) StartWatchingSourceFiles() error {
5757
if c.interruptionChannel != nil {
5858
return burrito.WrappedError("Files are already being watched.")
5959
}
60-
rpWatcher, err := NewDirWatcher(c.Config.ResourceFolder)
61-
if err != nil {
62-
return burrito.WrapError(err, "Could not create resource pack watcher.")
63-
}
64-
bpWatcher, err := NewDirWatcher(c.Config.BehaviorFolder)
65-
if err != nil {
66-
return burrito.WrapError(err, "Could not create behavior pack watcher.")
67-
}
68-
dataWatcher, err := NewDirWatcher(c.Config.DataPath)
69-
if err != nil {
70-
return burrito.WrapError(err, "Could not create data watcher.")
71-
}
60+
7261
c.interruptionChannel = make(chan string)
7362
yieldChanges := func(
7463
watcher *DirWatcher, sourceName string,
@@ -81,16 +70,36 @@ func (c *RunContext) StartWatchingSourceFiles() error {
8170
}
8271
}
8372
}
84-
go yieldChanges(rpWatcher, "rp")
85-
go yieldChanges(bpWatcher, "bp")
86-
go yieldChanges(dataWatcher, "data")
87-
return nil
88-
}
8973

90-
// AwaitInterruption locks the goroutine with the interruption channel until
91-
// the Config is interrupted and returns the interruption message.
92-
func (c *RunContext) AwaitInterruption() string {
93-
return <-c.interruptionChannel
74+
addWatcher := func(watchedPath, watcherString string) error {
75+
watcher, err := NewDirWatcher(watchedPath)
76+
if err != nil {
77+
return burrito.PassError(err)
78+
}
79+
go yieldChanges(watcher, watcherString)
80+
return nil
81+
}
82+
83+
var err error
84+
if c.Config.ResourceFolder != "" {
85+
err = addWatcher(c.Config.ResourceFolder, "rp")
86+
if err != nil {
87+
return burrito.WrapError(err, "Could not create resource pack watcher.")
88+
}
89+
}
90+
if c.Config.BehaviorFolder != "" {
91+
err = addWatcher(c.Config.BehaviorFolder, "bp")
92+
if err != nil {
93+
return burrito.WrapError(err, "Could not create behavior pack watcher.")
94+
}
95+
}
96+
if c.Config.DataPath != "" {
97+
err = addWatcher(c.Config.DataPath, "data")
98+
if err != nil {
99+
return burrito.WrapError(err, "Could not create data watcher.")
100+
}
101+
}
102+
return nil
94103
}
95104

96105
// IsInterrupted returns true if there is a message on the interruptionChannel

regolith/filter_remote.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ func FilterDefinitionFromTheInternet(
342342
if version == "" { // "" locks the version to the latest
343343
version, err = GetRemoteFilterDownloadRef(url, name, version)
344344
if err != nil {
345-
return nil, burrito.WrappedErrorf(
346-
getRemoteFilterDownloadRefError, url, name, version)
345+
return nil, burrito.WrapErrorf(
346+
err, getRemoteFilterDownloadRefError, url, name, version)
347347
}
348348
version = trimFilterPrefix(version, name)
349349
}
@@ -547,10 +547,10 @@ func (f *RemoteFilterDefinition) InstalledVersion(dotRegolithPath string) (strin
547547
return versionStr, nil
548548
}
549549

550-
func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath string, isInstall, refreshFilters bool) error {
550+
func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath, dataPath string, refreshFilters bool) error {
551551
installedVersion, err := f.InstalledVersion(dotRegolithPath)
552552
installedVersion = trimFilterPrefix(installedVersion, f.Id)
553-
if err != nil && (!isInstall || force) {
553+
if err != nil && force {
554554
Logger.Warnf("Unable to get installed version of filter %q.", f.Id)
555555
}
556556
MeasureStart("Get remote filter download ref")
@@ -569,6 +569,8 @@ func (f *RemoteFilterDefinition) Update(force bool, dotRegolithPath string, isIn
569569
if err != nil {
570570
return burrito.PassError(err)
571571
}
572+
// Copy the data of the remote filter to the data path
573+
f.CopyFilterData(dataPath, dotRegolithPath)
572574
err = f.InstallDependencies(f, dotRegolithPath)
573575
if err != nil {
574576
return burrito.PassError(err)

regolith/install_add.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package regolith
22

33
import (
4+
"encoding/json"
45
"os"
56
"os/exec"
67
"path/filepath"
@@ -28,8 +29,8 @@ type parsedInstallFilterArg struct {
2829
// and copies their data to the data path. If the filter is already installed,
2930
// it returns an error unless the force flag is set.
3031
func installFilters(
31-
filterDefinitions map[string]FilterInstaller, force bool,
32-
dataPath, dotRegolithPath string, isInstall, refreshFilters bool,
32+
filtersToInstall map[string]FilterInstaller, force bool,
33+
dataPath, dotRegolithPath string, refreshFilters bool,
3334
) error {
3435
joinedPath := filepath.Join(dotRegolithPath, "cache/filters")
3536
err := os.MkdirAll(joinedPath, 0755)
@@ -43,16 +44,14 @@ func installFilters(
4344
}
4445

4546
// Download all the remote filters
46-
for name, filterDefinition := range filterDefinitions {
47+
for name, filterDefinition := range filtersToInstall {
4748
Logger.Infof("Downloading %q filter...", name)
4849
if remoteFilter, ok := filterDefinition.(*RemoteFilterDefinition); ok {
4950
// Download the remote filter, and its dependencies
50-
err := remoteFilter.Update(force, dotRegolithPath, isInstall, refreshFilters)
51+
err := remoteFilter.Update(force, dotRegolithPath, dataPath, refreshFilters)
5152
if err != nil {
5253
return burrito.WrapErrorf(err, remoteFilterDownloadError, name)
5354
}
54-
// Copy the data of the remote filter to the data path
55-
remoteFilter.CopyFilterData(dataPath, dotRegolithPath)
5655
} else {
5756
// Non-remote filters must always update their dependencies.
5857
// TODO - add option to track if the filter already installed
@@ -70,6 +69,51 @@ func installFilters(
7069
return nil
7170
}
7271

72+
// addFiltersToConfig modifies the config by adding the specified filters
73+
// to the list of the filters in the project. If the profiles list is not
74+
// empty, it also adds the filters to the specified profiles. After modifying
75+
// the config, it saves it to the standard config file location.
76+
func addFiltersToConfig(
77+
config map[string]interface{},
78+
filterInstallers map[string]FilterInstaller,
79+
profiles []string,
80+
) error {
81+
filterDefinitions, err := filterDefinitionsFromConfigMap(config)
82+
if err != nil {
83+
return burrito.WrapError(
84+
err,
85+
"Failed to get the list of filter definitions from config file.")
86+
}
87+
// Add the filters to the config
88+
for name, downloadedFilter := range filterInstallers {
89+
// Add the filter to config file
90+
filterDefinitions[name] = downloadedFilter
91+
// Add the filter to the profile
92+
for _, profile := range profiles {
93+
profileMap, err := FindByJSONPath[map[string]interface{}](config, "regolith/profiles/"+EscapePathPart(profile))
94+
if err != nil {
95+
return burrito.WrapErrorf(
96+
err, "Profile %s does not exist or is invalid.", profile)
97+
}
98+
if profileMap["filters"] == nil {
99+
profileMap["filters"] = make([]interface{}, 0)
100+
}
101+
// Add the filter to the profile
102+
profileMap["filters"] = append(
103+
profileMap["filters"].([]interface{}), map[string]interface{}{
104+
"filter": name,
105+
})
106+
}
107+
}
108+
// Save the config file
109+
jsonBytes, _ := json.MarshalIndent(config, "", "\t")
110+
err = os.WriteFile(ConfigFilePath, jsonBytes, 0644)
111+
if err != nil {
112+
return burrito.WrapErrorf(err, fileWriteError, ConfigFilePath)
113+
}
114+
return nil
115+
}
116+
73117
// parseInstallFilterArgs parses a list of arguments of the
74118
// "regolith install" command and returns a list of download tasks.
75119
func parseInstallFilterArgs(

0 commit comments

Comments
 (0)