UNPKG

ember-codemod-pod-to-octane

Version:
40 lines (39 loc) 1.39 kB
import { findFiles } from '@codemod-utils/files'; import { renamePodPath } from '../../../../../utils/files/index.js'; export function mapRouteControllers(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}/**/controller-test.{js,ts}`, { ignoreList: ['tests/unit/controllers/**'], projectRoot, }); const filePathMap1 = filePaths1.map((oldFilePath) => { const newFilePath = renamePodPath(oldFilePath, { podDir: podDir1, replace: (key) => { return `tests/unit/controllers/${key}-test`; }, }); return [oldFilePath, newFilePath]; }); /* Case 2: Passed the --pod flag to Ember CLI */ const podDir2 = 'tests/unit/controllers'; const filePaths2 = findFiles(`${podDir2}/**/controller-test.{js,ts}`, { projectRoot, }); const filePathMap2 = filePaths2.map((oldFilePath) => { const newFilePath = renamePodPath(oldFilePath, { podDir: podDir2, replace: (key) => { return `tests/unit/controllers/${key}-test`; }, }); return [oldFilePath, newFilePath]; }); return [...filePathMap1, ...filePathMap2]; }