Skip to content

Commit 43d6225

Browse files
committed
Refactored migrator by creating skipTemplatesUsedAsPartial method
1 parent e660109 commit 43d6225

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

lib/migrator.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ module.exports = class Migrator {
5858
return templateFilePaths;
5959
}
6060

61+
skipTemplatesUsedAsPartial(templateFilePaths) {
62+
const componentsWithPartial = getPartialTemplates(this.findTemplates());
63+
64+
if (componentsWithPartial.length) {
65+
componentsWithPartial.sort().forEach(component => {
66+
console.info(`❌ Did not move '${component}' due to usage as a "partial"`);
67+
});
68+
69+
templateFilePaths = templateFilePaths.filter(templateFilePath => {
70+
// Extract '/app/templates/components/nested1/nested-component.hbs'
71+
let filePathFromApp = templateFilePath.slice(this.projectRoot.length);
72+
73+
if (/\/\-[\w\-]+\.hbs/.test(filePathFromApp)) {
74+
filePathFromApp = filePathFromApp.replace('/-', '/');
75+
}
76+
77+
// Extract '/components/nested1/nested-component.hbs'
78+
const filePathFromAppTemplates = filePathFromApp.slice('app/templates/'.length);
79+
80+
// Extract 'components/nested1/nested-component'
81+
const classFilePath = filePathFromAppTemplates.slice(1).replace('.hbs', '');
82+
83+
return !componentsWithPartial.includes(classFilePath);
84+
});
85+
}
86+
87+
return templateFilePaths;
88+
}
89+
6190
async removeEmptyClassicComponentDirectories(removeOnlyEmptyDirectories) {
6291
const templateFolderPath = path.join(this.projectRoot, 'app/templates/components');
6392

@@ -69,21 +98,9 @@ module.exports = class Migrator {
6998
let classFilePaths = this.findClassicComponentClasses();
7099

71100
templateFilePaths = this.skipTemplatesUsedAsLayoutName(templateFilePaths);
101+
templateFilePaths = this.skipTemplatesUsedAsPartial(templateFilePaths);
72102

73103

74-
let sourceTemplateFilePaths = this.findTemplates();
75-
let templatesInPartials = getPartialTemplates(sourceTemplateFilePaths);
76-
if (templatesInPartials.length) {
77-
templateFilePaths = templateFilePaths.filter(sourceTemplateFilePath => {
78-
let sourceTemplatePathInApp = sourceTemplateFilePath.slice(this.projectRoot.length); // '/app/templates/components/nested1/nested-component.hbs'
79-
if (/\/\-[\w\-]+\.hbs/.test(sourceTemplatePathInApp)) {
80-
sourceTemplatePathInApp = sourceTemplatePathInApp.replace('/-', '/');
81-
}
82-
let templatePath = sourceTemplatePathInApp.slice('app/templates/'.length); // '/nested1/nested-component.hbs'
83-
return !templatesInPartials.includes(templatePath.slice(1).replace('.hbs', ''));
84-
});
85-
}
86-
87104
templateFilePaths.forEach(sourceTemplateFilePath => {
88105
let sourceTemplatePathInApp = sourceTemplateFilePath.slice(this.projectRoot.length); // '/app/templates/components/nested1/nested-component.hbs'
89106
let templatePath = sourceTemplatePathInApp.slice('app/templates/components/'.length); // '/nested1/nested-component.hbs'
@@ -93,11 +110,6 @@ module.exports = class Migrator {
93110

94111

95112
const templatesWithLayoutName = getLayoutNameTemplates(classFilePaths);
96-
97-
templatesInPartials.sort().forEach(template => {
98-
console.info(`❌ Did not move '${template}' due to usage as a "partial"`);
99-
});
100-
101113
const removeOnlyEmptyDirectories = Boolean(templatesWithLayoutName.length);
102114
await this.removeEmptyClassicComponentDirectories(removeOnlyEmptyDirectories);
103115
}

0 commit comments

Comments
 (0)