Skip to content

Commit

Permalink
feat: onReady plugin hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Feb 12, 2025
1 parent 1dac8dc commit d929eb7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-walls-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-cms/core": patch
"kopflos": patch
---

New plugin hook: `onReady`
1 change: 1 addition & 0 deletions packages/cli/lib/command/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function run({

const server = app.listen(port, host, () => {
log.info(`Server running on ${port}. API URL: ${config.baseIri}`)
instance.ready()
})

if (config.watch) {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/lib/Kopflos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface PluginConfig {
export interface KopflosPlugin {
readonly name?: string
onStart?(): Promise<void> | void
onReady?(): Promise<void> | void
onStop?(): Promise<void> | void
apiTriples?(): Promise<DatasetCore | Stream> | DatasetCore | Stream
}
Expand Down Expand Up @@ -121,6 +122,7 @@ export default class Impl implements Kopflos {
readonly env: KopflosEnvironment
readonly plugins: Array<KopflosPlugin>
readonly start: () => Promise<void>
readonly ready: () => Promise<void>

constructor({ variables = {}, ...config }: KopflosConfig, private readonly options: Options = {}) {
this.env = createEnv({ variables, ...config })
Expand Down Expand Up @@ -148,6 +150,10 @@ export default class Impl implements Kopflos {
this.start = onetime(async function (this: Impl) {
await Promise.all(this.plugins.map(plugin => plugin.onStart?.()))
}).bind(this)

this.ready = onetime(async function (this: Impl) {
await Promise.all(this.plugins.map(plugin => plugin.onReady?.()))

Check warning on line 155 in packages/core/lib/Kopflos.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/lib/Kopflos.ts#L155

Added line #L155 was not covered by tests
}).bind(this)
}

get graph() {
Expand Down

0 comments on commit d929eb7

Please sign in to comment.