Add mage commands to generate new notifications
This commit is contained in:
parent
07bf0a7bd4
commit
fdb60d3a5d
58
magefile.go
58
magefile.go
|
@ -61,15 +61,16 @@ var (
|
|||
|
||||
// Aliases are mage aliases of targets
|
||||
Aliases = map[string]interface{}{
|
||||
"build": Build.Build,
|
||||
"do-the-swag": DoTheSwag,
|
||||
"check:got-swag": Check.GotSwag,
|
||||
"release:os-package": Release.OsPackage,
|
||||
"dev:make-migration": Dev.MakeMigration,
|
||||
"dev:make-event": Dev.MakeEvent,
|
||||
"dev:make-listener": Dev.MakeListener,
|
||||
"generate-docs": GenerateDocs,
|
||||
"check:golangci-fix": Check.GolangciFix,
|
||||
"build": Build.Build,
|
||||
"do-the-swag": DoTheSwag,
|
||||
"check:got-swag": Check.GotSwag,
|
||||
"release:os-package": Release.OsPackage,
|
||||
"dev:make-migration": Dev.MakeMigration,
|
||||
"dev:make-event": Dev.MakeEvent,
|
||||
"dev:make-listener": Dev.MakeListener,
|
||||
"dev:make-notification": Dev.MakeNotification,
|
||||
"generate-docs": GenerateDocs,
|
||||
"check:golangci-fix": Check.GolangciFix,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -894,6 +895,45 @@ func (s *` + name + `) Handle(payload message.Payload) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Create a new notification. Takes the name of the notification as the first argument and the module where the notification should be created as the second argument. Notifications will be appended to the pkg/<module>/notifications.go file.
|
||||
func (Dev) MakeNotification(name, module string) error {
|
||||
|
||||
name = strcase.ToCamel(name)
|
||||
|
||||
if !strings.HasSuffix(name, "Notification") {
|
||||
name += "Notification"
|
||||
}
|
||||
|
||||
newNotificationCode := `
|
||||
// ` + name + ` represents a ` + name + ` notification
|
||||
type ` + name + ` struct {
|
||||
}
|
||||
|
||||
// ToMail returns the mail notification for ` + name + `
|
||||
func (t *` + name + `) ToMail() *notifications.Mail {
|
||||
return notifications.NewMail().
|
||||
To().
|
||||
Subject("").
|
||||
Greeting("Hi ").
|
||||
Line("").
|
||||
Action("", "")
|
||||
}
|
||||
|
||||
// ToDB returns the ` + name + ` notification in a format which can be saved in the db
|
||||
func (t *` + name + `) ToDB() interface{} {
|
||||
return nil
|
||||
}
|
||||
`
|
||||
filename := "./pkg/" + module + "/notifications.go"
|
||||
if err := appendToFile(filename, newNotificationCode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printSuccess("The new notification has been created successfully! Head over to %s and adjust its content.", filename)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type configOption struct {
|
||||
key string
|
||||
description string
|
||||
|
|
Loading…
Reference in New Issue