Register registers the jsvm plugin in the provided app instance.
(app core.App, config Config)
| 126 | |
| 127 | // Register registers the jsvm plugin in the provided app instance. |
| 128 | func Register(app core.App, config Config) error { |
| 129 | p := &plugin{app: app, config: config} |
| 130 | |
| 131 | if p.config.HooksDir == "" { |
| 132 | p.config.HooksDir = filepath.Join(app.DataDir(), "../pb_hooks") |
| 133 | } |
| 134 | |
| 135 | if p.config.MigrationsDir == "" { |
| 136 | p.config.MigrationsDir = filepath.Join(app.DataDir(), "../pb_migrations") |
| 137 | } |
| 138 | |
| 139 | if p.config.HooksFilesPattern == "" { |
| 140 | p.config.HooksFilesPattern = `^.*(\.pb\.js|\.pb\.ts)$` |
| 141 | } |
| 142 | |
| 143 | if p.config.MigrationsFilesPattern == "" { |
| 144 | p.config.MigrationsFilesPattern = `^.*(\.js|\.ts)$` |
| 145 | } |
| 146 | |
| 147 | if p.config.TypesDir == "" { |
| 148 | p.config.TypesDir = app.DataDir() |
| 149 | } |
| 150 | |
| 151 | p.app.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error { |
| 152 | err := e.Next() |
| 153 | if err != nil { |
| 154 | return err |
| 155 | } |
| 156 | |
| 157 | // ensure that the user has the latest types declaration |
| 158 | err = p.refreshTypesFile() |
| 159 | if err != nil { |
| 160 | color.Yellow("Unable to refresh app types file: %v", err) |
| 161 | } |
| 162 | |
| 163 | return nil |
| 164 | }) |
| 165 | |
| 166 | if err := p.registerMigrations(); err != nil { |
| 167 | return fmt.Errorf("registerMigrations: %w", err) |
| 168 | } |
| 169 | |
| 170 | if err := p.registerHooks(); err != nil { |
| 171 | return fmt.Errorf("registerHooks: %w", err) |
| 172 | } |
| 173 | |
| 174 | return nil |
| 175 | } |
| 176 | |
| 177 | type plugin struct { |
| 178 | app core.App |
no test coverage detected
searching dependent graphs…