-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui-devkit): Support module path mappings for UI extensions #1994
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,11 +113,99 @@ export interface AdminUiExtension | |
* scss style sheets etc. | ||
*/ | ||
extensionPath: string; | ||
|
||
/** | ||
* @description | ||
* One or more Angular modules which extend the default Admin UI. | ||
*/ | ||
ngModules: Array<AdminUiExtensionSharedModule | AdminUiExtensionLazyModule>; | ||
|
||
/** | ||
* @description | ||
* An optional alias for the module so it can be referenced by other UI extension modules. | ||
* | ||
* By default, Angular modules declared in an AdminUiExtension do not have access to code outside the directory | ||
* defined by the `extensionPath`. A scenario in which that can be useful though is in a monorepo codebase where | ||
* a common NgModule is shared across different plugins, each defined in its own package. An example can be found | ||
* below - note that the main `tsconfig.json` also maps the target module but using a path relative to the project's | ||
* root folder. The UI module is not part of the main TypeScript build task as explained in | ||
* [Extending the Admin UI](https://www.vendure.io/docs/plugins/extending-the-admin-ui/) but having `paths` | ||
* properly configured helps with usual IDE code editing features such as code completion and quick navigation, as | ||
* well as linting. | ||
* | ||
* @example | ||
* ```ts | ||
* // packages/common-ui-module/src/ui/ui-shared.module.ts | ||
* import { NgModule } from '@angular/core'; | ||
* import { SharedModule } from '@vendure/admin-ui/core'; | ||
* import { CommonUiComponent } from './components/common-ui/common-ui.component'; | ||
* | ||
* export { CommonUiComponent }; | ||
* | ||
* \@NgModule({ | ||
* imports: [SharedModule], | ||
* exports: [CommonUiComponent], | ||
* declarations: [CommonUiComponent], | ||
* }) | ||
* export class CommonSharedUiModule {} | ||
* ``` | ||
* | ||
* ```ts | ||
* // packages/common-ui-module/src/index.ts | ||
* import path from 'path'; | ||
* | ||
* import { AdminUiExtension } from '@vendure/ui-devkit/compiler'; | ||
* | ||
* export const uiExtensions: AdminUiExtension = { | ||
* pathAlias: '@common-ui-module', // this is the important part | ||
* extensionPath: path.join(__dirname, 'ui'), | ||
* ngModules: [ | ||
* { | ||
* type: 'shared' as const, | ||
* ngModuleFileName: 'ui-shared.module.ts', | ||
* ngModuleName: 'CommonSharedUiModule', | ||
* }, | ||
* ], | ||
* }; | ||
* ``` | ||
* | ||
* ```json | ||
* // tsconfig.json | ||
* { | ||
* "compilerOptions": { | ||
* "baseUrl": ".", | ||
* "paths": { | ||
* "@common-ui-module/*": ["packages/common-ui-module/src/ui/*"] | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* ```ts | ||
* // packages/sample-plugin/src/ui/ui-extension.module.ts | ||
* import { NgModule } from '@angular/core'; | ||
* import { SharedModule } from '@vendure/admin-ui/core'; | ||
* // the import below works both in the context of the custom Admin UI app as well as the main project | ||
* // '@common-ui-module' is the value of "pathAlias" and 'ui-shared.module' is the file we want to reference inside "extensionPath" | ||
* import { CommonSharedUiModule, CommonUiComponent } from '@common-ui-module/ui-shared.module'; | ||
* | ||
* \@NgModule({ | ||
* imports: [ | ||
* SharedModule, | ||
* CommonSharedUiModule, | ||
* RouterModule.forChild([ | ||
* { | ||
* path: '', | ||
* pathMatch: 'full', | ||
* component: CommonUiComponent, | ||
* }, | ||
* ]), | ||
* ], | ||
* }) | ||
* export class SampleUiExtensionModule {} | ||
* ``` | ||
*/ | ||
pathAlias?: string; | ||
} | ||
|
||
/** | ||
|
@@ -280,3 +368,7 @@ export interface BrandingOptions { | |
largeLogoPath?: string; | ||
faviconPath?: string; | ||
} | ||
|
||
export interface AdminUiExtensionWithId extends AdminUiExtension { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not very elegant but that was the only way I found to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine - it communicates the type and it's internal anyway. |
||
id: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to not break the docs, every
@
character in a code block needs to be escaped.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Is there a way to check the final docs as they appear on the website? I can see the
md
file generated after runningyarn docs:generate-typescript-docs
locally but I don't think I have the right tool to visualise it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Unfortunately not at the moment. I plan to move the doc gen stuff back into the monorepo soon when we update our website.