Skip to content

Commit

Permalink
Add support for copying the public assets all at once.
Browse files Browse the repository at this point in the history
  • Loading branch information
phndiaye committed Feb 25, 2023
1 parent 565e9e5 commit 6813c5f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/addon-dev/src/rollup-public-reexports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';

export default function publicAssets(opts: { exclude: string[] }): Plugin {
return {
name: 'public-assets-bundler',
generateBundle() {
let pkg = readJsonSync('package.json');
let filenames;

filenames = walkSync('public', {
directories: false,
ignore: opts.exclude || [],
});

const publicAssets: Record<string, string> = filenames.reduce(
(acc: Record<string, string>, v): Record<string, string> => {
acc['./public/' + v] = ['/', pkg.name, '/', 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 publicReexports } from './rollup-public-reexports';
import type { Plugin } from 'rollup';

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

publicAssets(opts: { exclude: string[] }) {
return publicReexports(opts);
}
}

0 comments on commit 6813c5f

Please sign in to comment.