Skip to content

Commit

Permalink
refactor: more be specific stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLeedham committed Mar 4, 2021
1 parent 646e85b commit 9f834ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/cf-definitions-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,26 @@ export default class CFDefinitionsBuilder {
declaration: InterfaceDeclaration,
field: Field,
): void => {
const type = renderProp(field);
declaration.addProperty({
name: field.id,
hasQuestionToken: field.omitted || (!field.required),
type: renderProp(field),
type,
});

// eslint-disable-next-line no-warning-comments
// TODO: dynamically define imports based on usage
file.addImportDeclaration({
moduleSpecifier: 'contentful',
namespaceImport: 'Contentful',
});
if (type.includes('Contentful.')) {
file.addImportDeclaration({
moduleSpecifier: 'contentful',
namespaceImport: 'Contentful',
});
}

if (type.includes('EntryLink')) {
file.addImportDeclaration({
moduleSpecifier: '@src/types/contentful/static',
namedImports: ['EntryLink'],
});
}

file.addImportDeclaration({
moduleSpecifier: '@contentful/rich-text-types',
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/cf-render-prop-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {renderUnionType} from './render-union-type';

const linkContentType = (field: Pick<Field, 'validations'>): string => {
const validations = linkContentTypeValidations(field);
return validations?.length > 0 ? renderUnionType(validations.map(moduleName)) : 'CMSEntries';
return validations?.length > 0 ? renderUnionType(validations.map(name => `EntryLink<${moduleName(name)}>`)) : 'EntryLink';
};

export const renderPropLink = (field: Pick<Field, 'validations' | 'linkType'>) => {
Expand Down

0 comments on commit 9f834ed

Please sign in to comment.