Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for keeping public assets and ember-addon.public-assets meta in sync #1368

Merged
merged 4 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/addon-dev/src/rollup-public-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';

export default function publicAssets(
path: string,
opts: { include: string[]; exclude: string[] }
): Plugin {
const includeGlobPatterns = opts?.include;
const excludedGlobPatterns = opts?.exclude || [];

return {
name: 'public-assets-bundler',
generateBundle() {
let pkg = readJsonSync('package.json');
const filenames = walkSync(path, {
directories: false,
globs: includeGlobPatterns,
ignore: excludedGlobPatterns,
});
const publicAssets: Record<string, string> = filenames.reduce(
(acc: Record<string, string>, v): Record<string, string> => {
acc[`./${path}/${v}`] = ['/', pkg.name, '/', path, '/', v].join('');
return acc;
},
{}
);

pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], {
'public-assets': publicAssets,
});

writeJsonSync('package.json', pkg, { spaces: 2 });
},
};
}
5 changes: 5 additions & 0 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { default as appReexports } from './rollup-app-reexports';
import { default as clean } from 'rollup-plugin-delete';
import { default as keepAssets } from './rollup-keep-assets';
import { default as dependencies } from './rollup-addon-dependencies';
import { default as publicAssets } from './rollup-public-assets';
import type { Plugin } from 'rollup';

export class Addon {
Expand Down Expand Up @@ -83,4 +84,8 @@ export class Addon {
dependencies() {
return dependencies();
}

publicAssets(path: string, opts: { include: string[]; exclude: string[] }) {
return publicAssets(path, opts);
}
}