Skip to content

Commit

Permalink
refactor: be specific stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLeedham committed Mar 4, 2021
1 parent 6a5f436 commit 8474ef8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/cf-definitions-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ export default class CFDefinitionsBuilder {
}

private addEntryTypeAlias = (file: SourceFile, aliasName: string, entryType: string) => {
const typeIdName = moduleTypeIdName(file.getBaseNameWithoutExtension());
file.addStatements([`export const ${typeIdName} = '${aliasName}';`]);
file.addStatements([`export const typeId = '${aliasName}';`]);
file.addTypeAlias({
isExported: true,
name: moduleName(aliasName),
type: renderGenericType('CMSEntry', `typeof ${typeIdName}, ${entryType}`),
type: renderGenericType('CMSEntry', `typeof typeId, ${entryType}`),
});
};

Expand Down Expand Up @@ -226,7 +225,7 @@ export default class CFDefinitionsBuilder {
namespaceImport: 'Contentful',
});
file.addImportDeclaration({
moduleSpecifier: '@src/types/contentful/static',
moduleSpecifier: '@common/helpers/contentful/getCMSEntry',
namedImports: ['CMSEntry'],
});
}
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(moduleName)) : 'CMSEntry<string, Record<string, any>>';
};

export const renderPropLink = (field: Pick<Field, 'validations' | 'linkType'>) => {
Expand Down
7 changes: 0 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ export const moduleName = (name: string): string => {
return pipe([replaceDash, upperFirst, addPrefix, removeSpace])(name);
};

export const moduleManagementName = (name: string): string => {
const removeSpace = (input: string): string => input.replace(/\s/g, '');
const replaceDash = (input: string): string => input.replace(/-/g, '__');
const addPrefix = (input: string): string => input.endsWith('CMSManagementEntry') ? input : `${input}CMSManagementEntry`;
return pipe([replaceDash, upperFirst, addPrefix, removeSpace])(name);
};

export const moduleFieldsName = (name: string): string => moduleName(name) + 'Fields';

export const moduleTypeIdName = (name: string): string => camelCase(moduleName(name).replace(/CMSEntry$/, '')) + 'TypeId';
Expand Down

0 comments on commit 8474ef8

Please sign in to comment.