Skip to content
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

Add reexports #613

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import generate from './component-generator';
it('generates', () => {
// #region EXPECTED
const EXPECTED = `
export {
ReexportedMember,
OtherReexportedMember,
} from "DX/WIDGET/PATH";
import dxCLASS_NAME, {
Properties
} from "DX/WIDGET/PATH";
Expand Down Expand Up @@ -34,13 +38,18 @@ export {
baseComponentPath: 'BASE_COMPONENT_PATH',
extensionComponentPath: 'EXTENSION_COMPONENT_PATH',
dxExportPath: 'DX/WIDGET/PATH',
reexports: ['ReexportedMember', 'OtherReexportedMember'],
}),
).toBe(EXPECTED);
});

it('generates extension component', () => {
// #region EXPECTED
const EXPECTED = `
export {
ReexportedMember,
OtherReexportedMember,
} from "DX/WIDGET/PATH";
import dxCLASS_NAME, {
Properties as ICLASS_NAMEOptions
} from "DX/WIDGET/PATH";
Expand Down Expand Up @@ -70,6 +79,7 @@ export {
extensionComponentPath: 'EXTENSION_COMPONENT_PATH',
dxExportPath: 'DX/WIDGET/PATH',
isExtension: true,
reexports: ['ReexportedMember', 'OtherReexportedMember', 'default'],
}),
).toBe(EXPECTED);
});
Expand Down
17 changes: 16 additions & 1 deletion packages/devextreme-react-generator/src/component-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type IComponent = {
templates?: string[];
propTypings?: IPropTyping[];
optionsTypeParams?: string[];
reexports?: string[];
} & {
nestedComponents?: INestedComponent[];
configComponentPath?: string;
Expand Down Expand Up @@ -173,8 +174,13 @@ const renderModule: (model: {
renderedNestedComponents?: string[];
defaultExport: string;
renderedExports: string;
renderedReexports?: string;
}) => string = createTempate(
'<#= it.renderedImports #>\n'
'<#? it.renderedReexports #>'
+ '<#= it.renderedReexports #>'
+ '<#?#>'

+ '<#= it.renderedImports #>\n'

+ '<#? it.renderedOptionsInterface #>'
+ '<#= it.renderedOptionsInterface #>\n\n'
Expand Down Expand Up @@ -546,6 +552,14 @@ function generate(component: IComponent): string {
.map((t) => renderPropTyping(createPropTypingModel(t)))
: undefined;

const reexports = component.reexports
?.filter((name) => name !== 'default')
?.filter((name) => name);
Igggr marked this conversation as resolved.
Show resolved Hide resolved

const renderedReexports = reexports?.length
Igggr marked this conversation as resolved.
Show resolved Hide resolved
? `export {\n ${reexports.join(',\n ')},\n} from "${component.dxExportPath}";\n`
: undefined;

return renderModule({

renderedImports: renderImports({
Expand Down Expand Up @@ -595,6 +609,7 @@ function generate(component: IComponent): string {

defaultExport: component.name,
renderedExports: renderExports(exportNames),
renderedReexports,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/devextreme-react-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export function mapWidget(
expectedChildren: raw.nesteds,
propTypings: propTypings.length > 0 ? propTypings : undefined,
optionsTypeParams: raw.optionsTypeParams,
reexports: raw.reexports,
},
};
}
Expand Down