ember-codemod-v1-to-v2
Version:
Codemod to convert Ember addons to v2 addon format
77 lines (64 loc) • 3.12 kB
JavaScript
import { Addon } from '@embroider/addon-dev/rollup';
import { babel } from '@rollup/plugin-babel';
const addon = new Addon({
srcDir: 'src',
destDir: 'dist',
});
export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
output: addon.output(),
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
// By default all your JavaScript modules (**/*.js) will be importable.
// But you are encouraged to tweak this to only cover the modules that make
// up your addon's public API. Also make sure your package.json#exports
// is aligned to the config here.
// See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
<% if (options.packages.addon.hasTypeScript) { %>addon.publicEntrypoints(['**/*.js', 'index.ts'<% if (options.packages.addon.hasGlint) {%>, 'template-registry.ts'<% } %>]),<% } else { %>addon.publicEntrypoints(['**/*.js', 'index.js']),<% } %>
// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'components/**/*.js',
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
]),
// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),
// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: 'bundled',
configFile: './babel.config.mjs',
extensions: <% if (options.packages.addon.hasTypeScript) { %>['.gjs', '.gts', '.js', '.ts']<% } else { %>['.gjs', '.js']<% } %>,
}),
// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),
// Ensure that .gjs files are properly integrated as Javascript
addon.gjs(),<% if (options.packages.addon.hasTypeScript) { %>
// Emit .d.ts declaration files
addon.declarations(
'declarations',
'pnpm ember-tsc --declaration --project tsconfig.json',
),<% } %>
// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),<% if (context.addon.hasPublicAssets) { %>
// Update public-assets field in package.json
addon.publicAssets('public/assets', {
exclude: ['**/.*'],
namespace: '<%= options.packages.addon.name %>',
}),<% } %>
// Remove leftover build artifacts when starting a new build.
addon.clean(),
],
};