ember-codemod-pod-to-octane
Version:
Codemod to un-pod Ember apps, addons, and engines
40 lines (39 loc) • 1.36 kB
JavaScript
import { findFiles } from '@codemod-utils/files';
import { renamePodPath } from '../../../../../utils/files/index.js';
export function mapRouteRoutes(options) {
const { projectRoot } = options;
/*
Case 1: Didn't pass the --pod flag, but configured { usePods: true } in .ember-cli
*/
const podDir1 = 'tests/unit';
const filePaths1 = findFiles(`${podDir1}/**/route-test.{js,ts}`, {
ignoreList: ['tests/unit/routes/**'],
projectRoot,
});
const filePathMap1 = filePaths1.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
podDir: podDir1,
replace: (key) => {
return `tests/unit/routes/${key}-test`;
},
});
return [oldFilePath, newFilePath];
});
/*
Case 2: Passed the --pod flag to Ember CLI
*/
const podDir2 = 'tests/unit/routes';
const filePaths2 = findFiles(`${podDir2}/**/route-test.{js,ts}`, {
projectRoot,
});
const filePathMap2 = filePaths2.map((oldFilePath) => {
const newFilePath = renamePodPath(oldFilePath, {
podDir: podDir2,
replace: (key) => {
return `tests/unit/routes/${key}-test`;
},
});
return [oldFilePath, newFilePath];
});
return [...filePathMap1, ...filePathMap2];
}