ember-codemod-remove-ember-css-modules
Version:
Codemod to replace ember-css-modules with embroider-css-modules
44 lines (43 loc) • 1.52 kB
JavaScript
import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
import { analyzeFilePaths } from '../../../../utils/steps/analyze-project/analyze-file-paths.js';
export function analyzeComponents(options) {
const { componentStructure, projectRoot } = options;
const classFilePaths = findFiles('app/components/**/*.{js,ts}', {
ignoreList: ['app/components/**/*.d.ts'],
projectRoot,
}).map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'app/components',
to: '',
});
});
const stylesheetFilePaths = findFiles('app/components/**/*.css', {
projectRoot,
}).map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'app/components',
to: '',
});
});
const templateFilePaths = findFiles('app/components/**/*.hbs', {
projectRoot,
}).map((filePath) => {
return renamePathByDirectory(filePath, {
from: 'app/components',
to: '',
});
});
const filePaths = [
...classFilePaths,
...stylesheetFilePaths,
...templateFilePaths,
].sort();
const entities = analyzeFilePaths(filePaths);
if (componentStructure === 'nested') {
return new Map(Array.from(entities.entries()).map(([entityName, extensions]) => {
const newEntityName = entityName.replace(/\/index$/, '');
return [newEntityName, extensions];
}));
}
return entities;
}