|
@@ -32,23 +32,23 @@ type FieldInfo struct {
|
|
|
const tsConfigTemplate = `// This file is auto-generated by notification generator. DO NOT EDIT.
|
|
|
import type { ExternalNotifyConfig } from './types'
|
|
|
|
|
|
-const {{.Name}}Config: ExternalNotifyConfig = {
|
|
|
+const {{.Name | replaceSpaces}}Config: ExternalNotifyConfig = {
|
|
|
name: () => $gettext('{{.Name}}'),
|
|
|
config: [
|
|
|
{{- range .Fields}}
|
|
|
{
|
|
|
key: '{{.Key}}',
|
|
|
- label: () => $gettext('{{.Title}}'),
|
|
|
+ label: '{{.Title}}',
|
|
|
},
|
|
|
{{- end}}
|
|
|
],
|
|
|
}
|
|
|
|
|
|
-export default {{.Name}}Config
|
|
|
+export default {{.Name | replaceSpaces}}Config
|
|
|
`
|
|
|
|
|
|
// Regular expression to extract @external_notifier annotation
|
|
|
-var externalNotifierRegex = regexp.MustCompile(`@external_notifier\((\w+)\)`)
|
|
|
+var externalNotifierRegex = regexp.MustCompile(`@external_notifier\(([a-zA-Z0-9 _]+)\)`)
|
|
|
|
|
|
func main() {
|
|
|
if err := GenerateExternalNotifiers(); err != nil {
|
|
@@ -142,7 +142,7 @@ func extractNotifierInfo(filePath string) (NotifierInfo, bool) {
|
|
|
if len(matches) > 1 {
|
|
|
notifierInfo.Name = matches[1]
|
|
|
notifierInfo.ConfigKey = strings.ToLower(typeSpec.Name.Name)
|
|
|
- notifierInfo.FileName = strings.ToLower(matches[1])
|
|
|
+ notifierInfo.FileName = strings.ToLower(strings.ReplaceAll(matches[1], " ", "_"))
|
|
|
found = true
|
|
|
|
|
|
// Extract fields
|
|
@@ -205,8 +205,15 @@ func extractNotifierInfo(filePath string) (NotifierInfo, bool) {
|
|
|
|
|
|
// Generate TypeScript config file for a notifier
|
|
|
func generateTSConfig(notifier NotifierInfo, outputDir string) error {
|
|
|
- // Create template
|
|
|
- tmpl, err := template.New("tsConfig").Parse(tsConfigTemplate)
|
|
|
+ // Create function map for template
|
|
|
+ funcMap := template.FuncMap{
|
|
|
+ "replaceSpaces": func(s string) string {
|
|
|
+ return strings.ReplaceAll(s, " ", "")
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create template with function map
|
|
|
+ tmpl, err := template.New("tsConfig").Funcs(funcMap).Parse(tsConfigTemplate)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("error creating template: %w", err)
|
|
|
}
|
|
@@ -242,7 +249,7 @@ func updateIndexFile(notifiers []NotifierInfo, outputDir string) error {
|
|
|
|
|
|
for _, notifier := range notifiers {
|
|
|
fileName := notifier.FileName
|
|
|
- configName := notifier.Name + "Config"
|
|
|
+ configName := strings.ReplaceAll(notifier.Name, " ", "") + "Config"
|
|
|
|
|
|
imports.WriteString(fmt.Sprintf("import %s from './%s'\n", configName, fileName))
|
|
|
}
|
|
@@ -250,7 +257,8 @@ func updateIndexFile(notifiers []NotifierInfo, outputDir string) error {
|
|
|
// Generate the map
|
|
|
configMap.WriteString("const configMap = {\n")
|
|
|
for _, notifier := range notifiers {
|
|
|
- configMap.WriteString(fmt.Sprintf(" %s: %sConfig", strings.ToLower(notifier.Name), notifier.Name))
|
|
|
+ configKey := strings.ToLower(strings.ReplaceAll(notifier.Name, " ", "_"))
|
|
|
+ configMap.WriteString(fmt.Sprintf(" %s: %sConfig", configKey, strings.ReplaceAll(notifier.Name, " ", "")))
|
|
|
configMap.WriteString(",\n")
|
|
|
}
|
|
|
configMap.WriteString("}\n")
|