Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
✨ add ability to add needed ngModule imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrixer committed Jun 7, 2017
1 parent 86e691a commit f11547a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/boostrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function bootstrap(sandBox: UIGuideSandbox): Promise<NgModuleRef<UIGuideM
/** grab all the ui guides */
const uiGuides = sandBox.loadUIGuides()
/** resolve all the ui guide components and ng module */
const resolved = getModuleForUIGuides(sandBox.ngModule, uiGuides)
const resolved = getModuleForUIGuides(sandBox.ngModule, uiGuides, sandBox.ngModuleImports)
/** this is the markdown used in your index page */
const entryMarkdown = sandBox.entryMarkdown

Expand Down
16 changes: 8 additions & 8 deletions src/generate-hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { UIGuide, ResolvedUIGuideSandbox, UIGuideExample } from './interfaces'
const flatten = require('lodash.flatten')

export function getModuleForUIGuides(
givenModule: ModuleWithProviders | Type<any>,
uiGuides: UIGuide[]
givenModule: Type<any>,
uiGuides: UIGuide[],
ngModuleImports: Type<any>[] = []
): ResolvedUIGuideSandbox {

const componentsWithIds: {id: string, component: Type<any>}[] = flatten(uiGuides.map((uiGuide => uiGuide.examples.map((ex => {
Expand All @@ -22,7 +23,8 @@ export function getModuleForUIGuides(
})
}, {})

const ngModule = generateNgModule(givenModule, componentsWithIds.map(e => e.component))
ngModuleImports.push(givenModule)
const ngModule = generateNgModule(ngModuleImports, componentsWithIds.map(e => e.component))
return {ngModule, components}
}

Expand All @@ -32,7 +34,7 @@ export function generateComponent(
@Component({
template: example.template,
styles: example.styles,
providers: [...example.providers]
providers: example.providers || []
})
class UIGuideExampleComponent {
constructor() {
Expand All @@ -44,13 +46,11 @@ export function generateComponent(
}

export function generateNgModule(
givenModule: ModuleWithProviders | Type<any>,
givenModules: Type<any>[],
components: Type<any>[]
): Type<any> {
@NgModule({
imports: [
givenModule
],
imports: givenModules,
declarations: [
...components
],
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface CompiledUIGuide {
}

export interface UIGuideSandbox {
module?: NodeModule
entryMarkdown: string
ngModule: Type<any> | ModuleWithProviders
ngModule: Type<any>
ngModuleImports?: Type<any>[]
loadUIGuides(): UIGuide[]
};

Expand Down

0 comments on commit f11547a

Please sign in to comment.