2022-04-14 01:27:39 +00:00
|
|
|
package cli
|
|
|
|
|
2023-12-07 16:57:31 +00:00
|
|
|
type LockfileVersion int
|
|
|
|
|
|
|
|
const (
|
|
|
|
InitialLockfileVersion = LockfileVersion(iota)
|
|
|
|
|
|
|
|
ModTargetsLockfileVersion
|
|
|
|
|
|
|
|
// Always last
|
|
|
|
nextLockfileVersion
|
|
|
|
CurrentLockfileVersion = nextLockfileVersion - 1
|
|
|
|
)
|
|
|
|
|
|
|
|
type LockFile struct {
|
|
|
|
Mods map[string]LockedMod `json:"mods"`
|
|
|
|
Version LockfileVersion `json:"version"`
|
|
|
|
}
|
2022-04-14 01:27:39 +00:00
|
|
|
|
|
|
|
type LockedMod struct {
|
2023-12-07 16:57:31 +00:00
|
|
|
Dependencies map[string]string `json:"dependencies"`
|
|
|
|
Targets map[string]LockedModTarget `json:"targets"`
|
|
|
|
Version string `json:"version"`
|
2022-04-14 01:27:39 +00:00
|
|
|
}
|
2022-05-02 20:07:15 +00:00
|
|
|
|
2023-12-07 16:57:31 +00:00
|
|
|
type LockedModTarget struct {
|
|
|
|
Hash string `json:"hash"`
|
|
|
|
Link string `json:"link"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeLockfile() *LockFile {
|
|
|
|
return &LockFile{
|
|
|
|
Mods: make(map[string]LockedMod),
|
|
|
|
Version: CurrentLockfileVersion,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *LockFile) Clone() *LockFile {
|
|
|
|
lockFile := &LockFile{
|
|
|
|
Mods: make(map[string]LockedMod),
|
|
|
|
Version: l.Version,
|
|
|
|
}
|
|
|
|
for k, v := range l.Mods {
|
|
|
|
lockFile.Mods[k] = v
|
2022-05-02 20:07:15 +00:00
|
|
|
}
|
|
|
|
return lockFile
|
|
|
|
}
|
2023-12-06 19:37:33 +00:00
|
|
|
|
|
|
|
func (l *LockFile) Remove(modID ...string) *LockFile {
|
|
|
|
for _, s := range modID {
|
2023-12-07 16:57:31 +00:00
|
|
|
delete(l.Mods, s)
|
2023-12-06 19:37:33 +00:00
|
|
|
}
|
2023-12-07 16:57:31 +00:00
|
|
|
return l
|
2023-12-06 19:37:33 +00:00
|
|
|
}
|