mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 02:07:04 +00:00
feat: add updater for package.json
This commit is contained in:
parent
942aa80aa9
commit
ecbd148e7a
14 changed files with 174 additions and 44 deletions
30
internal/updater/packagejson.go
Normal file
30
internal/updater/packagejson.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
// We strip the "v" prefix to match npm versioning convention
|
||||
version := strings.TrimPrefix(info.Version, "v")
|
||||
|
||||
// Regex to match "version": "..." with flexible whitespace and quote styles
|
||||
versionRegex := regexp.MustCompile(`("version"\s*:\s*)"[^"]*"`)
|
||||
|
||||
// Check if the file contains a version field
|
||||
if !versionRegex.MatchString(content) {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// Replace the version value while preserving the original formatting
|
||||
updatedContent := versionRegex.ReplaceAllString(content, `${1}"`+version+`"`)
|
||||
|
||||
return updatedContent, nil
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue