-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modular-station): Expose simpler global hooks API (#124)
Co-authored-by: Florian Lefebvre <[email protected]>
- Loading branch information
1 parent
1ba729c
commit fe6f703
Showing
9 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@inox-tools/content-utils': patch | ||
--- | ||
|
||
Simplify internal hook wiring using Modular Station's global hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@inox-tools/modular-station': patch | ||
--- | ||
|
||
Add a global hook API for custom hooks without using an AIK plugin. | ||
|
||
This allows for simpler and more intuitive implementations of hooks outside of main lifecycle in the implementations of official Astro hooks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { AstroIntegration, AstroIntegrationLogger } from 'astro'; | ||
import { runHook, type PluginApi } from './hooks.js'; | ||
|
||
let logger: AstroIntegrationLogger; | ||
let integrations: AstroIntegration[]; | ||
|
||
export const setGlobal = ( | ||
newLogger: AstroIntegrationLogger, | ||
newIntegrations: AstroIntegration[] | ||
) => { | ||
logger = newLogger; | ||
integrations = newIntegrations; | ||
}; | ||
|
||
export const hooks: PluginApi['hooks'] = { | ||
run: (hook, params) => { | ||
if (logger === undefined || integrations === undefined || integrations.length === 0) { | ||
return Promise.reject(new Error('Cannot run hook at this point')); | ||
} | ||
return runHook(integrations, logger, hook, params); | ||
}, | ||
getTrigger: (hook) => (params) => { | ||
if (logger === undefined || integrations === undefined || integrations.length === 0) { | ||
return Promise.resolve(); | ||
} | ||
return runHook(integrations, logger, hook, params); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters