Skip to content

Commit 3dfca97

Browse files
committed
refactor: templates
1 parent c0bb699 commit 3dfca97

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/templates.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,31 @@ class Templates {
119119
);
120120
};
121121

122+
findTemplateWithExt = (path) => {
123+
const raw = this.cropExtension(path);
124+
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
125+
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
126+
};
127+
122128
getTemplateContent = (path) => {
123129
const foundTemplatePathKey = _.keys(this.config.templatePaths).find((key) => _.startsWith(path, `@${key}`));
124130

125-
const findPathWithExt = (path) => {
126-
const raw = this.cropExtension(path);
127-
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
128-
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
129-
};
130-
131131
const rawPath = resolve(
132132
_.replace(path, `@${foundTemplatePathKey}`, this.config.templatePaths[foundTemplatePathKey]),
133133
);
134-
const fixedPath = findPathWithExt(rawPath);
134+
const fixedPath = this.findTemplateWithExt(rawPath);
135135

136136
if (fixedPath) {
137137
return this.fileSystem.getFileContent(fixedPath);
138138
}
139139

140-
const customPath = findPathWithExt(resolve(this.config.templatePaths.custom, path));
140+
const customPath = this.findTemplateWithExt(resolve(this.config.templatePaths.custom, path));
141141

142142
if (customPath) {
143143
return this.fileSystem.getFileContent(customPath);
144144
}
145145

146-
const originalPath = findPathWithExt(resolve(this.config.templatePaths.original, path));
146+
const originalPath = this.findTemplateWithExt(resolve(this.config.templatePaths.original, path));
147147

148148
if (originalPath) {
149149
return this.fileSystem.getFileContent(originalPath);

0 commit comments

Comments
 (0)