-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sedge): initial plugin prototype (#9)
- Loading branch information
Showing
6 changed files
with
72 additions
and
231 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './config' | ||
export { definePlugin } from './plugin' | ||
export * from './sedge' |
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,30 @@ | ||
import { createHooks } from 'hookable' | ||
|
||
interface PluginHooks { | ||
/** | ||
* Runs once before the compiler starts. | ||
*/ | ||
buildStart?(): Promise<void> | void | ||
|
||
/** | ||
* Transforms a compiled file. | ||
* @param path The path of the original file. | ||
* @param content The content of the compiled file. | ||
*/ | ||
transformFile?(path: string, content: any): Promise<any> | any | ||
} | ||
|
||
export const pluginHooks = createHooks<Required<PluginHooks>>() | ||
|
||
export function definePlugin(hooks: PluginHooks) { | ||
if (Object.keys(hooks).length === 0) { | ||
throw new Error('At least one hook is required in `definePlugin`') | ||
} | ||
|
||
if (hooks.buildStart) { | ||
pluginHooks.hookOnce('buildStart', hooks.buildStart) | ||
} | ||
if (hooks.transformFile) { | ||
pluginHooks.hook('transformFile', hooks.transformFile) | ||
} | ||
} |
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
Oops, something went wrong.