UNPKG

ember-codemod-pod-to-octane

Version:
41 lines (40 loc) 1.45 kB
import { join } from 'node:path'; import { findFiles } from '@codemod-utils/files'; import { renamePodPath } from '../../../../../utils/files/index.js'; export function mapRouteRoutes(options) { const { podPath, projectRoot } = options; /* Case 1: Didn't pass the --pod flag, but configured { usePods: true } in .ember-cli */ const podDir1 = join('tests/unit', podPath); const filePaths1 = findFiles(`${podDir1}/**/route-test.{js,ts}`, { ignoreList: [join('tests/unit', podPath, '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 = join('tests/unit', podPath, '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]; }