ember-codemod-v1-to-v2
Version:
Codemod to convert Ember addons to v2 addon format
69 lines (68 loc) • 2.23 kB
JavaScript
import { findFiles, mapFilePaths, moveFiles, removeFiles, } from '@codemod-utils/files';
function moveAddonFolder(options) {
const { locations, projectRoot } = options;
const filePaths = findFiles('addon/**/*', {
projectRoot,
});
const filePathMap = mapFilePaths(filePaths, {
from: 'addon',
to: `${locations.addon}/src`,
});
moveFiles(filePathMap, options);
}
function moveAddonTestSupportFolder(options) {
const { locations, projectRoot } = options;
let filePaths = findFiles('addon-test-support/index.{js,ts}', {
projectRoot,
});
if (filePaths.length === 1) {
const oldPath = filePaths[0];
const newPath = `${locations.addon}/src/test-support${oldPath.endsWith('.ts') ? '.ts' : 'js'}`;
moveFiles(new Map([[oldPath, newPath]]), options);
}
filePaths = findFiles('addon-test-support/**/*', {
ignoreList: ['addon-test-support/index.{js,ts}'],
projectRoot,
});
const filePathMap = mapFilePaths(filePaths, {
from: 'addon-test-support',
to: `${locations.addon}/src/test-support`,
});
moveFiles(filePathMap, options);
}
function moveBlueprintsFolder(options) {
const { locations, projectRoot } = options;
const filePaths = findFiles('blueprints/**/*', {
projectRoot,
});
const filePathMap = mapFilePaths(filePaths, {
from: 'blueprints',
to: `${locations.addon}/blueprints`,
});
moveFiles(filePathMap, options);
}
function movePublicFolder(options) {
const { locations, projectRoot } = options;
const filePaths = findFiles('public/**/*', {
projectRoot,
});
const filePathMap = mapFilePaths(filePaths, {
from: 'public',
to: `${locations.addon}/public`,
});
moveFiles(filePathMap, options);
}
function removeAppFolder(options) {
const { projectRoot } = options;
const filePaths = findFiles('app/**/*', {
projectRoot,
});
removeFiles(filePaths, options);
}
export function moveAddonFiles(options) {
moveAddonFolder(options);
moveAddonTestSupportFolder(options);
moveBlueprintsFolder(options);
movePublicFolder(options);
removeAppFolder(options);
}