ember-codemod-remove-ember-css-modules
Version:
Codemod to replace ember-css-modules with embroider-css-modules
46 lines (45 loc) • 1.38 kB
JavaScript
import { createFiles, findFiles, mapFilePaths, moveFiles, } from '@codemod-utils/files';
function canSkip(options) {
const { projectRoot } = options;
const filePaths = findFiles('app/assets/app.css', {
projectRoot,
});
return filePaths.length === 1;
}
function moveRouteStylesheets(options) {
const { projectRoot } = options;
const filePaths = findFiles('app/styles/**/*.css', {
ignoreList: ['app/styles/app.css'],
projectRoot,
});
const pathMapping = mapFilePaths(filePaths, {
from: 'app/styles',
to: 'app/controllers',
});
moveFiles(pathMapping, options);
}
function moveAppCssToAssets(options) {
if (canSkip(options)) {
return;
}
const { projectRoot } = options;
const filePaths = findFiles('app/styles/app.css', {
projectRoot,
});
const pathMapping = mapFilePaths(filePaths, {
from: 'app/styles',
to: 'app/assets',
});
moveFiles(pathMapping, options);
const fileMap = new Map([
[
'app/styles/app.css',
'/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */\n',
],
]);
createFiles(fileMap, options);
}
export function moveStylesheets(options) {
moveRouteStylesheets(options);
moveAppCssToAssets(options);
}