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 #1206

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -210,7 +210,7 @@ describe("metadata-generator", function() {
});

it("should generate proper optionsTypeParams", function() {
expect(metas.DxTestWidget.optionsTypeParams).toBe(["T1", "T2"]);
expect(metas.DxTestWidget.optionsTypeParams).toEqual(["T1", "T2"]);
});

it("should detect editors", function() {
Expand Down Expand Up @@ -294,7 +294,8 @@ describe("metadata-generator", function() {
]
}
},
Module: 'typed_widget'
Module: 'typed_widget',
Reexports: ['OnClickEvent', 'OnChangeEvent', 'default'],
},
dxWidgetWithPromise: {
Options: {
Expand Down Expand Up @@ -358,6 +359,12 @@ describe("metadata-generator", function() {
}
]);
});

it("should generate reexports", function(){
expect(metas.DxTypedWidget.reexports).toEqual([
'OnClickEvent', 'OnChangeEvent', 'default'
])
})
});

describe("complex widgets", function() {
Expand Down
16 changes: 13 additions & 3 deletions packages/devextreme-angular-generator/src/facade-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs = require('fs');
import path = require('path');
import logger from './logger';
import inflector = require('inflector-js');

export default class FacadeGenerator {
private _encoding = 'utf8';
Expand All @@ -10,17 +11,26 @@ export default class FacadeGenerator {
let facadeConfig = config.facades[facadeFilePath],
resultContent = '';

resultContent += `export * from 'devextreme-angular/core'\n`;
resultContent += `export * from './ui/all'\n`;
resultContent += `export * from 'devextreme-angular/core';\n`;
resultContent += `export * from './ui/all';\n`;
fs.readdirSync(facadeConfig.sourceDirectories[0])
.filter(fileName => fs.lstatSync(path.join(facadeConfig.sourceDirectories[0], fileName)).isFile())
.forEach(fileName => {
const { name } = path.parse(path.join(facadeConfig.sourceDirectories[0], fileName));
resultContent += `export * from 'devextreme-angular/ui/${name}'\n`;
const formattedName = formatName(name);
resultContent += `export { Dx${formattedName}Component, Dx${formattedName}Module } from 'devextreme-angular/ui/${name}';\n`;
});

logger('Write result to ' + facadeFilePath);
fs.writeFileSync(facadeFilePath, resultContent, { encoding: this._encoding });
});
}
}


function formatName(name: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-use prepareModuleName from module.facade-generator?

Copy link
Contributor Author

@Igggr Igggr Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, can't. it first merged strings, and then camilized. And here i need first camilized and then merge. Also it add Module in the end, end i need one Module and one component

if (!name.includes('-')) {
return inflector.camelize(name);
}
return name.split('-').map((n) => inflector.camelize(n)).join('');
}
15 changes: 9 additions & 6 deletions packages/devextreme-angular-generator/src/metadata-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface WidgetComponent extends ComponentMeta, Container {
isEditor: boolean;
packageName: string;
optionsTypeParams: string[];
reexports: string[];
}

interface Component extends ComponentMeta, Container {
Expand Down Expand Up @@ -242,7 +243,8 @@ export default class DXComponentMetadataGenerator {
packageName: config.wrapperPackageName,
imports: buildImports(getValues(widget.Options), config.widgetPackageName),
nestedComponents: widgetNestedComponents,
optionsTypeParams: widget.OptionsTypeParams
optionsTypeParams: widget.OptionsTypeParams,
reexports: widget.Reexports,
};

logger('Write metadata to file ' + outputFilePath);
Expand Down Expand Up @@ -327,12 +329,12 @@ export default class DXComponentMetadataGenerator {
return result;
}

private mergeArrayTypes(array1, array2) {
private mergeArrayTypes<T>(array1: T[], array2: T[]): T[] {
let newTypes = array2.filter(type => array1.indexOf(type) === -1);
return [].concat(array1, newTypes);
}

private getExternalObjectInfo(metadata: Metadata, typeName) {
private getExternalObjectInfo(metadata: Metadata, typeName: string) {
let externalObject = metadata.ExtraObjects[typeName];

if (!externalObject) {
Expand Down Expand Up @@ -492,7 +494,7 @@ export default class DXComponentMetadataGenerator {
} else {
existingComponent.properties = existingComponent.properties
.concat(...component.properties)
.reduce((properties, property) => {
.reduce((properties: Property[], property) => {
if (properties.filter(p => p.name === property.name).length === 0) {
properties.push(property);
} else {
Expand All @@ -515,7 +517,7 @@ export default class DXComponentMetadataGenerator {

existingComponent.events = existingComponent.events
.concat(...component.events)
.reduce((events, event) => {
.reduce((events: Event[], event) => {
if (events.filter(e => e.emit === event.emit).length === 0) {
events.push(event);
}
Expand All @@ -535,7 +537,8 @@ export default class DXComponentMetadataGenerator {
}, []);

normalizedMetadata.forEach(component => {
component.collectionNestedComponents = component.collectionNestedComponents.reduce((result, nestedComponent) => {
component.collectionNestedComponents = component.collectionNestedComponents
.reduce((result: NestedComponent[], nestedComponent) => {
if (result.filter(c => nestedComponent.className === c.className).length === 0) {
result.push(nestedComponent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Metadata {
[optionName: string]: Option;
};
OptionsTypeParams: string[];
Reexports: string[];
}
};
ExtraObjects: any[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ var implementedInterfaces = ['OnDestroy'];

it.isEditor && implementedInterfaces.push('ControlValueAccessor');
collectionProperties.length && implementedInterfaces.push('OnChanges', 'DoCheck');

var reexports = it.reexports?.filter(n => n !== 'default');
var reexportStr = reexports?.join(',\n ');
#>

<#? reexports?.length #>
export {
<#= reexportStr #>,
} from '<#= it.module #>';
<#?#>

import { BrowserTransferStateModule } from '@angular/platform-browser';
import { TransferState } from '@angular/platform-browser';

Expand Down