Skip to content

Commit e264611

Browse files
committed
Refactored migrator by creating changeComponentStructureToFlat method
1 parent 43d6225 commit e264611

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/migrator.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ module.exports = class Migrator {
8787
return templateFilePaths;
8888
}
8989

90+
changeComponentStructureToFlat(templateFilePaths) {
91+
templateFilePaths.forEach(templateFilePath => {
92+
// Extract '/app/templates/components/nested1/nested-component.hbs'
93+
const filePathFromApp = templateFilePath.slice(this.projectRoot.length);
94+
95+
// Extract '/nested1/nested-component.hbs'
96+
const filePathFromAppTemplatesComponents = filePathFromApp.slice('app/templates/components/'.length);
97+
98+
// '[APP_PATH]/app/components/nested1/nested-component.hbs'
99+
const newTemplateFilePath = path.join(this.projectRoot, 'app/components', filePathFromAppTemplatesComponents);
100+
moveFile(templateFilePath, newTemplateFilePath);
101+
});
102+
}
103+
90104
async removeEmptyClassicComponentDirectories(removeOnlyEmptyDirectories) {
91105
const templateFolderPath = path.join(this.projectRoot, 'app/templates/components');
92106

@@ -100,14 +114,7 @@ module.exports = class Migrator {
100114
templateFilePaths = this.skipTemplatesUsedAsLayoutName(templateFilePaths);
101115
templateFilePaths = this.skipTemplatesUsedAsPartial(templateFilePaths);
102116

103-
104-
templateFilePaths.forEach(sourceTemplateFilePath => {
105-
let sourceTemplatePathInApp = sourceTemplateFilePath.slice(this.projectRoot.length); // '/app/templates/components/nested1/nested-component.hbs'
106-
let templatePath = sourceTemplatePathInApp.slice('app/templates/components/'.length); // '/nested1/nested-component.hbs'
107-
let targetTemplateFilePath = path.join(this.projectRoot, 'app/components', templatePath); // '[APP_PATH]/app/components/nested1/nested-component.hbs'
108-
moveFile(sourceTemplateFilePath, targetTemplateFilePath);
109-
});
110-
117+
this.changeComponentStructureToFlat(templateFilePaths);
111118

112119
const templatesWithLayoutName = getLayoutNameTemplates(classFilePaths);
113120
const removeOnlyEmptyDirectories = Boolean(templatesWithLayoutName.length);

0 commit comments

Comments
 (0)