-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docz-core): add basic plugin logic
- Loading branch information
1 parent
5ec9fde
commit add17ad
Showing
8 changed files
with
188 additions
and
35 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,3 +1,48 @@ | ||
export function createPlugin<Config = any, Server = any>() { | ||
return null | ||
import { isFn } from './utils/helpers' | ||
|
||
export type IBundlerConfig = <Config>(config: Config, dev: boolean) => Config | ||
export type IBundlerCompiler = <Compiler>(compiler: Compiler) => void | ||
export type IBundlerServer = <Server>(server: Server) => void | ||
export type IBeforeRender = () => void | ||
export type IAfterRender = () => void | ||
export type IWrapper = <R>(props: { children: any }) => R | ||
|
||
export interface IPluginFactory { | ||
bundlerConfig: IBundlerConfig | ||
bundlerCompiler: IBundlerCompiler | ||
bundlerServer: IBundlerServer | ||
beforeRender: IBeforeRender | ||
afterRender: IAfterRender | ||
wrapper: IWrapper | ||
} | ||
|
||
export class Plugin { | ||
readonly bundlerConfig: IBundlerConfig | ||
readonly bundlerCompiler: IBundlerCompiler | ||
readonly bundlerServer: IBundlerServer | ||
readonly beforeRender: IBeforeRender | ||
readonly afterRender: IAfterRender | ||
readonly wrapper: IWrapper | ||
|
||
constructor(p: IPluginFactory) { | ||
this.bundlerConfig = (config: any, dev: boolean) => { | ||
return isFn(p.bundlerConfig) && p.bundlerConfig(config, dev) | ||
} | ||
|
||
this.bundlerCompiler = async (compiler: any) => { | ||
isFn(p.bundlerCompiler) && (await p.bundlerCompiler(compiler)) | ||
} | ||
|
||
this.bundlerServer = async (server: any) => { | ||
isFn(p.bundlerServer) && (await p.bundlerServer(server)) | ||
} | ||
|
||
this.beforeRender = p.beforeRender | ||
this.afterRender = p.afterRender | ||
this.wrapper = p.wrapper | ||
} | ||
} | ||
|
||
export function createPlugin(factory: IPluginFactory) { | ||
return new Plugin(factory) | ||
} |
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,7 +1,24 @@ | ||
<% entries.forEach(function(entry) { %>import '<%- entry.filepath %>' | ||
<% ENTRIES.forEach(function(entry) { %>import '<%- entry.filepath %>' | ||
<% }); %> | ||
import React from 'react' | ||
import { hot } from 'react-hot-loader' | ||
import { Theme } from '<%- theme %>' | ||
import { Theme } from '<%- THEME %>' | ||
|
||
export const App = hot(module)(Theme) | ||
const _wrappers = [<%- WRAPPERS %>] | ||
|
||
const recursiveWrappers = ([Wrapper, ...rest], props) => ( | ||
<Wrapper {...props}> | ||
{rest.length ? recursiveWrappers(rest, props) : props.children} | ||
</Wrapper> | ||
) | ||
|
||
const Wrapper = props => | ||
_wrappers.length ? recursiveWrappers(_wrappers, props) : props.children | ||
|
||
const WrappedTheme = () => ( | ||
<Wrapper> | ||
<Theme routes={<%- ROUTES %>} /> | ||
</Wrapper> | ||
) | ||
|
||
export const App = hot(module)(WrappedTheme) |
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