Skip to content

Commit

Permalink
Refactor angular wrappers generation: keep popupService files from cl…
Browse files Browse the repository at this point in the history
…eaning. Add to config name for generated component file
  • Loading branch information
GoodDayForSurf committed Jan 9, 2025
1 parent c7dc0e1 commit 0ee06c5
Show file tree
Hide file tree
Showing 48 changed files with 244 additions and 481 deletions.
149 changes: 74 additions & 75 deletions packages/devextreme-angular/build.config.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
module.exports = {
tools: {
metadataGenerator: {
sourceMetadataFilePath: './metadata/NGMetaData.json',
imdMetadataFilePath: './metadata/integration-data.json',
outputFolderPath: './metadata/generated',
nestedPathPart: 'nested',
basePathPart: 'base',
widgetPackageName: "devextreme",
wrapperPackageName: 'devextreme-angular',
generateReexports: true,
},
componentGenerator: {
metadataFolderPath: './metadata/generated/',
outputFolderPath: './src/ui/',
nestedPathPart: 'nested',
basePathPart: 'base'
},
facadeGenerator: {
facades: {
'./src/index.ts': {
sourceDirectories: [
'./metadata/generated'
]
}
},
commonImports: [
'./common',
'./common/grids',
'./common/charts',
]
},
moduleFacadeGenerator: {
moduleFacades: {
'./src/ui/all.ts': {
sourceComponentDirectories: [
'./src/ui'
],
additionalImports: {
'DxTemplateModule': 'import { DxTemplateModule } from \'devextreme-angular/core\''
}
}
}
},
componentNamesGenerator: {
componentFilesPath: './src/ui/',
excludedFileNames: [
'nested',
'validation-group',
'validation-summary',
'validator',
'button-group',
'drop-down-button',
'file-manager' ],
outputFileName: 'tests/src/server/component-names.ts'
},
commonReexportsGenerator: {
imdMetadataFilePath: './metadata/integration-data.json',
outputPath: './src/'
tools: {
metadataGenerator: {
sourceMetadataFilePath: './metadata/NGMetaData.json',
imdMetadataFilePath: './metadata/integration-data.json',
outputFolderPath: './metadata/generated',
nestedPathPart: 'nested',
basePathPart: 'base',
widgetPackageName: 'devextreme',
wrapperPackageName: 'devextreme-angular',
generateReexports: true,
},
componentGenerator: {
metadataFolderPath: './metadata/generated/',
outputFolderPath: './src/ui/',
entryFileNames: {
popup: 'component.ts',
},
nestedPathPart: 'nested',
basePathPart: 'base',
},
facadeGenerator: {
facades: {
'./src/index.ts': {
sourceDirectories: [
'./metadata/generated',
],
},
},
commonImports: [
'./common',
'./common/grids',
'./common/charts',
],
},
afterGenerate: {
preserveComponentFiles: ['popup/service', 'popup/index.ts'],
renameGeneratedFiles: [{ path: 'popup/index.ts', newName: 'component.ts' }],
temporaryFolderForPreserved: './tmp-preserved/'
moduleFacadeGenerator: {
moduleFacades: {
'./src/ui/all.ts': {
sourceComponentDirectories: [
'./src/ui',
],
additionalImports: {
DxTemplateModule: 'import { DxTemplateModule } from \'devextreme-angular/core\'',
},
},
},
},
components: {
srcFilesPattern: '**/*.ts',
tsTestSrc: ['tests/src/**/*.spec.ts', 'tests/src/**/component-names.ts'],
testsPath: 'tests/dist',
sourcesGlobs: ['src/**/*.*', './package.json', './ng-package.json'],
tsSourcesGlob: 'src/**/*.ts',
outputPath: 'dist'
componentNamesGenerator: {
componentFilesPath: './src/ui/',
excludedFileNames: [
'nested',
'validation-group',
'validation-summary',
'validator',
'button-group',
'drop-down-button',
'file-manager'],
outputFileName: 'tests/src/server/component-names.ts',
},
tests: {
tsConfigPath: "tsconfig.tests.json"
commonReexportsGenerator: {
imdMetadataFilePath: './metadata/integration-data.json',
outputPath: './src/',
},
npm: {
distPath: "npm/dist",
content: [ "./LICENSE", "./README.md" ]
}
},
components: {
srcFilesPattern: '**/*.ts',
tsTestSrc: ['tests/src/**/*.spec.ts', 'tests/src/**/component-names.ts'],
testsPath: 'tests/dist',
sourcesGlobs: ['src/**/*.*', './package.json', './ng-package.json'],
skipFromCleaningFiles: ['popup/service/**', 'popup/index.ts'],
tsSourcesGlob: 'src/**/*.ts',
outputPath: 'dist',
},
tests: {
tsConfigPath: 'tsconfig.tests.json',
},
npm: {
distPath: 'npm/dist',
content: ['./LICENSE', './README.md'],
},
};
72 changes: 24 additions & 48 deletions packages/devextreme-angular/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ gulp.task('generate.metadata', gulp.series('clean.metadata', (done) => {

gulp.task('clean.generatedComponents', (done) => {
const { outputFolderPath } = buildConfig.tools.componentGenerator;
del.sync([`${outputFolderPath}/**`]);
const { skipFromCleaningFiles } = buildConfig.components;

del.sync([
`${outputFolderPath}/*/**`,
...skipFromCleaningFiles.flatMap(keepPattern => {
const pathParts = keepPattern.match(/[\*\/]$/) ? keepPattern.split('/') : [keepPattern];

const patternsToKeep = pathParts.reduce((acc, pathPart) => {

if(pathPart) {
acc.path += '/' + pathPart;
acc.patterns.push(`!${acc.path}`);
}

return acc;
}, {
patterns: [],
path: outputFolderPath.replace(/\/$/,'')
}).patterns;

return patternsToKeep;
})
]);

done();
});

Expand Down Expand Up @@ -109,51 +132,6 @@ gulp.task('generate.common-reexports', (done) => {
done();
});

gulp.task('after-generate.rename-files', (done) => {
const { outputFolderPath } = buildConfig.tools.componentGenerator;
const { renameGeneratedFiles } = buildConfig.afterGenerate;
const rename = require('gulp-rename');

const actions = (renameGeneratedFiles || []).map(({ path, newName }) =>
() => gulp
.src(outputFolderPath + path)
.pipe(rename(newName))
.pipe(gulp.dest((file) => file.base))
);

gulp.parallel(...actions)(done);
});

gulp.task('after-generate.restore-preserved', (done) => {
const { outputFolderPath } = buildConfig.tools.componentGenerator;
const { preserveComponentFiles, temporaryFolderForPreserved } = buildConfig.afterGenerate;

const actions = preserveComponentFiles.map((folderOrFile) => {
let src = temporaryFolderForPreserved + folderOrFile;
let dest = outputFolderPath + folderOrFile;
const isFile = fs.statSync(src).isFile();

if (isFile) {
dest = path.dirname(dest);
} else {
src += `/**/*`;
}

return () => gulp.src(src).pipe(gulp.dest(dest));
});

gulp.parallel(...actions)(() => fs.rm(
temporaryFolderForPreserved,
{ recursive: true, force: true },
(err) => done(err)
));
});

gulp.task('after-generate', gulp.series(
'after-generate.rename-files',
'after-generate.restore-preserved',
));

gulp.task('build.license-headers', () => {
const config = buildConfig.components;
const pkg = require('./package.json');
Expand Down Expand Up @@ -264,10 +242,8 @@ const buildTask = gulp.series('build.components');
gulp.task('build', buildTask);
gulp.task('default', buildTask);
gulp.task('generate', gulp.series(
'before-generate.preserve-component-files',
'generate.facades',
'generate.common-reexports',
'after-generate',
));

// ------------Testing------------
Expand Down
7 changes: 2 additions & 5 deletions packages/devextreme-angular/src/ui/accordion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent i
return this._getOption('items');
}
set itemsChildren(value) {
this.setContentChildren('items', value, 'DxiAccordionItemComponent');
this.setChildren('items', value);
this._setChildren('items', value, 'DxiAccordionItemComponent');
}


Expand All @@ -724,9 +723,7 @@ export class DxAccordionComponent<TItem = any, TKey = any> extends DxComponent i
return this._getOption('items');
}
set itemsLegacyChildren(value) {
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
this.setChildren('items', value);
}
this._setChildren('items', value, 'DxiItemComponent');
}


Expand Down
7 changes: 2 additions & 5 deletions packages/devextreme-angular/src/ui/action-sheet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent
return this._getOption('items');
}
set itemsChildren(value) {
this.setContentChildren('items', value, 'DxiActionSheetItemComponent');
this.setChildren('items', value);
this._setChildren('items', value, 'DxiActionSheetItemComponent');
}


Expand All @@ -516,9 +515,7 @@ export class DxActionSheetComponent<TItem = any, TKey = any> extends DxComponent
return this._getOption('items');
}
set itemsLegacyChildren(value) {
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
this.setChildren('items', value);
}
this._setChildren('items', value, 'DxiItemComponent');
}


Expand Down
14 changes: 4 additions & 10 deletions packages/devextreme-angular/src/ui/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,17 +1363,15 @@ export class DxAutocompleteComponent extends DxComponent implements OnDestroy, C
return this._getOption('buttons');
}
set buttonsChildren(value) {
this.setContentChildren('buttons', value, 'DxiAutocompleteButtonComponent');
this.setChildren('buttons', value);
this._setChildren('buttons', value, 'DxiAutocompleteButtonComponent');
}

@ContentChildren(DxiAutocompleteItemComponent)
get itemsChildren(): QueryList<DxiAutocompleteItemComponent> {
return this._getOption('items');
}
set itemsChildren(value) {
this.setContentChildren('items', value, 'DxiAutocompleteItemComponent');
this.setChildren('items', value);
this._setChildren('items', value, 'DxiAutocompleteItemComponent');
}


Expand All @@ -1382,19 +1380,15 @@ export class DxAutocompleteComponent extends DxComponent implements OnDestroy, C
return this._getOption('buttons');
}
set buttonsLegacyChildren(value) {
if (this.checkContentChildren('buttons', value, 'DxiButtonComponent')) {
this.setChildren('buttons', value);
}
this._setChildren('buttons', value, 'DxiButtonComponent');
}

@ContentChildren(DxiItemComponent)
get itemsLegacyChildren(): QueryList<DxiItemComponent> {
return this._getOption('items');
}
set itemsLegacyChildren(value) {
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
this.setChildren('items', value);
}
this._setChildren('items', value, 'DxiItemComponent');
}


Expand Down
7 changes: 2 additions & 5 deletions packages/devextreme-angular/src/ui/box/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ export class DxBoxComponent<TItem = any, TKey = any> extends DxComponent impleme
return this._getOption('items');
}
set itemsChildren(value) {
this.setContentChildren('items', value, 'DxiBoxItemComponent');
this.setChildren('items', value);
this._setChildren('items', value, 'DxiBoxItemComponent');
}


Expand All @@ -429,9 +428,7 @@ export class DxBoxComponent<TItem = any, TKey = any> extends DxComponent impleme
return this._getOption('items');
}
set itemsLegacyChildren(value) {
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
this.setChildren('items', value);
}
this._setChildren('items', value, 'DxiItemComponent');
}


Expand Down
7 changes: 2 additions & 5 deletions packages/devextreme-angular/src/ui/button-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ export class DxButtonGroupComponent extends DxComponent implements OnDestroy, On
return this._getOption('items');
}
set itemsChildren(value) {
this.setContentChildren('items', value, 'DxiButtonGroupItemComponent');
this.setChildren('items', value);
this._setChildren('items', value, 'DxiButtonGroupItemComponent');
}


Expand All @@ -509,9 +508,7 @@ export class DxButtonGroupComponent extends DxComponent implements OnDestroy, On
return this._getOption('items');
}
set itemsLegacyChildren(value) {
if (this.checkContentChildren('items', value, 'DxiItemComponent')) {
this.setChildren('items', value);
}
this._setChildren('items', value, 'DxiItemComponent');
}


Expand Down
Loading

0 comments on commit 0ee06c5

Please sign in to comment.