mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +00:00
refactor: let updaters define the files they want to run on (#233)
This change reverses the responsibility for which files the updaters are run on. Now each updater can specify the list of files and wether the files should be created when they do not exist yet. This simplifies the handling of each update in releaserpleaser.go, as we can just iterate over all updaters and call it for each file of that updater. Also update the flags to allow users to easily define which updaters should run.
This commit is contained in:
parent
1e9e0aa5d9
commit
f1aa1a2ef4
20 changed files with 307 additions and 151 deletions
|
|
@ -6,11 +6,22 @@ import (
|
|||
)
|
||||
|
||||
// PackageJson creates an updater that modifies the version field in package.json files
|
||||
func PackageJson(info ReleaseInfo) Updater {
|
||||
return func(content string, filename string) (string, error) {
|
||||
if filename != "package.json" {
|
||||
return content, nil // No update needed for non-package.json files
|
||||
}
|
||||
func PackageJson() Updater {
|
||||
return packagejson{}
|
||||
}
|
||||
|
||||
type packagejson struct{}
|
||||
|
||||
func (p packagejson) Files() []string {
|
||||
return []string{"package.json"}
|
||||
}
|
||||
|
||||
func (p packagejson) CreateNewFiles() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p packagejson) Update(info ReleaseInfo) func(content string) (string, error) {
|
||||
return func(content string) (string, error) {
|
||||
// We strip the "v" prefix to match npm versioning convention
|
||||
version := strings.TrimPrefix(info.Version, "v")
|
||||
|
||||
|
|
@ -23,8 +34,6 @@ func PackageJson(info ReleaseInfo) Updater {
|
|||
}
|
||||
|
||||
// Replace the version value while preserving the original formatting
|
||||
updatedContent := versionRegex.ReplaceAllString(content, `${1}"`+version+`"`)
|
||||
|
||||
return updatedContent, nil
|
||||
return versionRegex.ReplaceAllString(content, `${1}"`+version+`"`), nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue