Skip to content

Commit

Permalink
feat: rename template as well while renaming component file
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jan 3, 2019
1 parent e65424a commit fedca70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions src/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,34 @@ export default function(
}

const componentFile = hub.filename;
const wasEntryPoint = type === "defineComponent";
const templateFile = hub.options.templateFile;
const newFile = getNewComponentPath(componentFile, templateFile, type);
const newTemplateFile = wasEntryPoint
? componentFile.replace(/\.[^.]+$/, ".marko")
: templateFile;
const newFile = getNewComponentPath(componentFile, newTemplateFile, type);

if (templateFile !== newTemplateFile) {
await helper.run("updateFilePath", {
from: templateFile,
to: newTemplateFile
});

await helper.run("updateDependentPaths", {
from: templateFile,
to: newTemplateFile
});
}

await helper.run("updateFilePath", {
from: componentFile,
to: newFile
});

if (type !== "defineComponent") {
await helper.run("updateDependentPaths", {
from: componentFile,
to: newFile
});
}
await helper.run("updateDependentPaths", {
from: componentFile,
to: wasEntryPoint ? newTemplateFile : newFile
});
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/get-new-component-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function(componentFile, templateFile, type) {
let base = templateFile.replace(EXT_REG, "");
let name = FILE_NAME_MAP[type];

if (base === "index") {
base = "";
if (base.endsWith("/index")) {
base = base.slice(0, -5);
} else {
name = `.${name}`;
}
Expand Down

0 comments on commit fedca70

Please sign in to comment.