ember-codemod-v1-to-v2
Version:
Codemod to convert Ember addons to v2 addon format
39 lines (38 loc) • 1.28 kB
JavaScript
import { relative, sep } from 'node:path';
import { findFiles } from '@codemod-utils/files';
import { getLatestVersion } from '../utils/blueprints.js';
function getPublicAssets(options) {
const { packages, projectRoot } = options;
const filePaths = findFiles('public/**/*', {
projectRoot,
});
return filePaths.reduce((accumulator, filePath) => {
const from = `./${filePath.replaceAll(sep, '/')}`;
const to = `/${packages.addon.name}/${relative('public', filePath).replaceAll(sep, '/')}`;
accumulator[from] = to;
return accumulator;
}, {});
}
function hasBlueprints(options) {
const { projectRoot } = options;
const filePaths = findFiles('blueprints/**/*', {
projectRoot,
});
return filePaths.length > 0;
}
export function analyzeAddon(options) {
const publicAssets = getPublicAssets(options);
return {
addon: {
hasBlueprints: hasBlueprints(options),
hasPublicAssets: Object.keys(publicAssets).length > 0,
publicAssets,
},
projectRoot: {
devDependencies: {
concurrently: getLatestVersion('concurrently'),
pnpm: getLatestVersion('pnpm').replace('^', ''),
},
},
};
}