ember-codemod-pod-to-octane
Version:
Codemod to un-pod Ember apps, addons, and engines
45 lines (44 loc) • 1.46 kB
JavaScript
import { findFiles, parseFilePath } from '@codemod-utils/files';
import { renamePodPath } from '../../../../../utils/files/index.js';
function getFileName(filePath) {
const { name } = parseFilePath(filePath);
return name;
}
export function mapRoutes(options) {
const { projectRoot } = options;
const podDir = 'app';
const filePathsForController = findFiles(`${podDir}/**/controller.js`, {
projectRoot,
});
const filePathsForRoute = findFiles(`${podDir}/**/route.js`, {
projectRoot,
});
const filePathsForTemplate = findFiles(`${podDir}/**/template.js`, {
ignoreList: ['app/components/**'],
projectRoot,
});
return [
...filePathsForController,
...filePathsForRoute,
...filePathsForTemplate,
].map((oldFilePath) => {
const fileName = getFileName(oldFilePath);
const newFilePath = renamePodPath(oldFilePath, {
podDir,
replace: (dir) => {
switch (fileName) {
case 'controller': {
return `app/controllers/${dir}`;
}
case 'route': {
return `app/routes/${dir}`;
}
case 'template': {
return `app/templates/${dir}`;
}
}
},
});
return [oldFilePath, newFilePath];
});
}